Alp?r javaslat?ra k?sz?tettem egy strukt?r?t 2 dimenzi?s vektorok (s?kvektorok) t?rol?s?ra. Olyasmiket tud, amiket s?kvektorokt?l szeretn?nk. A neve: xy, a hasonl? nevu .h file-ban tal?lhat?.
2 #ifndef GRAPH_WRAPPER_H
3 #define GRAPH_WRAPPER_H
9 template<typename Graph>
10 class TrivGraphWrapper {
15 typedef Graph BaseGraph;
17 typedef typename Graph::Node Node;
18 typedef typename Graph::NodeIt NodeIt;
20 typedef typename Graph::Edge Edge;
21 typedef typename Graph::OutEdgeIt OutEdgeIt;
22 typedef typename Graph::InEdgeIt InEdgeIt;
23 //typedef typename Graph::SymEdgeIt SymEdgeIt;
24 typedef typename Graph::EdgeIt EdgeIt;
26 //TrivGraphWrapper() : graph(0) { }
27 TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
29 void setGraph(Graph& _graph) { graph = &_graph; }
30 Graph& getGraph() const { return (*graph); }
32 template<typename I> I& /*getF*/first(I& i) const { return graph->/*getF*/first(i); }
33 template<typename I, typename P> I& /*getF*/first(I& i, const P& p) const {
34 return graph->/*getF*/first(i, p); }
36 template<typename I> I getNext(const I& i) const {
37 return graph->getNext(i); }
38 template<typename I> I& next(I &i) const { return graph->next(i); }
40 template< typename It > It first() const {
41 It e; /*getF*/first(e); return e; }
43 template< typename It > It first(const Node& v) const {
44 It e; /*getF*/first(e, v); return e; }
46 Node head(const Edge& e) const { return graph->head(e); }
47 Node tail(const Edge& e) const { return graph->tail(e); }
49 template<typename I> bool valid(const I& i) const
50 { return graph->valid(i); }
52 //template<typename I> void setInvalid(const I &i);
53 //{ return graph->setInvalid(i); }
55 int nodeNum() const { return graph->nodeNum(); }
56 int edgeNum() const { return graph->edgeNum(); }
58 template<typename I> Node aNode(const I& e) const {
59 return graph->aNode(e); }
60 template<typename I> Node bNode(const I& e) const {
61 return graph->bNode(e); }
63 Node addNode() const { return graph->addNode(); }
64 Edge addEdge(const Node& tail, const Node& head) const {
65 return graph->addEdge(tail, head); }
67 template<typename I> void erase(const I& i) const { graph->erase(i); }
69 void clear() const { graph->clear(); }
71 template<typename T> class NodeMap : public Graph::NodeMap<T> {
73 NodeMap(const TrivGraphWrapper<Graph>& _G) :
74 Graph::NodeMap<T>(_G.getGraph()) { }
75 NodeMap(const TrivGraphWrapper<Graph>& _G, T a) :
76 Graph::NodeMap<T>(_G.getGraph(), a) { }
79 template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
81 EdgeMap(const TrivGraphWrapper<Graph>& _G) :
82 Graph::EdgeMap<T>(_G.getGraph()) { }
83 EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) :
84 Graph::EdgeMap<T>(_G.getGraph(), a) { }
88 template<typename Graph>
95 typedef Graph BaseGraph;
97 typedef typename Graph::Node Node;
98 typedef typename Graph::NodeIt NodeIt;
100 typedef typename Graph::Edge Edge;
101 typedef typename Graph::OutEdgeIt InEdgeIt;
102 typedef typename Graph::InEdgeIt OutEdgeIt;
103 //typedef typename Graph::SymEdgeIt SymEdgeIt;
104 typedef typename Graph::EdgeIt EdgeIt;
106 //RevGraphWrapper() : graph(0) { }
107 RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
109 void setGraph(Graph& _graph) { graph = &_graph; }
110 Graph& getGraph() const { return (*graph); }
112 template<typename I> I& /*getF*/first(I& i) const { return graph->/*getF*/first(i); }
113 template<typename I, typename P> I& /*getF*/first(I& i, const P& p) const {
114 return graph->/*getF*/first(i, p); }
116 template<typename I> I getNext(const I& i) const {
117 return graph->getNext(i); }
118 template<typename I> I& next(I &i) const { return graph->next(i); }
120 template< typename It > It first() const {
121 It e; /*getF*/first(e); return e; }
123 template< typename It > It first(const Node& v) const {
124 It e; /*getF*/first(e, v); return e; }
126 Node head(const Edge& e) const { return graph->tail(e); }
127 Node tail(const Edge& e) const { return graph->head(e); }
129 template<typename I> bool valid(const I& i) const
130 { return graph->valid(i); }
132 //template<typename I> void setInvalid(const I &i);
133 //{ return graph->setInvalid(i); }
135 template<typename I> Node aNode(const I& e) const {
136 return graph->aNode(e); }
137 template<typename I> Node bNode(const I& e) const {
138 return graph->bNode(e); }
140 Node addNode() const { return graph->addNode(); }
141 Edge addEdge(const Node& tail, const Node& head) const {
142 return graph->addEdge(tail, head); }
144 int nodeNum() const { return graph->nodeNum(); }
145 int edgeNum() const { return graph->edgeNum(); }
147 template<typename I> void erase(const I& i) const { graph->erase(i); }
149 void clear() const { graph->clear(); }
151 template<typename T> class NodeMap : public Graph::NodeMap<T> {
153 NodeMap(const RevGraphWrapper<Graph>& _G) :
154 Graph::NodeMap<T>(_G.getGraph()) { }
155 NodeMap(const RevGraphWrapper<Graph>& _G, T a) :
156 Graph::NodeMap<T>(_G.getGraph(), a) { }
159 template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
161 EdgeMap(const RevGraphWrapper<Graph>& _G) :
162 Graph::EdgeMap<T>(_G.getGraph()) { }
163 EdgeMap(const RevGraphWrapper<Graph>& _G, T a) :
164 Graph::EdgeMap<T>(_G.getGraph(), a) { }
169 template<typename Graph>
170 class UndirGraphWrapper {
175 typedef Graph BaseGraph;
177 typedef typename Graph::Node Node;
178 typedef typename Graph::NodeIt NodeIt;
180 //typedef typename Graph::Edge Edge;
181 //typedef typename Graph::OutEdgeIt OutEdgeIt;
182 //typedef typename Graph::InEdgeIt InEdgeIt;
183 //typedef typename Graph::SymEdgeIt SymEdgeIt;
184 //typedef typename Graph::EdgeIt EdgeIt;
187 typedef typename Graph::Edge GraphEdge;
188 typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
189 typedef typename Graph::InEdgeIt GraphInEdgeIt;
192 //UndirGraphWrapper() : graph(0) { }
193 UndirGraphWrapper(Graph& _graph) : graph(&_graph) { }
195 void setGraph(Graph& _graph) { graph = &_graph; }
196 Graph& getGraph() const { return (*graph); }
199 friend class UndirGraphWrapper<Graph>;
200 bool out_or_in; //true iff out
204 Edge() : out_or_in(), out(), in() { }
205 Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
206 operator GraphEdge() const {
207 if (out_or_in) return(out); else return(in);
209 friend bool operator==(const Edge& u, const Edge& v) {
211 return (u.out_or_in && u.out==v.out);
213 return (!u.out_or_in && u.in==v.in);
215 friend bool operator!=(const Edge& u, const Edge& v) {
217 return (!u.out_or_in || u.out!=v.out);
219 return (u.out_or_in || u.in!=v.in);
223 class OutEdgeIt : public Edge {
224 friend class UndirGraphWrapper<Graph>;
226 OutEdgeIt() : Edge() { }
227 OutEdgeIt(const Invalid& i) : Edge(i) { }
228 OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() {
230 _G.graph->/*getF*/first(out, n);
231 if (!(_G.graph->valid(out))) {
233 _G.graph->/*getF*/first(in, n);
238 OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const {
240 graph->/*getF*/first(e.out, n);
241 if (!(graph->valid(e.out))) {
243 graph->/*getF*/first(e.in, n);
248 OutEdgeIt& next(OutEdgeIt& e) const {
250 Node n=graph->tail(e.out);
252 if (!graph->valid(e.out)) {
254 graph->/*getF*/first(e.in, n);
262 Node aNode(const OutEdgeIt& e) const {
263 if (e.out_or_in) return graph->tail(e); else return graph->head(e); }
264 Node bNode(const OutEdgeIt& e) const {
265 if (e.out_or_in) return graph->head(e); else return graph->tail(e); }
267 typedef OutEdgeIt InEdgeIt;
269 template<typename I> I& /*getF*/first(I& i) const { return graph->/*getF*/first(i); }
270 // template<typename I, typename P> I& /*getF*/first(I& i, const P& p) const {
271 // return graph->/*getF*/first(i, p); }
273 template<typename I> I getNext(const I& i) const {
274 return graph->getNext(i); }
275 template<typename I> I& next(I &i) const { return graph->next(i); }
277 template< typename It > It first() const {
278 It e; /*getF*/first(e); return e; }
280 template< typename It > It first(const Node& v) const {
281 It e; /*getF*/first(e, v); return e; }
283 Node head(const Edge& e) const { return graph->head(e); }
284 Node tail(const Edge& e) const { return graph->tail(e); }
286 template<typename I> bool valid(const I& i) const
287 { return graph->valid(i); }
289 //template<typename I> void setInvalid(const I &i);
290 //{ return graph->setInvalid(i); }
292 int nodeNum() const { return graph->nodeNum(); }
293 int edgeNum() const { return graph->edgeNum(); }
295 // template<typename I> Node aNode(const I& e) const {
296 // return graph->aNode(e); }
297 // template<typename I> Node bNode(const I& e) const {
298 // return graph->bNode(e); }
300 Node addNode() const { return graph->addNode(); }
301 Edge addEdge(const Node& tail, const Node& head) const {
302 return graph->addEdge(tail, head); }
304 template<typename I> void erase(const I& i) const { graph->erase(i); }
306 void clear() const { graph->clear(); }
308 template<typename T> class NodeMap : public Graph::NodeMap<T> {
310 NodeMap(const UndirGraphWrapper<Graph>& _G) :
311 Graph::NodeMap<T>(_G.getGraph()) { }
312 NodeMap(const UndirGraphWrapper<Graph>& _G, T a) :
313 Graph::NodeMap<T>(_G.getGraph(), a) { }
316 template<typename T> class EdgeMap : public Graph::EdgeMap<T> {
318 EdgeMap(const UndirGraphWrapper<Graph>& _G) :
319 Graph::EdgeMap<T>(_G.getGraph()) { }
320 EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) :
321 Graph::EdgeMap<T>(_G.getGraph(), a) { }
327 // template<typename Graph>
328 // class SymGraphWrapper
333 // typedef Graph BaseGraph;
335 // typedef typename Graph::Node Node;
336 // typedef typename Graph::Edge Edge;
338 // typedef typename Graph::NodeIt NodeIt;
340 // //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
341 // //iranyitatlant, ami van
342 // //mert csak 1 dolgot lehet be typedef-elni
343 // typedef typename Graph::OutEdgeIt SymEdgeIt;
344 // //typedef typename Graph::InEdgeIt SymEdgeIt;
345 // //typedef typename Graph::SymEdgeIt SymEdgeIt;
346 // typedef typename Graph::EdgeIt EdgeIt;
348 // int nodeNum() const { return graph->nodeNum(); }
349 // int edgeNum() const { return graph->edgeNum(); }
351 // template<typename I> I& /*getF*/first(I& i) const { return graph->/*getF*/first(i); }
352 // template<typename I, typename P> I& /*getF*/first(I& i, const P& p) const {
353 // return graph->/*getF*/first(i, p); }
354 // //template<typename I> I next(const I i); { return graph->goNext(i); }
355 // //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
357 // template< typename It > It first() const {
358 // It e; /*getF*/first(e); return e; }
360 // template< typename It > It first(Node v) const {
361 // It e; /*getF*/first(e, v); return e; }
363 // Node head(const Edge& e) const { return graph->head(e); }
364 // Node tail(const Edge& e) const { return graph->tail(e); }
366 // template<typename I> Node aNode(const I& e) const {
367 // return graph->aNode(e); }
368 // template<typename I> Node bNode(const I& e) const {
369 // return graph->bNode(e); }
371 // //template<typename I> bool valid(const I i);
372 // //{ return graph->valid(i); }
374 // //template<typename I> void setInvalid(const I &i);
375 // //{ return graph->setInvalid(i); }
377 // Node addNode() { return graph->addNode(); }
378 // Edge addEdge(const Node& tail, const Node& head) {
379 // return graph->addEdge(tail, head); }
381 // template<typename I> void erase(const I& i) { graph->erase(i); }
383 // void clear() { graph->clear(); }
385 // template<typename T> class NodeMap : public Graph::NodeMap<T> { };
386 // template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
388 // void setGraph(Graph& _graph) { graph = &_graph; }
389 // Graph& getGraph() { return (*graph); }
391 // //SymGraphWrapper() : graph(0) { }
392 // SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
396 template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
397 class ResGraphWrapper {
399 typedef Graph BaseGraph;
400 typedef typename Graph::Node Node;
401 typedef typename Graph::NodeIt NodeIt;
403 typedef typename Graph::OutEdgeIt OldOutEdgeIt;
404 typedef typename Graph::InEdgeIt OldInEdgeIt;
408 const CapacityMap* capacity;
411 ResGraphWrapper(const Graph& _G, FlowMap& _flow,
412 const CapacityMap& _capacity) :
413 graph(&_G), flow(&_flow), capacity(&_capacity) { }
415 void setGraph(const Graph& _graph) { graph = &_graph; }
416 const Graph& getGraph() const { return (*graph); }
421 friend class OutEdgeIt;
424 friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
426 bool out_or_in; //true, iff out
430 Edge() : out_or_in(true) { }
431 Edge(const Invalid& i) : out_or_in(false), out(), in(i) { }
432 // bool valid() const {
433 // return out_or_in && out.valid() || in.valid(); }
434 friend bool operator==(const Edge& u, const Edge& v) {
436 return (u.out_or_in && u.out==v.out);
438 return (!u.out_or_in && u.in==v.in);
440 friend bool operator!=(const Edge& u, const Edge& v) {
442 return (!u.out_or_in || u.out!=v.out);
444 return (u.out_or_in || u.in!=v.in);
449 class OutEdgeIt : public Edge {
450 friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
454 OutEdgeIt(const Edge& e) : Edge(e) { }
455 OutEdgeIt(const Invalid& i) : Edge(i) { }
457 OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
458 resG.graph->/*getF*/first(out, v);
459 while( resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
460 if (!resG.graph->valid(out)) {
462 resG.graph->/*getF*/first(in, v);
463 while( resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
467 // OutEdgeIt& operator++() {
469 // Node v=/*resG->*/G->aNode(out);
471 // while( out.valid() && !(Edge::free()>0) ) { ++out; }
472 // if (!out.valid()) {
474 // G->/*getF*/first(in, v);
475 // while( in.valid() && !(Edge::free()>0) ) { ++in; }
479 // while( in.valid() && !(Edge::free()>0) ) { ++in; }
485 class EdgeIt : public Edge {
486 friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
487 typename Graph::NodeIt v;
490 //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
491 EdgeIt(const Invalid& i) : Edge(i) { }
492 EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() {
493 resG.graph->/*getF*/first(v);
494 if (resG.graph->valid(v)) resG.graph->/*getF*/first(out, v); else out=OldOutEdgeIt(INVALID);
495 while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
496 while (resG.graph->valid(v) && !resG.graph->valid(out)) {
498 if (resG.graph->valid(v)) resG.graph->/*getF*/first(out, v);
499 while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); }
501 if (!resG.graph->valid(out)) {
503 resG.graph->/*getF*/first(v);
504 if (resG.graph->valid(v)) resG.graph->/*getF*/first(in, v); else in=OldInEdgeIt(INVALID);
505 while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
506 while (resG.graph->valid(v) && !resG.graph->valid(in)) {
508 if (resG.graph->valid(v)) resG.graph->/*getF*/first(in, v);
509 while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); }
513 // EdgeIt& operator++() {
516 // while (out.valid() && !(Edge::free()>0) ) { ++out; }
517 // while (v.valid() && !out.valid()) {
519 // if (v.valid()) G->/*getF*/first(out, v);
520 // while (out.valid() && !(Edge::free()>0) ) { ++out; }
522 // if (!out.valid()) {
524 // G->/*getF*/first(v);
525 // if (v.valid()) G->/*getF*/first(in, v); else in=OldInEdgeIt();
526 // while (in.valid() && !(Edge::free()>0) ) { ++in; }
527 // while (v.valid() && !in.valid()) {
529 // if (v.valid()) G->/*getF*/first(in, v);
530 // while (in.valid() && !(Edge::free()>0) ) { ++in; }
535 // while (in.valid() && !(Edge::free()>0) ) { ++in; }
536 // while (v.valid() && !in.valid()) {
538 // if (v.valid()) G->/*getF*/first(in, v);
539 // while (in.valid() && !(Edge::free()>0) ) { ++in; }
546 NodeIt& /*getF*/first(NodeIt& v) const { return graph->/*getF*/first(v); }
547 OutEdgeIt& /*getF*/first(OutEdgeIt& e, Node v) const {
548 e=OutEdgeIt(*this, v);
551 EdgeIt& /*getF*/first(EdgeIt& e) const {
556 NodeIt& next(NodeIt& n) const { return graph->next(n); }
558 OutEdgeIt& next(OutEdgeIt& e) const {
560 Node v=graph->aNode(e.out);
562 while( graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
563 if (!graph->valid(e.out)) {
565 graph->/*getF*/first(e.in, v);
566 while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
570 while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
575 EdgeIt& next(EdgeIt& e) const {
578 while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
579 while (graph->valid(e.v) && !graph->valid(e.out)) {
581 if (graph->valid(e.v)) graph->/*getF*/first(e.out, e.v);
582 while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); }
584 if (!graph->valid(e.out)) {
586 graph->/*getF*/first(e.v);
587 if (graph->valid(e.v)) graph->/*getF*/first(e.in, e.v); else e.in=OldInEdgeIt(INVALID);
588 while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
589 while (graph->valid(e.v) && !graph->valid(e.in)) {
591 if (graph->valid(e.v)) graph->/*getF*/first(e.in, e.v);
592 while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
597 while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
598 while (graph->valid(e.v) && !graph->valid(e.in)) {
600 if (graph->valid(e.v)) graph->/*getF*/first(e.in, e.v);
601 while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); }
608 template< typename It >
615 template< typename It >
616 It first(Node v) const {
622 Node tail(Edge e) const {
623 return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
624 Node head(Edge e) const {
625 return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
627 Node aNode(OutEdgeIt e) const {
628 return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); }
629 Node bNode(OutEdgeIt e) const {
630 return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); }
632 int id(Node v) const { return graph->id(v); }
634 bool valid(Node n) const { return graph->valid(n); }
635 bool valid(Edge e) const {
636 return e.out_or_in ? graph->valid(e.out) : graph->valid(e.in); }
638 void augment(const Edge& e, Number a) const {
640 flow->set(e.out, flow->get(e.out)+a);
642 flow->set(e.in, flow->get(e.in)-a);
645 Number free(const Edge& e) const {
647 return (capacity->get(e.out)-flow->get(e.out));
649 return (flow->get(e.in));
652 Number free(OldOutEdgeIt out) const {
653 return (capacity->get(out)-flow->get(out));
656 Number free(OldInEdgeIt in) const {
657 return (flow->get(in));
660 template<typename T> class NodeMap : public Graph::NodeMap<T> {
662 NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G)
663 : Graph::NodeMap<T>(_G.getGraph()) { }
664 NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G,
665 T a) : Graph::NodeMap<T>(_G.getGraph(), a) { }
668 // template <typename T>
670 // typename Graph::NodeMap<T> node_map;
672 // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { }
673 // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { }
674 // void set(Node nit, T a) { node_map.set(nit, a); }
675 // T get(Node nit) const { return node_map.get(nit); }
678 template <typename T>
680 typename Graph::EdgeMap<T> forward_map, backward_map;
682 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.getGraph()), backward_map(_G.getGraph()) { }
683 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.getGraph(), a), backward_map(_G.getGraph(), a) { }
684 void set(Edge e, T a) {
686 forward_map.set(e.out, a);
688 backward_map.set(e.in, a);
692 return forward_map.get(e.out);
694 return backward_map.get(e.in);
699 template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
700 class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
702 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
703 //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
705 ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow,
706 const CapacityMap& _capacity) :
707 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity),
708 first_out_edges(*this) /*, dist(*this)*/ {
709 for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {
711 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::/*getF*/first(e, n);
712 first_out_edges.set(n, e);
716 //void setGraph(Graph& _graph) { graph = &_graph; }
717 //Graph& getGraph() const { return (*graph); }
719 //TrivGraphWrapper() : graph(0) { }
720 //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }
722 //typedef Graph BaseGraph;
724 //typedef typename Graph::Node Node;
725 //typedef typename Graph::NodeIt NodeIt;
727 //typedef typename Graph::Edge Edge;
728 //typedef typename Graph::OutEdgeIt OutEdgeIt;
729 //typedef typename Graph::InEdgeIt InEdgeIt;
730 //typedef typename Graph::SymEdgeIt SymEdgeIt;
731 //typedef typename Graph::EdgeIt EdgeIt;
733 typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
734 typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
736 typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
737 typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
738 //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
739 //typedef typename Graph::SymEdgeIt SymEdgeIt;
740 //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
742 NodeIt& /*getF*/first(NodeIt& n) const {
743 return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::/*getF*/first(n);
746 OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const {
747 e=first_out_edges.get(n);
751 //ROSSZ template<typename I> I& /*getF*/first(I& i) const { return /*getF*/first(i); }
752 //ROSSZ template<typename I, typename P> I& /*getF*/first(I& i, const P& p) const {
753 // return /*getF*/first(i, p); }
755 //template<typename I> I getNext(const I& i) const {
756 // return graph->getNext(i); }
757 //template<typename I> I& next(I &i) const { return graph->next(i); }
759 template< typename It > It first() const {
760 It e; /*getF*/first(e); return e; }
762 template< typename It > It first(const Node& v) const {
763 It e; /*getF*/first(e, v); return e; }
765 //Node head(const Edge& e) const { return graph->head(e); }
766 //Node tail(const Edge& e) const { return graph->tail(e); }
768 //template<typename I> bool valid(const I& i) const
769 // { return graph->valid(i); }
771 //int nodeNum() const { return graph->nodeNum(); }
772 //int edgeNum() const { return graph->edgeNum(); }
774 //template<typename I> Node aNode(const I& e) const {
775 // return graph->aNode(e); }
776 //template<typename I> Node bNode(const I& e) const {
777 // return graph->bNode(e); }
779 //Node addNode() const { return graph->addNode(); }
780 //Edge addEdge(const Node& tail, const Node& head) const {
781 // return graph->addEdge(tail, head); }
783 //void erase(const OutEdgeIt& e) {
784 // first_out_edge(this->tail(e))=e;
786 void erase(const Edge& e) {
789 first_out_edges.set(this->tail(e), f);
791 //template<typename I> void erase(const I& i) const { graph->erase(i); }
793 //void clear() const { graph->clear(); }
795 template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
797 NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
798 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
799 NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
800 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
803 template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
805 EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :
806 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
807 EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :
808 ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
812 template<typename GraphWrapper>
813 class FilterGraphWrapper {
816 template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
817 class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {
822 //typedef Graph BaseGraph;
824 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;
825 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;
827 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;
828 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;
829 //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;
830 //typedef typename Graph::SymEdgeIt SymEdgeIt;
831 typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;
833 //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;
836 FilterGraphWrapper(const Graph& _G, FlowMap& _flow,
837 const CapacityMap& _capacity) :
838 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, graph->nodeNum()) {
841 OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const {
842 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::/*getF*/first(e, n);
843 while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e))))
844 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
848 NodeIt& next(NodeIt& e) const {
849 return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
852 OutEdgeIt& next(OutEdgeIt& e) const {
853 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
854 while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e))))
855 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);
859 NodeIt& /*getF*/first(NodeIt& n) const {
860 return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::/*getF*/first(n);
863 void erase(const Edge& e) {
865 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
866 while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f))))
867 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);
868 first_out_edges.set(this->tail(e), f);
871 //TrivGraphWrapper() : graph(0) { }
872 //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
874 //void setGraph(Graph& _graph) { graph = &_graph; }
875 //Graph& getGraph() const { return (*graph); }
877 //template<typename I> I& /*getF*/first(I& i) const { return graph->/*getF*/first(i); }
878 //template<typename I, typename P> I& /*getF*/first(I& i, const P& p) const {
879 // return graph->/*getF*/first(i, p); }
881 //template<typename I> I getNext(const I& i) const {
882 // return graph->getNext(i); }
883 //template<typename I> I& next(I &i) const { return graph->next(i); }
885 template< typename It > It first() const {
886 It e; /*getF*/first(e); return e; }
888 template< typename It > It first(const Node& v) const {
889 It e; /*getF*/first(e, v); return e; }
891 //Node head(const Edge& e) const { return graph->head(e); }
892 //Node tail(const Edge& e) const { return graph->tail(e); }
894 //template<typename I> bool valid(const I& i) const
895 // { return graph->valid(i); }
897 //template<typename I> void setInvalid(const I &i);
898 //{ return graph->setInvalid(i); }
900 //int nodeNum() const { return graph->nodeNum(); }
901 //int edgeNum() const { return graph->edgeNum(); }
903 //template<typename I> Node aNode(const I& e) const {
904 // return graph->aNode(e); }
905 //template<typename I> Node bNode(const I& e) const {
906 // return graph->bNode(e); }
908 //Node addNode() const { return graph->addNode(); }
909 //Edge addEdge(const Node& tail, const Node& head) const {
910 // return graph->addEdge(tail, head); }
912 //template<typename I> void erase(const I& i) const { graph->erase(i); }
914 //void clear() const { graph->clear(); }
916 template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {
918 NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
919 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }
920 NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
921 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }
924 template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {
926 EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :
927 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }
928 EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :
929 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }
933 ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;
939 // // FIXME: comparison should be made better!!!
940 // template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
941 // class ResGraphWrapper
946 // typedef Graph BaseGraph;
948 // typedef typename Graph::Node Node;
949 // typedef typename Graph::Edge Edge;
951 // typedef typename Graph::NodeIt NodeIt;
957 // typename Graph::OutEdgeIt o;
958 // typename Graph::InEdgeIt i;
964 // typename Graph::OutEdgeIt o;
965 // typename Graph::InEdgeIt i;
967 // typedef typename Graph::SymEdgeIt SymEdgeIt;
968 // typedef typename Graph::EdgeIt EdgeIt;
970 // int nodeNum() const { return graph->nodeNum(); }
971 // int edgeNum() const { return graph->edgeNum(); }
973 // Node& /*getF*/first(Node& n) const { return graph->/*getF*/first(n); }
975 // // Edge and SymEdge is missing!!!!
976 // // Edge <-> In/OutEdgeIt conversion is missing!!!!
979 // OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const
982 // graph->/*getF*/first(e.o,n);
983 // while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
984 // graph->goNext(e.o);
985 // if(!graph->valid(e.o)) {
986 // graph->/*getF*/first(e.i,n);
987 // while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
988 // graph->goNext(e.i);
993 // OutEdgeIt &goNext(OutEdgeIt &e)
995 // if(graph->valid(e.o)) {
996 // while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
997 // graph->goNext(e.o);
998 // if(graph->valid(e.o)) return e;
999 // else graph->/*getF*/first(e.i,e.n);
1002 // while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
1003 // graph->goNext(e.i);
1007 // OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
1009 // //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
1012 // InEdgeIt& /*getF*/first(InEdgeIt& e, const Node& n) const
1015 // graph->/*getF*/first(e.i,n);
1016 // while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1017 // graph->goNext(e.i);
1018 // if(!graph->valid(e.i)) {
1019 // graph->/*getF*/first(e.o,n);
1020 // while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1021 // graph->goNext(e.o);
1026 // InEdgeIt &goNext(InEdgeIt &e)
1028 // if(graph->valid(e.i)) {
1029 // while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
1030 // graph->goNext(e.i);
1031 // if(graph->valid(e.i)) return e;
1032 // else graph->/*getF*/first(e.o,e.n);
1035 // while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
1036 // graph->goNext(e.o);
1040 // InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
1042 // //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
1044 // //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
1045 // //template<typename I> I next(const I i); { return graph->goNext(i); }
1047 // template< typename It > It first() const {
1048 // It e; /*getF*/first(e); return e; }
1050 // template< typename It > It first(Node v) const {
1051 // It e; /*getF*/first(e, v); return e; }
1053 // Node head(const Edge& e) const { return graph->head(e); }
1054 // Node tail(const Edge& e) const { return graph->tail(e); }
1056 // template<typename I> Node aNode(const I& e) const {
1057 // return graph->aNode(e); }
1058 // template<typename I> Node bNode(const I& e) const {
1059 // return graph->bNode(e); }
1061 // //template<typename I> bool valid(const I i);
1062 // //{ return graph->valid(i); }
1064 // //template<typename I> void setInvalid(const I &i);
1065 // //{ return graph->setInvalid(i); }
1067 // Node addNode() { return graph->addNode(); }
1068 // Edge addEdge(const Node& tail, const Node& head) {
1069 // return graph->addEdge(tail, head); }
1071 // template<typename I> void erase(const I& i) { graph->erase(i); }
1073 // void clear() { graph->clear(); }
1075 // template<typename S> class NodeMap : public Graph::NodeMap<S> { };
1076 // template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
1078 // void setGraph(Graph& _graph) { graph = &_graph; }
1079 // Graph& getGraph() { return (*graph); }
1081 // //ResGraphWrapper() : graph(0) { }
1082 // ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
1087 #endif //GRAPH_WRAPPER_H