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@368
|
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@368
|
13 |
|
marci@368
|
14 |
using namespace hugo;
|
marci@368
|
15 |
|
marci@368
|
16 |
int main() {
|
marci@368
|
17 |
typedef UndirListGraph Graph;
|
marci@368
|
18 |
typedef Graph::Node Node;
|
marci@368
|
19 |
typedef Graph::NodeIt NodeIt;
|
marci@368
|
20 |
typedef Graph::Edge Edge;
|
marci@368
|
21 |
typedef Graph::EdgeIt EdgeIt;
|
marci@368
|
22 |
typedef Graph::OutEdgeIt OutEdgeIt;
|
marci@368
|
23 |
|
marci@368
|
24 |
Graph g;
|
marci@368
|
25 |
//Node s, t;
|
marci@368
|
26 |
//Graph::EdgeMap<int> cap(g);
|
marci@368
|
27 |
//readDimacsMaxFlow(std::cin, g, s, t, cap);
|
marci@368
|
28 |
std::vector<Graph::Node> s_nodes;
|
marci@368
|
29 |
std::vector<Graph::Node> t_nodes;
|
marci@368
|
30 |
for (int i=0; i<3; ++i) s_nodes.push_back(g.addNode());
|
marci@368
|
31 |
for (int i=0; i<3; ++i) t_nodes.push_back(g.addNode());
|
marci@368
|
32 |
g.addEdge(s_nodes[0], t_nodes[2]);
|
marci@368
|
33 |
g.addEdge(t_nodes[1], s_nodes[2]);
|
marci@368
|
34 |
|
marci@368
|
35 |
Graph::NodeMap<int> ref_map(g, -1);
|
marci@368
|
36 |
IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
|
marci@368
|
37 |
for (int i=0; i<3; ++i) bipartite_map.insert(s_nodes[i], false);
|
marci@368
|
38 |
for (int i=0; i<3; ++i) bipartite_map.insert(t_nodes[i], true);
|
marci@368
|
39 |
typedef BipartiteGraphWrapper<Graph> BGW;
|
marci@368
|
40 |
BGW bgw(g, bipartite_map);
|
marci@368
|
41 |
FOR_EACH_LOC(BGW::EdgeIt, e, bgw) {
|
marci@368
|
42 |
std::cout << bgw.tail(e) << "->" << bgw.head(e) << std::endl;
|
marci@368
|
43 |
}
|
marci@368
|
44 |
// Graph::NodeMap<OutEdgeIt> pred(G);
|
marci@368
|
45 |
// Timer ts;
|
marci@368
|
46 |
// {
|
marci@368
|
47 |
// ts.reset();
|
marci@368
|
48 |
// Graph::NodeMap<bool> reached(G);
|
marci@368
|
49 |
// reached.set(s, true);
|
marci@368
|
50 |
// pred.set(s, INVALID);
|
marci@368
|
51 |
// std::queue<Node> bfs_queue;
|
marci@368
|
52 |
// bfs_queue.push(t);
|
marci@368
|
53 |
// while (!bfs_queue.empty()) {
|
marci@368
|
54 |
// Node v=bfs_queue.front();
|
marci@368
|
55 |
// bfs_queue.pop();
|
marci@368
|
56 |
// OutEdgeIt e;
|
marci@368
|
57 |
// for(G.first(e,v); G.valid(e); G.next(e)) {
|
marci@368
|
58 |
// Node w=G.head(e);
|
marci@368
|
59 |
// if (!reached[w]) {
|
marci@368
|
60 |
// bfs_queue.push(w);
|
marci@368
|
61 |
// reached.set(w, true);
|
marci@368
|
62 |
// pred.set(w, e);
|
marci@368
|
63 |
// }
|
marci@368
|
64 |
// }
|
marci@368
|
65 |
// }
|
marci@368
|
66 |
|
marci@368
|
67 |
// std::cout << ts << std::endl;
|
marci@368
|
68 |
// }
|
marci@368
|
69 |
|
marci@368
|
70 |
// {
|
marci@368
|
71 |
// ts.reset();
|
marci@368
|
72 |
// BfsIterator< Graph, Graph::NodeMap<bool> > bfs(G);
|
marci@368
|
73 |
// bfs.pushAndSetReached(s);
|
marci@368
|
74 |
// pred.set(s, INVALID);
|
marci@368
|
75 |
// while (!bfs.finished()) {
|
marci@368
|
76 |
// ++bfs;
|
marci@368
|
77 |
// if (G.valid(bfs) && bfs.isBNodeNewlyReached())
|
marci@368
|
78 |
// pred.set(bfs.bNode(), bfs);
|
marci@368
|
79 |
// }
|
marci@368
|
80 |
// std::cout << ts << std::endl;
|
marci@368
|
81 |
// }
|
marci@368
|
82 |
|
marci@368
|
83 |
return 0;
|
marci@368
|
84 |
}
|