2 #ifndef GRAPH_WRAPPER_H
3 #define GRAPH_WRAPPER_H
7 template<typename Graph>
8 class TrivGraphWrapper {
12 typedef Graph BaseGraph;
14 typedef typename Graph::NodeIt NodeIt;
15 typedef typename Graph::EdgeIt EdgeIt;
17 typedef typename Graph::EachNodeIt EachNodeIt;
19 typedef typename Graph::OutEdgeIt OutEdgeIt;
20 typedef typename Graph::InEdgeIt InEdgeIt;
21 typedef typename Graph::SymEdgeIt SymEdgeIt;
22 typedef typename Graph::EachEdgeIt EachEdgeIt;
24 int nodeNum() const { return graph->nodeNum(); }
25 int edgeNum() const { return graph->edgeNum(); }
27 template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
28 template<typename I, typename P> I& getFirst(I& i, const P& p) const {
29 return graph->getFirst(i, p); }
30 //template<typename I> I next(const I i); { return graph->goNext(i); }
31 //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
33 template< typename It > It first() const {
34 It e; getFirst(e); return e; }
36 template< typename It > It first(NodeIt v) const {
37 It e; getFirst(e, v); return e; }
39 NodeIt head(const EdgeIt& e) const { return graph->head(e); }
40 NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
42 template<typename I> NodeIt aNode(const I& e) const {
43 return graph->aNode(e); }
44 template<typename I> NodeIt bNode(const I& e) const {
45 return graph->bNode(e); }
47 //template<typename I> bool valid(const I& i)
48 //{ return graph->valid(i); }
50 //template<typename I> void setInvalid(const I &i);
51 //{ return graph->setInvalid(i); }
53 NodeIt addNode() const { return graph->addNode(); }
54 EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const {
55 return graph->addEdge(tail, head); }
57 template<typename I> void erase(const I& i) const { graph->erase(i); }
59 void clear() const { graph->clear(); }
61 template<typename T> class NodeMap : public Graph::NodeMap<T> {
63 NodeMap(const Graph& _G) : Graph::NodeMap<T>(_G) { }
64 NodeMap(const Graph& _G, T a) : Graph::NodeMap<T>(_G, a) { }
66 template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
68 void setGraph(Graph& _graph) { graph = &_graph; }
69 Graph& getGraph() { return (*graph); }
71 //TrivGraphWrapper() : graph(0) { }
72 TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
75 template<typename Graph>
76 class ConstTrivGraphWrapper {
80 typedef Graph BaseGraph;
82 typedef typename Graph::NodeIt NodeIt;
83 typedef typename Graph::EdgeIt EdgeIt;
85 typedef typename Graph::EachNodeIt EachNodeIt;
87 typedef typename Graph::OutEdgeIt OutEdgeIt;
88 typedef typename Graph::InEdgeIt InEdgeIt;
89 typedef typename Graph::SymEdgeIt SymEdgeIt;
90 typedef typename Graph::EachEdgeIt EachEdgeIt;
92 int nodeNum() const { return graph->nodeNum(); }
93 int edgeNum() const { return graph->edgeNum(); }
95 template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
96 template<typename I, typename P> I& getFirst(I& i, const P& p) const {
97 return graph->getFirst(i, p); }
98 //template<typename I> I next(const I i); { return graph->goNext(i); }
99 //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
101 template< typename It > It first() const {
102 It e; getFirst(e); return e; }
104 template< typename It > It first(NodeIt v) const {
105 It e; getFirst(e, v); return e; }
107 NodeIt head(const EdgeIt& e) const { return graph->head(e); }
108 NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
110 template<typename I> NodeIt aNode(const I& e) const {
111 return graph->aNode(e); }
112 template<typename I> NodeIt bNode(const I& e) const {
113 return graph->bNode(e); }
115 //template<typename I> bool valid(const I& i)
116 //{ return graph->valid(i); }
118 //template<typename I> void setInvalid(const I &i);
119 //{ return graph->setInvalid(i); }
121 NodeIt addNode() const { return graph->addNode(); }
122 EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) const {
123 return graph->addEdge(tail, head); }
125 template<typename I> void erase(const I& i) const { graph->erase(i); }
127 void clear() const { graph->clear(); }
129 template<typename T> class NodeMap : public Graph::NodeMap<T> {
131 NodeMap(const Graph& _G) : Graph::NodeMap<T>(_G) { }
132 NodeMap(const Graph& _G, T a) : Graph::NodeMap<T>(_G, a) { }
134 template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
136 void setGraph(const Graph& _graph) { graph = &_graph; }
137 const Graph& getGraph() { return (*graph); }
139 //ConstTrivGraphWrapper() : graph(0) { }
140 ConstTrivGraphWrapper(const Graph& _graph) : graph(&_graph) { }
144 template<typename Graph>
145 class RevGraphWrapper
150 typedef Graph BaseGraph;
152 typedef typename Graph::NodeIt NodeIt;
153 typedef typename Graph::EdgeIt EdgeIt;
155 typedef typename Graph::EachNodeIt EachNodeIt;
157 typedef typename Graph::OutEdgeIt InEdgeIt;
158 typedef typename Graph::InEdgeIt OutEdgeIt;
159 typedef typename Graph::SymEdgeIt SymEdgeIt;
160 typedef typename Graph::EachEdgeIt EachEdgeIt;
162 int nodeNum() const { return graph->nodeNum(); }
163 int edgeNum() const { return graph->edgeNum(); }
165 template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
166 template<typename I, typename P> I& getFirst(I& i, const P& p) const {
167 return graph->getFirst(i, p); }
168 //template<typename I> I next(const I i); { return graph->goNext(i); }
169 //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
171 template< typename It > It first() const {
172 It e; getFirst(e); return e; }
174 template< typename It > It first(NodeIt v) const {
175 It e; getFirst(e, v); return e; }
177 NodeIt head(const EdgeIt& e) const { return graph->tail(e); }
178 NodeIt tail(const EdgeIt& e) const { return graph->head(e); }
180 template<typename I> NodeIt aNode(const I& e) const {
181 return graph->aNode(e); }
182 template<typename I> NodeIt bNode(const I& e) const {
183 return graph->bNode(e); }
185 //template<typename I> bool valid(const I i);
186 //{ return graph->valid(i); }
188 //template<typename I> void setInvalid(const I &i);
189 //{ return graph->setInvalid(i); }
191 NodeIt addNode() { return graph->addNode(); }
192 EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) {
193 return graph->addEdge(tail, head); }
195 template<typename I> void erase(const I& i) { graph->erase(i); }
197 void clear() { graph->clear(); }
199 template<typename T> class NodeMap : public Graph::NodeMap<T> { };
200 template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
202 void setGraph(Graph& _graph) { graph = &_graph; }
203 Graph& getGraph() { return (*graph); }
205 //RevGraphWrapper() : graph(0) { }
206 RevGraphWrapper(Graph& _graph) : graph(&_graph) { }
209 template<typename Graph>
210 class SymGraphWrapper
215 typedef Graph BaseGraph;
217 typedef typename Graph::NodeIt NodeIt;
218 typedef typename Graph::EdgeIt EdgeIt;
220 typedef typename Graph::EachNodeIt EachNodeIt;
222 //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon
223 //iranyitatlant, ami van
224 //mert csak 1 dolgot lehet be typedef-elni
225 typedef typename Graph::OutEdgeIt SymEdgeIt;
226 //typedef typename Graph::InEdgeIt SymEdgeIt;
227 //typedef typename Graph::SymEdgeIt SymEdgeIt;
228 typedef typename Graph::EachEdgeIt EachEdgeIt;
230 int nodeNum() const { return graph->nodeNum(); }
231 int edgeNum() const { return graph->edgeNum(); }
233 template<typename I> I& getFirst(I& i) const { return graph->getFirst(i); }
234 template<typename I, typename P> I& getFirst(I& i, const P& p) const {
235 return graph->getFirst(i, p); }
236 //template<typename I> I next(const I i); { return graph->goNext(i); }
237 //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
239 template< typename It > It first() const {
240 It e; getFirst(e); return e; }
242 template< typename It > It first(NodeIt v) const {
243 It e; getFirst(e, v); return e; }
245 NodeIt head(const EdgeIt& e) const { return graph->head(e); }
246 NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
248 template<typename I> NodeIt aNode(const I& e) const {
249 return graph->aNode(e); }
250 template<typename I> NodeIt bNode(const I& e) const {
251 return graph->bNode(e); }
253 //template<typename I> bool valid(const I i);
254 //{ return graph->valid(i); }
256 //template<typename I> void setInvalid(const I &i);
257 //{ return graph->setInvalid(i); }
259 NodeIt addNode() { return graph->addNode(); }
260 EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) {
261 return graph->addEdge(tail, head); }
263 template<typename I> void erase(const I& i) { graph->erase(i); }
265 void clear() { graph->clear(); }
267 template<typename T> class NodeMap : public Graph::NodeMap<T> { };
268 template<typename T> class EdgeMap : public Graph::EdgeMap<T> { };
270 void setGraph(Graph& _graph) { graph = &_graph; }
271 Graph& getGraph() { return (*graph); }
273 //SymGraphWrapper() : graph(0) { }
274 SymGraphWrapper(Graph& _graph) : graph(&_graph) { }
278 // FIXME: comparison should be made better!!!
279 template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
280 class ResGraphWrapper
285 typedef Graph BaseGraph;
287 typedef typename Graph::NodeIt NodeIt;
288 typedef typename Graph::EdgeIt EdgeIt;
290 typedef typename Graph::EachNodeIt EachNodeIt;
296 typename Graph::OutEdgeIt o;
297 typename Graph::InEdgeIt i;
303 typename Graph::OutEdgeIt o;
304 typename Graph::InEdgeIt i;
306 typedef typename Graph::SymEdgeIt SymEdgeIt;
307 typedef typename Graph::EachEdgeIt EachEdgeIt;
309 int nodeNum() const { return graph->nodeNum(); }
310 int edgeNum() const { return graph->edgeNum(); }
312 NodeIt& getFirst(NodeIt& n) const { return graph->getFirst(n); }
314 // EachEdge and SymEdge is missing!!!!
315 // EdgeIt <-> In/OutEdgeIt conversion is missing!!!!
318 OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const
321 graph->getFirst(e.o,n);
322 while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
324 if(!graph->valid(e.o)) {
325 graph->getFirst(e.i,n);
326 while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
332 OutEdgeIt &goNext(OutEdgeIt &e)
334 if(graph->valid(e.o)) {
335 while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
337 if(graph->valid(e.o)) return e;
338 else graph->getFirst(e.i,e.n);
341 while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
346 OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
348 //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
351 InEdgeIt& getFirst(InEdgeIt& e, const NodeIt& n) const
354 graph->getFirst(e.i,n);
355 while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
357 if(!graph->valid(e.i)) {
358 graph->getFirst(e.o,n);
359 while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
365 InEdgeIt &goNext(InEdgeIt &e)
367 if(graph->valid(e.i)) {
368 while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
370 if(graph->valid(e.i)) return e;
371 else graph->getFirst(e.o,e.n);
374 while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
379 InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
381 //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
383 //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
384 //template<typename I> I next(const I i); { return graph->goNext(i); }
386 template< typename It > It first() const {
387 It e; getFirst(e); return e; }
389 template< typename It > It first(NodeIt v) const {
390 It e; getFirst(e, v); return e; }
392 NodeIt head(const EdgeIt& e) const { return graph->head(e); }
393 NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
395 template<typename I> NodeIt aNode(const I& e) const {
396 return graph->aNode(e); }
397 template<typename I> NodeIt bNode(const I& e) const {
398 return graph->bNode(e); }
400 //template<typename I> bool valid(const I i);
401 //{ return graph->valid(i); }
403 //template<typename I> void setInvalid(const I &i);
404 //{ return graph->setInvalid(i); }
406 NodeIt addNode() { return graph->addNode(); }
407 EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) {
408 return graph->addEdge(tail, head); }
410 template<typename I> void erase(const I& i) { graph->erase(i); }
412 void clear() { graph->clear(); }
414 template<typename S> class NodeMap : public Graph::NodeMap<S> { };
415 template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
417 void setGraph(Graph& _graph) { graph = &_graph; }
418 Graph& getGraph() { return (*graph); }
420 //ResGraphWrapper() : graph(0) { }
421 ResGraphWrapper(Graph& _graph) : graph(&_graph) { }
425 // FIXME: comparison should be made better!!!
426 template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap>
427 class ConstResGraphWrapper
434 typedef Graph BaseGraph;
436 typedef typename Graph::NodeIt NodeIt;
437 typedef typename Graph::EdgeIt EdgeIt;
439 typedef typename Graph::EachNodeIt EachNodeIt;
445 typename Graph::SymEdgeIt sym;
451 typename Graph::OutEdgeIt sym;
453 //typedef typename Graph::SymEdgeIt SymEdgeIt;
454 //typedef typename Graph::EachEdgeIt EachEdgeIt;
456 int nodeNum() const { return graph->nodeNum(); }
457 //int edgeNum() const { return graph->edgeNum(); }
459 NodeIt& getFirst(NodeIt& n) const { return graph->getFirst(n); }
461 // EachEdge and SymEdge is missing!!!!
462 // EdgeIt <-> In/OutEdgeIt conversion is missing!!!!
466 OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt& n) const
469 graph->getFirst(e.o,n);
470 while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
472 if(!graph->valid(e.o)) {
473 graph->getFirst(e.i,n);
474 while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
480 OutEdgeIt &goNext(OutEdgeIt &e)
482 if(graph->valid(e.o)) {
483 while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o))
485 if(graph->valid(e.o)) return e;
486 else graph->getFirst(e.i,e.n);
489 while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i))
494 OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);}
496 //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);}
499 InEdgeIt& getFirst(InEdgeIt& e, const NodeIt& n) const
502 graph->getFirst(e.i,n);
503 while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
505 if(!graph->valid(e.i)) {
506 graph->getFirst(e.o,n);
507 while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
513 InEdgeIt &goNext(InEdgeIt &e)
515 if(graph->valid(e.i)) {
516 while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i))
518 if(graph->valid(e.i)) return e;
519 else graph->getFirst(e.o,e.n);
522 while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o))
527 InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);}
529 //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);}
531 //template<typename I> I &goNext(I &i); { return graph->goNext(i); }
532 //template<typename I> I next(const I i); { return graph->goNext(i); }
534 template< typename It > It first() const {
535 It e; getFirst(e); return e; }
537 template< typename It > It first(NodeIt v) const {
538 It e; getFirst(e, v); return e; }
540 NodeIt head(const EdgeIt& e) const { return graph->head(e); }
541 NodeIt tail(const EdgeIt& e) const { return graph->tail(e); }
543 template<typename I> NodeIt aNode(const I& e) const {
544 return graph->aNode(e); }
545 template<typename I> NodeIt bNode(const I& e) const {
546 return graph->bNode(e); }
548 //template<typename I> bool valid(const I i);
549 //{ return graph->valid(i); }
551 //template<typename I> void setInvalid(const I &i);
552 //{ return graph->setInvalid(i); }
554 NodeIt addNode() { return graph->addNode(); }
555 EdgeIt addEdge(const NodeIt& tail, const NodeIt& head) {
556 return graph->addEdge(tail, head); }
558 template<typename I> void erase(const I& i) { graph->erase(i); }
560 void clear() { graph->clear(); }
562 template<typename S> class NodeMap : public Graph::NodeMap<S> { };
563 template<typename S> class EdgeMap : public Graph::EdgeMap<S> { };
565 void setGraph(const Graph& _graph) { graph = &_graph; }
566 const Graph& getGraph() { return (*graph); }
568 //ConstResGraphWrapper() : graph(0) { }
569 ConstResGraphWrapper(const Graph& _graph) : graph(&_graph) { }
578 #endif //GRAPH_WRAPPER_H
581 // NodeIt &getFirst(NodeIt &n) { return graph->getFirst(n); }
582 // InEdgeIt &getFirst(InEdgeIt &e,const NodeIt &n);
583 // { return graph->getFirst(e,n); }
584 // OutEdgeIt &getFirst(OutEdgeIt &e,const NodeIt &n);
585 // { return graph->getFirst(e,n); }
586 // SymEdgeIt &getFirst(SymEdgeIt &e,const NodeIt &n);
587 // { return graph->getFirst(e,n); }
588 // EachEdgeIt &getFirst(EachEdgeIt &e);
589 // { return graph->getFirst(e); }
591 // NodeIt next(const NodeIt &n);
592 // { return graph->next(n); }
593 // InEdgeIt next(const InEdgeIt &e);
594 // { return graph->next(e); }
595 // OutEdgeIt next(const OutEdgeIt &e);
596 // { return graph->next(e); }
597 // SymEdgeIt next(const SymEdgeIt &e);
598 // { return graph->next(e); }
599 // EachEdgeIt next(const EachEdgeIt &e);
600 // { return graph->next(e); }
602 // NodeIt &goNext(NodeIt &n);
603 // { return graph->goNext(n); }
604 // InEdgeIt &goNext(InEdgeIt &e);
605 // { return graph->goNext(e); }
606 // OutEdgeIt &goNext(OutEdgeIt &e);
607 // { return graph->goNext(e); }
608 // SymEdgeIt &goNext(SymEdgeIt &e);
609 // { return graph->goNext(e); }
610 // EachEdgeIt &goNext(EachEdgeIt &e);
611 // { return graph->goNext(e); }