# HG changeset patch # User marci # Date 1078748947 0 # Node ID 4f54d89fa9d256865ad215007cb7ce0599cd938f # Parent ee17030e5f47afbe8ce660783a6b98abf8737458 a lot of interesting and very useful wrapper graphs diff -r ee17030e5f47 -r 4f54d89fa9d2 src/work/bfs_iterator.hh --- a/src/work/bfs_iterator.hh Sun Mar 07 19:33:34 2004 +0000 +++ b/src/work/bfs_iterator.hh Mon Mar 08 12:29:07 2004 +0000 @@ -623,10 +623,11 @@ }; - template */ > class BfsIterator5 { typedef typename GraphWrapper::NodeIt NodeIt; + typedef typename GraphWrapper::OutEdgeIt OutEdgeIt; GraphWrapper G; std::queue bfs_queue; ReachedMap& reached; @@ -640,6 +641,13 @@ BfsIterator5(const GraphWrapper& _G) : G(_G), reached(*(new ReachedMap(G /*, false*/))), own_reached_map(true) { } +// BfsIterator5(const typename GraphWrapper::BaseGraph& _G, +// ReachedMap& _reached) : +// G(_G), reached(_reached), +// own_reached_map(false) { } +// BfsIterator5(const typename GraphWrapper::BaseGraph& _G) : +// G(_G), reached(*(new ReachedMap(G /*, false*/))), +// own_reached_map(true) { } ~BfsIterator5() { if (own_reached_map) delete &reached; } void pushAndSetReached(NodeIt s) { reached.set(s, true); @@ -660,7 +668,7 @@ bfs_queue.push(s); } } - BfsIterator5& + BfsIterator5& operator++() { if (G.valid(actual_edge)/*.valid()*/) { /*++*/G.next(actual_edge); @@ -758,10 +766,11 @@ const std::stack& getDfsStack() const { return dfs_stack; } }; - template */ > class DfsIterator5 { typedef typename GraphWrapper::NodeIt NodeIt; + typedef typename GraphWrapper::OutEdgeIt OutEdgeIt; GraphWrapper G; std::stack dfs_stack; bool b_node_newly_reached; @@ -782,7 +791,7 @@ reached.set(s, true); dfs_stack.push(G.template first(s)); } - DfsIterator5& + DfsIterator5& operator++() { actual_edge=dfs_stack.top(); //actual_node=G.aNode(actual_edge); diff -r ee17030e5f47 -r 4f54d89fa9d2 src/work/iterator_bfs_demo.cc --- a/src/work/iterator_bfs_demo.cc Sun Mar 07 19:33:34 2004 +0000 +++ b/src/work/iterator_bfs_demo.cc Mon Mar 08 12:29:07 2004 +0000 @@ -7,16 +7,32 @@ #include using namespace hugo; +using std::cout; +using std::endl; +using std::string; + +template +class EdgeNameMap { + Graph& graph; + NodeNameMap& node_name_map; +public: + EdgeNameMap(Graph& _graph, NodeNameMap& _node_name_map) : + graph(_graph), node_name_map(_node_name_map) { } + string get(typename Graph::EdgeIt e) const { + return + (node_name_map.get(graph.tail(e))+"->"+node_name_map.get(graph.head(e))); + } +}; 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; + //typedef ListGraph::EachNodeIt EachNodeIt; + //typedef ListGraph::EachEdgeIt EachEdgeIt; + //typedef ListGraph::OutEdgeIt OutEdgeIt; + //typedef ListGraph::InEdgeIt InEdgeIt; + //typedef ListGraph::SymEdgeIt SymEdgeIt; ListGraph G; @@ -27,6 +43,14 @@ NodeIt v4=G.addNode(); NodeIt t=G.addNode(); + ListGraph::NodeMap node_name(G); + node_name.set(s, "s"); + node_name.set(v1, "v1"); + node_name.set(v2, "v2"); + node_name.set(v3, "v3"); + node_name.set(v4, "v4"); + node_name.set(t, "t"); + G.addEdge(s, v1); G.addEdge(s, v2); G.addEdge(v1, v2); @@ -38,123 +62,317 @@ 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; + cout << " /--> -------------> "<< endl; + cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl; + cout << " / | | / /-> \\ "<< endl; + cout << " / | | / | ^ \\ "<< endl; + cout << "s | | / | | \\-> t "<< endl; + cout << " \\ | | / | | /-> "<< endl; + cout << " \\ | --/ / | | / "<< endl; + cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl; + cout << " \\--> -------------> "<< endl; + +/* + { + cout << "iterator bfs demo 4 ..." << endl; + BfsIterator4< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap > bfs(G); + bfs.pushAndSetReached(s); + while (!bfs.finished()) { + if (OutEdgeIt(bfs).valid()) { + cout << "OutEdgeIt: " << bfs; + cout << " aNode: " << G.aNode(bfs); + cout << " bNode: " << G.bNode(bfs) << " "; + } else { + cout << "OutEdgeIt: " << "invalid"; + cout << " aNode: " << bfs.aNode(); + cout << " bNode: " << "invalid" << " "; } - + if (bfs.isBNodeNewlyReached()) { + cout << "bNodeIsNewlyReached "; + } else { + cout << "bNodeIsNotNewlyReached "; + } + if (bfs.isANodeExamined()) { + cout << "aNodeIsExamined "; + } else { + cout << "aNodeIsNotExamined "; + } + cout << endl; + ++bfs; + } + } + { - std::cout << "iterator bfs demo 4 ..." << std::endl; - BfsIterator4< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap > bfs(G); + cout << "iterator dfs demo 4 ..." << endl; + DfsIterator4< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap > dfs(G); + dfs.pushAndSetReached(s); + while (!dfs.finished()) { + ++dfs; + if (OutEdgeIt(dfs).valid()) { + cout << "OutEdgeIt: " << dfs; + cout << " aNode: " << G.aNode(dfs); + cout << " bNode: " << G.bNode(dfs) << " "; + } else { + cout << "OutEdgeIt: " << "invalid"; + cout << " aNode: " << dfs.aNode(); + cout << " bNode: " << "invalid" << " "; + } + if (dfs.isBNodeNewlyReached()) { + cout << "bNodeIsNewlyReached "; + } else { + cout << "bNodeIsNotNewlyReached "; + } + if (dfs.isANodeExamined()) { + cout << "aNodeIsExamined "; + } else { + cout << "aNodeIsNotExamined "; + } + cout << endl; + //++dfs; + } + } +*/ + +// typedef TrivGraphWrapper CGW; +// CGW wG(G); + +// cout << "bfs and dfs demo on the directed graph" << endl; +// for(CGW::EachNodeIt n=wG.first(); n.valid(); ++n) { +// cout << n << ": "; +// cout << "out edges: "; +// for(CGW::OutEdgeIt e=wG.first(n); e.valid(); ++e) +// cout << e << " "; +// cout << "in edges: "; +// for(CGW::InEdgeIt e=wG.first(n); e.valid(); ++e) +// cout << e << " "; +// cout << endl; +// } + + { + typedef TrivGraphWrapper GW; + GW wG(G); + + EdgeNameMap< GW, ListGraph::NodeMap > edge_name(wG, node_name); + + cout << "bfs and dfs iterator demo on the directed graph" << endl; + for(GW::EachNodeIt n=wG.first(); wG.valid(n); wG.next(n)) { + cout << node_name.get(n) << ": "; + cout << "out edges: "; + for(GW::OutEdgeIt e=wG.first(n); wG.valid(e); wG.next(e)) + cout << edge_name.get(e) << " "; + cout << "in edges: "; + for(GW::InEdgeIt e=wG.first(n); wG.valid(e); wG.next(e)) + cout << edge_name.get(e) << " "; + cout << endl; + } + + cout << "bfs from s ..." << endl; + BfsIterator5< GW, GW::NodeMap > bfs(wG); 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) << " "; + //cout << "edge: "; + if (wG.valid(bfs)) { + cout << edge_name.get(bfs) << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(wG.aNode(bfs)) << + (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ node_name.get(wG.bNode(bfs)) << + (bfs.isBNodeNewlyReached() ? ": is newly reached." : + ": is not newly reached."); } else { - std::cout << "OutEdgeIt: " << "invalid"; - std::cout << " aNode: " << bfs.aNode(); - std::cout << " bNode: " << "invalid" << " "; + cout << "invalid" << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(bfs.aNode()) << + (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ + "invalid."; } - if (bfs.isBNodeNewlyReached()) { - std::cout << "bNodeIsNewlyReached "; + cout << endl; + ++bfs; + } + + cout << " /--> -------------> "<< endl; + cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl; + cout << " / | | / /-> \\ "<< endl; + cout << " / | | / | ^ \\ "<< endl; + cout << "s | | / | | \\-> t "<< endl; + cout << " \\ | | / | | /-> "<< endl; + cout << " \\ | --/ / | | / "<< endl; + cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl; + cout << " \\--> -------------> "<< endl; + + cout << "dfs from s ..." << endl; + DfsIterator5< GW, GW::NodeMap > dfs(wG); + dfs.pushAndSetReached(s); + while (!dfs.finished()) { + ++dfs; + //cout << "edge: "; + if (wG.valid(dfs)) { + cout << edge_name.get(dfs) << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(wG.aNode(dfs)) << + (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ node_name.get(wG.bNode(dfs)) << + (dfs.isBNodeNewlyReached() ? ": is newly reached." : + ": is not newly reached."); } else { - std::cout << "bNodeIsNotNewlyReached "; - } - if (bfs.isANodeExamined()) { - std::cout << "aNodeIsExamined "; + cout << "invalid" << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(dfs.aNode()) << + (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ + "invalid."; + } + cout << endl; + } + } + + + { + typedef RevGraphWrapper GW; + GW wG(G); + + EdgeNameMap< GW, ListGraph::NodeMap > edge_name(wG, node_name); + + cout << "bfs and dfs iterator demo on the reversed directed graph" << endl; + for(GW::EachNodeIt n=wG.first(); wG.valid(n); wG.next(n)) { + cout << node_name.get(n) << ": "; + cout << "out edges: "; + for(GW::OutEdgeIt e=wG.first(n); wG.valid(e); wG.next(e)) + cout << edge_name.get(e) << " "; + cout << "in edges: "; + for(GW::InEdgeIt e=wG.first(n); wG.valid(e); wG.next(e)) + cout << edge_name.get(e) << " "; + cout << endl; + } + + cout << "bfs from t ..." << endl; + BfsIterator5< GW, GW::NodeMap > bfs(wG); + bfs.pushAndSetReached(t); + while (!bfs.finished()) { + //cout << "edge: "; + if (wG.valid(bfs)) { + cout << edge_name.get(bfs) << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(wG.aNode(bfs)) << + (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ node_name.get(wG.bNode(bfs)) << + (bfs.isBNodeNewlyReached() ? ": is newly reached." : + ": is not newly reached."); } else { - std::cout << "aNodeIsNotExamined "; - } - std::cout< -------------> "<< endl; + cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl; + cout << " / | | / /-> \\ "<< endl; + cout << " / | | / | ^ \\ "<< endl; + cout << "s | | / | | \\-> t "<< endl; + cout << " \\ | | / | | /-> "<< endl; + cout << " \\ | --/ / | | / "<< endl; + cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl; + cout << " \\--> -------------> "<< endl; + + cout << "dfs from t ..." << endl; + DfsIterator5< GW, GW::NodeMap > dfs(wG); + dfs.pushAndSetReached(t); + while (!dfs.finished()) { + ++dfs; + //cout << "edge: "; + if (wG.valid(dfs)) { + cout << edge_name.get(dfs) << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(wG.aNode(dfs)) << + (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ node_name.get(wG.bNode(dfs)) << + (dfs.isBNodeNewlyReached() ? ": is newly reached." : + ": is not newly reached."); + } else { + cout << "invalid" << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(dfs.aNode()) << + (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ + "invalid."; + } + cout << endl; + } } { - std::cout << "iterator dfs demo 4 ..." << std::endl; - DfsIterator4< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap > dfs(G); - dfs.pushAndSetReached(s); + typedef UndirGraphWrapper GW; + GW wG(G); + + EdgeNameMap< GW, ListGraph::NodeMap > edge_name(wG, node_name); + + cout << "bfs and dfs iterator demo on the undirected graph" << endl; + for(GW::EachNodeIt n=wG.first(); wG.valid(n); wG.next(n)) { + cout << node_name.get(n) << ": "; + cout << "out edges: "; + for(GW::OutEdgeIt e=wG.first(n); wG.valid(e); wG.next(e)) + cout << edge_name.get(e) << " "; + cout << "in edges: "; + for(GW::InEdgeIt e=wG.first(n); wG.valid(e); wG.next(e)) + cout << edge_name.get(e) << " "; + cout << endl; + } + + cout << "bfs from t ..." << endl; + BfsIterator5< GW, GW::NodeMap > bfs(wG); + bfs.pushAndSetReached(t); + while (!bfs.finished()) { + //cout << "edge: "; + if (wG.valid(GW::OutEdgeIt(bfs))) { + cout << edge_name.get(GW::OutEdgeIt(bfs)) << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(wG.aNode(bfs)) << + (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ node_name.get(wG.bNode(bfs)) << + (bfs.isBNodeNewlyReached() ? ": is newly reached." : + ": is not newly reached."); + } else { + cout << "invalid" << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(bfs.aNode()) << + (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ + "invalid."; + } + cout << endl; + ++bfs; + } + + cout << " /--> -------------> "<< endl; + cout << " / /-- v1 <-\\ /---- v3-\\ "<< endl; + cout << " / | | / /-> \\ "<< endl; + cout << " / | | / | ^ \\ "<< endl; + cout << "s | | / | | \\-> t "<< endl; + cout << " \\ | | / | | /-> "<< endl; + cout << " \\ | --/ / | | / "<< endl; + cout << " \\ \\-> v2 <--/ \\-- v4 -/ "<< endl; + cout << " \\--> -------------> "<< endl; + + cout << "dfs from t ..." << endl; + DfsIterator5< GW, GW::NodeMap > dfs(wG); + dfs.pushAndSetReached(t); while (!dfs.finished()) { ++dfs; - if (OutEdgeIt(dfs).valid()) { - std::cout << "OutEdgeIt: " << dfs; - std::cout << " aNode: " << G.aNode(dfs); - std::cout << " bNode: " << G.bNode(dfs) << " "; + //cout << "edge: "; + if (wG.valid(GW::OutEdgeIt(dfs))) { + cout << edge_name.get(GW::OutEdgeIt(dfs)) << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(wG.aNode(dfs)) << + (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ node_name.get(wG.bNode(dfs)) << + (dfs.isBNodeNewlyReached() ? ": is newly reached." : + ": is not newly reached."); } else { - std::cout << "OutEdgeIt: " << "invalid"; - std::cout << " aNode: " << dfs.aNode(); - std::cout << " bNode: " << "invalid" << " "; + cout << "invalid" << /*endl*/", " << + /*" aNode: " <<*/ node_name.get(dfs.aNode()) << + (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << + /*" bNode: " <<*/ + "invalid."; } - if (dfs.isBNodeNewlyReached()) { - std::cout << "bNodeIsNewlyReached "; - } else { - std::cout << "bNodeIsNotNewlyReached "; - } - if (dfs.isANodeExamined()) { - std::cout << "aNodeIsExamined "; - } else { - std::cout << "aNodeIsNotExamined "; - } - std::cout< CTGW; - CTGW wG(G); - - std::cout << "bfs and dfs demo on the directed graph" << std::endl; - for(CTGW::EachNodeIt i=wG.first(); i.valid(); ++i) { - std::cout << i << ": "; - std::cout << "out edges: "; - for(CTGW::OutEdgeIt j=wG.first(i); j.valid(); ++j) - std::cout << j << " "; - std::cout << "in edges: "; - for(CTGW::InEdgeIt j=wG.first(i); j.valid(); ++j) - std::cout << j << " "; - std::cout << std::endl; - } - - - { - std::cout << "iterator bfs demo 5 ..." << std::endl; - BfsIterator5< CTGW, CTGW::NodeMap > bfs(wG); - bfs.pushAndSetReached(s); - while (!bfs.finished()) { - if (OutEdgeIt(bfs).valid()) { - std::cout << "OutEdgeIt: " << bfs; - std::cout << " aNode: " << wG.aNode(bfs); - std::cout << " bNode: " << wG.bNode(bfs) << " "; - } else { - std::cout << "OutEdgeIt: " << "invalid"; - std::cout << " aNode: " << bfs.aNode(); - 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< class NodeMap : public Graph::NodeMap { public: NodeMap(const TrivGraphWrapper& _G) : - Graph::NodeMap(*(_G.G)) { } + Graph::NodeMap(_G.getGraph()) { } NodeMap(const TrivGraphWrapper& _G, T a) : - Graph::NodeMap(*(_G.G), a) { } + Graph::NodeMap(_G.getGraph(), a) { } }; template class EdgeMap : public Graph::EdgeMap { public: EdgeMap(const TrivGraphWrapper& _G) : - Graph::EdgeMap(*(_G.G)) { } + Graph::EdgeMap(_G.getGraph()) { } EdgeMap(const TrivGraphWrapper& _G, T a) : - Graph::EdgeMap(*(_G.G), a) { } + Graph::EdgeMap(_G.getGraph(), a) { } }; void setGraph(Graph& _graph) { graph = &_graph; } @@ -140,16 +140,16 @@ template class NodeMap : public Graph::NodeMap { public: NodeMap(const RevGraphWrapper& _G) : - Graph::NodeMap(*(_G.G)) { } + Graph::NodeMap(_G.getGraph()) { } NodeMap(const RevGraphWrapper& _G, T a) : - Graph::NodeMap(*(_G.G), a) { } + Graph::NodeMap(_G.getGraph(), a) { } }; template class EdgeMap : public Graph::EdgeMap { public: EdgeMap(const RevGraphWrapper& _G) : - Graph::EdgeMap(*(_G.G)) { } + Graph::EdgeMap(_G.getGraph()) { } EdgeMap(const RevGraphWrapper& _G, T a) : - Graph::EdgeMap(*(_G.G), a) { } + Graph::EdgeMap(_G.getGraph(), a) { } }; void setGraph(Graph& _graph) { graph = &_graph; } @@ -160,6 +160,150 @@ }; + template + class UndirGraphWrapper { + Graph* graph; + + public: + typedef Graph BaseGraph; + + typedef typename Graph::NodeIt NodeIt; + typedef typename Graph::EachNodeIt EachNodeIt; + + //typedef typename Graph::EdgeIt EdgeIt; + //typedef typename Graph::OutEdgeIt OutEdgeIt; + //typedef typename Graph::InEdgeIt InEdgeIt; + //typedef typename Graph::SymEdgeIt SymEdgeIt; + //typedef typename Graph::EachEdgeIt EachEdgeIt; + + //private: + typedef typename Graph::EdgeIt GraphEdgeIt; + typedef typename Graph::OutEdgeIt GraphOutEdgeIt; + typedef typename Graph::InEdgeIt GraphInEdgeIt; + //public: + + class EdgeIt { + friend class UndirGraphWrapper; + bool out_or_in; //true iff out + GraphOutEdgeIt out; + GraphInEdgeIt in; + public: + EdgeIt() : out_or_in(true), out(), in() { } + operator GraphEdgeIt() const { + if (out_or_in) return(out); else return(in); + } + }; + + class OutEdgeIt : public EdgeIt { + friend class UndirGraphWrapper; + //bool out_or_in; //true iff out + //GraphOutEdgeIt out; + //GraphInEdgeIt in; + public: + OutEdgeIt() : EdgeIt() { } + OutEdgeIt(const UndirGraphWrapper& _G, const NodeIt& n) : EdgeIt() { + _G.graph->getFirst(out, n); + if (!(_G.graph->valid(out))) { + out_or_in=false; + _G.graph->getFirst(in, n); + } + } + }; + + OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const { + e.out_or_in=true; + graph->getFirst(e.out, n); + if (!(graph->valid(e.out))) { + e.out_or_in=false; + graph->getFirst(e.in, n); + } + return e; + } + + OutEdgeIt& next(OutEdgeIt& e) const { + if (e.out_or_in) { + NodeIt n=graph->tail(e.out); + graph->next(e.out); + if (!graph->valid(e.out)) { + e.out_or_in=false; + graph->getFirst(e.in, n); + } + } else { + graph->next(e.in); + } + return e; + } + + NodeIt aNode(const OutEdgeIt& e) const { + if (e.out_or_in) return graph->tail(e); else return graph->head(e); } + NodeIt bNode(const OutEdgeIt& e) const { + if (e.out_or_in) return graph->head(e); else return graph->tail(e); } + + typedef OutEdgeIt InEdgeIt; + + template I& getFirst(I& i) const { return graph->getFirst(i); } +// template I& getFirst(I& i, const P& p) const { +// return graph->getFirst(i, p); } + + template I getNext(const I& i) const { + return graph->getNext(i); } + template I& next(I &i) const { return graph->next(i); } + + template< typename It > It first() const { + It e; getFirst(e); return e; } + + template< typename It > It first(const NodeIt& v) const { + It e; getFirst(e, v); return e; } + + NodeIt head(const EdgeIt& e) const { return graph->head(e); } + NodeIt tail(const EdgeIt& e) const { return graph->tail(e); } + + template bool valid(const I& i) const + { return graph->valid(i); } + + //template void setInvalid(const I &i); + //{ return graph->setInvalid(i); } + + int nodeNum() const { return graph->nodeNum(); } + int edgeNum() const { return graph->edgeNum(); } + +// template NodeIt aNode(const I& e) const { +// return graph->aNode(e); } +// template NodeIt bNode(const I& e) const { +// return graph->bNode(e); } + + NodeIt addNode() const { return graph->addNode(); } + EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const { + return graph->addEdge(tail, head); } + + template void erase(const I& i) const { graph->erase(i); } + + void clear() const { graph->clear(); } + + template class NodeMap : public Graph::NodeMap { + public: + NodeMap(const UndirGraphWrapper& _G) : + Graph::NodeMap(_G.getGraph()) { } + NodeMap(const UndirGraphWrapper& _G, T a) : + Graph::NodeMap(_G.getGraph(), a) { } + }; + template class EdgeMap : public Graph::EdgeMap { + public: + EdgeMap(const UndirGraphWrapper& _G) : + Graph::EdgeMap(_G.getGraph()) { } + EdgeMap(const UndirGraphWrapper& _G, T a) : + Graph::EdgeMap(_G.getGraph(), a) { } + }; + + void setGraph(Graph& _graph) { graph = &_graph; } + Graph& getGraph() const { return (*graph); } + + //TrivGraphWrapper() : graph(0) { } + UndirGraphWrapper(Graph& _graph) : graph(&_graph) { } + }; + + + // template // class SymGraphWrapper // { @@ -247,6 +391,8 @@ G(&_G), flow(&_flow), capacity(&_capacity) { } // ResGraphWrapper(const ResGraphWrapper& res_graph_wrapper) : // G(res_graph_wrapper.G), flow(res_graph_wrapper.flow), capacity(res_graph_wrapper.capacity) { } + void setGraph(Graph& _graph) { graph = &_graph; } + Graph& getGraph() const { return (*graph); } class EdgeIt; class OutEdgeIt; friend class EdgeIt; @@ -499,9 +645,9 @@ template class NodeMap : public Graph::NodeMap { public: NodeMap(const ResGraphWrapper& _G) - : Graph::NodeMap(*(_G.G)) { } + : Graph::NodeMap(_G.getGraph()) { } NodeMap(const ResGraphWrapper& _G, - T a) : Graph::NodeMap(*(_G.G), a) { } + T a) : Graph::NodeMap(_G.getGraph(), a) { } }; // template @@ -518,8 +664,8 @@ class EdgeMap { typename Graph::EdgeMap forward_map, backward_map; public: - EdgeMap(const ResGraphWrapper& _G) : forward_map(*(_G.G)), backward_map(*(_G.G)) { } - EdgeMap(const ResGraphWrapper& _G, T a) : forward_map(*(_G.G), a), backward_map(*(_G.G), a) { } + EdgeMap(const ResGraphWrapper& _G) : forward_map(_G.getGraph()), backward_map(_G.getGraph()) { } + EdgeMap(const ResGraphWrapper& _G, T a) : forward_map(_G.getGraph(), a), backward_map(_G.getGraph(), a) { } void set(EdgeIt e, T a) { if (e.out_or_in) forward_map.set(e.out, a);