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