# HG changeset patch # User marci # Date 1081335478 0 # Node ID 54e07057eb47f084e94518e8162e51126935d317 # Parent 6635b11938feeaaa570143bd714dbd3990c78f3d gw diff -r 6635b11938fe -r 54e07057eb47 src/work/marci/edmonds_karp.h --- a/src/work/marci/edmonds_karp.h Tue Apr 06 12:00:34 2004 +0000 +++ b/src/work/marci/edmonds_karp.h Wed Apr 07 10:57:58 2004 +0000 @@ -274,8 +274,7 @@ ResGW res_graph(*g, *flow, *capacity); bool _augment=false; - typedef typename ResGW::NodeMap ReachedMap; - BfsIterator5< ResGW, ReachedMap > bfs(res_graph); + BfsIterator5< ResGW, typename ResGW::NodeMap > bfs(res_graph); bfs.pushAndSetReached(s); typename ResGW::NodeMap pred(res_graph); @@ -339,8 +338,7 @@ ResGW res_graph(*g, *flow, *capacity); - typedef typename ResGW::NodeMap ReachedMap; - BfsIterator5< ResGW, ReachedMap > bfs(res_graph); + BfsIterator5< ResGW, typename ResGW::NodeMap > bfs(res_graph); bfs.pushAndSetReached(s); //typename ResGW::NodeMap dist(res_graph); //filled up with 0's @@ -391,8 +389,8 @@ while (__augment) { __augment=false; //computing blocking flow with dfs - typedef typename TrivGraphWrapper::NodeMap BlockingReachedMap; - DfsIterator5< TrivGraphWrapper, BlockingReachedMap > dfs(F); + + DfsIterator5< MG, typename MG::NodeMap > dfs(F); typename MG::NodeMap pred(F); pred.set(sF, INVALID); //invalid iterators for sources @@ -450,8 +448,7 @@ ResGW res_graph(*g, *flow, *capacity); //bfs for distances on the residual graph - typedef typename ResGW::NodeMap ReachedMap; - BfsIterator5< ResGW, ReachedMap > bfs(res_graph); + BfsIterator5< ResGW, typename ResGW::NodeMap > bfs(res_graph); bfs.pushAndSetReached(s); typename ResGW::NodeMap dist(res_graph); //filled up with 0's @@ -499,8 +496,7 @@ while (__augment) { __augment=false; //computing blocking flow with dfs - typedef typename TrivGraphWrapper::NodeMap BlockingReachedMap; - DfsIterator5< TrivGraphWrapper, BlockingReachedMap > dfs(F); + DfsIterator5< MG, typename MG::NodeMap > dfs(F); typename MG::NodeMap pred(F); pred.set(sF, INVALID); //invalid iterators for sources @@ -556,8 +552,7 @@ ResGW res_graph(*g, *flow, *capacity); - typedef typename ResGW::NodeMap ReachedMap; - BfsIterator5< ResGW, ReachedMap > bfs(res_graph); + BfsIterator5< ResGW, typename ResGW::NodeMap > bfs(res_graph); bfs.pushAndSetReached(s); DistanceMap dist(res_graph); @@ -597,8 +592,7 @@ __augment=false; //computing blocking flow with dfs - typedef typename ErasingResGW::NodeMap BlockingReachedMap; - DfsIterator5< ErasingResGW, BlockingReachedMap > + DfsIterator5< ErasingResGW, typename ErasingResGW::NodeMap > dfs(erasing_res_graph); typename ErasingResGW::NodeMap pred(erasing_res_graph); diff -r 6635b11938fe -r 54e07057eb47 src/work/marci/graph_wrapper.h --- a/src/work/marci/graph_wrapper.h Tue Apr 06 12:00:34 2004 +0000 +++ b/src/work/marci/graph_wrapper.h Wed Apr 07 10:57:58 2004 +0000 @@ -6,158 +6,154 @@ namespace hugo { - template - class TrivGraphWrapper { - protected: - Graph* graph; +// template +// class TrivGraphWrapper { +// protected: +// Graph* graph; - public: -// typedef Graph BaseGraph; - typedef Graph ParentGraph; +// public: +// // typedef Graph BaseGraph; +// typedef Graph ParentGraph; -// TrivGraphWrapper() : graph(0) { } - TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } -// void setGraph(Graph& _graph) { graph = &_graph; } -// Graph& getGraph() const { return *graph; } +// // TrivGraphWrapper() : graph(0) { } +// TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } +// // void setGraph(Graph& _graph) { graph = &_graph; } +// // Graph& getGraph() const { return *graph; } - typedef typename Graph::Node Node; - class NodeIt : public Graph::NodeIt { - public: - NodeIt() { } - NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { } -// NodeIt(const typename BaseGraph::NodeIt& n) : Graph::NodeIt(n) { } - NodeIt(const Invalid& i) : Graph::NodeIt(i) { } - NodeIt(const TrivGraphWrapper& _G) : - Graph::NodeIt(*(_G.graph)) { } -// operator typename BaseGraph::NodeIt() { -// return typename BaseGraph::NodeIt(this->Graph::NodeIt); -// } - }; - typedef typename Graph::Edge Edge; - class OutEdgeIt : public Graph::OutEdgeIt { - public: - OutEdgeIt() { } - OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { } - OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { } - OutEdgeIt(const TrivGraphWrapper& _G, const Node& n) : - Graph::OutEdgeIt(*(_G.graph), n) { } - }; - class InEdgeIt : public Graph::InEdgeIt { - public: - InEdgeIt() { } - InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { } - InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { } - InEdgeIt(const TrivGraphWrapper& _G, const Node& n) : - Graph::InEdgeIt(*(_G.graph), n) { } - }; - //typedef typename Graph::SymEdgeIt SymEdgeIt; - class EdgeIt : public Graph::EdgeIt { - public: - EdgeIt() { } - EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { } - EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { } - EdgeIt(const TrivGraphWrapper& _G) : - Graph::EdgeIt(*(_G.graph)) { } - }; +// typedef typename Graph::Node Node; +// class NodeIt : public Graph::NodeIt { +// public: +// NodeIt() { } +// NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { } +// NodeIt(const Invalid& i) : Graph::NodeIt(i) { } +// NodeIt(const TrivGraphWrapper& _G) : +// Graph::NodeIt(*(_G.graph)) { } +// }; +// typedef typename Graph::Edge Edge; +// class OutEdgeIt : public Graph::OutEdgeIt { +// public: +// OutEdgeIt() { } +// OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { } +// OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { } +// OutEdgeIt(const TrivGraphWrapper& _G, const Node& n) : +// Graph::OutEdgeIt(*(_G.graph), n) { } +// }; +// class InEdgeIt : public Graph::InEdgeIt { +// public: +// InEdgeIt() { } +// InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { } +// InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { } +// InEdgeIt(const TrivGraphWrapper& _G, const Node& n) : +// Graph::InEdgeIt(*(_G.graph), n) { } +// }; +// //typedef typename Graph::SymEdgeIt SymEdgeIt; +// class EdgeIt : public Graph::EdgeIt { +// public: +// EdgeIt() { } +// EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { } +// EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { } +// EdgeIt(const TrivGraphWrapper& _G) : +// Graph::EdgeIt(*(_G.graph)) { } +// }; - NodeIt& first(NodeIt& i) const { - i=NodeIt(*this); - return i; - } -// template I& first(I& i) const { -// i=I(*this); +// NodeIt& first(NodeIt& i) const { +// i=NodeIt(*this); // return i; // } - OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { - i=OutEdgeIt(*this, p); - return i; - } - InEdgeIt& first(InEdgeIt& i, const Node& p) const { - i=InEdgeIt(*this, p); - return i; - } - EdgeIt& first(EdgeIt& i) const { - i=EdgeIt(*this); - return i; - } -// template I& first(I& i, const P& p) const { -// i=I(*this, p); +// OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { +// i=OutEdgeIt(*this, p); // return i; // } +// InEdgeIt& first(InEdgeIt& i, const Node& p) const { +// i=InEdgeIt(*this, p); +// return i; +// } +// EdgeIt& first(EdgeIt& i) const { +// i=EdgeIt(*this); +// return i; +// } +// // template I& first(I& i) const { +// // i=I(*this); +// // return i; +// // } +// // template I& first(I& i, const P& p) const { +// // i=I(*this, p); +// // return i; +// // } -// template I getNext(const I& i) const { -// return graph->getNext(i); } -// template I& next(I &i) const { graph->next(i); return i; } - NodeIt& next(NodeIt& i) const { graph->next(i); return i; } - OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i); return i; } - InEdgeIt& next(InEdgeIt& i) const { graph->next(i); return i; } - EdgeIt& next(EdgeIt& i) const { graph->next(i); return i; } +// // template I getNext(const I& i) const { +// // return graph->getNext(i); } - template< typename It > It first() const { - It e; this->first(e); return e; } +// NodeIt& next(NodeIt& i) const { graph->next(i); return i; } +// OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i); return i; } +// InEdgeIt& next(InEdgeIt& i) const { graph->next(i); return i; } +// EdgeIt& next(EdgeIt& i) const { graph->next(i); return i; } +// // template I& next(I &i) const { graph->next(i); return i; } +// template< typename It > It first() const { +// It e; this->first(e); return e; } - template< typename It > It first(const Node& v) const { - It e; this->first(e, v); return e; } +// template< typename It > It first(const Node& v) const { +// It e; this->first(e, v); return e; } - Node head(const Edge& e) const { return graph->head(e); } - Node tail(const Edge& e) const { return graph->tail(e); } +// Node head(const Edge& e) const { return graph->head(e); } +// Node tail(const Edge& e) const { return graph->tail(e); } - template bool valid(const I& i) const { - return graph->valid(i); } +// template bool valid(const I& i) const { +// return graph->valid(i); } - //template void setInvalid(const I &i); - //{ return graph->setInvalid(i); } +// //template void setInvalid(const I &i); +// //{ return graph->setInvalid(i); } - int nodeNum() const { return graph->nodeNum(); } - int edgeNum() const { return graph->edgeNum(); } +// int nodeNum() const { return graph->nodeNum(); } +// int edgeNum() const { return graph->edgeNum(); } - template Node aNode(const I& e) const { - return graph->aNode(e); } - template Node bNode(const I& e) const { - return graph->bNode(e); } +// template Node aNode(const I& e) const { +// return graph->aNode(e); } +// template Node bNode(const I& e) const { +// return graph->bNode(e); } - Node addNode() const { return graph->addNode(); } - Edge addEdge(const Node& tail, const Node& head) const { - return graph->addEdge(tail, head); } +// Node addNode() const { return graph->addNode(); } +// Edge addEdge(const Node& tail, const Node& head) const { +// return graph->addEdge(tail, head); } - template void erase(const I& i) const { graph->erase(i); } +// template void erase(const I& i) const { graph->erase(i); } - void clear() const { graph->clear(); } +// void clear() const { graph->clear(); } - template class NodeMap : public Graph::NodeMap { - public: - NodeMap(const TrivGraphWrapper& _G) : - Graph::NodeMap(*(_G.graph)) { } - NodeMap(const TrivGraphWrapper& _G, T a) : - Graph::NodeMap(*(_G.graph), a) { } - }; - - template class EdgeMap : public Graph::EdgeMap { - public: - EdgeMap(const TrivGraphWrapper& _G) : - Graph::EdgeMap(*(_G.graph)) { } - EdgeMap(const TrivGraphWrapper& _G, T a) : - Graph::EdgeMap(*(_G.graph), a) { } - }; - -// template class NodeMapWrapper { -// protected: -// Map* map; +// template class NodeMap : public Graph::NodeMap { // public: -// NodeMapWrapper(Map& _map) : map(&_map) { } -// void set(Node n, T a) { map->set(n, a); } -// T get(Node n) const { return map->get(n); } +// NodeMap(const TrivGraphWrapper& _G) : +// Graph::NodeMap(*(_G.graph)) { } +// NodeMap(const TrivGraphWrapper& _G, T a) : +// Graph::NodeMap(*(_G.graph), a) { } // }; -// template class EdgeMapWrapper { -// protected: -// Map* map; +// template class EdgeMap : public Graph::EdgeMap { // public: -// EdgeMapWrapper(Map& _map) : map(&_map) { } -// void set(Edge n, T a) { map->set(n, a); } -// T get(Edge n) const { return map->get(n); } +// EdgeMap(const TrivGraphWrapper& _G) : +// Graph::EdgeMap(*(_G.graph)) { } +// EdgeMap(const TrivGraphWrapper& _G, T a) : +// Graph::EdgeMap(*(_G.graph), a) { } // }; - }; + +// // template class NodeMapWrapper { +// // protected: +// // Map* map; +// // public: +// // NodeMapWrapper(Map& _map) : map(&_map) { } +// // void set(Node n, T a) { map->set(n, a); } +// // T get(Node n) const { return map->get(n); } +// // }; + +// // template class EdgeMapWrapper { +// // protected: +// // Map* map; +// // public: +// // EdgeMapWrapper(Map& _map) : map(&_map) { } +// // void set(Edge n, T a) { map->set(n, a); } +// // T get(Edge n) const { return map->get(n); } +// // }; +// }; template @@ -176,48 +172,64 @@ typedef typename Graph::Node Node; class NodeIt : public Graph::NodeIt { + typedef typename Graph::NodeIt GraphNodeIt; public: NodeIt() { } NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { } NodeIt(const Invalid& i) : Graph::NodeIt(i) { } NodeIt(const GraphWrapper& _G) : Graph::NodeIt(*(_G.graph)) { } +// operator Node() const { +// std::cout << "ize" << std::endl; +// return Node(this->GraphNodeIt); +// } }; typedef typename Graph::Edge Edge; class OutEdgeIt : public Graph::OutEdgeIt { + typedef typename Graph::OutEdgeIt GraphOutEdgeIt; public: OutEdgeIt() { } OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { } OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { } OutEdgeIt(const GraphWrapper& _G, const Node& n) : Graph::OutEdgeIt(*(_G.graph), n) { } +// operator Edge() const { +// std::cout << "ize" << std::endl; +// return Edge(this->GraphOutEdgeIt); +// } }; class InEdgeIt : public Graph::InEdgeIt { + typedef typename Graph::InEdgeIt GraphInEdgeIt; public: InEdgeIt() { } InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { } InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { } InEdgeIt(const GraphWrapper& _G, const Node& n) : Graph::InEdgeIt(*(_G.graph), n) { } +// operator Edge() const { +// std::cout << "ize" << std::endl; +// return Edge(this->InOutEdgeIt); +// } }; //typedef typename Graph::SymEdgeIt SymEdgeIt; class EdgeIt : public Graph::EdgeIt { + typedef typename Graph::EdgeIt GraphEdgeIt; public: EdgeIt() { } EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { } EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { } EdgeIt(const GraphWrapper& _G) : Graph::EdgeIt(*(_G.graph)) { } +// operator Edge() const { +// std::cout << "ize" << std::endl; +// return Edge(this->GraphEdgeIt); +// } }; NodeIt& first(NodeIt& i) const { i=NodeIt(*this); return i; } -// template I& first(I& i) const { -// i=I(*this); -// return i; -// } OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { i=OutEdgeIt(*this, p); return i; @@ -230,6 +242,10 @@ i=EdgeIt(*this); return i; } +// template I& first(I& i) const { +// i=I(*this); +// return i; +// } // template I& first(I& i, const P& p) const { // i=I(*this, p); // return i; @@ -237,12 +253,12 @@ // template I getNext(const I& i) const { // return gw.getNext(i); } -// template I& next(I &i) const { graph->next(i); return i; } + NodeIt& next(NodeIt& i) const { graph->next(i); return i; } OutEdgeIt& next(OutEdgeIt& i) const { graph->next(i); return i; } InEdgeIt& next(InEdgeIt& i) const { graph->next(i); return i; } EdgeIt& next(EdgeIt& i) const { graph->next(i); return i; } - +// template I& next(I &i) const { graph->next(i); return i; } template< typename It > It first() const { It e; this->first(e); return e; } @@ -251,6 +267,7 @@ Node head(const Edge& e) const { return graph->head(e); } Node tail(const Edge& e) const { return graph->tail(e); } +// Node tail(const OutEdgeIt& e) const { return graph->tail(Edge(e)); } template bool valid(const I& i) const { return graph->valid(i); } diff -r 6635b11938fe -r 54e07057eb47 src/work/marci/iterator_bfs_demo.cc --- a/src/work/marci/iterator_bfs_demo.cc Tue Apr 06 12:00:34 2004 +0000 +++ b/src/work/marci/iterator_bfs_demo.cc Wed Apr 07 10:57:58 2004 +0000 @@ -88,33 +88,30 @@ // } { - typedef TrivGraphWrapper GW; - GW gw(G); - - EdgeNameMap< GW, Graph::NodeMap > edge_name(gw, node_name); + EdgeNameMap< Graph, Graph::NodeMap > edge_name(G, node_name); cout << "bfs and dfs iterator demo on the directed graph" << endl; - for(GW::NodeIt n(gw); gw.valid(n); gw.next(n)) { + for(Graph::NodeIt n(G); G.valid(n); G.next(n)) { cout << node_name[n] << ": "; cout << "out edges: "; - for(GW::OutEdgeIt e(gw, n); gw.valid(e); gw.next(e)) + for(Graph::OutEdgeIt e(G, n); G.valid(e); G.next(e)) cout << edge_name[e] << " "; cout << "in edges: "; - for(GW::InEdgeIt e(gw, n); gw.valid(e); gw.next(e)) + for(Graph::InEdgeIt e(G, n); G.valid(e); G.next(e)) cout << edge_name[e] << " "; cout << endl; } cout << "bfs from s ..." << endl; - BfsIterator5< GW, GW::NodeMap > bfs(gw); + BfsIterator5< Graph, Graph::NodeMap > bfs(G); bfs.pushAndSetReached(s); while (!bfs.finished()) { //cout << "edge: "; - if (gw.valid(bfs)) { + if (G.valid(bfs)) { cout << edge_name[bfs] << /*endl*/", " << - node_name[gw.aNode(bfs)] << + node_name[G.aNode(bfs)] << (bfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << - node_name[gw.bNode(bfs)] << + node_name[G.bNode(bfs)] << (bfs.isBNodeNewlyReached() ? ": is newly reached." : ": is not newly reached."); } else { @@ -139,16 +136,16 @@ cout << " \\--> -------------> "<< endl; cout << "dfs from s ..." << endl; - DfsIterator5< GW, GW::NodeMap > dfs(gw); + DfsIterator5< Graph, Graph::NodeMap > dfs(G); dfs.pushAndSetReached(s); while (!dfs.finished()) { ++dfs; //cout << "edge: "; - if (gw.valid(dfs)) { + if (G.valid(dfs)) { cout << edge_name[dfs] << /*endl*/", " << - node_name[gw.aNode(dfs)] << + node_name[G.aNode(dfs)] << (dfs.isANodeExamined() ? ": is examined, " : ": is not examined, ") << - node_name[gw.bNode(dfs)] << + node_name[G.bNode(dfs)] << (dfs.isBNodeNewlyReached() ? ": is newly reached." : ": is not newly reached."); } else { @@ -164,7 +161,7 @@ { - typedef RevGraphWrapper > GW; + typedef RevGraphWrapper GW; GW gw(G); EdgeNameMap< GW, Graph::NodeMap > edge_name(gw, node_name); @@ -240,7 +237,7 @@ { //typedef UndirGraphWrapper GW; - typedef UndirGraphWrapper > GW; + typedef UndirGraphWrapper GW; GW gw(G); EdgeNameMap< GW, Graph::NodeMap > edge_name(gw, node_name);