marci@358: // -*- c++ -*- marci@358: #include marci@358: #include marci@358: marci@944: //#include alpar@921: #include marci@944: #include alpar@921: #include alpar@921: #include alpar@921: //#include marci@944: #include marci@944: #include marci@358: alpar@921: using namespace lemon; marci@358: marci@773: using std::cout; marci@773: using std::endl; marci@773: marci@358: int main() { marci@944: // typedef SageGraph Graph; marci@944: typedef SmartGraph Graph ; marci@944: //typedef ListGraph Graph; marci@358: typedef Graph::Node Node; marci@358: typedef Graph::NodeIt NodeIt; marci@358: typedef Graph::Edge Edge; marci@358: typedef Graph::EdgeIt EdgeIt; marci@358: typedef Graph::OutEdgeIt OutEdgeIt; marci@358: marci@577: Graph g; marci@577: readDimacs(std::cin, g); marci@944: NodeIt s(g); marci@773: marci@773: cout << g.nodeNum() << endl; marci@773: cout << g.edgeNum() << endl; marci@577: marci@777: Graph::NodeMap pred(g); marci@773: cout << "iteration time of bfs written by hand..." << endl; marci@358: Timer ts; marci@944: ts.reset(); marci@944: for (int i=0; i<100; ++i) marci@358: { marci@577: Graph::NodeMap reached(g); marci@358: reached.set(s, true); marci@358: pred.set(s, INVALID); marci@358: std::queue bfs_queue; marci@773: bfs_queue.push(s); marci@358: while (!bfs_queue.empty()) { marci@358: Node v=bfs_queue.front(); marci@358: bfs_queue.pop(); marci@944: for(OutEdgeIt e(g,v); e!=INVALID; ++e) { marci@577: Node w=g.head(e); marci@358: if (!reached[w]) { marci@358: bfs_queue.push(w); marci@358: reached.set(w, true); marci@358: pred.set(w, e); marci@358: } marci@358: } marci@358: } marci@358: } marci@944: std::cout << ts << std::endl; marci@358: marci@773: cout << "iteration time with bfs iterator..." << endl; marci@944: ts.reset(); marci@944: for (int i=0; i<100; ++i) marci@358: { marci@944: Graph::NodeMap reached(g); marci@944: marci::BfsIterator< Graph, Graph::NodeMap > bfs(g, reached); marci@358: bfs.pushAndSetReached(s); marci@358: pred.set(s, INVALID); marci@358: while (!bfs.finished()) { marci@358: ++bfs; marci@944: if (Graph::Edge(bfs)!=INVALID && bfs.isBNodeNewlyReached()) marci@777: pred.set(bfs.head(), Graph::Edge(bfs)); marci@358: } marci@358: } marci@944: std::cout << ts << std::endl; marci@944: marci@944: cout << "iteration time with bfs aplar..." << endl; marci@944: ts.reset(); marci@944: for (int i=0; i<100; ++i) marci@944: { marci@944: Bfs bfs(g); marci@944: bfs.setPredMap(pred); marci@944: bfs.run(s); marci@944: } marci@944: std::cout << ts << std::endl; marci@944: marci@358: marci@358: return 0; marci@358: }