marci@915: #include marci@1009: #include marci@915: alpar@921: #include alpar@921: #include marci@1009: #include marci@1025: #include marci@1013: #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@1013: template marci@1013: void printGraph(const Graph& g) { marci@1009: cout << " nodes:" << endl; marci@1013: for (typename Graph::NodeIt n(g); n!=INVALID; ++n) { marci@1025: cout << " " << g.id(n) << ": out edges:" << endl; marci@1025: for (typename Graph::OutEdgeIt e(g, n); e!=INVALID; ++e) marci@1025: cout << " " << g.id(g.source(e)) << "->" << g.id(g.target(e)) << endl; marci@1009: } marci@1009: cout << " edges:" << endl; marci@1025: for (typename Graph::EdgeIt e(g); e!=INVALID; ++e) { marci@1025: cout << " " << g.id(e) << ": " marci@1025: << g.id(g.source(e)) << "->" << g.id(g.target(e)) << endl; marci@1013: } marci@1013: } marci@1013: marci@1013: int main() { marci@1013: { marci@1013: cout << "FIRST TEST" << endl; marci@1025: //typedef SmartGraph Graph1; marci@1025: typedef ListGraph Graph1; marci@1013: typedef ListGraph Graph2; marci@1025: typedef SmartGraph Graph3; marci@1013: marci@1025: // { marci@1025: // checkConcept >(); marci@1025: // MergeEdgeGraphWrapper::printNode(); marci@1025: // MergeEdgeGraphWrapper::printEdge(); marci@1025: // checkConcept >(); marci@1025: // MergeEdgeGraphWrapper::printNode(); marci@1025: // MergeEdgeGraphWrapper::printEdge(); marci@1025: // typedef ResGraphWrapper, ConstMap > Graph4; marci@1025: // checkConcept >(); marci@1025: // MergeEdgeGraphWrapper::printNode(); marci@1025: // MergeEdgeGraphWrapper::printEdge(); marci@1025: // checkConcept >(); marci@1025: // MergeEdgeGraphWrapper::printNode(); marci@1025: // MergeEdgeGraphWrapper::printEdge(); marci@1025: // } marci@1013: marci@1013: Graph1 g1; marci@1013: Graph2 g2; marci@1013: typedef MergeEdgeGraphWrapper GW; marci@1013: GW gw(g1, g2); marci@1025: Graph1::Node s1, t1; marci@1025: Graph2::Node s2, t2; marci@1025: Graph1::EdgeMap cap1(g1); marci@1025: Graph2::EdgeMap cap2(g2); marci@1013: marci@1013: std::ifstream f1("graph1.dim"); marci@1013: std::ifstream f2("graph2.dim"); marci@1013: readDimacs(f1, g1); marci@1013: readDimacs(f2, g2); marci@1025: marci@1025: // GW::NodeMap ize(gw, 8); marci@1025: // for (GW::NodeIt n(gw); n!=INVALID; ++n) ize.set(n, 9); marci@1025: // GW::EdgeMap mize(gw, 8); marci@1025: // for (GW::EdgeIt n(gw); n!=INVALID; ++n) mize.set(n, 7); marci@1025: marci@1025: // std::ifstream f1("flow-1.dim"); marci@1025: // std::ifstream f2("flow2.dim"); marci@1025: // readDimacs(f1, g1, cap1, s1, t1); marci@1025: // readDimacs(f2, g2, cap2, s2, t2); marci@1013: marci@1025: // GW::EdgeMap cap(gw); marci@1025: // for (GW::EdgeIt e(gw); e!=INVALID; ++e) { marci@1025: // if (gw.forward(e)) cap.set(e, cap1[e]); marci@1025: // if (gw.backward(e)) cap.set(e, cap2[e]); marci@1025: // } marci@1013: marci@1025: // { marci@1025: // GW::EdgeMap flow(gw, 0); marci@1025: // Preflow preflow(gw, GW::Node(s1, INVALID, false), marci@1025: // GW::Node(t1, INVALID, false), cap, flow); marci@1025: // preflow.run(); marci@1025: // std::cout << "s1->t1: " << preflow.flowValue() << std::endl; marci@1025: // } marci@1025: // { marci@1025: // GW::EdgeMap flow(gw, 0); marci@1025: // Preflow preflow(gw, GW::Node(INVALID, s2, true), marci@1025: // GW::Node(INVALID, t2, true), cap, flow); marci@1025: // preflow.run(); marci@1025: // std::cout << "s2->t2: " << preflow.flowValue() << std::endl; marci@1025: // } marci@1025: // { marci@1025: // GW::EdgeMap flow(gw, 0); marci@1025: // Preflow preflow(gw, GW::Node(s1, INVALID, false), marci@1025: // GW::Node(INVALID, t2, true), cap, flow); marci@1025: // preflow.run(); marci@1025: // std::cout << "s1->t2: " << preflow.flowValue() << std::endl; marci@1025: // } marci@1025: // { marci@1025: // GW::EdgeMap flow(gw, 0); marci@1025: // Preflow preflow(gw, GW::Node(INVALID, s2, true), marci@1025: // GW::Node(s1, INVALID, false), cap, flow); marci@1025: // preflow.run(); marci@1025: // std::cout << "s2->t1: " << preflow.flowValue() << std::endl; marci@1025: // } marci@1025: cout << "1st graph" << endl; marci@1025: printGraph(g1); marci@1013: marci@1025: cout << "2nd graph" << endl; marci@1025: printGraph(g2); marci@1013: marci@1025: cout << "merged graph" << endl; marci@1025: printGraph(gw); marci@1025: marci@1025: // for (GW::NodeIt n(gw); n!=INVALID; ++n) marci@1025: // std::cout << ize[n] << std::endl; marci@1025: // for (GW::EdgeIt n(gw); n!=INVALID; ++n) marci@1025: // std::cout << mize[n] << std::endl; marci@1025: marci@1025: typedef NewEdgeSetGraphWrapper2 GWW; marci@1025: // { marci@1025: // checkConcept(); marci@1025: // } marci@1025: marci@1025: GWW gww(gw); marci@1025: marci@1025: cout << "new edges graph" << endl; marci@1025: printGraph(gww); marci@1025: marci@1025: GWW::NodeIt n(gww); marci@1025: GWW::Node n1=n; marci@1025: ++n; marci@1025: GWW::Node n2=n; marci@1025: gww.addEdge(n1, n2); marci@1025: // gww.addNode(); marci@1025: // gww.addNode(); marci@1025: marci@1025: cout << "new edges graph" << endl; marci@1025: printGraph(gww); marci@1025: marci@1025: typedef AugmentingGraphWrapper GWWW; marci@1025: // { marci@1025: // checkConcept(); marci@1025: // } marci@1025: GWWW gwww(gw, gww); marci@1025: marci@1025: cout << "fully merged graph" << endl; marci@1025: printGraph(gwww); marci@915: } marci@917: marci@1013: marci@1013: { marci@1013: cout << "SECOND TEST" << endl; marci@1013: typedef SmartGraph Graph1; marci@1025: // { marci@1025: // checkConcept(); marci@1025: // } marci@1013: marci@1013: Graph1 g1; marci@1013: marci@1013: FullGraph pre_g2(2); marci@1013: ConstMap const_false_map(false); marci@1013: typedef EdgeSubGraphWrapper > marci@1013: Graph2; marci@1025: // { marci@1025: // checkConcept(); marci@1025: // } marci@1013: marci@1013: Graph2 g2(pre_g2, const_false_map); marci@1013: marci@1013: typedef MergeEdgeGraphWrapper GW; marci@1025: // { marci@1025: // checkConcept(); marci@1025: // } marci@1013: GW gw(g1, g2); marci@1013: GW::Node sw; marci@1013: GW::Node tw; marci@1013: { marci@1013: Graph2::NodeIt k(g2); marci@1013: sw=GW::Node(INVALID, k, true); marci@1013: ++k; marci@1013: tw=GW::Node(INVALID, k, true); marci@1013: } marci@1013: marci@1013: std::ifstream f1("graph2.dim"); marci@1013: readDimacs(f1, g1); marci@1013: marci@1013: cout << "1st graph" << endl; marci@1013: printGraph(g1); marci@1013: marci@1013: cout << "2nd graph" << endl; marci@1013: printGraph(g2); marci@1013: marci@1013: cout << "merged graph" << endl; marci@1013: printGraph(gw); marci@1013: marci@1013: typedef ListGraph Graph3; marci@1016: //typedef SmartGraph Graph3; marci@1013: Graph3 g3; marci@1013: GW::NodeMap gwn(gw); marci@1013: Graph3::NodeMap g3n(g3); marci@1013: for (GW::NodeIt n(gw); n!=INVALID; ++n) { marci@1013: Graph3::Node m=g3.addNode(); marci@1013: gwn.set(n, m); marci@1013: g3n.set(m, n); marci@1013: } marci@1013: marci@1013: typedef NewEdgeSetGraphWrapper GWW; marci@1025: // { marci@1025: // checkConcept(); marci@1025: // } marci@1013: marci@1013: GWW gww(gw, g3, gwn, g3n); marci@1013: marci@1013: for (Graph1::NodeIt n(g1); n!=INVALID; ++n) { marci@1013: g3.addEdge(gwn[sw], gwn[GW::Node(n,INVALID,false)]); marci@1013: } marci@1013: marci@1013: // for (Graph1::NodeIt n(g1); n!=INVALID; ++n) { marci@1013: // gww.addEdge(sw, GW::Node(n,INVALID,false)); marci@1013: // } marci@1013: marci@1013: cout << "new edges" << endl; marci@1013: printGraph(g3); marci@1013: marci@1013: cout << "new edges in the new graph" << endl; marci@1013: printGraph(gww); marci@1013: marci@1013: typedef AugmentingGraphWrapper GWWW; marci@1025: // { marci@1025: // checkConcept(); marci@1025: // } marci@1013: GWWW gwww(gw, gww); marci@1013: marci@1013: cout << "new edges merged into the original graph" << endl; marci@1013: printGraph(gwww); marci@1013: marci@917: } marci@1007: marci@915: }