Merge back the whole branches/hugo++ to trunk.
6 #include <sage_graph.h>
7 //#include <smart_graph.h>
9 #include <hugo/time_measure.h>
10 #include <for_each_macros.h>
12 #include <hugo/graph_wrapper.h>
13 #include <bipartite_graph_wrapper.h>
14 #include <hugo/maps.h>
15 #include <hugo/max_flow.h>
16 #include <augmenting_flow.h>
21 typedef UndirSageGraph Graph;
22 typedef Graph::Node Node;
23 typedef Graph::NodeIt NodeIt;
24 typedef Graph::Edge Edge;
25 typedef Graph::EdgeIt EdgeIt;
26 typedef Graph::OutEdgeIt OutEdgeIt;
29 // std::vector<Graph::Node> s_nodes;
30 // std::vector<Graph::Node> t_nodes;
31 // for (int i=0; i<3; ++i) s_nodes.push_back(g.addNode());
32 // for (int i=0; i<3; ++i) t_nodes.push_back(g.addNode());
33 // g.addEdge(s_nodes[0], t_nodes[2]);
34 // g.addEdge(t_nodes[1], s_nodes[2]);
35 // g.addEdge(s_nodes[0], t_nodes[1]);
37 // Graph::NodeMap<int> ref_map(g, -1);
38 // IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
39 // for (int i=0; i<3; ++i) bipartite_map.insert(s_nodes[i], false);
40 // for (int i=0; i<3; ++i) bipartite_map.insert(t_nodes[i], true);
42 std::vector<Graph::Node> nodes;
43 for (int i=0; i<3; ++i) nodes.push_back(g.addNode());
44 for (int i=3; i<6; ++i) nodes.push_back(g.addNode());
45 g.addEdge(nodes[0], nodes[3+2]);
46 g.addEdge(nodes[3+1], nodes[2]);
47 g.addEdge(nodes[0], nodes[3+1]);
49 Graph::NodeMap<int> ref_map(g, -1);
50 IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
51 for (int i=0; i<3; ++i) bipartite_map.insert(nodes[i], false);
52 for (int i=3; i<6; ++i) bipartite_map.insert(nodes[i], true);
55 std::cout << "These nodes will be in S:\n";
56 //FIXME azert kellene ++, es invalid vizsgalat u-bol, hogy ezt le lehessen
57 //irni 1etlen FOR_EACH-csel.
58 for (bipartite_map.first(u, false); g.valid(u); bipartite_map.next(u))
59 std::cout << u << " ";
61 std::cout << "These nodes will be in T:\n";
62 for (bipartite_map.first(u, true); g.valid(u); bipartite_map.next(u))
63 std::cout << u << " ";
66 typedef BipartiteGraphWrapper<Graph> BGW;
67 BGW bgw(g, bipartite_map);
69 std::cout << "Nodes by NodeIt:\n";
70 FOR_EACH_LOC(BGW::NodeIt, n, bgw) {
71 std::cout << n << " ";
74 std::cout << "Nodes in S by ClassNodeIt:\n";
75 FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.S_CLASS) {
76 std::cout << n << " ";
79 std::cout << "Nodes in T by ClassNodeIt:\n";
80 FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.T_CLASS) {
81 std::cout << n << " ";
84 std::cout << "Edges of the bipartite graph:\n";
85 FOR_EACH_LOC(BGW::EdgeIt, e, bgw) {
86 std::cout << bgw.tail(e) << "->" << bgw.head(e) << std::endl;
89 BGW::NodeMap<int> dbyj(bgw);
90 BGW::EdgeMap<int> dbyxcj(bgw);
92 typedef stBipartiteGraphWrapper<BGW> stGW;
94 ConstMap<stGW::Edge, int> const1map(1);
95 stGW::NodeMap<int> ize(stgw);
96 stGW::EdgeMap<int> flow(stgw);
98 BfsIterator< BGW, BGW::NodeMap<bool> > bfs(bgw);
102 bfs.pushAndSetReached(BGW::Node(s));
103 while (!bfs.finished()) { ++bfs; }
105 FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
106 std::cout << "out-edges of " << n << ":\n";
107 FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) {
108 std::cout << " " << e << "\n";
109 std::cout << " aNode: " << stgw.aNode(e) << "\n";
110 std::cout << " bNode: " << stgw.bNode(e) << "\n";
112 std::cout << "in-edges of " << n << ":\n";
113 FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) {
114 std::cout << " " << e << "\n";
115 std::cout << " aNode: " << stgw.aNode(e) << "\n";
116 std::cout << " bNode: " << stgw.bNode(e) << "\n";
119 std::cout << "Edges of the stGraphWrapper:\n";
120 FOR_EACH_LOC(stGW::EdgeIt, n, stgw) {
121 std::cout << " " << n << "\n";
124 stGW::NodeMap<bool> b(stgw);
125 FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
126 std::cout << n << ": " << b[n] <<"\n";
129 std::cout << "Bfs from s: \n";
130 BfsIterator< stGW, stGW::NodeMap<bool> > bfs_stgw(stgw);
131 bfs_stgw.pushAndSetReached(stgw.S_NODE);
132 while (!bfs_stgw.finished()) {
133 std::cout << " " << stGW::OutEdgeIt(bfs_stgw) << "\n";
137 AugmentingFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
138 max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
139 while (max_flow_test.augmentOnShortestPath()) { }
141 std::cout << max_flow_test.flowValue() << std::endl;