// -*-mode: c++; -*- #ifndef GRAPH_WRAPPER_H #define GRAPH_WRAPPER_H namespace hugo { template class TrivGraphWrapper { 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; //TrivGraphWrapper() : graph(0) { } TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } void setGraph(Graph& _graph) { graph = &_graph; } Graph& getGraph() const { return (*graph); } 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 TrivGraphWrapper& _G) : Graph::NodeMap(_G.getGraph()) { } NodeMap(const TrivGraphWrapper& _G, T a) : Graph::NodeMap(_G.getGraph(), a) { } }; template class EdgeMap : public Graph::EdgeMap { public: EdgeMap(const TrivGraphWrapper& _G) : Graph::EdgeMap(_G.getGraph()) { } EdgeMap(const TrivGraphWrapper& _G, T a) : Graph::EdgeMap(_G.getGraph(), a) { } }; }; template class RevGraphWrapper { 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 InEdgeIt; typedef typename Graph::InEdgeIt OutEdgeIt; //typedef typename Graph::SymEdgeIt SymEdgeIt; typedef typename Graph::EachEdgeIt EachEdgeIt; //RevGraphWrapper() : graph(0) { } RevGraphWrapper(Graph& _graph) : graph(&_graph) { } void setGraph(Graph& _graph) { graph = &_graph; } Graph& getGraph() const { return (*graph); } 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->tail(e); } NodeIt tail(const EdgeIt& e) const { return graph->head(e); } template bool valid(const I& i) const { return graph->valid(i); } //template void setInvalid(const I &i); //{ return graph->setInvalid(i); } 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); } int nodeNum() const { return graph->nodeNum(); } int edgeNum() const { return graph->edgeNum(); } template void erase(const I& i) const { graph->erase(i); } void clear() const { graph->clear(); } template class NodeMap : public Graph::NodeMap { public: NodeMap(const RevGraphWrapper& _G) : Graph::NodeMap(_G.getGraph()) { } NodeMap(const RevGraphWrapper& _G, T a) : Graph::NodeMap(_G.getGraph(), a) { } }; template class EdgeMap : public Graph::EdgeMap { public: EdgeMap(const RevGraphWrapper& _G) : Graph::EdgeMap(_G.getGraph()) { } EdgeMap(const RevGraphWrapper& _G, T a) : Graph::EdgeMap(_G.getGraph(), a) { } }; }; 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: //UndirGraphWrapper() : graph(0) { } UndirGraphWrapper(Graph& _graph) : graph(&_graph) { } void setGraph(Graph& _graph) { graph = &_graph; } Graph& getGraph() const { return (*graph); } 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; 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) { } }; }; // template // class SymGraphWrapper // { // Graph* graph; // public: // typedef Graph BaseGraph; // typedef typename Graph::NodeIt NodeIt; // typedef typename Graph::EdgeIt EdgeIt; // typedef typename Graph::EachNodeIt EachNodeIt; // //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon // //iranyitatlant, ami van // //mert csak 1 dolgot lehet be typedef-elni // typedef typename Graph::OutEdgeIt SymEdgeIt; // //typedef typename Graph::InEdgeIt SymEdgeIt; // //typedef typename Graph::SymEdgeIt SymEdgeIt; // typedef typename Graph::EachEdgeIt EachEdgeIt; // int nodeNum() const { return graph->nodeNum(); } // int edgeNum() const { return graph->edgeNum(); } // 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 next(const I i); { return graph->goNext(i); } // //template I &goNext(I &i); { return graph->goNext(i); } // template< typename It > It first() const { // It e; getFirst(e); return e; } // template< typename It > It first(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 NodeIt aNode(const I& e) const { // return graph->aNode(e); } // template NodeIt bNode(const I& e) const { // return graph->bNode(e); } // //template bool valid(const I i); // //{ return graph->valid(i); } // //template void setInvalid(const I &i); // //{ return graph->setInvalid(i); } // NodeIt addNode() { return graph->addNode(); } // EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) { // return graph->addEdge(tail, head); } // template void erase(const I& i) { graph->erase(i); } // void clear() { graph->clear(); } // template class NodeMap : public Graph::NodeMap { }; // template class EdgeMap : public Graph::EdgeMap { }; // void setGraph(Graph& _graph) { graph = &_graph; } // Graph& getGraph() { return (*graph); } // //SymGraphWrapper() : graph(0) { } // SymGraphWrapper(Graph& _graph) : graph(&_graph) { } // }; template class ResGraphWrapper { public: typedef Graph BaseGraph; typedef typename Graph::NodeIt NodeIt; typedef typename Graph::EachNodeIt EachNodeIt; private: typedef typename Graph::OutEdgeIt OldOutEdgeIt; typedef typename Graph::InEdgeIt OldInEdgeIt; const Graph* G; FlowMap* flow; const CapacityMap* capacity; public: ResGraphWrapper(const Graph& _G, FlowMap& _flow, const CapacityMap& _capacity) : 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(const Graph& _graph) { graph = &_graph; } const Graph& getGraph() const { return (*G); } class EdgeIt; class OutEdgeIt; friend class EdgeIt; friend class OutEdgeIt; class EdgeIt { friend class ResGraphWrapper; protected: bool out_or_in; //true, iff out OldOutEdgeIt out; OldInEdgeIt in; public: EdgeIt() : out_or_in(true) { } // bool valid() const { // return out_or_in && out.valid() || in.valid(); } }; class OutEdgeIt : public EdgeIt { friend class ResGraphWrapper; public: OutEdgeIt() { } //FIXME OutEdgeIt(const EdgeIt& e) : EdgeIt(e) { } private: OutEdgeIt(const ResGraphWrapper& resG, NodeIt v) : EdgeIt() { resG.G->getFirst(out, v); while( out.valid() && !(resG.free(out)>0) ) { ++out; } if (!out.valid()) { out_or_in=0; resG.G->getFirst(in, v); while( in.valid() && !(resG.free(in)>0) ) { ++in; } } } // public: // OutEdgeIt& operator++() { // if (out_or_in) { // NodeIt v=/*resG->*/G->aNode(out); // ++out; // while( out.valid() && !(EdgeIt::free()>0) ) { ++out; } // if (!out.valid()) { // out_or_in=0; // G->getFirst(in, v); // while( in.valid() && !(EdgeIt::free()>0) ) { ++in; } // } // } else { // ++in; // while( in.valid() && !(EdgeIt::free()>0) ) { ++in; } // } // return *this; // } }; class EachEdgeIt : public EdgeIt { friend class ResGraphWrapper; typename Graph::EachNodeIt v; public: EachEdgeIt() { } //EachEdgeIt(const EachEdgeIt& e) : EdgeIt(e), v(e.v) { } EachEdgeIt(const ResGraphWrapper& resG) : EdgeIt() { resG.G->getFirst(v); if (v.valid()) resG.G->getFirst(out, v); else out=OldOutEdgeIt(); while (out.valid() && !(resG.free(out)>0) ) { ++out; } while (v.valid() && !out.valid()) { ++v; if (v.valid()) resG.G->getFirst(out, v); while (out.valid() && !(resG.free(out)>0) ) { ++out; } } if (!out.valid()) { out_or_in=0; resG.G->getFirst(v); if (v.valid()) resG.G->getFirst(in, v); else in=OldInEdgeIt(); while (in.valid() && !(resG.free(in)>0) ) { ++in; } while (v.valid() && !in.valid()) { ++v; if (v.valid()) resG.G->getFirst(in, v); while (in.valid() && !(resG.free(in)>0) ) { ++in; } } } } // EachEdgeIt& operator++() { // if (out_or_in) { // ++out; // while (out.valid() && !(EdgeIt::free()>0) ) { ++out; } // while (v.valid() && !out.valid()) { // ++v; // if (v.valid()) G->getFirst(out, v); // while (out.valid() && !(EdgeIt::free()>0) ) { ++out; } // } // if (!out.valid()) { // out_or_in=0; // G->getFirst(v); // if (v.valid()) G->getFirst(in, v); else in=OldInEdgeIt(); // while (in.valid() && !(EdgeIt::free()>0) ) { ++in; } // while (v.valid() && !in.valid()) { // ++v; // if (v.valid()) G->getFirst(in, v); // while (in.valid() && !(EdgeIt::free()>0) ) { ++in; } // } // } // } else { // ++in; // while (in.valid() && !(EdgeIt::free()>0) ) { ++in; } // while (v.valid() && !in.valid()) { // ++v; // if (v.valid()) G->getFirst(in, v); // while (in.valid() && !(EdgeIt::free()>0) ) { ++in; } // } // } // return *this; // } }; EachNodeIt& getFirst(EachNodeIt& v) const { G->getFirst(v); } OutEdgeIt& getFirst(OutEdgeIt& e, NodeIt v) const { e=OutEdgeIt(*this, v); } EachEdgeIt& getFirst(EachEdgeIt& e) const { e=EachEdgeIt(*this); } EachNodeIt& next(EachNodeIt& n) const { return G->next(n); } OutEdgeIt& next(OutEdgeIt& e) const { if (e.out_or_in) { NodeIt v=G->aNode(e.out); ++(e.out); while( G->valid(e.out) && !(free(e.out)>0) ) { ++(e.out); } if (!G->valid(e.out)) { e.out_or_in=0; G->getFirst(e.in, v); while( G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); } } } else { ++(e.in); while( G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); } } return e; } EachEdgeIt& next(EachEdgeIt& e) const { if (e.out_or_in) { ++(e.out); while (G->valid(e.out) && !(free(e.out)>0) ) { ++(e.out); } while (G->valid(e.v) && !G->valid(e.out)) { ++(e.v); if (G->valid(e.v)) G->getFirst(e.out, e.v); while (G->valid(e.out) && !(free(e.out)>0) ) { ++(e.out); } } if (!G->valid(e.out)) { e.out_or_in=0; G->getFirst(e.v); if (G->valid(e.v)) G->getFirst(e.in, e.v); else e.in=OldInEdgeIt(); while (G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); } while (G->valid(e.v) && !G->valid(e.in)) { ++(e.v); if (G->valid(e.v)) G->getFirst(e.in, e.v); while (G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); } } } } else { ++(e.in); while (G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); } while (G->valid(e.v) && !G->valid(e.in)) { ++(e.v); if (G->valid(e.v)) G->getFirst(e.in, e.v); while (G->valid(e.in) && !(free(e.in)>0) ) { ++(e.in); } } } return e; } template< typename It > It first() const { It e; getFirst(e); return e; } template< typename It > It first(NodeIt v) const { It e; getFirst(e, v); return e; } NodeIt tail(EdgeIt e) const { return ((e.out_or_in) ? G->aNode(e.out) : G->aNode(e.in)); } NodeIt head(EdgeIt e) const { return ((e.out_or_in) ? G->bNode(e.out) : G->bNode(e.in)); } NodeIt aNode(OutEdgeIt e) const { return ((e.out_or_in) ? G->aNode(e.out) : G->aNode(e.in)); } NodeIt bNode(OutEdgeIt e) const { return ((e.out_or_in) ? G->bNode(e.out) : G->bNode(e.in)); } int id(NodeIt v) const { return G->id(v); } bool valid(NodeIt n) const { return G->valid(n); } bool valid(EdgeIt e) const { return e.out_or_in ? G->valid(e.out) : G->valid(e.in); } void augment(const EdgeIt& e, Number a) const { if (e.out_or_in) flow->set(e.out, flow->get(e.out)+a); else flow->set(e.in, flow->get(e.in)-a); } Number free(const EdgeIt& e) const { if (e.out_or_in) return (capacity->get(e.out)-flow->get(e.out)); else return (flow->get(e.in)); } Number free(OldOutEdgeIt out) const { return (capacity->get(out)-flow->get(out)); } Number free(OldInEdgeIt in) const { return (flow->get(in)); } template class NodeMap : public Graph::NodeMap { public: NodeMap(const ResGraphWrapper& _G) : Graph::NodeMap(_G.getGraph()) { } NodeMap(const ResGraphWrapper& _G, T a) : Graph::NodeMap(_G.getGraph(), a) { } }; // template // class NodeMap { // typename Graph::NodeMap node_map; // public: // NodeMap(const ResGraphWrapper& _G) : node_map(*(_G.G)) { } // NodeMap(const ResGraphWrapper& _G, T a) : node_map(*(_G.G), a) { } // void set(NodeIt nit, T a) { node_map.set(nit, a); } // T get(NodeIt nit) const { return node_map.get(nit); } // }; template class EdgeMap { typename Graph::EdgeMap forward_map, backward_map; public: 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); else backward_map.set(e.in, a); } T get(EdgeIt e) { if (e.out_or_in) return forward_map.get(e.out); else return backward_map.get(e.in); } }; }; template class ErasingResGraphWrapper : public ResGraphWrapper { protected: ResGraphWrapper::NodeMap::OutEdgeIt> first_out_edges; //ResGraphWrapper::NodeMap dist; public: ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow, const CapacityMap& _capacity) : ResGraphWrapper(_G, _flow, _capacity), first_out_edges(*this) /*, dist(*this)*/ { for(EachNodeIt n=this->template first(); this->valid(n); this->next(n)) { OutEdgeIt e; ResGraphWrapper::getFirst(e, n); first_out_edges.set(n, e); } } //void setGraph(Graph& _graph) { graph = &_graph; } //Graph& getGraph() const { return (*graph); } //TrivGraphWrapper() : graph(0) { } //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { } //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; typedef typename ResGraphWrapper::NodeIt NodeIt; typedef typename ResGraphWrapper::EachNodeIt EachNodeIt; typedef typename ResGraphWrapper::EdgeIt EdgeIt; typedef typename ResGraphWrapper::OutEdgeIt OutEdgeIt; //typedef typename ResGraphWrapper::InEdgeIt InEdgeIt; //typedef typename Graph::SymEdgeIt SymEdgeIt; //typedef typename ResGraphWrapper::EachEdgeIt EachEdgeIt; EachNodeIt& getFirst(EachNodeIt& n) const { return ResGraphWrapper::getFirst(n); } OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const { e=first_out_edges.get(n); return e; } //ROSSZ template I& getFirst(I& i) const { return getFirst(i); } //ROSSZ template I& getFirst(I& i, const P& p) const { // return 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); } //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); } //void erase(const OutEdgeIt& e) { // first_out_edge(this->tail(e))=e; //} void erase(const EdgeIt& e) { OutEdgeIt f(e); next(f); first_out_edges.set(this->tail(e), f); } //template void erase(const I& i) const { graph->erase(i); } //void clear() const { graph->clear(); } template class NodeMap : public ResGraphWrapper::NodeMap { public: NodeMap(const ErasingResGraphWrapper& _G) : ResGraphWrapper::NodeMap(_G /*_G.getGraph()*/) { } NodeMap(const ErasingResGraphWrapper& _G, T a) : ResGraphWrapper::NodeMap(_G /*_G.getGraph()*/, a) { } }; template class EdgeMap : public ResGraphWrapper::EdgeMap { public: EdgeMap(const ErasingResGraphWrapper& _G) : ResGraphWrapper::EdgeMap(_G /*_G.getGraph()*/) { } EdgeMap(const ErasingResGraphWrapper& _G, T a) : ResGraphWrapper::EdgeMap(_G /*_G.getGraph()*/, a) { } }; }; template class FilterGraphWrapper { }; template class FilterGraphWrapper > : public ErasingResGraphWrapper { //Graph* graph; public: //typedef Graph BaseGraph; typedef typename ErasingResGraphWrapper::NodeIt NodeIt; typedef typename ErasingResGraphWrapper::EachNodeIt EachNodeIt; typedef typename ErasingResGraphWrapper::EdgeIt EdgeIt; typedef typename ErasingResGraphWrapper::OutEdgeIt OutEdgeIt; //typedef typename ErasingResGraphWrapper::InEdgeIt InEdgeIt; //typedef typename Graph::SymEdgeIt SymEdgeIt; typedef typename ErasingResGraphWrapper::EachEdgeIt EachEdgeIt; //FilterGraphWrapper::NodeMap::OutEdgeIt> first_out_edges; public: FilterGraphWrapper(const Graph& _G, FlowMap& _flow, const CapacityMap& _capacity) : ErasingResGraphWrapper(_G, _flow, _capacity), dist(*this) { } OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const { ErasingResGraphWrapper::getFirst(e, n); while (valid(e) && (dist.get(tail(e))+1!=dist.get(head(e)))) ErasingResGraphWrapper::next(e); return e; } EachNodeIt& next(EachNodeIt& e) const { return ErasingResGraphWrapper::next(e); } OutEdgeIt& next(OutEdgeIt& e) const { ErasingResGraphWrapper::next(e); while (valid(e) && (dist.get(tail(e))+1!=dist.get(head(e)))) ErasingResGraphWrapper::next(e); return e; } EachNodeIt& getFirst(EachNodeIt& n) const { return ErasingResGraphWrapper::getFirst(n); } void erase(const EdgeIt& e) { OutEdgeIt f(e); ErasingResGraphWrapper::next(f); while (valid(f) && (dist.get(tail(f))+1!=dist.get(head(f)))) ErasingResGraphWrapper::next(f); first_out_edges.set(this->tail(e), f); } //TrivGraphWrapper() : graph(0) { } //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } //void setGraph(Graph& _graph) { graph = &_graph; } //Graph& getGraph() const { return (*graph); } //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 ErasingResGraphWrapper::NodeMap { public: NodeMap(const FilterGraphWrapper >& _G) : ErasingResGraphWrapper::NodeMap(_G /*_G.getGraph()*/) { } NodeMap(const FilterGraphWrapper >& _G, T a) : ErasingResGraphWrapper::NodeMap(_G /*_G.getGraph()*/, a) { } }; template class EdgeMap : public ErasingResGraphWrapper::EdgeMap { public: EdgeMap(const FilterGraphWrapper >& _G) : ErasingResGraphWrapper::EdgeMap(_G /*_G.getGraph()*/) { } EdgeMap(const FilterGraphWrapper >& _G, T a) : ErasingResGraphWrapper::EdgeMap(_G /*_G.getGraph()*/, a) { } }; public: ErasingResGraphWrapper::NodeMap dist; }; // // FIXME: comparison should be made better!!! // template // class ResGraphWrapper // { // Graph* graph; // public: // typedef Graph BaseGraph; // typedef typename Graph::NodeIt NodeIt; // typedef typename Graph::EdgeIt EdgeIt; // typedef typename Graph::EachNodeIt EachNodeIt; // class OutEdgeIt { // public: // //Graph::NodeIt n; // bool out_or_in; // typename Graph::OutEdgeIt o; // typename Graph::InEdgeIt i; // }; // class InEdgeIt { // public: // //Graph::NodeIt n; // bool out_or_in; // typename Graph::OutEdgeIt o; // typename Graph::InEdgeIt i; // }; // typedef typename Graph::SymEdgeIt SymEdgeIt; // typedef typename Graph::EachEdgeIt EachEdgeIt; // int nodeNum() const { return graph->nodeNum(); } // int edgeNum() const { return graph->edgeNum(); } // NodeIt& getFirst(NodeIt& n) const { return graph->getFirst(n); } // // EachEdge and SymEdge is missing!!!! // // EdgeIt <-> In/OutEdgeIt conversion is missing!!!! // //FIXME // OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const // { // e.n=n; // graph->getFirst(e.o,n); // while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o)) // graph->goNext(e.o); // if(!graph->valid(e.o)) { // graph->getFirst(e.i,n); // while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i)) // graph->goNext(e.i); // } // return e; // } // /* // OutEdgeIt &goNext(OutEdgeIt &e) // { // if(graph->valid(e.o)) { // while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o)) // graph->goNext(e.o); // if(graph->valid(e.o)) return e; // else graph->getFirst(e.i,e.n); // } // else { // while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i)) // graph->goNext(e.i); // return e; // } // } // OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);} // */ // //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);} // //FIXME // InEdgeIt& getFirst(InEdgeIt& e, const NodeIt& n) const // { // e.n=n; // graph->getFirst(e.i,n); // while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i)) // graph->goNext(e.i); // if(!graph->valid(e.i)) { // graph->getFirst(e.o,n); // while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o)) // graph->goNext(e.o); // } // return e; // } // /* // InEdgeIt &goNext(InEdgeIt &e) // { // if(graph->valid(e.i)) { // while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i)) // graph->goNext(e.i); // if(graph->valid(e.i)) return e; // else graph->getFirst(e.o,e.n); // } // else { // while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o)) // graph->goNext(e.o); // return e; // } // } // InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);} // */ // //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);} // //template I &goNext(I &i); { return graph->goNext(i); } // //template I next(const I i); { return graph->goNext(i); } // template< typename It > It first() const { // It e; getFirst(e); return e; } // template< typename It > It first(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 NodeIt aNode(const I& e) const { // return graph->aNode(e); } // template NodeIt bNode(const I& e) const { // return graph->bNode(e); } // //template bool valid(const I i); // //{ return graph->valid(i); } // //template void setInvalid(const I &i); // //{ return graph->setInvalid(i); } // NodeIt addNode() { return graph->addNode(); } // EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) { // return graph->addEdge(tail, head); } // template void erase(const I& i) { graph->erase(i); } // void clear() { graph->clear(); } // template class NodeMap : public Graph::NodeMap { }; // template class EdgeMap : public Graph::EdgeMap { }; // void setGraph(Graph& _graph) { graph = &_graph; } // Graph& getGraph() { return (*graph); } // //ResGraphWrapper() : graph(0) { } // ResGraphWrapper(Graph& _graph) : graph(&_graph) { } // }; } //namespace hugo #endif //GRAPH_WRAPPER_H