marci@915: #include marci@1009: #include marci@915: alpar@921: #include alpar@921: #include marci@1009: #include marci@915: #include marci@915: marci@1008: #include marci@1008: #include marci@1008: marci@915: using std::cout; marci@915: using std::endl; marci@915: alpar@921: using namespace lemon; marci@1008: using namespace lemon::concept; marci@915: marci@1007: class Graph3 : ListGraph { marci@1007: public: marci@1007: class Node : public ListGraph::Node { }; marci@1007: class Edge { }; marci@1007: }; marci@1007: marci@915: int main() { marci@917: typedef SmartGraph Graph1; marci@917: typedef ListGraph Graph2; marci@1008: marci@1008: { marci@1009: checkConcept >(); marci@1009: } marci@1009: { marci@1009: checkConcept >(); marci@1009: } marci@1009: marci@917: Graph1 g; marci@917: Graph2 h; marci@1009: typedef MergeEdgeGraphWrapper GW; marci@915: GW gw(g, h); marci@1009: marci@1009: std::ifstream f1("graph1.dim"); marci@1009: std::ifstream f2("graph2.dim"); marci@1009: readDimacs(f1, g); marci@1009: readDimacs(f2, h); marci@1009: { marci@1009: marci@1009: // Graph1::Node n1=g.addNode(); marci@1009: // Graph1::Node n2=g.addNode(); marci@1009: // Graph1::Node n3=g.addNode(); marci@1009: // Graph2::Node n4=h.addNode(); marci@1009: // Graph2::Node n5=h.addNode(); marci@1009: // Graph2::Node n6=h.addNode(); marci@1009: // Graph1::Edge e1=g.addEdge(n1, n2); marci@1009: // Graph1::Edge e2=g.addEdge(n1, n3); marci@1009: // Graph2::Edge e3=h.addEdge(n4, n5); marci@1009: // Graph2::Edge e4=h.addEdge(n4, n5); marci@915: //GW::NodeIt n(gw) marci@1009: cout << "1st graph" << endl; marci@1009: cout << " nodes:" << endl; marci@1009: for (Graph1::NodeIt n(g); n!=INVALID; ++n) { marci@1009: cout << " " << g.id(n) << endl; marci@1009: } marci@1009: cout << " edges:" << endl; marci@1009: for (Graph1::EdgeIt n(g); n!=INVALID; ++n) { marci@1009: cout << " " << g.id(n) << ": " marci@1009: << g.id(g.source(n)) << "->" << g.id(g.target(n)) << endl; marci@1009: } marci@1009: cout << "2nd graph" << endl; marci@1009: cout << " nodes:" << endl; marci@1009: for (Graph2::NodeIt n(h); n!=INVALID; ++n) { marci@1009: cout << " " << h.id(n) << endl; marci@1009: } marci@1009: cout << " edges:" << endl; marci@1009: for (Graph2::EdgeIt n(h); n!=INVALID; ++n) { marci@1009: cout << " " << h.id(n) << ": " marci@1009: << h.id(h.source(n)) << "->" << h.id(h.target(n)) << endl; marci@1009: } marci@1009: cout << "merged graph" << endl; marci@1009: cout << " nodes:" << endl; marci@915: for (GW::NodeIt n(gw); n!=INVALID; ++n) { marci@1009: cout << " "<< gw.id(n) << endl; marci@1009: } marci@1009: cout << " edges:" << endl; marci@1009: for (GW::EdgeIt n(gw); n!=INVALID; ++n) { marci@1009: cout << " " << gw.id(n) << ": " marci@1009: << gw.id(gw.source(n)) << "->" << gw.id(gw.target(n)) << endl; marci@915: } marci@917: marci@917: GW::NodeMap nm(gw); marci@917: int i=0; marci@917: for (GW::NodeIt n(gw); n!=INVALID; ++n) { marci@917: ++i; marci@917: nm.set(n, i); marci@917: } marci@917: for (Graph1::NodeIt n(g); n!=INVALID; ++n) { marci@1009: cout << nm[GW::Node(n,INVALID,false)] << endl; marci@917: } marci@917: for (Graph2::NodeIt n(h); n!=INVALID; ++n) { marci@1009: cout << nm[GW::Node(INVALID,n,true)] << endl; marci@917: } marci@1007: marci@1009: gw.printNode(); marci@1007: marci@1007: { marci@1007: // typedef SmartGraph Graph1; marci@1007: typedef ListGraph Graph1; marci@1007: typedef ListGraph Graph2; marci@1007: Graph1 g; marci@1007: Graph2 h; marci@1007: typedef MergeNodeGraphWrapper GW; marci@1007: GW gw(g, h); marci@1009: gw.printNode(); marci@1007: } marci@1007: { marci@1007: // typedef SmartGraph Graph1; marci@1007: typedef Graph3 Graph1; marci@1007: typedef ListGraph Graph2; marci@1007: Graph1 g; marci@1007: Graph2 h; marci@1007: typedef MergeNodeGraphWrapper GW; marci@1007: GW gw(g, h); marci@1009: gw.printNode(); marci@1007: } marci@1007: { marci@1007: // typedef SmartGraph Graph1; marci@1007: typedef ListGraph Graph1; marci@1007: typedef Graph3 Graph2; marci@1007: Graph1 g; marci@1007: Graph2 h; marci@1007: typedef MergeNodeGraphWrapper GW; marci@1007: GW gw(g, h); marci@1009: gw.printNode(); marci@1007: } marci@1008: } marci@1008: { marci@1008: Graph1 g; marci@1008: Graph2 h; marci@1008: typedef Graph1::Node Node1; marci@1008: typedef Graph2::Node Node2; marci@1008: typedef NewEdgeSetGraphWrapper GW; marci@1008: Graph1::NodeMap e_node(g); marci@1008: Graph2::NodeMap n_node(h); marci@1008: GW gw(g, h, e_node, n_node); marci@1008: for (int i=0; i<4; ++i) { marci@1008: Node1 n=g.addNode(); marci@1008: e_node.set(n, INVALID); marci@1008: } marci@1008: for (int i=0; i<4; ++i) { marci@1008: Graph1::Node n1=g.addNode(); marci@1008: Graph2::Node n2=h.addNode(); marci@1008: e_node.set(n1, n2); marci@1008: n_node.set(n2, n1); marci@1008: } marci@1008: for (Graph2::NodeIt n(h); n!=INVALID; ++n) marci@1008: for (Graph2::NodeIt m(h); m!=INVALID; ++m) marci@1008: if ((h.id(n)+h.id(m))%3==0) h.addEdge(n, m); marci@1008: // Graph1::NodeIt n(g); marci@1008: // Node1 n1=n; marci@1008: // Node1 n2=++n; marci@1008: // Node1 n3=++n; marci@1008: // Node1 n4=n; marci@1008: // gw.addEdge(n1, n2); marci@1008: // gw.addEdge(n1, n2); marci@1008: // for (EdgeIt(e)) marci@1008: // Graph1::Node n1=g.addNode(); marci@1008: // Graph1::Node n2=g.addNode(); marci@1008: // Graph1::Node n3=g.addNode(); marci@1008: // Graph2::Node n4=h.addNode(); marci@1008: // Graph2::Node n5=h.addNode(); marci@1008: for (GW::EdgeIt e(gw); e!=INVALID; ++e) marci@1008: cout << gw.id(e) << endl; marci@1008: for (GW::NodeIt n(gw); n!=INVALID; ++n) { marci@1008: if (e_node[n]==INVALID) { marci@1008: cout<