diff -r cb0ac054ea92 -r 4f064aff855e src/work/marci/bfsit_vs_byhand.cc --- a/src/work/marci/bfsit_vs_byhand.cc Wed Oct 13 15:52:35 2004 +0000 +++ b/src/work/marci/bfsit_vs_byhand.cc Sat Oct 16 00:20:13 2004 +0000 @@ -2,12 +2,14 @@ #include #include -#include +//#include #include +#include #include #include //#include -#include +#include +#include using namespace lemon; @@ -15,7 +17,9 @@ using std::endl; int main() { - typedef SageGraph Graph; + // typedef SageGraph Graph; + typedef SmartGraph Graph ; + //typedef ListGraph Graph; typedef Graph::Node Node; typedef Graph::NodeIt NodeIt; typedef Graph::Edge Edge; @@ -23,12 +27,8 @@ typedef Graph::OutEdgeIt OutEdgeIt; Graph g; - //Node s; - //Graph::EdgeMap cap(g); - //readDimacsMaxFlow(std::cin, g, s, t, cap); readDimacs(std::cin, g); - NodeIt s; - g.first(s); + NodeIt s(g); cout << g.nodeNum() << endl; cout << g.edgeNum() << endl; @@ -36,8 +36,9 @@ Graph::NodeMap pred(g); cout << "iteration time of bfs written by hand..." << endl; Timer ts; + ts.reset(); + for (int i=0; i<100; ++i) { - ts.reset(); Graph::NodeMap reached(g); reached.set(s, true); pred.set(s, INVALID); @@ -46,8 +47,7 @@ while (!bfs_queue.empty()) { Node v=bfs_queue.front(); bfs_queue.pop(); - OutEdgeIt e; - for(g.first(e,v); g.valid(e); g.next(e)) { + for(OutEdgeIt e(g,v); e!=INVALID; ++e) { Node w=g.head(e); if (!reached[w]) { bfs_queue.push(w); @@ -56,23 +56,35 @@ } } } - - std::cout << ts << std::endl; } + std::cout << ts << std::endl; cout << "iteration time with bfs iterator..." << endl; + ts.reset(); + for (int i=0; i<100; ++i) { - ts.reset(); - BfsIterator< Graph, Graph::NodeMap > bfs(g); + Graph::NodeMap reached(g); + marci::BfsIterator< Graph, Graph::NodeMap > bfs(g, reached); bfs.pushAndSetReached(s); pred.set(s, INVALID); while (!bfs.finished()) { ++bfs; - if (g.valid(bfs) && bfs.isBNodeNewlyReached()) + if (Graph::Edge(bfs)!=INVALID && bfs.isBNodeNewlyReached()) pred.set(bfs.head(), Graph::Edge(bfs)); } - std::cout << ts << std::endl; } + std::cout << ts << std::endl; + + cout << "iteration time with bfs aplar..." << endl; + ts.reset(); + for (int i=0; i<100; ++i) + { + Bfs bfs(g); + bfs.setPredMap(pred); + bfs.run(s); + } + std::cout << ts << std::endl; + return 0; }