marci@368
|
1 |
// -*- c++ -*-
|
marci@368
|
2 |
#include <iostream>
|
marci@368
|
3 |
#include <fstream>
|
marci@368
|
4 |
#include <vector>
|
marci@368
|
5 |
|
marci@368
|
6 |
#include <list_graph.h>
|
marci@389
|
7 |
//#include <smart_graph.h>
|
marci@368
|
8 |
//#include <dimacs.h>
|
marci@368
|
9 |
#include <time_measure.h>
|
marci@368
|
10 |
#include <for_each_macros.h>
|
marci@368
|
11 |
#include <bfs_iterator.h>
|
marci@368
|
12 |
#include <graph_wrapper.h>
|
marci@379
|
13 |
#include <maps.h>
|
marci@379
|
14 |
#include <edmonds_karp.h>
|
marci@368
|
15 |
|
marci@368
|
16 |
using namespace hugo;
|
marci@368
|
17 |
|
marci@368
|
18 |
int main() {
|
marci@368
|
19 |
typedef UndirListGraph Graph;
|
marci@368
|
20 |
typedef Graph::Node Node;
|
marci@368
|
21 |
typedef Graph::NodeIt NodeIt;
|
marci@368
|
22 |
typedef Graph::Edge Edge;
|
marci@368
|
23 |
typedef Graph::EdgeIt EdgeIt;
|
marci@368
|
24 |
typedef Graph::OutEdgeIt OutEdgeIt;
|
marci@368
|
25 |
|
marci@368
|
26 |
Graph g;
|
marci@368
|
27 |
//Node s, t;
|
marci@368
|
28 |
//Graph::EdgeMap<int> cap(g);
|
marci@368
|
29 |
//readDimacsMaxFlow(std::cin, g, s, t, cap);
|
marci@368
|
30 |
std::vector<Graph::Node> s_nodes;
|
marci@368
|
31 |
std::vector<Graph::Node> t_nodes;
|
marci@368
|
32 |
for (int i=0; i<3; ++i) s_nodes.push_back(g.addNode());
|
marci@368
|
33 |
for (int i=0; i<3; ++i) t_nodes.push_back(g.addNode());
|
marci@368
|
34 |
g.addEdge(s_nodes[0], t_nodes[2]);
|
marci@368
|
35 |
g.addEdge(t_nodes[1], s_nodes[2]);
|
marci@368
|
36 |
|
marci@368
|
37 |
Graph::NodeMap<int> ref_map(g, -1);
|
marci@368
|
38 |
IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
|
marci@368
|
39 |
for (int i=0; i<3; ++i) bipartite_map.insert(s_nodes[i], false);
|
marci@368
|
40 |
for (int i=0; i<3; ++i) bipartite_map.insert(t_nodes[i], true);
|
marci@368
|
41 |
typedef BipartiteGraphWrapper<Graph> BGW;
|
marci@368
|
42 |
BGW bgw(g, bipartite_map);
|
marci@368
|
43 |
FOR_EACH_LOC(BGW::EdgeIt, e, bgw) {
|
marci@368
|
44 |
std::cout << bgw.tail(e) << "->" << bgw.head(e) << std::endl;
|
marci@368
|
45 |
}
|
marci@368
|
46 |
|
marci@379
|
47 |
BGW::NodeMap<int> dbyj(bgw);
|
marci@379
|
48 |
BGW::EdgeMap<int> dbyxcj(bgw);
|
marci@368
|
49 |
|
marci@379
|
50 |
typedef stGraphWrapper<BGW> stGW;
|
marci@379
|
51 |
stGW stgw(bgw);
|
marci@379
|
52 |
ConstMap<stGW::Edge, int> const1map(1);
|
marci@379
|
53 |
stGW::NodeMap<int> ize(stgw);
|
marci@379
|
54 |
stGW::EdgeMap<int> flow(stgw);
|
marci@379
|
55 |
|
marci@379
|
56 |
BfsIterator< BGW, BGW::NodeMap<bool> > bfs(bgw);
|
marci@379
|
57 |
Graph::NodeIt si;
|
marci@379
|
58 |
Graph::Node s;
|
marci@379
|
59 |
s=g.first(si);
|
marci@379
|
60 |
bfs.pushAndSetReached(BGW::Node(s));
|
marci@379
|
61 |
while (!bfs.finished()) ++bfs;
|
marci@379
|
62 |
|
marci@379
|
63 |
BGW::EdgeMap<bool> cap(bgw);
|
marci@379
|
64 |
BGW::EdgeMap<bool> flow1(bgw);
|
marci@379
|
65 |
|
marci@379
|
66 |
typedef ResGraphWrapper< BGW, int, BGW::EdgeMap<bool>, BGW::EdgeMap<bool> >
|
marci@379
|
67 |
RBGW;
|
marci@379
|
68 |
RBGW rbgw(bgw, cap, flow1);
|
marci@379
|
69 |
RBGW::NodeMap<int> u(rbgw);
|
marci@379
|
70 |
|
marci@379
|
71 |
|
marci@379
|
72 |
MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
|
marci@379
|
73 |
max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
|
marci@379
|
74 |
max_flow_test.augmentOnShortestPath();
|
marci@393
|
75 |
max_flow_test.augmentOnShortestPath();
|
marci@393
|
76 |
|
marci@393
|
77 |
std::cout << max_flow_test.flowValue() << std::endl;
|
marci@368
|
78 |
|
marci@368
|
79 |
return 0;
|
marci@368
|
80 |
}
|