diff -r ee5959aa4410 -r c280de819a73 src/work/iterator_bfs_dfs_demo.cc --- a/src/work/iterator_bfs_dfs_demo.cc Sun Apr 17 18:57:22 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,319 +0,0 @@ -#include -#include -#include - -#include -#include - -using namespace lemon; - -int main (int, char*[]) -{ - typedef ListGraph::NodeIt NodeIt; - typedef ListGraph::EdgeIt EdgeIt; - typedef ListGraph::EachNodeIt EachNodeIt; - typedef ListGraph::EachEdgeIt EachEdgeIt; - typedef ListGraph::OutEdgeIt OutEdgeIt; - typedef ListGraph::InEdgeIt InEdgeIt; - typedef ListGraph::SymEdgeIt SymEdgeIt; - - ListGraph G; - - NodeIt s=G.addNode(); - NodeIt v1=G.addNode(); - NodeIt v2=G.addNode(); - NodeIt v3=G.addNode(); - NodeIt v4=G.addNode(); - NodeIt t=G.addNode(); - - G.addEdge(s, v1); - G.addEdge(s, v2); - G.addEdge(v1, v2); - G.addEdge(v2, v1); - G.addEdge(v1, v3); - G.addEdge(v3, v2); - G.addEdge(v2, v4); - G.addEdge(v4, v3); - G.addEdge(v3, t); - G.addEdge(v4, t); - - std::cout << "bfs and dfs demo on the directed graph" << std::endl; - for(EachNodeIt i=G.first(); i.valid(); ++i) { - std::cout << i << ": "; - std::cout << "out edges: "; - for(OutEdgeIt j=G.first(i); j.valid(); ++j) - std::cout << j << " "; - std::cout << "in edges: "; - for(InEdgeIt j=G.first(i); j.valid(); ++j) - std::cout << j << " "; - std::cout << std::endl; - } - - //std::cout << std::endl; - //EachNodeIt u1=G.first(); - //EachEdgeIt u=G.first(); - //OutEdgeIt u=G.first(s); - //InEdgeIt u=G.first(s); - //SymEdgeIt u=G.first(s); - //OutEdgeIt u=G.first(s); - //EachNodeIt u=G.first(); - //EachEdgeIt u=G.first(); - //OutEdgeIt u=G.first(s); - //InEdgeIt u=G.first(s); - //SymEdgeIt u=G.first(s); - //u=G.first(s); - //u=G.first_ize(s, OutEdgeIt()); - //std::cout << "ize " << u << std::endl; - - /* - { - std::cout << "iterator bfs demo..." << std::endl; - NodePropertyVector reached(G, false); - reached.set(s, true); - std::queue bfs_queue; - bfs_queue.push(G.firstOutEdge(G.firstNode())); - BfsIterator< ListGraph, ListGraph::OutEdgeIt, NodePropertyVector > bfs(G, bfs_queue, reached); - for ( ; !bfs.finished(); ++bfs) { - if (OutEdgeIt(bfs).valid()) { - std::cout << "OutEdgeIt: " << bfs; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << G.bNode(bfs) << " "; - } else { - std::cout << "OutEdgeIt: " << "invalid"; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << "invalid" << " "; - } - if (bfs.bNodeIsNewlyReached()) { - std::cout << "bNodeIsNewlyReached "; - } else { - std::cout << "bNodeIsNotNewlyReached "; - } - if (bfs.aNodeIsExamined()) { - std::cout << "aNodeIsExamined "; - } else { - std::cout << "aNodeIsNotExamined "; - } - std::cout< reached(G, false); - reached.set(s, true); - std::stack dfs_stack; - dfs_stack.push(G.firstOutEdge(G.firstNode())); - DfsIterator< ListGraph, ListGraph::OutEdgeIt, NodePropertyVector > dfs(G, dfs_stack, reached); - for(; !dfs.finished(); ++dfs) { - if (OutEdgeIt(dfs).valid()) { - std::cout << "OutEdgeIt: " << dfs; - std::cout << " aNode: " << G.aNode(dfs); - std::cout << " bNode: " << G.bNode(dfs) << " "; - } else { - std::cout << "OutEdgeIt: " << "invalid"; - std::cout << " aNode: " << G.aNode(dfs); - std::cout << " bNode: " << "invalid" << " "; - } - if (dfs.bNodeIsNewlyReached()) { - std::cout << "bNodeIsNewlyReached "; - } else { - std::cout << "bNodeIsNotNewlyReached "; - } - if (dfs.aNodeIsLeaved()) { - std::cout << "aNodeIsLeaved "; - } else { - std::cout << "aNodeIsNotLeaved "; - } - std::cout< reached(G, false); - reached.set(s, true); - std::queue bfs_queue; - bfs_queue.push(G.first(s)); - BfsIterator1< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap > bfs(G, bfs_queue, reached); - while (!bfs.finished()) { - if (OutEdgeIt(bfs).valid()) { - std::cout << "OutEdgeIt: " << bfs; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << G.bNode(bfs) << " "; - } else { - std::cout << "OutEdgeIt: " << "invalid"; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << "invalid" << " "; - } - if (bfs.bNodeIsNewlyReached()) { - std::cout << "bNodeIsNewlyReached "; - } else { - std::cout << "bNodeIsNotNewlyReached "; - } - if (bfs.aNodeIsExamined()) { - std::cout << "aNodeIsExamined "; - } else { - std::cout << "aNodeIsNotExamined "; - } - std::cout< reached(G, false); - //reached.set(s, true); - //std::queue bfs_queue; - //bfs_queue.push(G.first(s)); - BfsIterator2< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap > bfs(G); - bfs.pushAndSetReached(s); - while (!bfs.finished()) { - if (OutEdgeIt(bfs).valid()) { - std::cout << "OutEdgeIt: " << bfs; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << G.bNode(bfs) << " "; - } else { - std::cout << "OutEdgeIt: " << "invalid"; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << "invalid" << " "; - } - if (bfs.isBNodeNewlyReached()) { - std::cout << "bNodeIsNewlyReached "; - } else { - std::cout << "bNodeIsNotNewlyReached "; - } - if (bfs.isANodeExamined()) { - std::cout << "aNodeIsExamined "; - } else { - std::cout << "aNodeIsNotExamined "; - } - std::cout< reached(G, false); - reached.set(s, true); - std::stack dfs_stack; - dfs_stack.push(G.first(s)); - DfsIterator1< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap > dfs(G, dfs_stack, reached); - do { - dfs.next(); - if (OutEdgeIt(dfs).valid()) { - std::cout << "OutEdgeIt: " << dfs; - std::cout << " aNode: " << G.aNode(dfs); - std::cout << " bNode: " << G.bNode(dfs) << " "; - } else { - std::cout << "OutEdgeIt: " << "invalid"; - std::cout << " aNode: " << G.aNode(dfs); - std::cout << " bNode: " << "invalid" << " "; - } - if (dfs.bNodeIsNewlyReached()) { - std::cout << "bNodeIsNewlyReached "; - } else { - std::cout << "bNodeIsNotNewlyReached "; - } - if (dfs.aNodeIsLeaved()) { - std::cout << "aNodeIsLeaved "; - } else { - std::cout << "aNodeIsNotLeaved "; - } - std::cout< reached(G, false); - reached.set(t, true); - std::queue bfs_queue; - bfs_queue.push(G.first(t)); - BfsIterator1< ListGraph, ListGraph::InEdgeIt, ListGraph::NodeMap > bfs(G, bfs_queue, reached); - while (!bfs.finished()) { - if (InEdgeIt(bfs).valid()) { - std::cout << "InEdgeIt: " << bfs; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << G.bNode(bfs) << " "; - } else { - std::cout << "InEdgeIt: " << "invalid"; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << "invalid" << " "; - } - if (bfs.bNodeIsNewlyReached()) { - std::cout << "bNodeIsNewlyReached "; - } else { - std::cout << "bNodeIsNotNewlyReached "; - } - if (bfs.aNodeIsExamined()) { - std::cout << "aNodeIsExamined "; - } else { - std::cout << "aNodeIsNotExamined "; - } - std::cout< reached(G, false); - reached.set(t, true); - std::queue bfs_queue; - bfs_queue.push(G.first(t)); - BfsIterator1< ListGraph, ListGraph::SymEdgeIt, ListGraph::NodeMap > bfs(G, bfs_queue, reached); - while (!bfs.finished()) { - if (SymEdgeIt(bfs).valid()) { - std::cout << "SymEdgeIt: " << bfs; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << G.bNode(bfs) << " "; - } else { - std::cout << "SymEdgeIt: " << "invalid"; - std::cout << " aNode: " << G.aNode(bfs); - std::cout << " bNode: " << "invalid" << " "; - } - if (bfs.bNodeIsNewlyReached()) { - std::cout << "bNodeIsNewlyReached "; - } else { - std::cout << "bNodeIsNotNewlyReached "; - } - if (bfs.aNodeIsExamined()) { - std::cout << "aNodeIsExamined "; - } else { - std::cout << "aNodeIsNotExamined "; - } - std::cout<