// -*- c++ -*- #include #include #include //#include #include //#include #include //#include #include #include #include #include #include #include using std::cout; using std::endl; using namespace lemon; int main() { //typedef UndirSageGraph Graph; typedef SmartGraph Graph; typedef Graph::Node Node; typedef Graph::NodeIt NodeIt; typedef Graph::Edge Edge; typedef Graph::EdgeIt EdgeIt; typedef Graph::OutEdgeIt OutEdgeIt; Graph g; // std::vector s_nodes; // std::vector t_nodes; // for (int i=0; i<3; ++i) s_nodes.push_back(g.addNode()); // for (int i=0; i<3; ++i) t_nodes.push_back(g.addNode()); // g.addEdge(s_nodes[0], t_nodes[2]); // g.addEdge(t_nodes[1], s_nodes[2]); // g.addEdge(s_nodes[0], t_nodes[1]); // Graph::NodeMap ref_map(g, -1); // IterableBoolMap< Graph::NodeMap > bipartite_map(ref_map); // for (int i=0; i<3; ++i) bipartite_map.insert(s_nodes[i], false); // for (int i=0; i<3; ++i) bipartite_map.insert(t_nodes[i], true); std::vector nodes; for (int i=0; i<3; ++i) nodes.push_back(g.addNode()); for (int i=3; i<6; ++i) nodes.push_back(g.addNode()); g.addEdge(nodes[0], nodes[3+2]); g.addEdge(nodes[3+1], nodes[2]); g.addEdge(nodes[0], nodes[3+1]); Graph::NodeMap ref_map(g, -1); IterableBoolMap< Graph::NodeMap > bipartite_map(ref_map); for (int i=0; i<3; ++i) bipartite_map.insert(nodes[i], false); for (int i=3; i<6; ++i) bipartite_map.insert(nodes[i], true); Graph::Node u; cout << "These nodes will be in S:" << endl; //FIXME azert kellene ++, es invalid vizsgalat u-bol, hogy ezt le lehessen //irni 1etlen FOR_EACH-csel. for (bipartite_map.first(u, false); u!=INVALID; bipartite_map.next(u)) cout << g.id(u) << " "; cout << endl; cout << "These nodes will be in T:" << endl; for (bipartite_map.first(u, true); u!=INVALID; bipartite_map.next(u)) cout << g.id(u) << " "; cout << endl; typedef BipartiteGraphWrapper BGW; BGW bgw(g, bipartite_map); cout << "Nodes by NodeIt:" << endl; for (BGW::NodeIt n(bgw); n!=INVALID; ++n) cout << g.id(n) << " "; cout << endl; cout << "Nodes in S by ClassNodeIt:" << endl; for (BGW::ClassNodeIt n(bgw, bgw.S_CLASS); n!=INVALID; ++n) cout << g.id(n) << " "; cout << endl; cout << "Nodes in T by ClassNodeIt:" << endl; for (BGW::ClassNodeIt n(bgw, bgw.T_CLASS); n!=INVALID; ++n) cout << g.id(n) << " "; cout << endl; cout << "Edges of the bipartite graph:" << endl; for (BGW::EdgeIt e(bgw); e!=INVALID; ++e) cout << g.id(bgw.tail(e)) << "->" << g.id(bgw.head(e)) << endl; BGW::NodeMap dbyj(bgw); BGW::EdgeMap dbyxcj(bgw); // typedef stBipartiteGraphWrapper stGW; // stGW stgw(bgw); // ConstMap const1map(1); // stGW::NodeMap ize(stgw); // stGW::EdgeMap flow(stgw); // BfsIterator< BGW, BGW::NodeMap > bfs(bgw); // Graph::NodeIt si; // Graph::Node s; // s=g.first(si); // bfs.pushAndSetReached(BGW::Node(s)); // while (!bfs.finished()) { ++bfs; } // FOR_EACH_LOC(stGW::NodeIt, n, stgw) { // cout << "out-edges of " << n << ":" << endl; // FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) { // cout << " " << e << endl; // cout << " aNode: " << stgw.aNode(e) << endl; // cout << " bNode: " << stgw.bNode(e) << endl; // } // cout << "in-edges of " << n << ":" << endl; // FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) { // cout << " " << e << endl; // cout << " aNode: " << stgw.aNode(e) << endl; // cout << " bNode: " << stgw.bNode(e) << endl; // } // } // cout << "Edges of the stGraphWrapper:" << endl; // FOR_EACH_LOC(stGW::EdgeIt, n, stgw) { // cout << " " << n << endl; // } // stGW::NodeMap b(stgw); // FOR_EACH_LOC(stGW::NodeIt, n, stgw) { // cout << n << ": " << b[n] << endl; // } // cout << "Bfs from s:" << endl; // BfsIterator< stGW, stGW::NodeMap > bfs_stgw(stgw); // bfs_stgw.pushAndSetReached(stgw.S_NODE); // while (!bfs_stgw.finished()) { // cout << " " << stGW::OutEdgeIt(bfs_stgw) << endl; // ++bfs_stgw; // } // AugmentingFlow, stGW::EdgeMap > // max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow); // while (max_flow_test.augmentOnShortestPath()) { } // cout << max_flow_test.flowValue() << std::endl; return 0; }