It breaks my heart to say them goodbye...
6 #include <list_graph.h>
7 //#include <smart_graph.h>
9 #include <time_measure.h>
10 #include <for_each_macros.h>
11 #include <bfs_iterator.h>
12 #include <graph_wrapper.h>
14 #include <edmonds_karp.h>
19 typedef UndirListGraph Graph;
20 typedef Graph::Node Node;
21 typedef Graph::NodeIt NodeIt;
22 typedef Graph::Edge Edge;
23 typedef Graph::EdgeIt EdgeIt;
24 typedef Graph::OutEdgeIt OutEdgeIt;
27 // std::vector<Graph::Node> s_nodes;
28 // std::vector<Graph::Node> t_nodes;
29 // for (int i=0; i<3; ++i) s_nodes.push_back(g.addNode());
30 // for (int i=0; i<3; ++i) t_nodes.push_back(g.addNode());
31 // g.addEdge(s_nodes[0], t_nodes[2]);
32 // g.addEdge(t_nodes[1], s_nodes[2]);
33 // g.addEdge(s_nodes[0], t_nodes[1]);
35 // Graph::NodeMap<int> ref_map(g, -1);
36 // IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
37 // for (int i=0; i<3; ++i) bipartite_map.insert(s_nodes[i], false);
38 // for (int i=0; i<3; ++i) bipartite_map.insert(t_nodes[i], true);
40 std::vector<Graph::Node> nodes;
41 for (int i=0; i<3; ++i) nodes.push_back(g.addNode());
42 for (int i=3; i<6; ++i) nodes.push_back(g.addNode());
43 g.addEdge(nodes[0], nodes[3+2]);
44 g.addEdge(nodes[3+1], nodes[2]);
45 g.addEdge(nodes[0], nodes[3+1]);
47 Graph::NodeMap<int> ref_map(g, -1);
48 IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
49 for (int i=0; i<3; ++i) bipartite_map.insert(nodes[i], false);
50 for (int i=3; i<6; ++i) bipartite_map.insert(nodes[i], true);
53 std::cout << "These nodes will be in S:\n";
54 //FIXME azert kellene ++, es invalid vizsgalat u-bol, hogy ezt le lehessen
55 //irni 1etlen FOR_EACH-csel.
56 for (bipartite_map.first(u, false); g.valid(u); bipartite_map.next(u))
57 std::cout << u << " ";
59 std::cout << "These nodes will be in T:\n";
60 for (bipartite_map.first(u, true); g.valid(u); bipartite_map.next(u))
61 std::cout << u << " ";
64 typedef BipartiteGraphWrapper<Graph> BGW;
65 BGW bgw(g, bipartite_map);
67 std::cout << "Nodes by NodeIt:\n";
68 FOR_EACH_LOC(BGW::NodeIt, n, bgw) {
69 std::cout << n << " ";
72 std::cout << "Nodes in S by ClassNodeIt:\n";
73 FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.S_CLASS) {
74 std::cout << n << " ";
77 std::cout << "Nodes in T by ClassNodeIt:\n";
78 FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.T_CLASS) {
79 std::cout << n << " ";
82 std::cout << "Edges of the bipartite graph:\n";
83 FOR_EACH_LOC(BGW::EdgeIt, e, bgw) {
84 std::cout << bgw.tail(e) << "->" << bgw.head(e) << std::endl;
87 BGW::NodeMap<int> dbyj(bgw);
88 BGW::EdgeMap<int> dbyxcj(bgw);
90 typedef stGraphWrapper<BGW> stGW;
92 ConstMap<stGW::Edge, int> const1map(1);
93 stGW::NodeMap<int> ize(stgw);
94 stGW::EdgeMap<int> flow(stgw);
96 BfsIterator< BGW, BGW::NodeMap<bool> > bfs(bgw);
100 bfs.pushAndSetReached(BGW::Node(s));
101 while (!bfs.finished()) { ++bfs; }
103 FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
104 std::cout << "out-edges of " << n << ":\n";
105 FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) {
106 std::cout << " " << e << "\n";
107 std::cout << " aNode: " << stgw.aNode(e) << "\n";
108 std::cout << " bNode: " << stgw.bNode(e) << "\n";
110 std::cout << "in-edges of " << n << ":\n";
111 FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) {
112 std::cout << " " << e << "\n";
113 std::cout << " aNode: " << stgw.aNode(e) << "\n";
114 std::cout << " bNode: " << stgw.bNode(e) << "\n";
117 std::cout << "Edges of the stGraphWrapper:\n";
118 FOR_EACH_LOC(stGW::EdgeIt, n, stgw) {
119 std::cout << " " << n << "\n";
122 stGW::NodeMap<bool> b(stgw);
123 FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
124 std::cout << n << ": " << b[n] <<"\n";
127 std::cout << "Bfs from s: \n";
128 BfsIterator< stGW, stGW::NodeMap<bool> > bfs_stgw(stgw);
129 bfs_stgw.pushAndSetReached(stgw.S_NODE);
130 while (!bfs_stgw.finished()) {
131 std::cout << " " << stGW::OutEdgeIt(bfs_stgw) << "\n";
135 MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
136 max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
137 while (max_flow_test.augmentOnShortestPath()) { }
139 std::cout << max_flow_test.flowValue() << std::endl;