1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/work/marci/bfsit_vs_byhand.cc Wed Apr 21 14:50:42 2004 +0000
1.3 @@ -0,0 +1,67 @@
1.4 +// -*- c++ -*-
1.5 +#include <iostream>
1.6 +#include <fstream>
1.7 +
1.8 +#include <list_graph.h>
1.9 +#include <smart_graph.h>
1.10 +#include <dimacs.h>
1.11 +#include <time_measure.h>
1.12 +#include <for_each_macros.h>
1.13 +#include <bfs_iterator.h>
1.14 +
1.15 +using namespace hugo;
1.16 +
1.17 +int main() {
1.18 + typedef ListGraph Graph;
1.19 + typedef Graph::Node Node;
1.20 + typedef Graph::NodeIt NodeIt;
1.21 + typedef Graph::Edge Edge;
1.22 + typedef Graph::EdgeIt EdgeIt;
1.23 + typedef Graph::OutEdgeIt OutEdgeIt;
1.24 +
1.25 + Graph G;
1.26 + Node s, t;
1.27 + Graph::EdgeMap<int> cap(G);
1.28 + readDimacsMaxFlow(std::cin, G, s, t, cap);
1.29 + Graph::NodeMap<OutEdgeIt> pred(G);
1.30 + Timer ts;
1.31 + {
1.32 + ts.reset();
1.33 + Graph::NodeMap<bool> reached(G);
1.34 + /*Reverse_bfs from t, to find the starting level.*/
1.35 + reached.set(s, true);
1.36 + pred.set(s, INVALID);
1.37 + std::queue<Node> bfs_queue;
1.38 + bfs_queue.push(t);
1.39 + while (!bfs_queue.empty()) {
1.40 + Node v=bfs_queue.front();
1.41 + bfs_queue.pop();
1.42 + OutEdgeIt e;
1.43 + for(G.first(e,v); G.valid(e); G.next(e)) {
1.44 + Node w=G.head(e);
1.45 + if (!reached[w]) {
1.46 + bfs_queue.push(w);
1.47 + reached.set(w, true);
1.48 + pred.set(w, e);
1.49 + }
1.50 + }
1.51 + }
1.52 +
1.53 + std::cout << ts << std::endl;
1.54 + }
1.55 +
1.56 + {
1.57 + ts.reset();
1.58 + BfsIterator5< Graph, Graph::NodeMap<bool> > bfs(G);
1.59 + bfs.pushAndSetReached(s);
1.60 + pred.set(s, INVALID);
1.61 + while (!bfs.finished()) {
1.62 + ++bfs;
1.63 + if (G.valid(bfs) && bfs.isBNodeNewlyReached())
1.64 + pred.set(bfs.bNode(), bfs);
1.65 + }
1.66 + std::cout << ts << std::endl;
1.67 + }
1.68 +
1.69 + return 0;
1.70 +}