⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 digraphdiagnose.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
📖 第 1 页 / 共 5 页
字号:
    if ((tmp_vertex = (GraphVertex<Char>*)assn_graph_0.getFirst()) ==	(GraphVertex<Char>*)NULL) {      return Error::handle(name(), L"insertArc", Error::TEST, __FILE__,			   __LINE__);    }    assn_graph_0.insertArc(tmp_vertex, assn_graph_0.getTerm(),			   false, -0.75);        DiGraph<Char> assn_graph_1(USER);    assn_graph_1.assign(assn_graph_0);        // the assigned graph should now have an arc from its start node to the    // char1 with a weight of 0.75 and an arc from the char1 to the terminal    // node with a weight of -0.75    //    cstr_arc = (GraphArc<Char>*)NULL;        if ((cstr_arc = assn_graph_1.getStart()->getFirst())	== (GraphArc<Char>*)NULL) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__,			   __LINE__);    }        if ((cstr_arc->getVertex()->getItem()->ne(*char1)) ||	cstr_arc->getEpsilon() ||	!Integral::almostEqual((double)cstr_arc->getWeight(), 0.75)) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__,			   __LINE__);    }        if ((cstr_arc = cstr_arc->getVertex()->getFirst())	== (GraphArc<Char>*)NULL) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__,			 __LINE__);    }    if ((cstr_arc->getVertex() != assn_graph_1.getTerm()) ||	cstr_arc->getEpsilon() ||	!Integral::almostEqual((double)cstr_arc->getWeight(), -0.75)) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__,			   __LINE__);    }    // clean up memory    //    delete char1;      }  // test the assign method in SYSTEM mode  //    // -------------------------------------------------  // START -(epi) -> a  // a     -(0.1) -> a  // a     -(0.5) -> b  // b     -(0.7) -> b  // b     -(epi) -> TERM   // -------------------------------------------------  // create the graph items  //  Char* a = new Char('a');  Char* b = new Char('b');  TopoTriple* triple;    // create the list of arcs  //  SingleLinkedList<TopoTriple> arcs;	  Float float_00(0.0);  Boolean bool_00(true);  Pair<Long, Long> pair_00(DiGraph<Char>::START_INDEX, 0);  triple = new TopoTriple(pair_00, float_00, bool_00);  arcs.insert(triple);  delete triple;  Float float_01(0.1);  Boolean bool_01(false);  Pair<Long, Long> pair_01(0, 0);  triple = new TopoTriple(pair_01, float_01, bool_01);  arcs.insert(triple);  delete triple;  Float float_02(0.5);  Boolean bool_02(false);  Pair<Long, Long> pair_02(0, 1);  triple = new TopoTriple(pair_02, float_02, bool_02);  arcs.insert(triple);  delete triple;  Float float_03(0.7);  Boolean bool_03(false);  Pair<Long, Long> pair_03(1, 1);  triple = new TopoTriple(pair_03, float_03, bool_03);  arcs.insert(triple);  delete triple;  Float float_04(0.0);  Boolean bool_04(true);  Pair<Long, Long> pair_04(1, DiGraph<Char>::TERM_INDEX);  triple = new TopoTriple(pair_04, float_04, bool_04);  arcs.insert(triple);  delete triple;    // create the list of data elements  //  SingleLinkedList<Char> dlist;  dlist.insert(a);  dlist.insert(b);      // create the graph using the lists  //  DiGraph<Char> assgn_graph;  assgn_graph.assign(dlist, arcs);  // the graph should contain 'a' and 'b'  //  if (!assgn_graph.contains(a)) {    return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);  }  if (!assgn_graph.contains(b)) {    return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);  }    // the start vertex should have an epsilon transition to 'a'  //  assgn_graph.gotoFirst();  if (!assgn_graph.getStart()->getFirst()->getVertex()->getItem()->eq(*a)) {    return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);  }  // 'a' should have a transition to 'b' and itself  //  assgn_graph.gotoFirst();  GraphVertex<Char>* ver_00 = (GraphVertex<Char>*)assgn_graph.getCurr();  ver_00->gotoFirst();  GraphArc<Char>* arc_00 = ver_00->getCurr();  if (!arc_00->getVertex()->getItem()->eq(*a)) {    return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);  }  GraphArc<Char>* arc_01 = ver_00->getNext();  if (!arc_01->getVertex()->getItem()->eq(*b)) {    return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);  }    // 'b' should have an epsilon transition to the term vertex and itself  //  assgn_graph.gotoNext();  GraphVertex<Char>* ver_01 = (GraphVertex<Char>*)assgn_graph.getCurr();  ver_01->gotoFirst();  GraphArc<Char>* arc_02 = ver_01->getCurr();  if (!arc_02->getVertex()->getItem()->eq(*b)) {    return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);  }  GraphArc<Char>* arc_03 = ver_01->getNext();  if (arc_03->getVertex() != assgn_graph.getTerm()) {    return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);  }  // clean up  //  delete a;  delete b;  arcs.clear(Integral::FREE);  dlist.clear(Integral::FREE);  assgn_graph.clear(Integral::FREE);  {    // -------------------------------------------------    // START -(epi) -> a    // a     -(0.1) -> a    // a     -(0.5) -> b    // b     -(0.7) -> b    // b     -(epi) -> TERM     // -------------------------------------------------        // create the graph items    //    Char* a = new Char('a');    Char* b = new Char('b');    TopoTriple* triple;      // create the list of arcs    //    SingleLinkedList<TopoTriple> arcs;        Float float_00(0.0);    Boolean bool_00(true);    Pair<Long, Long> pair_00(DiGraph<Char>::START_INDEX, 0);    triple = new TopoTriple(pair_00, float_00, bool_00);    arcs.insert(triple);    delete triple;        Float float_01(0.1);    Boolean bool_01(false);    Pair<Long, Long> pair_01(0, 0);    triple = new TopoTriple(pair_01, float_01, bool_01);    arcs.insert(triple);    delete triple;        Float float_02(0.5);    Boolean bool_02(false);    Pair<Long, Long> pair_02(0, 1);    triple = new TopoTriple(pair_02, float_02, bool_02);    arcs.insert(triple);    delete triple;        Float float_03(0.7);    Boolean bool_03(false);    Pair<Long, Long> pair_03(1, 1);    triple = new TopoTriple(pair_03, float_03, bool_03);    arcs.insert(triple);    delete triple;        Float float_04(0.0);    Boolean bool_04(true);    Pair<Long, Long> pair_04(1, DiGraph<Char>::TERM_INDEX);    triple = new TopoTriple(pair_04, float_04, bool_04);    arcs.insert(triple);    delete triple;        // create the list of data elements    //    SingleLinkedList<Char> dlist;    dlist.insert(a);    dlist.insert(b);          // create the graph using the lists    //    DiGraph<Char> assgn_graph(USER);    assgn_graph.assign(dlist, arcs);        // the graph should contain 'a' and 'b'    //    if (!assgn_graph.contains(a)) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);    }    if (!assgn_graph.contains(b)) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);    }          // the start vertex should have an epsilon transition to 'a'    //    assgn_graph.gotoFirst();    if (!assgn_graph.getStart()->getFirst()->getVertex()->getItem()->eq(*a)) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);    }        // 'a' should have a transition to 'b' and itself    //    assgn_graph.gotoFirst();    GraphVertex<Char>* ver_00 = (GraphVertex<Char>*)assgn_graph.getCurr();    ver_00->gotoFirst();    GraphArc<Char>* arc_00 = ver_00->getCurr();    if (!arc_00->getVertex()->getItem()->eq(*a)) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);    }    GraphArc<Char>* arc_01 = ver_00->getNext();    if (!arc_01->getVertex()->getItem()->eq(*b)) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);    }          // 'b' should have an epsilon transition to the term vertex and itself    //    assgn_graph.gotoNext();    GraphVertex<Char>* ver_01 = (GraphVertex<Char>*)assgn_graph.getCurr();    ver_01->gotoFirst();    GraphArc<Char>* arc_02 = ver_01->getCurr();    if (!arc_02->getVertex()->getItem()->eq(*b)) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);    }    GraphArc<Char>* arc_03 = ver_01->getNext();    if (arc_03->getVertex() != assgn_graph.getTerm()) {      return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);    }        // clean up    //    delete a;    delete b;        arcs.clear(Integral::FREE);  }  // testing i/o methods in SYSTEM mode  //  // -------------------------------------------------  // START    -> a   //          -> b  //          -> c  // a        -> d  // a        -> f    // b        -> d  // c        -> g    // c        -> d  // d        -> e  // e        -> f  // e        -> g          // f        -> TERM  // g        -> TERM     // -------------------------------------------------    DiGraph<Char> write_graph;  write_graph.insertArc(write_graph.getStart(), write_graph.getTerm(), true);    Char* chr = new Char(L'a');  GraphVertex<Char>* ptr_a = write_graph.insertVertex(chr);  write_graph.insertArc(write_graph.getStart(), ptr_a, true);  delete chr;    chr = new Char(L'b');  GraphVertex<Char>* ptr_b = write_graph.insertVertex(chr);  write_graph.insertArc(write_graph.getStart(), ptr_b, true);  delete chr;    chr = new Char(L'c');  GraphVertex<Char>* ptr_c = write_graph.insertVertex(chr);  write_graph.insertArc(write_graph.getStart(), ptr_c, true);  delete chr;    chr = new Char(L'd');  GraphVertex<Char>* ptr_d = write_graph.insertVertex(chr);  delete chr;    write_graph.insertArc(ptr_a, ptr_d, false, (float)0.7);  write_graph.insertArc(ptr_b, ptr_d, false, (float)0.9);  write_graph.insertArc(ptr_c, ptr_d, false, (float)3.7);  chr = new Char(L'e');  GraphVertex<Char>* ptr_e = write_graph.insertVertex(chr);  write_graph.insertArc(ptr_d, ptr_e, false, (float)1.2);  delete chr;    chr = new Char(L'f');  GraphVertex<Char>* ptr_f = write_graph.insertVertex(chr);  write_graph.insertArc(ptr_a, ptr_f, false, (float)0.8);  write_graph.insertArc(ptr_e, ptr_f, false, (float)6.1);  delete chr;    chr = new Char(L'g');  GraphVertex<Char>* ptr_g = write_graph.insertVertex(chr);   delete chr;    write_graph.insertArc(ptr_c, ptr_g, false, (float)3.1);  write_graph.insertArc(ptr_e, ptr_g, false, (float)1.7);  write_graph.insertArc(ptr_f, write_graph.getTerm(), true);  write_graph.insertArc(ptr_g, write_graph.getTerm(), true);  Filename file_text_00;  Filename file_bin_00;    Integral::makeTemp(file_text_00);  Integral::makeTemp(file_bin_00);  File::registerTemp(file_text_00);  File::registerTemp(file_bin_00);    Sof out_text_00;  Sof out_bin_00;    out_text_00.open(file_text_00, File::WRITE_ONLY, File::TEXT);  out_bin_00.open(file_bin_00, File::WRITE_ONLY, File::BINARY);  write_graph.write(out_text_00, 0);  write_graph.write(out_bin_00, 0);  out_text_00.close();  out_bin_00.close();    Sof in_text_00;  Sof in_bin_00;  DiGraph<Char> read_graph_text_00;  DiGraph<Char> read_graph_bin_00;    in_text_00.open(file_text_00, File::READ_PLUS);  in_bin_00.open(file_bin_00, File::READ_PLUS);    read_graph_text_00.read(in_text_00, 0);  read_graph_bin_00.read(in_bin_00, 0);  in_text_00.close();  in_bin_00.close();    Filename file_text_01;  Filename file_bin_01;  Integral::makeTemp(file_text_01);  Integral::makeTemp(file_bin_01);  File::registerTemp(file_text_01);  File::registerTemp(file_bin_01);     Sof out_text_01;  Sof out_bin_01;  out_text_01.open(file_text_01, File::WRITE_ONLY, File::TEXT);  out_bin_01.open(file_bin_01, File::WRITE_ONLY, File::BINARY);      read_graph_text_00.write(out_text_01, 0);  read_graph_bin_00.write(out_bin_01, 0);  out_text_01.close();  out_bin_01.close();    // test to see if the graphs are equal  //  if (!write_graph.eq(read_graph_text_00)) {    return Error::handle(name(), L"i/o", Error::TEST,			 __FILE__, __LINE__);  }  if (!write_graph.eq(read_graph_bin_00)) {    return Error::handle(name(), L"i/o", Error::TEST,			 __FILE__, __LINE__);  }  Sof in_text_01;  Sof in_bin_01;  DiGraph<Char> read_graph_text_01;  DiGraph<Char> read_graph_bin_01;    in_text_01.open(file_text_01, File::READ_PLUS);  in_bin_01.open(file_bin_01, File::READ_PLUS);    read_graph_text_01.read(in_text_01, 0);  read_graph_bin_01.read(in_bin_01, 0);    // close file descriptors  //  in_text_01.close();  in_bin_01.close();  // test to see if the graphs are equal  //  if (!write_graph.eq(read_graph_text_01)) {    return Error::handle(name(), L"i/o", Error::TEST,			 __FILE__, __LINE__);  }  if (!write_graph.eq(read_graph_bin_01)) {    return Error::handle(name(), L"i/o", Error::TEST,			 __FILE__, __LINE__);  }    // clean up allocated memory  //  write_graph.clear(Integral::FREE);  read_graph_text_00.clear(Integral::FREE);  read_graph_bin_00.clear(Integral::FREE);  read_graph_text_01.clear(Integral::FREE);  read_graph_bin_01.clear(Integral::FREE);    // read in two graph text files with different indeces for the vertices  // but the same structure and compare them for equality in SYSTEM-allocation  //  DiGraph<Char> read_graph_utext_00;  DiGraph<Char> read_graph_utext_01;  DiGraph<Char> read_graph_utext_02;  DiGraph<Char> read_graph_utext_03;    Sof in_utext_00;    String file_utext_00(L"graph.sof");  in_utext_00.open(file_utext_00);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -