// -*- c++ -*- #include #include #include #include #include #include //#include #include using namespace hugo; using std::cout; using std::endl; int main() { typedef SageGraph Graph; typedef Graph::Node Node; typedef Graph::NodeIt NodeIt; typedef Graph::Edge Edge; typedef Graph::EdgeIt EdgeIt; 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); cout << g.nodeNum() << endl; cout << g.edgeNum() << endl; Graph::NodeMap pred(g); cout << "iteration time of bfs written by hand..." << endl; Timer ts; { ts.reset(); Graph::NodeMap reached(g); reached.set(s, true); pred.set(s, INVALID); std::queue bfs_queue; bfs_queue.push(s); 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)) { Node w=g.head(e); if (!reached[w]) { bfs_queue.push(w); reached.set(w, true); pred.set(w, e); } } } std::cout << ts << std::endl; } cout << "iteration time with bfs iterator..." << endl; { ts.reset(); BfsIterator< Graph, Graph::NodeMap > bfs(g); bfs.pushAndSetReached(s); pred.set(s, INVALID); while (!bfs.finished()) { ++bfs; if (g.valid(bfs) && bfs.isBNodeNewlyReached()) pred.set(bfs.head(), Graph::Edge(bfs)); } std::cout << ts << std::endl; } return 0; }