marci@75: #include marci@75: #include marci@75: #include marci@75: marci@75: #include marci@75: #include marci@75: #include marci@75: marci@75: using namespace marci; marci@75: marci@75: int main (int, char*[]) marci@75: { marci@75: typedef ListGraph::NodeIt NodeIt; marci@75: typedef ListGraph::EdgeIt EdgeIt; marci@75: typedef ListGraph::EachNodeIt EachNodeIt; marci@75: typedef ListGraph::EachEdgeIt EachEdgeIt; marci@75: typedef ListGraph::OutEdgeIt OutEdgeIt; marci@75: typedef ListGraph::InEdgeIt InEdgeIt; marci@75: typedef ListGraph::SymEdgeIt SymEdgeIt; marci@75: marci@75: ListGraph G; marci@75: marci@75: NodeIt s=G.addNode(); marci@75: NodeIt v1=G.addNode(); marci@75: NodeIt v2=G.addNode(); marci@75: NodeIt v3=G.addNode(); marci@75: NodeIt v4=G.addNode(); marci@75: NodeIt t=G.addNode(); marci@75: marci@75: G.addEdge(s, v1); marci@75: G.addEdge(s, v2); marci@75: G.addEdge(v1, v2); marci@75: G.addEdge(v2, v1); marci@75: G.addEdge(v1, v3); marci@75: G.addEdge(v3, v2); marci@75: G.addEdge(v2, v4); marci@75: G.addEdge(v4, v3); marci@75: G.addEdge(v3, t); marci@75: G.addEdge(v4, t); marci@75: marci@75: std::cout << "bfs and dfs demo on the directed graph" << std::endl; marci@75: for(EachNodeIt i=G.first(); i.valid(); ++i) { marci@75: std::cout << i << ": "; marci@75: std::cout << "out edges: "; marci@75: for(OutEdgeIt j=G.first(i); j.valid(); ++j) marci@75: std::cout << j << " "; marci@75: std::cout << "in edges: "; marci@75: for(InEdgeIt j=G.first(i); j.valid(); ++j) marci@75: std::cout << j << " "; marci@75: std::cout << std::endl; marci@75: } marci@75: marci@75: { marci@75: std::cout << "iterator bfs demo 4 ..." << std::endl; marci@75: BfsIterator4< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap > bfs(G); marci@75: bfs.pushAndSetReached(s); marci@75: while (!bfs.finished()) { marci@75: if (OutEdgeIt(bfs).valid()) { marci@75: std::cout << "OutEdgeIt: " << bfs; marci@75: std::cout << " aNode: " << G.aNode(bfs); marci@75: std::cout << " bNode: " << G.bNode(bfs) << " "; marci@75: } else { marci@75: std::cout << "OutEdgeIt: " << "invalid"; marci@75: std::cout << " aNode: " << bfs.aNode(); marci@75: std::cout << " bNode: " << "invalid" << " "; marci@75: } marci@75: if (bfs.isBNodeNewlyReached()) { marci@75: std::cout << "bNodeIsNewlyReached "; marci@75: } else { marci@75: std::cout << "bNodeIsNotNewlyReached "; marci@75: } marci@75: if (bfs.isANodeExamined()) { marci@75: std::cout << "aNodeIsExamined "; marci@75: } else { marci@75: std::cout << "aNodeIsNotExamined "; marci@75: } marci@75: std::cout< CTGW; marci@75: CTGW wG(G); marci@75: marci@75: std::cout << "bfs and dfs demo on the directed graph" << std::endl; marci@75: for(CTGW::EachNodeIt i=wG.first(); i.valid(); ++i) { marci@75: std::cout << i << ": "; marci@75: std::cout << "out edges: "; marci@75: for(CTGW::OutEdgeIt j=wG.first(i); j.valid(); ++j) marci@75: std::cout << j << " "; marci@75: std::cout << "in edges: "; marci@75: for(CTGW::InEdgeIt j=wG.first(i); j.valid(); ++j) marci@75: std::cout << j << " "; marci@75: std::cout << std::endl; marci@75: } marci@75: marci@75: marci@75: { marci@75: std::cout << "iterator bfs demo 5 ..." << std::endl; marci@75: BfsIterator5< CTGW, CTGW::NodeMap > bfs(wG); marci@75: bfs.pushAndSetReached(s); marci@75: while (!bfs.finished()) { marci@75: if (OutEdgeIt(bfs).valid()) { marci@75: std::cout << "OutEdgeIt: " << bfs; marci@75: std::cout << " aNode: " << wG.aNode(bfs); marci@75: std::cout << " bNode: " << wG.bNode(bfs) << " "; marci@75: } else { marci@75: std::cout << "OutEdgeIt: " << "invalid"; marci@75: std::cout << " aNode: " << bfs.aNode(); marci@75: std::cout << " bNode: " << "invalid" << " "; marci@75: } marci@75: if (bfs.isBNodeNewlyReached()) { marci@75: std::cout << "bNodeIsNewlyReached "; marci@75: } else { marci@75: std::cout << "bNodeIsNotNewlyReached "; marci@75: } marci@75: if (bfs.isANodeExamined()) { marci@75: std::cout << "aNodeIsExamined "; marci@75: } else { marci@75: std::cout << "aNodeIsNotExamined "; marci@75: } marci@75: std::cout<