A year has passed again.
6 //#include <sage_graph.h>
7 #include <lemon/smart_graph.h>
9 #include <lemon/time_measure.h>
10 //#include <for_each_macros.h>
12 #include <lemon/graph_wrapper.h>
13 #include <bipartite_graph_wrapper.h>
14 #include <lemon/maps.h>
15 #include <lemon/preflow.h>
16 #include <augmenting_flow.h>
21 using namespace lemon;
24 //typedef UndirSageGraph Graph;
25 typedef SmartGraph Graph;
26 typedef Graph::Node Node;
27 typedef Graph::NodeIt NodeIt;
28 typedef Graph::Edge Edge;
29 typedef Graph::EdgeIt EdgeIt;
30 typedef Graph::OutEdgeIt OutEdgeIt;
33 // std::vector<Graph::Node> s_nodes;
34 // std::vector<Graph::Node> t_nodes;
35 // for (int i=0; i<3; ++i) s_nodes.push_back(g.addNode());
36 // for (int i=0; i<3; ++i) t_nodes.push_back(g.addNode());
37 // g.addEdge(s_nodes[0], t_nodes[2]);
38 // g.addEdge(t_nodes[1], s_nodes[2]);
39 // g.addEdge(s_nodes[0], t_nodes[1]);
41 // Graph::NodeMap<int> ref_map(g, -1);
42 // IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
43 // for (int i=0; i<3; ++i) bipartite_map.insert(s_nodes[i], false);
44 // for (int i=0; i<3; ++i) bipartite_map.insert(t_nodes[i], true);
46 std::vector<Graph::Node> nodes;
47 for (int i=0; i<3; ++i) nodes.push_back(g.addNode());
48 for (int i=3; i<6; ++i) nodes.push_back(g.addNode());
49 g.addEdge(nodes[0], nodes[3+2]);
50 g.addEdge(nodes[3+1], nodes[2]);
51 g.addEdge(nodes[0], nodes[3+1]);
53 Graph::NodeMap<int> ref_map(g, -1);
54 IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
55 for (int i=0; i<3; ++i) bipartite_map.insert(nodes[i], false);
56 for (int i=3; i<6; ++i) bipartite_map.insert(nodes[i], true);
59 cout << "These nodes will be in S:" << endl;
60 //FIXME azert kellene ++, es invalid vizsgalat u-bol, hogy ezt le lehessen
61 //irni 1etlen FOR_EACH-csel.
62 for (bipartite_map.first(u, false); u!=INVALID; bipartite_map.next(u))
63 cout << g.id(u) << " ";
65 cout << "These nodes will be in T:" << endl;
66 for (bipartite_map.first(u, true); u!=INVALID; bipartite_map.next(u))
67 cout << g.id(u) << " ";
70 typedef BipartiteGraphWrapper<Graph> BGW;
71 BGW bgw(g, bipartite_map);
73 cout << "Nodes by NodeIt:" << endl;
74 for (BGW::NodeIt n(bgw); n!=INVALID; ++n)
75 cout << g.id(n) << " ";
78 cout << "Nodes in S by ClassNodeIt:" << endl;
79 for (BGW::ClassNodeIt n(bgw, bgw.S_CLASS); n!=INVALID; ++n)
80 cout << g.id(n) << " ";
83 cout << "Nodes in T by ClassNodeIt:" << endl;
84 for (BGW::ClassNodeIt n(bgw, bgw.T_CLASS); n!=INVALID; ++n)
85 cout << g.id(n) << " ";
88 cout << "Edges of the bipartite graph:" << endl;
89 for (BGW::EdgeIt e(bgw); e!=INVALID; ++e)
90 cout << g.id(bgw.source(e)) << "->" << g.id(bgw.target(e)) << endl;
92 BGW::NodeMap<int> dbyj(bgw);
93 BGW::EdgeMap<int> dbyxcj(bgw);
95 // typedef stBipartiteGraphWrapper<BGW> stGW;
97 // ConstMap<stGW::Edge, int> const1map(1);
98 // stGW::NodeMap<int> ize(stgw);
99 // stGW::EdgeMap<int> flow(stgw);
101 // BfsIterator< BGW, BGW::NodeMap<bool> > bfs(bgw);
105 // bfs.pushAndSetReached(BGW::Node(s));
106 // while (!bfs.finished()) { ++bfs; }
108 // FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
109 // cout << "out-edges of " << n << ":" << endl;
110 // FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) {
111 // cout << " " << e << endl;
112 // cout << " aNode: " << stgw.aNode(e) << endl;
113 // cout << " bNode: " << stgw.bNode(e) << endl;
115 // cout << "in-edges of " << n << ":" << endl;
116 // FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) {
117 // cout << " " << e << endl;
118 // cout << " aNode: " << stgw.aNode(e) << endl;
119 // cout << " bNode: " << stgw.bNode(e) << endl;
122 // cout << "Edges of the stGraphWrapper:" << endl;
123 // FOR_EACH_LOC(stGW::EdgeIt, n, stgw) {
124 // cout << " " << n << endl;
127 // stGW::NodeMap<bool> b(stgw);
128 // FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
129 // cout << n << ": " << b[n] << endl;
132 // cout << "Bfs from s:" << endl;
133 // BfsIterator< stGW, stGW::NodeMap<bool> > bfs_stgw(stgw);
134 // bfs_stgw.pushAndSetReached(stgw.S_NODE);
135 // while (!bfs_stgw.finished()) {
136 // cout << " " << stGW::OutEdgeIt(bfs_stgw) << endl;
140 // AugmentingFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
141 // max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
142 // while (max_flow_test.augmentOnShortestPath()) { }
144 // cout << max_flow_test.flowValue() << std::endl;