📄 bigraphdiagnose.h
字号:
// perform the same test using the new[] and delete [] operators // for (long j = 1; j <= 100; j++) { // allocate a large number of nodes // BiGraph<TObject>* self_graphs = new BiGraph<TObject>[j * 50]; BiGraph<TObject>* graphs = new BiGraph<TObject>[j * 50](USER); // clean up memory // delete [] self_graphs; delete [] graphs; } } // test assign method in SYSTEM-allocation mode // BiGraph<Char> assn_graph_0; // create an arc from the first to a common node // Char* char1 = new Char('k'); assn_graph_0.insertArc(assn_graph_0.getStart(), assn_graph_0.insertVertex(char1), false, 0.75); BiGraphVertex<Char>* tmp_vertex; if ((tmp_vertex = (BiGraphVertex<Char>*)assn_graph_0.getFirst()) == (BiGraphVertex<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); BiGraph<Char> assn_graph_1; 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 = (BiGraphArc<Char>*)NULL; if ((cstr_arc = assn_graph_1.getStart()->getFirstChild()) == (BiGraphArc<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()->getFirstChild()) == (BiGraphArc<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__); } // the assigned graph should also have an arc from the char1 node to the // start with a weight of 0.75 and an arc from the term to the char1 // node with a weight of -0.75 // cstr_arc = (BiGraphArc<Char>*)NULL; if ((cstr_arc = assn_graph_1.getTerm()->getFirstParent()) == (BiGraphArc<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()->getFirstParent()) == (BiGraphArc<Char>*)NULL) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex() != assn_graph_1.getStart()) || cstr_arc->getEpsilon() || !Integral::almostEqual((double)cstr_arc->getWeight(), 0.75)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // test the assign from a DiGraph // DiGraph<Char> digraph_0; // create an arc from the first to a common node // Char* char_a = new Char('a'); Char* char_b = new Char('b'); GraphVertex<Char>* vertex_a = digraph_0.insertVertex(char_a); GraphVertex<Char>* vertex_b = digraph_0.insertVertex(char_b); digraph_0.insertArc(digraph_0.getStart(), vertex_a, false, 1.0); digraph_0.insertArc(vertex_a, vertex_a, false, 0.5); digraph_0.insertArc(vertex_a, vertex_b, false, 0.5); digraph_0.insertArc(vertex_b, digraph_0.getTerm(), false, 1.0); // assign it to the BiGraph // BiGraph<Char> bigraph_0; bigraph_0.assign(digraph_0); // get the term vertex // BiGraphVertex<Char>* temp_vertex = bigraph_0.getTerm(); // check for TREM -> 'b' // temp_vertex->gotoFirstParent(); BiGraphArc<Char>* temp_arc = temp_vertex->getCurrParent(); if (temp_arc->getVertex()->getItem()->ne(*char_b)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // check for 'b' -> 'a' // temp_vertex = temp_arc->getVertex(); temp_vertex->gotoFirstParent(); temp_arc = temp_vertex->getCurrParent(); if (temp_arc->getVertex()->getItem()->ne(*char_a)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // check for 'a' -> start and 'a' -> 'a' // temp_vertex = temp_arc->getVertex(); temp_vertex->gotoFirstParent(); temp_arc = temp_vertex->getCurrParent(); if (temp_arc->getVertex() != bigraph_0.getStart()) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } temp_vertex->gotoNextParent(); temp_arc = temp_vertex->getCurrParent(); if (temp_arc->getVertex()->getItem()->ne(*char_a)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete char1; delete char_a; delete char_b; { // test assign method in USER-allocation mode // BiGraph<Char> assn_graph_0(USER); // create an arc from the first to a common node // Char* char1 = new Char('k'); assn_graph_0.insertArc(assn_graph_0.getStart(), assn_graph_0.insertVertex(char1), false, 0.75); BiGraphVertex<Char>* tmp_vertex; if ((tmp_vertex = (BiGraphVertex<Char>*)assn_graph_0.getFirst()) == (BiGraphVertex<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); BiGraph<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 = (BiGraphArc<Char>*)NULL; if ((cstr_arc = assn_graph_1.getStart()->getFirstChild()) == (BiGraphArc<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()->getFirstChild()) == (BiGraphArc<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__); } // the assigned graph should also have an arc from the char1 node to the // start with a weight of 0.75 and an arc from the term to the char1 // node with a weight of -0.75 // cstr_arc = (BiGraphArc<Char>*)NULL; if ((cstr_arc = assn_graph_1.getTerm()->getFirstParent()) == (BiGraphArc<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()->getFirstParent()) == (BiGraphArc<Char>*)NULL) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } if ((cstr_arc->getVertex() != assn_graph_1.getStart()) || cstr_arc->getEpsilon() || !Integral::almostEqual((double)cstr_arc->getWeight(), 0.75)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // test the assign from a DiGraph // DiGraph<Char> digraph_0(USER); // create an arc from the first to a common node // Char* char_a = new Char('a'); Char* char_b = new Char('b'); GraphVertex<Char>* vertex_a = digraph_0.insertVertex(char_a); GraphVertex<Char>* vertex_b = digraph_0.insertVertex(char_b); digraph_0.insertArc(digraph_0.getStart(), vertex_a, false, 1.0); digraph_0.insertArc(vertex_a, vertex_a, false, 0.5); digraph_0.insertArc(vertex_a, vertex_b, false, 0.5); digraph_0.insertArc(vertex_b, digraph_0.getTerm(), false, 1.0); // assign it to the BiGraph // BiGraph<Char> bigraph_0(USER); bigraph_0.assign(digraph_0); // get the term vertex // BiGraphVertex<Char>* temp_vertex = bigraph_0.getTerm(); // check for TREM -> 'b' // temp_vertex->gotoFirstParent(); BiGraphArc<Char>* temp_arc = temp_vertex->getCurrParent(); if (temp_arc->getVertex()->getItem()->ne(*char_b)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // check for 'b' -> 'a' // temp_vertex = temp_arc->getVertex(); temp_vertex->gotoFirstParent(); temp_arc = temp_vertex->getCurrParent(); if (temp_arc->getVertex()->getItem()->ne(*char_a)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // check for 'a' -> start and 'a' -> 'a' // temp_vertex = temp_arc->getVertex(); temp_vertex->gotoFirstParent(); temp_arc = temp_vertex->getCurrParent(); if (temp_arc->getVertex() != bigraph_0.getStart()) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } temp_vertex->gotoNextParent(); temp_arc = temp_vertex->getCurrParent(); if (temp_arc->getVertex()->getItem()->ne(*char_a)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // clean up memory // delete char1; delete char_a; delete char_b; } // 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 // // 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 // DoubleLinkedList<TopoTriple> arcs; Float float_00(0.0); Boolean bool_00(true); Pair<Long, Long> pair_00(BiGraph<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, BiGraph<Char>::TERM_INDEX); triple = new TopoTriple(pair_04, float_04, bool_04); arcs.insert(triple); delete triple; // create the list of data elements // DoubleLinkedList<Char> dlist; dlist.insert(a); dlist.insert(b); // create the graph using the lists // BiGraph<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()->getFirstChild()->getVertex()->getItem()->eq(*a)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // the 'a' vertex should have an epsilon transition to start // BiGraphVertex<Char>* ver_test = assgn_graph.getStart()->getFirstChild()->getVertex(); if (ver_test->getFirstParent()->getVertex() != assgn_graph.getStart()) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // 'a' should have a transition to 'b' and itself // assgn_graph.gotoFirst(); BiGraphVertex<Char>* ver_00 = (BiGraphVertex<Char>*)assgn_graph.getCurr(); ver_00->gotoFirstChild(); BiGraphArc<Char>* arc_00 = ver_00->getCurrChild(); if (!arc_00->getVertex()->getItem()->eq(*a)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } BiGraphArc<Char>* arc_01 = ver_00->getNextChild(); if (!arc_01->getVertex()->getItem()->eq(*b)) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); } // 'a' should have transition to start and itself // ver_00->gotoFirstParent(); arc_00 = ver_00->getCurrParent(); if (arc_00->getVertex() != assgn_graph.getStart()) { return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -