// -*- c++ -*- #ifndef GRAPH_WRAPPER_H #define GRAPH_WRAPPER_H #include namespace hugo { template class TrivGraphWrapper { Graph* graph; public: typedef Graph BaseGraph; typedef typename Graph::Node Node; typedef typename Graph::NodeIt NodeIt; typedef typename Graph::Edge Edge; typedef typename Graph::OutEdgeIt OutEdgeIt; typedef typename Graph::InEdgeIt InEdgeIt; //typedef typename Graph::SymEdgeIt SymEdgeIt; typedef typename Graph::EdgeIt EdgeIt; //TrivGraphWrapper() : graph(0) { } TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } void setGraph(Graph& _graph) { graph = &_graph; } Graph& getGraph() const { return (*graph); } template I& /*getF*/first(I& i) const { return graph->/*getF*/first(i); } template I& /*getF*/first(I& i, const P& p) const { return graph->/*getF*/first(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; /*getF*/first(e); return e; } template< typename It > It first(const Node& v) const { It e; /*getF*/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); } 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 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); } 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::Node Node; typedef typename Graph::NodeIt NodeIt; typedef typename Graph::Edge Edge; typedef typename Graph::OutEdgeIt InEdgeIt; typedef typename Graph::InEdgeIt OutEdgeIt; //typedef typename Graph::SymEdgeIt SymEdgeIt; typedef typename Graph::EdgeIt EdgeIt; //RevGraphWrapper() : graph(0) { } RevGraphWrapper(Graph& _graph) : graph(&_graph) { } void setGraph(Graph& _graph) { graph = &_graph; } Graph& getGraph() const { return (*graph); } template I& /*getF*/first(I& i) const { return graph->/*getF*/first(i); } template I& /*getF*/first(I& i, const P& p) const { return graph->/*getF*/first(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; /*getF*/first(e); return e; } template< typename It > It first(const Node& v) const { It e; /*getF*/first(e, v); return e; } Node head(const Edge& e) const { return graph->tail(e); } Node tail(const Edge& 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 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); } 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::Node Node; typedef typename Graph::NodeIt NodeIt; //typedef typename Graph::Edge Edge; //typedef typename Graph::OutEdgeIt OutEdgeIt; //typedef typename Graph::InEdgeIt InEdgeIt; //typedef typename Graph::SymEdgeIt SymEdgeIt; //typedef typename Graph::EdgeIt EdgeIt; //private: typedef typename Graph::Edge GraphEdge; 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 Edge { friend class UndirGraphWrapper; bool out_or_in; //true iff out GraphOutEdgeIt out; GraphInEdgeIt in; public: Edge() : out_or_in(), out(), in() { } Edge(const Invalid& i) : out_or_in(false), out(), in(i) { } operator GraphEdge() const { if (out_or_in) return(out); else return(in); } friend bool operator==(const Edge& u, const Edge& v) { if (v.out_or_in) return (u.out_or_in && u.out==v.out); else return (!u.out_or_in && u.in==v.in); } friend bool operator!=(const Edge& u, const Edge& v) { if (v.out_or_in) return (!u.out_or_in || u.out!=v.out); else return (u.out_or_in || u.in!=v.in); } }; class OutEdgeIt : public Edge { friend class UndirGraphWrapper; public: OutEdgeIt() : Edge() { } OutEdgeIt(const Invalid& i) : Edge(i) { } OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() { out_or_in=true; _G.graph->/*getF*/first(out, n); if (!(_G.graph->valid(out))) { out_or_in=false; _G.graph->/*getF*/first(in, n); } } }; OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const { e.out_or_in=true; graph->/*getF*/first(e.out, n); if (!(graph->valid(e.out))) { e.out_or_in=false; graph->/*getF*/first(e.in, n); } return e; } OutEdgeIt& next(OutEdgeIt& e) const { if (e.out_or_in) { Node n=graph->tail(e.out); graph->next(e.out); if (!graph->valid(e.out)) { e.out_or_in=false; graph->/*getF*/first(e.in, n); } } else { graph->next(e.in); } return e; } Node aNode(const OutEdgeIt& e) const { if (e.out_or_in) return graph->tail(e); else return graph->head(e); } Node bNode(const OutEdgeIt& e) const { if (e.out_or_in) return graph->head(e); else return graph->tail(e); } typedef OutEdgeIt InEdgeIt; template I& /*getF*/first(I& i) const { return graph->/*getF*/first(i); } // template I& /*getF*/first(I& i, const P& p) const { // return graph->/*getF*/first(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; /*getF*/first(e); return e; } template< typename It > It first(const Node& v) const { It e; /*getF*/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); } 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 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); } 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::Node Node; // typedef typename Graph::Edge Edge; // typedef typename Graph::NodeIt NodeIt; // //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::EdgeIt EdgeIt; // int nodeNum() const { return graph->nodeNum(); } // int edgeNum() const { return graph->edgeNum(); } // template I& /*getF*/first(I& i) const { return graph->/*getF*/first(i); } // template I& /*getF*/first(I& i, const P& p) const { // return graph->/*getF*/first(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; /*getF*/first(e); return e; } // template< typename It > It first(Node v) const { // It e; /*getF*/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); } // template Node aNode(const I& e) const { // return graph->aNode(e); } // template Node 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); } // Node addNode() { return graph->addNode(); } // Edge addEdge(const Node& tail, const Node& 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::Node Node; typedef typename Graph::NodeIt NodeIt; private: typedef typename Graph::OutEdgeIt OldOutEdgeIt; typedef typename Graph::InEdgeIt OldInEdgeIt; const Graph* graph; FlowMap* flow; const CapacityMap* capacity; public: ResGraphWrapper(const Graph& _G, FlowMap& _flow, const CapacityMap& _capacity) : graph(&_G), flow(&_flow), capacity(&_capacity) { } void setGraph(const Graph& _graph) { graph = &_graph; } const Graph& getGraph() const { return (*graph); } class Edge; class OutEdgeIt; friend class Edge; friend class OutEdgeIt; class Edge { friend class ResGraphWrapper; protected: bool out_or_in; //true, iff out OldOutEdgeIt out; OldInEdgeIt in; public: Edge() : out_or_in(true) { } Edge(const Invalid& i) : out_or_in(false), out(), in(i) { } // bool valid() const { // return out_or_in && out.valid() || in.valid(); } friend bool operator==(const Edge& u, const Edge& v) { if (v.out_or_in) return (u.out_or_in && u.out==v.out); else return (!u.out_or_in && u.in==v.in); } friend bool operator!=(const Edge& u, const Edge& v) { if (v.out_or_in) return (!u.out_or_in || u.out!=v.out); else return (u.out_or_in || u.in!=v.in); } }; class OutEdgeIt : public Edge { friend class ResGraphWrapper; public: OutEdgeIt() { } //FIXME OutEdgeIt(const Edge& e) : Edge(e) { } OutEdgeIt(const Invalid& i) : Edge(i) { } private: OutEdgeIt(const ResGraphWrapper& resG, Node v) : Edge() { resG.graph->/*getF*/first(out, v); while( resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); } if (!resG.graph->valid(out)) { out_or_in=0; resG.graph->/*getF*/first(in, v); while( resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); } } } // public: // OutEdgeIt& operator++() { // if (out_or_in) { // Node v=/*resG->*/G->aNode(out); // ++out; // while( out.valid() && !(Edge::free()>0) ) { ++out; } // if (!out.valid()) { // out_or_in=0; // G->/*getF*/first(in, v); // while( in.valid() && !(Edge::free()>0) ) { ++in; } // } // } else { // ++in; // while( in.valid() && !(Edge::free()>0) ) { ++in; } // } // return *this; // } }; class EdgeIt : public Edge { friend class ResGraphWrapper; typename Graph::NodeIt v; public: EdgeIt() { } //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { } EdgeIt(const Invalid& i) : Edge(i) { } EdgeIt(const ResGraphWrapper& resG) : Edge() { resG.graph->/*getF*/first(v); if (resG.graph->valid(v)) resG.graph->/*getF*/first(out, v); else out=OldOutEdgeIt(INVALID); while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); } while (resG.graph->valid(v) && !resG.graph->valid(out)) { resG.graph->next(v); if (resG.graph->valid(v)) resG.graph->/*getF*/first(out, v); while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); } } if (!resG.graph->valid(out)) { out_or_in=0; resG.graph->/*getF*/first(v); if (resG.graph->valid(v)) resG.graph->/*getF*/first(in, v); else in=OldInEdgeIt(INVALID); while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); } while (resG.graph->valid(v) && !resG.graph->valid(in)) { resG.graph->next(v); if (resG.graph->valid(v)) resG.graph->/*getF*/first(in, v); while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); } } } } // EdgeIt& operator++() { // if (out_or_in) { // ++out; // while (out.valid() && !(Edge::free()>0) ) { ++out; } // while (v.valid() && !out.valid()) { // ++v; // if (v.valid()) G->/*getF*/first(out, v); // while (out.valid() && !(Edge::free()>0) ) { ++out; } // } // if (!out.valid()) { // out_or_in=0; // G->/*getF*/first(v); // if (v.valid()) G->/*getF*/first(in, v); else in=OldInEdgeIt(); // while (in.valid() && !(Edge::free()>0) ) { ++in; } // while (v.valid() && !in.valid()) { // ++v; // if (v.valid()) G->/*getF*/first(in, v); // while (in.valid() && !(Edge::free()>0) ) { ++in; } // } // } // } else { // ++in; // while (in.valid() && !(Edge::free()>0) ) { ++in; } // while (v.valid() && !in.valid()) { // ++v; // if (v.valid()) G->/*getF*/first(in, v); // while (in.valid() && !(Edge::free()>0) ) { ++in; } // } // } // return *this; // } }; NodeIt& /*getF*/first(NodeIt& v) const { return graph->/*getF*/first(v); } OutEdgeIt& /*getF*/first(OutEdgeIt& e, Node v) const { e=OutEdgeIt(*this, v); return e; } EdgeIt& /*getF*/first(EdgeIt& e) const { e=EdgeIt(*this); return e; } NodeIt& next(NodeIt& n) const { return graph->next(n); } OutEdgeIt& next(OutEdgeIt& e) const { if (e.out_or_in) { Node v=graph->aNode(e.out); graph->next(e.out); while( graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); } if (!graph->valid(e.out)) { e.out_or_in=0; graph->/*getF*/first(e.in, v); while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } } } else { graph->next(e.in); while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } } return e; } EdgeIt& next(EdgeIt& e) const { if (e.out_or_in) { graph->next(e.out); while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); } while (graph->valid(e.v) && !graph->valid(e.out)) { graph->next(e.v); if (graph->valid(e.v)) graph->/*getF*/first(e.out, e.v); while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); } } if (!graph->valid(e.out)) { e.out_or_in=0; graph->/*getF*/first(e.v); if (graph->valid(e.v)) graph->/*getF*/first(e.in, e.v); else e.in=OldInEdgeIt(INVALID); while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } while (graph->valid(e.v) && !graph->valid(e.in)) { graph->next(e.v); if (graph->valid(e.v)) graph->/*getF*/first(e.in, e.v); while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } } } } else { graph->next(e.in); while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } while (graph->valid(e.v) && !graph->valid(e.in)) { graph->next(e.v); if (graph->valid(e.v)) graph->/*getF*/first(e.in, e.v); while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } } } return e; } template< typename It > It first() const { It e; /*getF*/first(e); return e; } template< typename It > It first(Node v) const { It e; /*getF*/first(e, v); return e; } Node tail(Edge e) const { return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); } Node head(Edge e) const { return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); } Node aNode(OutEdgeIt e) const { return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); } Node bNode(OutEdgeIt e) const { return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); } int id(Node v) const { return graph->id(v); } bool valid(Node n) const { return graph->valid(n); } bool valid(Edge e) const { return e.out_or_in ? graph->valid(e.out) : graph->valid(e.in); } void augment(const Edge& 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 Edge& 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.graph)) { } // NodeMap(const ResGraphWrapper& _G, T a) : node_map(*(_G.graph), a) { } // void set(Node nit, T a) { node_map.set(nit, a); } // T get(Node 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(Edge e, T a) { if (e.out_or_in) forward_map.set(e.out, a); else backward_map.set(e.in, a); } T get(Edge 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(NodeIt n=this->template first(); this->valid(n); this->next(n)) { OutEdgeIt e; ResGraphWrapper::/*getF*/first(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::Node Node; //typedef typename Graph::NodeIt NodeIt; //typedef typename Graph::Edge Edge; //typedef typename Graph::OutEdgeIt OutEdgeIt; //typedef typename Graph::InEdgeIt InEdgeIt; //typedef typename Graph::SymEdgeIt SymEdgeIt; //typedef typename Graph::EdgeIt EdgeIt; typedef typename ResGraphWrapper::Node Node; typedef typename ResGraphWrapper::NodeIt NodeIt; typedef typename ResGraphWrapper::Edge Edge; typedef typename ResGraphWrapper::OutEdgeIt OutEdgeIt; //typedef typename ResGraphWrapper::InEdgeIt InEdgeIt; //typedef typename Graph::SymEdgeIt SymEdgeIt; //typedef typename ResGraphWrapper::EdgeIt EdgeIt; NodeIt& /*getF*/first(NodeIt& n) const { return ResGraphWrapper::/*getF*/first(n); } OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const { e=first_out_edges.get(n); return e; } //ROSSZ template I& /*getF*/first(I& i) const { return /*getF*/first(i); } //ROSSZ template I& /*getF*/first(I& i, const P& p) const { // return /*getF*/first(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; /*getF*/first(e); return e; } template< typename It > It first(const Node& v) const { It e; /*getF*/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); } //template bool valid(const I& i) const // { return graph->valid(i); } //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); } //Node addNode() const { return graph->addNode(); } //Edge addEdge(const Node& tail, const Node& head) const { // return graph->addEdge(tail, head); } //void erase(const OutEdgeIt& e) { // first_out_edge(this->tail(e))=e; //} void erase(const Edge& 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::Node Node; typedef typename ErasingResGraphWrapper::NodeIt NodeIt; typedef typename ErasingResGraphWrapper::Edge Edge; typedef typename ErasingResGraphWrapper::OutEdgeIt OutEdgeIt; //typedef typename ErasingResGraphWrapper::InEdgeIt InEdgeIt; //typedef typename Graph::SymEdgeIt SymEdgeIt; typedef typename ErasingResGraphWrapper::EdgeIt EdgeIt; //FilterGraphWrapper::NodeMap::OutEdgeIt> first_out_edges; public: FilterGraphWrapper(const Graph& _G, FlowMap& _flow, const CapacityMap& _capacity) : ErasingResGraphWrapper(_G, _flow, _capacity), dist(*this) { } OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const { ErasingResGraphWrapper::/*getF*/first(e, n); while (valid(e) && (dist.get(tail(e))+1!=dist.get(head(e)))) ErasingResGraphWrapper::next(e); return e; } NodeIt& next(NodeIt& 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; } NodeIt& /*getF*/first(NodeIt& n) const { return ErasingResGraphWrapper::/*getF*/first(n); } void erase(const Edge& 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& /*getF*/first(I& i) const { return graph->/*getF*/first(i); } //template I& /*getF*/first(I& i, const P& p) const { // return graph->/*getF*/first(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; /*getF*/first(e); return e; } template< typename It > It first(const Node& v) const { It e; /*getF*/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); } //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 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); } //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::Node Node; // typedef typename Graph::Edge Edge; // typedef typename Graph::NodeIt NodeIt; // class OutEdgeIt { // public: // //Graph::Node n; // bool out_or_in; // typename Graph::OutEdgeIt o; // typename Graph::InEdgeIt i; // }; // class InEdgeIt { // public: // //Graph::Node n; // bool out_or_in; // typename Graph::OutEdgeIt o; // typename Graph::InEdgeIt i; // }; // typedef typename Graph::SymEdgeIt SymEdgeIt; // typedef typename Graph::EdgeIt EdgeIt; // int nodeNum() const { return graph->nodeNum(); } // int edgeNum() const { return graph->edgeNum(); } // Node& /*getF*/first(Node& n) const { return graph->/*getF*/first(n); } // // Edge and SymEdge is missing!!!! // // Edge <-> In/OutEdgeIt conversion is missing!!!! // //FIXME // OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const // { // e.n=n; // graph->/*getF*/first(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->/*getF*/first(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->/*getF*/first(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& /*getF*/first(InEdgeIt& e, const Node& n) const // { // e.n=n; // graph->/*getF*/first(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->/*getF*/first(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->/*getF*/first(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; /*getF*/first(e); return e; } // template< typename It > It first(Node v) const { // It e; /*getF*/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); } // template Node aNode(const I& e) const { // return graph->aNode(e); } // template Node 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); } // Node addNode() { return graph->addNode(); } // Edge addEdge(const Node& tail, const Node& 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