Changeset 303:1b377a730d02 in lemon-0.x for src/work/marci/graph_wrapper.h
- Timestamp:
- 04/05/04 18:52:46 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@421
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/marci/graph_wrapper.h
r279 r303 13 13 14 14 public: 15 typedef Graph BaseGraph; 15 typedef Graph ParentGraph; 16 17 // TrivGraphWrapper() : graph(0) { } 18 TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } 19 // void setGraph(Graph& _graph) { graph = &_graph; } 20 // Graph& getGraph() const { return *graph; } 16 21 17 22 typedef typename Graph::Node Node; … … 25 30 }; 26 31 typedef typename Graph::Edge Edge; 27 //typedef typename Graph::OutEdgeIt OutEdgeIt;28 32 class OutEdgeIt : public Graph::OutEdgeIt { 29 33 public: … … 34 38 Graph::OutEdgeIt(*(_G.graph), n) { } 35 39 }; 36 //typedef typename Graph::InEdgeIt InEdgeIt;37 40 class InEdgeIt : public Graph::InEdgeIt { 38 41 public: … … 44 47 }; 45 48 //typedef typename Graph::SymEdgeIt SymEdgeIt; 46 //typedef typename Graph::EdgeIt EdgeIt;47 49 class EdgeIt : public Graph::EdgeIt { 48 50 public: … … 54 56 }; 55 57 56 //TrivGraphWrapper() : graph(0) { }57 TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }58 59 // void setGraph(Graph& _graph) { graph = &_graph; }60 // Graph& getGraph() const { return (*graph); }61 62 58 NodeIt& first(NodeIt& i) const { 63 59 i=NodeIt(*this); … … 69 65 } 70 66 // template<typename I> I& first(I& i) const { 71 // //return graph->first(i);72 67 // i=I(*this); 73 68 // return i; … … 82 77 } 83 78 // template<typename I, typename P> I& first(I& i, const P& p) const { 84 // //return graph->first(i, p);85 79 // i=I(*this, p); 86 80 // return i; … … 92 86 93 87 template< typename It > It first() const { 94 It e; first(e); return e; }88 It e; this->first(e); return e; } 95 89 96 90 template< typename It > It first(const Node& v) const { 97 It e; first(e, v); return e; }91 It e; this->first(e, v); return e; } 98 92 99 93 Node head(const Edge& e) const { return graph->head(e); } 100 94 Node tail(const Edge& e) const { return graph->tail(e); } 101 95 102 template<typename I> bool valid(const I& i) const 103 {return graph->valid(i); }96 template<typename I> bool valid(const I& i) const { 97 return graph->valid(i); } 104 98 105 99 //template<typename I> void setInvalid(const I &i); … … 138 132 }; 139 133 140 template<typename Map, typename T> class NodeMapWrapper { 141 protected: 142 Map* map; 143 public: 144 NodeMapWrapper(Map& _map) : map(&_map) { } 145 //template<typename T> 146 void set(Node n, T a) { map->set(n, a); } 147 //template<typename T> 148 T get(Node n) const { return map->get(n); } 149 }; 150 151 template<typename Map, typename T> class EdgeMapWrapper { 152 protected: 153 Map* map; 154 public: 155 EdgeMapWrapper(Map& _map) : map(&_map) { } 156 //template<typename T> 157 void set(Edge n, T a) { map->set(n, a); } 158 //template<typename T> 159 T get(Edge n) const { return map->get(n); } 160 }; 134 // template<typename Map, typename T> class NodeMapWrapper { 135 // protected: 136 // Map* map; 137 // public: 138 // NodeMapWrapper(Map& _map) : map(&_map) { } 139 // void set(Node n, T a) { map->set(n, a); } 140 // T get(Node n) const { return map->get(n); } 141 // }; 142 143 // template<typename Map, typename T> class EdgeMapWrapper { 144 // protected: 145 // Map* map; 146 // public: 147 // EdgeMapWrapper(Map& _map) : map(&_map) { } 148 // void set(Edge n, T a) { map->set(n, a); } 149 // T get(Edge n) const { return map->get(n); } 150 // }; 161 151 }; 162 152 163 template<typename GraphWrapper> 164 class GraphWrapperSkeleton { 153 154 template<typename Graph> 155 class GraphWrapper { 165 156 protected: 166 Graph Wrapper gw;157 Graph* graph; 167 158 168 159 public: 169 //typedef typename GraphWrapper::BaseGraph BaseGraph; 170 171 // typedef typename GraphWrapper::Node Node; 172 // typedef typename GraphWrapper::NodeIt NodeIt; 173 174 // typedef typename GraphWrapper::Edge Edge; 175 // typedef typename GraphWrapper::OutEdgeIt OutEdgeIt; 176 // typedef typename GraphWrapper::InEdgeIt InEdgeIt; 177 // //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt; 178 // typedef typename GraphWrapper::EdgeIt EdgeIt; 179 180 typedef typename GraphWrapper::Node Node; 181 class NodeIt : public GraphWrapper::NodeIt { 160 typedef Graph ParentGraph; 161 162 // GraphWrapper() : graph(0) { } 163 GraphWrapper(Graph& _graph) : graph(&_graph) { } 164 // void setGraph(Graph& _graph) { graph=&_graph; } 165 // Graph& getGraph() const { return *graph; } 166 167 typedef typename Graph::Node Node; 168 class NodeIt : public Graph::NodeIt { 182 169 public: 183 170 NodeIt() { } 184 NodeIt(const typename GraphWrapper::NodeIt& n) : 185 GraphWrapper::NodeIt(n) { } 186 NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { } 187 NodeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 188 GraphWrapper::NodeIt(_G.gw) { } 189 }; 190 typedef typename GraphWrapper::Edge Edge; 191 //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt; 192 class OutEdgeIt : public GraphWrapper::OutEdgeIt { 171 NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { } 172 NodeIt(const Invalid& i) : Graph::NodeIt(i) { } 173 NodeIt(const GraphWrapper<Graph>& _G) : 174 Graph::NodeIt(*(_G.graph)) { } 175 }; 176 typedef typename Graph::Edge Edge; 177 class OutEdgeIt : public Graph::OutEdgeIt { 193 178 public: 194 179 OutEdgeIt() { } 195 OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) : 196 GraphWrapper::OutEdgeIt(e) { } 197 OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { } 198 OutEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 199 GraphWrapper::OutEdgeIt(_G.gw, n) { } 200 }; 201 //typedef typename GraphWrapper::InEdgeIt InEdgeIt; 202 class InEdgeIt : public GraphWrapper::InEdgeIt { 180 OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { } 181 OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { } 182 OutEdgeIt(const GraphWrapper<Graph>& _G, const Node& n) : 183 Graph::OutEdgeIt(*(_G.graph), n) { } 184 }; 185 class InEdgeIt : public Graph::InEdgeIt { 203 186 public: 204 187 InEdgeIt() { } 205 InEdgeIt(const typename GraphWrapper::InEdgeIt& e) : 206 GraphWrapper::InEdgeIt(e) { } 207 InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { } 208 InEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 209 GraphWrapper::InEdgeIt(_G.gw, n) { } 210 }; 211 //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt; 212 //typedef typename GraphWrapper::EdgeIt EdgeIt; 213 class EdgeIt : public GraphWrapper::EdgeIt { 188 InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { } 189 InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { } 190 InEdgeIt(const GraphWrapper<Graph>& _G, const Node& n) : 191 Graph::InEdgeIt(*(_G.graph), n) { } 192 }; 193 //typedef typename Graph::SymEdgeIt SymEdgeIt; 194 class EdgeIt : public Graph::EdgeIt { 214 195 public: 215 196 EdgeIt() { } 216 EdgeIt(const typename GraphWrapper::EdgeIt& e) : 217 GraphWrapper::EdgeIt(e) { } 218 EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { } 219 EdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 220 GraphWrapper::EdgeIt(_G.gw) { } 221 }; 222 223 224 //GraphWrapperSkeleton() : gw() { } 225 GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { } 226 227 //void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); } 228 //BaseGraph& getGraph() const { return gw.getGraph(); } 229 230 template<typename I> I& first(I& i) const { 231 i=I(*this); 197 EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { } 198 EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { } 199 EdgeIt(const GraphWrapper<Graph>& _G) : 200 Graph::EdgeIt(*(_G.graph)) { } 201 }; 202 203 NodeIt& first(NodeIt& i) const { 204 i=NodeIt(*this); 232 205 return i; 233 206 } 234 template<typename I, typename P> I& first(I& i, const P& p) const { 235 i=I(*this, p); 236 return i; 237 } 238 239 // template<typename I> I getNext(const I& i) const { return gw.getNext(i); } 240 template<typename I> I& next(I &i) const { gw.next(i); return i; } 207 EdgeIt& first(EdgeIt& i) const { 208 i=EdgeIt(*this); 209 return i; 210 } 211 // template<typename I> I& first(I& i) const { 212 // i=I(*this); 213 // return i; 214 // } 215 OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 216 i=OutEdgeIt(*this, p); 217 return i; 218 } 219 InEdgeIt& first(InEdgeIt& i, const Node& p) const { 220 i=InEdgeIt(*this, p); 221 return i; 222 } 223 // template<typename I, typename P> I& first(I& i, const P& p) const { 224 // i=I(*this, p); 225 // return i; 226 // } 227 228 // template<typename I> I getNext(const I& i) const { 229 // return gw.getNext(i); } 230 template<typename I> I& next(I &i) const { graph->next(i); return i; } 241 231 242 232 template< typename It > It first() const { … … 246 236 It e; this->first(e, v); return e; } 247 237 248 Node head(const Edge& e) const { return gw.head(e); } 249 Node tail(const Edge& e) const { return gw.tail(e); } 250 251 template<typename I> bool valid(const I& i) const { return gw.valid(i); } 238 Node head(const Edge& e) const { return graph->head(e); } 239 Node tail(const Edge& e) const { return graph->tail(e); } 240 241 template<typename I> bool valid(const I& i) const { 242 return graph->valid(i); } 252 243 253 244 //template<typename I> void setInvalid(const I &i); 254 245 //{ return graph->setInvalid(i); } 255 246 256 int nodeNum() const { return gw.nodeNum(); } 257 int edgeNum() const { return gw.edgeNum(); } 258 259 template<typename I> Node aNode(const I& e) const { return gw.aNode(e); } 260 template<typename I> Node bNode(const I& e) const { return gw.bNode(e); } 261 262 Node addNode() const { return gw.addNode(); } 247 int nodeNum() const { return graph->nodeNum(); } 248 int edgeNum() const { return graph->edgeNum(); } 249 250 template<typename I> Node aNode(const I& e) const { 251 return graph->aNode(e); } 252 template<typename I> Node bNode(const I& e) const { 253 return graph->bNode(e); } 254 255 Node addNode() const { return graph->addNode(); } 263 256 Edge addEdge(const Node& tail, const Node& head) const { 264 return g w.addEdge(tail, head); }265 266 template<typename I> void erase(const I& i) const { g w.erase(i); }267 268 void clear() const { g w.clear(); }269 270 template<typename T> class NodeMap : public Graph Wrapper::NodeMap<T> {271 public: 272 NodeMap(const GraphWrapper Skeleton<GraphWrapper>& _G) :273 Graph Wrapper::NodeMap<T>(_G.gw) { }274 NodeMap(const GraphWrapper Skeleton<GraphWrapper>& _G, T a) :275 Graph Wrapper::NodeMap<T>(_G.gw, a) { }276 }; 277 278 template<typename T> class EdgeMap : public Graph Wrapper::EdgeMap<T> {279 public: 280 EdgeMap(const GraphWrapper Skeleton<GraphWrapper>& _G) :281 Graph Wrapper::EdgeMap<T>(_G.gw) { }282 EdgeMap(const GraphWrapper Skeleton<GraphWrapper>& _G, T a) :283 Graph Wrapper::EdgeMap<T>(_G.gw, a) { }257 return graph->addEdge(tail, head); } 258 259 template<typename I> void erase(const I& i) const { graph->erase(i); } 260 261 void clear() const { graph->clear(); } 262 263 template<typename T> class NodeMap : public Graph::NodeMap<T> { 264 public: 265 NodeMap(const GraphWrapper<Graph>& _G) : 266 Graph::NodeMap<T>(*(_G.graph)) { } 267 NodeMap(const GraphWrapper<Graph>& _G, T a) : 268 Graph::NodeMap<T>(*(_G.graph), a) { } 269 }; 270 271 template<typename T> class EdgeMap : public Graph::EdgeMap<T> { 272 public: 273 EdgeMap(const GraphWrapper<Graph>& _G) : 274 Graph::EdgeMap<T>(*(_G.graph)) { } 275 EdgeMap(const GraphWrapper<Graph>& _G, T a) : 276 Graph::EdgeMap<T>(*(_G.graph), a) { } 284 277 }; 285 278 }; 279 286 280 287 281 // template<typename Graph> … … 292 286 293 287 // public: 294 // typedef Graph BaseGraph;288 // typedef Graph ParentGraph; 295 289 296 290 // typedef typename Graph::Node Node; … … 365 359 // }; 366 360 367 // template<typename /*Graph*/GraphWrapper 368 // /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ > 369 // class RevGraphWrapper : 370 // public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ { 371 // protected: 372 // //Graph* graph; 373 374 // public: 375 // //typedef Graph BaseGraph; 376 377 // //typedef typename Graph::Node Node; 378 // //typedef typename Graph::NodeIt NodeIt; 379 380 // //typedef typename Graph::Edge Edge; 381 // typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt; 382 // typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt; 383 // //typedef typename Graph::SymEdgeIt SymEdgeIt; 384 // //typedef typename Graph::EdgeIt EdgeIt; 385 386 // //RevGraphWrapper() : graph(0) { } 387 // RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { } 388 389 // //void setGraph(Graph& _graph) { graph = &_graph; } 390 // //Graph& getGraph() const { return (*graph); } 391 392 // //template<typename I> I& first(I& i) const { return graph->first(i); } 393 // //template<typename I, typename P> I& first(I& i, const P& p) const { 394 // // return graph->first(i, p); } 395 396 // //template<typename I> I getNext(const I& i) const { 397 // // return graph->getNext(i); } 398 // //template<typename I> I& next(I &i) const { return graph->next(i); } 399 400 // //template< typename It > It first() const { 401 // // It e; first(e); return e; } 402 403 // //template< typename It > It first(const Node& v) const { 404 // // It e; first(e, v); return e; } 405 406 // //Node head(const Edge& e) const { return graph->tail(e); } 407 // //Node tail(const Edge& e) const { return graph->head(e); } 408 409 // //template<typename I> bool valid(const I& i) const 410 // // { return graph->valid(i); } 411 412 // //template<typename I> void setInvalid(const I &i); 413 // //{ return graph->setInvalid(i); } 414 415 // //template<typename I> Node aNode(const I& e) const { 416 // // return graph->aNode(e); } 417 // //template<typename I> Node bNode(const I& e) const { 418 // // return graph->bNode(e); } 419 420 // //Node addNode() const { return graph->addNode(); } 421 // //Edge addEdge(const Node& tail, const Node& head) const { 422 // // return graph->addEdge(tail, head); } 423 424 // //int nodeNum() const { return graph->nodeNum(); } 425 // //int edgeNum() const { return graph->edgeNum(); } 426 427 // //template<typename I> void erase(const I& i) const { graph->erase(i); } 428 429 // //void clear() const { graph->clear(); } 430 431 // template<typename T> class NodeMap : 432 // public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T> 433 // { 434 // public: 435 // NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 436 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { } 437 // NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 438 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { } 439 // }; 440 441 // template<typename T> class EdgeMap : 442 // public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> { 443 // public: 444 // EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) : 445 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { } 446 // EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : 447 // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { } 448 // }; 449 // }; 450 451 template<typename GraphWrapper> 452 class RevGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> { 361 362 template<typename Graph> 363 class RevGraphWrapper : public GraphWrapper<Graph> { 453 364 public: 454 typedef typename GraphWrapper Skeleton<GraphWrapper>::Node Node;455 typedef typename GraphWrapper Skeleton<GraphWrapper>::Edge Edge;365 typedef typename GraphWrapper<Graph>::Node Node; 366 typedef typename GraphWrapper<Graph>::Edge Edge; 456 367 //FIXME 457 //If Graph Wrapper::OutEdgeIt is not defined368 //If Graph::OutEdgeIt is not defined 458 369 //and we do not want to use RevGraphWrapper::InEdgeIt, 459 370 //this won't work, because of typedef … … 462 373 //Unfortunately all the typedefs are instantiated in templates, 463 374 //unlike other stuff 464 typedef typename GraphWrapper Skeleton<GraphWrapper>::OutEdgeIt InEdgeIt;465 typedef typename GraphWrapper Skeleton<GraphWrapper>::InEdgeIt OutEdgeIt;466 467 RevGraphWrapper(GraphWrapper _gw) : 468 GraphWrapperSkeleton<GraphWrapper>(_gw) { }375 typedef typename GraphWrapper<Graph>::OutEdgeIt InEdgeIt; 376 typedef typename GraphWrapper<Graph>::InEdgeIt OutEdgeIt; 377 378 // RevGraphWrapper() : GraphWrapper<Graph>() { } 379 RevGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { } 469 380 470 381 Node head(const Edge& e) const 471 { return GraphWrapper Skeleton<GraphWrapper>::tail(e); }382 { return GraphWrapper<Graph>::tail(e); } 472 383 Node tail(const Edge& e) const 473 { return GraphWrapper Skeleton<GraphWrapper>::head(e); }384 { return GraphWrapper<Graph>::head(e); } 474 385 }; 475 386 476 387 //Subgraph on the same node-set and partial edge-set 477 template<typename Graph Wrapper, typename EdgeFilterMap>478 class SubGraphWrapper : public GraphWrapper Skeleton<GraphWrapper> {388 template<typename Graph, typename EdgeFilterMap> 389 class SubGraphWrapper : public GraphWrapper<Graph> { 479 390 protected: 480 391 EdgeFilterMap* filter_map; 481 392 public: 482 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node; 483 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt; 484 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge; 485 typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt; 486 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt; 487 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt; 488 489 SubGraphWrapper(GraphWrapper _gw, EdgeFilterMap& _filter_map) : 490 GraphWrapperSkeleton<GraphWrapper>(_gw), filter_map(&_filter_map) { } 393 typedef typename GraphWrapper<Graph>::Node Node; 394 typedef typename GraphWrapper<Graph>::NodeIt NodeIt; 395 typedef typename GraphWrapper<Graph>::Edge Edge; 396 typedef typename GraphWrapper<Graph>::EdgeIt EdgeIt; 397 typedef typename GraphWrapper<Graph>::InEdgeIt InEdgeIt; 398 typedef typename GraphWrapper<Graph>::OutEdgeIt OutEdgeIt; 399 400 // SubGraphWrapper() : GraphWrapper<Graph>(), filter_map(0) { } 401 SubGraphWrapper(Graph& _graph, EdgeFilterMap& _filter_map) : 402 GraphWrapper<Graph>(_graph), filter_map(&_filter_map) { } 491 403 492 404 template<typename I> I& first(I& i) const { 493 gw.first(i); 494 while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); } 405 graph->first(i); 406 //while (graph->valid(i) && !filter_map->get(i)) { graph->next(i); } 407 while (graph->valid(i) && !(*filter_map)[i]) { graph->next(i); } 495 408 return i; 496 409 } 497 410 template<typename I, typename P> I& first(I& i, const P& p) const { 498 gw.first(i, p); 499 while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); } 411 graph->first(i, p); 412 // while (graph->valid(i) && !filter_map->get(i)) { graph->next(i); } 413 while (graph->valid(i) && !(*filter_map)[i]) { graph->next(i); } 500 414 return i; 501 415 } … … 505 419 //} 506 420 template<typename I> I& next(I &i) const { 507 gw.next(i); 508 while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); } 421 graph->next(i); 422 // while (graph->valid(i) && !filter_map-get(i)) { graph->next(i); } 423 while (graph->valid(i) && !(*filter_map)[i]) { graph->next(i); } 509 424 return i; 510 425 } … … 524 439 525 440 // public: 526 // typedef GraphWrapper BaseGraph;441 // typedef GraphWrapper ParentGraph; 527 442 528 443 // typedef typename GraphWrapper::Node Node; … … 677 592 678 593 679 template<typename Graph Wrapper>680 class UndirGraphWrapper : public GraphWrapper Skeleton<GraphWrapper> {594 template<typename Graph> 595 class UndirGraphWrapper : public GraphWrapper<Graph> { 681 596 protected: 682 // GraphWrapper gw; 683 597 typedef typename Graph::Edge GraphEdge; 598 typedef typename Graph::OutEdgeIt GraphOutEdgeIt; 599 typedef typename Graph::InEdgeIt GraphInEdgeIt; 684 600 public: 685 //typedef GraphWrapper BaseGraph; 686 687 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node; 688 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt; 689 690 //private: 691 //FIXME ezeknek valojaban a GraphWrapper megfelelo dolgai kellene hogy 692 //legyenek, at kell irni 693 typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/ 694 GraphWrapper::Edge GraphEdge; 695 typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/ 696 GraphWrapper::OutEdgeIt GraphOutEdgeIt; 697 typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/ 698 GraphWrapper::InEdgeIt GraphInEdgeIt; 699 //public: 700 701 //UndirGraphWrapper() : graph(0) { } 702 UndirGraphWrapper(GraphWrapper _gw) : 703 GraphWrapperSkeleton<GraphWrapper>(_gw) { } 704 705 //UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { } 706 707 //void setGraph(Graph& _graph) { graph = &_graph; } 708 //Graph& getGraph() const { return (*graph); } 709 601 typedef typename GraphWrapper<Graph>::Node Node; 602 typedef typename GraphWrapper<Graph>::NodeIt NodeIt; 603 604 // UndirGraphWrapper() : GraphWrapper<Graph>() { } 605 UndirGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) { } 606 710 607 class Edge { 711 friend class UndirGraphWrapper<Graph Wrapper>;608 friend class UndirGraphWrapper<Graph>; 712 609 protected: 713 610 bool out_or_in; //true iff out … … 742 639 743 640 class OutEdgeIt : public Edge { 744 friend class UndirGraphWrapper<Graph Wrapper>;641 friend class UndirGraphWrapper<Graph>; 745 642 public: 746 643 OutEdgeIt() : Edge() { } 747 644 OutEdgeIt(const Invalid& i) : Edge(i) { } 748 OutEdgeIt(const UndirGraphWrapper<Graph Wrapper>& _G, const Node& n)645 OutEdgeIt(const UndirGraphWrapper<Graph>& _G, const Node& n) 749 646 : Edge() { 750 out_or_in=true; _G.g w.first(out, n);751 if (!(_G.g w.valid(out))) { out_or_in=false; _G.gw.first(in, n); }647 out_or_in=true; _G.graph->first(out, n); 648 if (!(_G.graph->valid(out))) { out_or_in=false; _G.graph->first(in, n); } 752 649 } 753 650 }; … … 756 653 757 654 class EdgeIt : public Edge { 758 friend class UndirGraphWrapper<Graph Wrapper>;655 friend class UndirGraphWrapper<Graph>; 759 656 protected: 760 657 NodeIt v; … … 762 659 EdgeIt() : Edge() { } 763 660 EdgeIt(const Invalid& i) : Edge(i) { } 764 EdgeIt(const UndirGraphWrapper<Graph Wrapper>& _G)661 EdgeIt(const UndirGraphWrapper<Graph>& _G) 765 662 : Edge() { 766 663 out_or_in=true; 767 664 //Node v; 768 665 _G.first(v); 769 if (_G.valid(v)) _G.g w.first(out); else out=INVALID;770 while (_G.valid(v) && !_G.g w.valid(out)) {771 _G.g w.next(v);772 if (_G.valid(v)) _G.g w.first(out);666 if (_G.valid(v)) _G.graph->first(out); else out=INVALID; 667 while (_G.valid(v) && !_G.graph->valid(out)) { 668 _G.graph->next(v); 669 if (_G.valid(v)) _G.graph->first(out); 773 670 } 774 671 } … … 776 673 777 674 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { 778 e.out_or_in=true; g w.first(e.out, n);779 if (!(g w.valid(e.out))) { e.out_or_in=false; gw.first(e.in, n); }675 e.out_or_in=true; graph->first(e.out, n); 676 if (!(graph->valid(e.out))) { e.out_or_in=false; graph->first(e.in, n); } 780 677 return e; 781 678 } … … 785 682 //NodeIt v; 786 683 first(e.v); 787 if (valid(e.v)) g w.first(e.out, e.v); else e.out=INVALID;788 while (valid(e.v) && !g w.valid(e.out)) {789 g w.next(e.v);790 if (valid(e.v)) g w.first(e.out, e.v);684 if (valid(e.v)) graph->first(e.out, e.v); else e.out=INVALID; 685 while (valid(e.v) && !graph->valid(e.out)) { 686 graph->next(e.v); 687 if (valid(e.v)) graph->first(e.out, e.v); 791 688 } 792 689 return e; 793 690 } 794 691 795 template<typename I> I& first(I& i) const { g w.first(i); return i; }692 template<typename I> I& first(I& i) const { graph->first(i); return i; } 796 693 template<typename I, typename P> I& first(I& i, const P& p) const { 797 g w.first(i, p); return i; }694 graph->first(i, p); return i; } 798 695 799 696 OutEdgeIt& next(OutEdgeIt& e) const { 800 697 if (e.out_or_in) { 801 Node n=g w.tail(e.out);802 g w.next(e.out);803 if (!g w.valid(e.out)) { e.out_or_in=false; gw.first(e.in, n); }698 Node n=graph->tail(e.out); 699 graph->next(e.out); 700 if (!graph->valid(e.out)) { e.out_or_in=false; graph->first(e.in, n); } 804 701 } else { 805 g w.next(e.in);702 graph->next(e.in); 806 703 } 807 704 return e; … … 810 707 EdgeIt& next(EdgeIt& e) const { 811 708 //NodeIt v=tail(e); 812 g w.next(e.out);813 while (valid(e.v) && !g w.valid(e.out)) {709 graph->next(e.out); 710 while (valid(e.v) && !graph->valid(e.out)) { 814 711 next(e.v); 815 if (valid(e.v)) g w.first(e.out, e.v);712 if (valid(e.v)) graph->first(e.out, e.v); 816 713 } 817 714 return e; 818 715 } 819 716 820 template<typename I> I& next(I &i) const { return g w.next(i); }717 template<typename I> I& next(I &i) const { return graph->next(i); } 821 718 // template<typename I> I getNext(const I& i) const { return gw.getNext(i); } 822 719 823 720 template< typename It > It first() const { 824 It e; first(e); return e; }721 It e; this->first(e); return e; } 825 722 826 723 template< typename It > It first(const Node& v) const { 827 It e; first(e, v); return e; }724 It e; this->first(e, v); return e; } 828 725 829 726 // Node head(const Edge& e) const { return gw.head(e); } … … 842 739 843 740 Node aNode(const OutEdgeIt& e) const { 844 if (e.out_or_in) return g w.tail(e); else return gw.head(e); }741 if (e.out_or_in) return graph->tail(e); else return graph->head(e); } 845 742 Node bNode(const OutEdgeIt& e) const { 846 if (e.out_or_in) return g w.head(e); else return gw.tail(e); }743 if (e.out_or_in) return graph->head(e); else return graph->tail(e); } 847 744 848 745 // Node addNode() const { return gw.addNode(); } … … 856 753 // void clear() const { gw.clear(); } 857 754 858 // template<typename T> class NodeMap : public Graph Wrapper::NodeMap<T> {859 // public: 860 // NodeMap(const UndirGraphWrapper<Graph Wrapper>& _G) :861 // Graph Wrapper::NodeMap<T>(_G.gw) { }862 // NodeMap(const UndirGraphWrapper<Graph Wrapper>& _G, T a) :863 // Graph Wrapper::NodeMap<T>(_G.gw, a) { }755 // template<typename T> class NodeMap : public Graph::NodeMap<T> { 756 // public: 757 // NodeMap(const UndirGraphWrapper<Graph>& _G) : 758 // Graph::NodeMap<T>(_G.gw) { } 759 // NodeMap(const UndirGraphWrapper<Graph>& _G, T a) : 760 // Graph::NodeMap<T>(_G.gw, a) { } 864 761 // }; 865 762 866 763 // template<typename T> class EdgeMap : 867 // public GraphWrapperSkeleton<Graph Wrapper>::EdgeMap<T> {868 // public: 869 // EdgeMap(const UndirGraphWrapper<Graph Wrapper>& _G) :870 // GraphWrapperSkeleton<Graph Wrapper>::EdgeMap<T>(_G.gw) { }871 // EdgeMap(const UndirGraphWrapper<Graph Wrapper>& _G, T a) :872 // Graph Wrapper::EdgeMap<T>(_G.gw, a) { }764 // public GraphWrapperSkeleton<Graph>::EdgeMap<T> { 765 // public: 766 // EdgeMap(const UndirGraphWrapper<Graph>& _G) : 767 // GraphWrapperSkeleton<Graph>::EdgeMap<T>(_G.gw) { } 768 // EdgeMap(const UndirGraphWrapper<Graph>& _G, T a) : 769 // Graph::EdgeMap<T>(_G.gw, a) { } 873 770 // }; 874 771 }; … … 884 781 885 782 // public: 886 // typedef Graph BaseGraph;783 // typedef Graph ParentGraph; 887 784 888 785 // typedef typename Graph::Node Node; … … 947 844 948 845 949 template<typename Graph Wrapper, typename Number, typename FlowMap, typename CapacityMap>950 class ResGraphWrapper : public GraphWrapper Skeleton<GraphWrapper>{846 template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> 847 class ResGraphWrapper : public GraphWrapper<Graph>{ 951 848 public: 952 //typedef Graph BaseGraph; 953 //typedef TrivGraphWrapper<const Graph> GraphWrapper; 954 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node; 955 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt; 956 private: 957 typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/ 958 GraphWrapper::OutEdgeIt OldOutEdgeIt; 959 typedef typename /*GraphWrapperSkeleton<GraphWrapper>*/ 960 GraphWrapper::InEdgeIt OldInEdgeIt; 849 typedef typename GraphWrapper<Graph>::Node Node; 850 typedef typename GraphWrapper<Graph>::NodeIt NodeIt; 961 851 protected: 962 //const Graph* graph; 963 //GraphWrapper gw; 852 typedef typename Graph::OutEdgeIt GraphOutEdgeIt; 853 typedef typename Graph::InEdgeIt GraphInEdgeIt; 854 typedef typename Graph::Edge GraphEdge; 964 855 FlowMap* flow; 965 856 const CapacityMap* capacity; 966 857 public: 967 858 968 ResGraphWrapper( const GraphWrapper& _gw, FlowMap& _flow,859 ResGraphWrapper(Graph& _graph, FlowMap& _flow, 969 860 const CapacityMap& _capacity) : 970 GraphWrapperSkeleton<GraphWrapper>(_gw), 971 flow(&_flow), capacity(&_capacity) { } 972 973 //void setGraph(const Graph& _graph) { graph = &_graph; } 974 //const Graph& getGraph() const { return (*graph); } 861 GraphWrapper<Graph>(_graph), flow(&_flow), capacity(&_capacity) { } 975 862 976 863 class Edge; … … 980 867 981 868 class Edge { 982 friend class ResGraphWrapper<Graph Wrapper, Number, FlowMap, CapacityMap>;869 friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; 983 870 protected: 984 871 bool out_or_in; //true, iff out 985 OldOutEdgeIt out;986 OldInEdgeIt in;872 GraphOutEdgeIt out; 873 GraphInEdgeIt in; 987 874 public: 988 875 Edge() : out_or_in(true) { } … … 1002 889 return (u.out_or_in || u.in!=v.in); 1003 890 } 891 operator GraphEdge() const { 892 if (out_or_in) return(out); else return(in); 893 } 1004 894 }; 1005 895 1006 896 1007 897 class OutEdgeIt : public Edge { 1008 friend class ResGraphWrapper<Graph Wrapper, Number, FlowMap, CapacityMap>;898 friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; 1009 899 public: 1010 900 OutEdgeIt() { } … … 1013 903 OutEdgeIt(const Invalid& i) : Edge(i) { } 1014 904 protected: 1015 OutEdgeIt(const ResGraphWrapper<Graph Wrapper, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {1016 resG.g w.first(out, v);1017 while( resG.g w.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }1018 if (!resG.g w.valid(out)) {905 OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { 906 resG.graph->first(out, v); 907 while( resG.graph->valid(out) && !(resG.resCap(out)>0) ) { resG.graph->next(out); } 908 if (!resG.graph->valid(out)) { 1019 909 out_or_in=0; 1020 resG.g w.first(in, v);1021 while( resG.g w.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }910 resG.graph->first(in, v); 911 while( resG.graph->valid(in) && !(resG.resCap(in)>0) ) { resG.graph->next(in); } 1022 912 } 1023 913 } … … 1045 935 1046 936 class EdgeIt : public Edge { 1047 friend class ResGraphWrapper<Graph Wrapper, Number, FlowMap, CapacityMap>;937 friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; 1048 938 NodeIt v; 1049 939 public: … … 1051 941 //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { } 1052 942 EdgeIt(const Invalid& i) : Edge(i) { } 1053 EdgeIt(const ResGraphWrapper<Graph Wrapper, Number, FlowMap, CapacityMap>& resG) : Edge() {1054 resG.g w.first(v);1055 if (resG.g w.valid(v)) resG.gw.first(out, v); else out=INVALID;1056 while (resG.g w.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }1057 while (resG.g w.valid(v) && !resG.gw.valid(out)) {1058 resG.g w.next(v);1059 if (resG.g w.valid(v)) resG.gw.first(out, v);1060 while (resG.g w.valid(out) && !(resG.resCap(out)>0) ) { resG.gw.next(out); }943 EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() { 944 resG.graph->first(v); 945 if (resG.graph->valid(v)) resG.graph->first(out, v); else out=INVALID; 946 while (resG.graph->valid(out) && !(resG.resCap(out)>0) ) { resG.graph->next(out); } 947 while (resG.graph->valid(v) && !resG.graph->valid(out)) { 948 resG.graph->next(v); 949 if (resG.graph->valid(v)) resG.graph->first(out, v); 950 while (resG.graph->valid(out) && !(resG.resCap(out)>0) ) { resG.graph->next(out); } 1061 951 } 1062 if (!resG.g w.valid(out)) {952 if (!resG.graph->valid(out)) { 1063 953 out_or_in=0; 1064 resG.g w.first(v);1065 if (resG.g w.valid(v)) resG.gw.first(in, v); else in=INVALID;1066 while (resG.g w.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }1067 while (resG.g w.valid(v) && !resG.gw.valid(in)) {1068 resG.g w.next(v);1069 if (resG.g w.valid(v)) resG.gw.first(in, v);1070 while (resG.g w.valid(in) && !(resG.resCap(in)>0) ) { resG.gw.next(in); }954 resG.graph->first(v); 955 if (resG.graph->valid(v)) resG.graph->first(in, v); else in=INVALID; 956 while (resG.graph->valid(in) && !(resG.resCap(in)>0) ) { resG.graph->next(in); } 957 while (resG.graph->valid(v) && !resG.graph->valid(in)) { 958 resG.graph->next(v); 959 if (resG.graph->valid(v)) resG.graph->first(in, v); 960 while (resG.graph->valid(in) && !(resG.resCap(in)>0) ) { resG.graph->next(in); } 1071 961 } 1072 962 } … … 1084 974 // out_or_in=0; 1085 975 // G->first(v); 1086 // if (v.valid()) G->first(in, v); else in= OldInEdgeIt();976 // if (v.valid()) G->first(in, v); else in=GraphInEdgeIt(); 1087 977 // while (in.valid() && !(Edge::resCap()>0) ) { ++in; } 1088 978 // while (v.valid() && !in.valid()) { … … 1105 995 }; 1106 996 1107 NodeIt& first(NodeIt& v) const { g w.first(v); return v; }997 NodeIt& first(NodeIt& v) const { graph->first(v); return v; } 1108 998 OutEdgeIt& first(OutEdgeIt& e, Node v) const { 1109 999 e=OutEdgeIt(*this, v); … … 1115 1005 } 1116 1006 1117 NodeIt& next(NodeIt& n) const { return g w.next(n); }1007 NodeIt& next(NodeIt& n) const { return graph->next(n); } 1118 1008 1119 1009 OutEdgeIt& next(OutEdgeIt& e) const { 1120 1010 if (e.out_or_in) { 1121 Node v=g w.aNode(e.out);1122 g w.next(e.out);1123 while( g w.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }1124 if (!g w.valid(e.out)) {1011 Node v=graph->aNode(e.out); 1012 graph->next(e.out); 1013 while( graph->valid(e.out) && !(resCap(e.out)>0) ) { graph->next(e.out); } 1014 if (!graph->valid(e.out)) { 1125 1015 e.out_or_in=0; 1126 g w.first(e.in, v);1127 while( g w.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }1016 graph->first(e.in, v); 1017 while( graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); } 1128 1018 } 1129 1019 } else { 1130 g w.next(e.in);1131 while( g w.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }1020 graph->next(e.in); 1021 while( graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); } 1132 1022 } 1133 1023 return e; … … 1136 1026 EdgeIt& next(EdgeIt& e) const { 1137 1027 if (e.out_or_in) { 1138 g w.next(e.out);1139 while (g w.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }1140 while (g w.valid(e.v) && !gw.valid(e.out)) {1141 g w.next(e.v);1142 if (g w.valid(e.v)) gw.first(e.out, e.v);1143 while (g w.valid(e.out) && !(resCap(e.out)>0) ) { gw.next(e.out); }1028 graph->next(e.out); 1029 while (graph->valid(e.out) && !(resCap(e.out)>0) ) { graph->next(e.out); } 1030 while (graph->valid(e.v) && !graph->valid(e.out)) { 1031 graph->next(e.v); 1032 if (graph->valid(e.v)) graph->first(e.out, e.v); 1033 while (graph->valid(e.out) && !(resCap(e.out)>0) ) { graph->next(e.out); } 1144 1034 } 1145 if (!g w.valid(e.out)) {1035 if (!graph->valid(e.out)) { 1146 1036 e.out_or_in=0; 1147 g w.first(e.v);1148 if (g w.valid(e.v)) gw.first(e.in, e.v); else e.in=INVALID;1149 while (g w.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }1150 while (g w.valid(e.v) && !gw.valid(e.in)) {1151 g w.next(e.v);1152 if (g w.valid(e.v)) gw.first(e.in, e.v);1153 while (g w.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }1037 graph->first(e.v); 1038 if (graph->valid(e.v)) graph->first(e.in, e.v); else e.in=INVALID; 1039 while (graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); } 1040 while (graph->valid(e.v) && !graph->valid(e.in)) { 1041 graph->next(e.v); 1042 if (graph->valid(e.v)) graph->first(e.in, e.v); 1043 while (graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); } 1154 1044 } 1155 1045 } 1156 1046 } else { 1157 g w.next(e.in);1158 while (g w.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }1159 while (g w.valid(e.v) && !gw.valid(e.in)) {1160 g w.next(e.v);1161 if (g w.valid(e.v)) gw.first(e.in, e.v);1162 while (g w.valid(e.in) && !(resCap(e.in)>0) ) { gw.next(e.in); }1047 graph->next(e.in); 1048 while (graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); } 1049 while (graph->valid(e.v) && !graph->valid(e.in)) { 1050 graph->next(e.v); 1051 if (graph->valid(e.v)) graph->first(e.in, e.v); 1052 while (graph->valid(e.in) && !(resCap(e.in)>0) ) { graph->next(e.in); } 1163 1053 } 1164 1054 } … … 1182 1072 1183 1073 Node tail(Edge e) const { 1184 return ((e.out_or_in) ? g w.aNode(e.out) : gw.aNode(e.in)); }1074 return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); } 1185 1075 Node head(Edge e) const { 1186 return ((e.out_or_in) ? g w.bNode(e.out) : gw.bNode(e.in)); }1076 return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); } 1187 1077 1188 1078 Node aNode(OutEdgeIt e) const { 1189 return ((e.out_or_in) ? g w.aNode(e.out) : gw.aNode(e.in)); }1079 return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); } 1190 1080 Node bNode(OutEdgeIt e) const { 1191 return ((e.out_or_in) ? g w.bNode(e.out) : gw.bNode(e.in)); }1192 1193 int nodeNum() const { return g w.nodeNum(); }1081 return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); } 1082 1083 int nodeNum() const { return graph->nodeNum(); } 1194 1084 //FIXME 1195 //int edgeNum() const { return g w.edgeNum(); }1196 1197 1198 int id(Node v) const { return g w.id(v); }1199 1200 bool valid(Node n) const { return g w.valid(n); }1085 //int edgeNum() const { return graph->edgeNum(); } 1086 1087 1088 int id(Node v) const { return graph->id(v); } 1089 1090 bool valid(Node n) const { return graph->valid(n); } 1201 1091 bool valid(Edge e) const { 1202 return e.out_or_in ? g w.valid(e.out) : gw.valid(e.in); }1092 return e.out_or_in ? graph->valid(e.out) : graph->valid(e.in); } 1203 1093 1204 1094 void augment(const Edge& e, Number a) const { 1205 1095 if (e.out_or_in) 1206 flow->set(e.out, flow->get(e.out)+a); 1096 // flow->set(e.out, flow->get(e.out)+a); 1097 flow->set(e.out, (*flow)[e.out]+a); 1207 1098 else 1208 flow->set(e.in, flow->get(e.in)-a); 1099 // flow->set(e.in, flow->get(e.in)-a); 1100 flow->set(e.in, (*flow)[e.in]-a); 1209 1101 } 1210 1102 1211 1103 Number resCap(const Edge& e) const { 1212 1104 if (e.out_or_in) 1213 return (capacity->get(e.out)-flow->get(e.out)); 1105 // return (capacity->get(e.out)-flow->get(e.out)); 1106 return ((*capacity)[e.out]-(*flow)[e.out]); 1214 1107 else 1215 return (flow->get(e.in)); 1216 } 1217 1218 Number resCap(OldOutEdgeIt out) const { 1219 return (capacity->get(out)-flow->get(out)); 1220 } 1221 1222 Number resCap(OldInEdgeIt in) const { 1223 return (flow->get(in)); 1224 } 1225 1226 // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { 1227 // public: 1228 // NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G) 1229 // : GraphWrapper::NodeMap<T>(_G.gw) { } 1230 // NodeMap(const ResGraphWrapper<GraphWrapper, Number, FlowMap, CapacityMap>& _G, 1231 // T a) : GraphWrapper::NodeMap<T>(_G.gw, a) { } 1108 // return (flow->get(e.in)); 1109 return ((*flow)[e.in]); 1110 } 1111 1112 Number resCap(GraphOutEdgeIt out) const { 1113 // return (capacity->get(out)-flow->get(out)); 1114 return ((*capacity)[out]-(*flow)[out]); 1115 } 1116 1117 Number resCap(GraphInEdgeIt in) const { 1118 // return (flow->get(in)); 1119 return ((*flow)[in]); 1120 } 1121 1122 // template<typename T> class NodeMap : public Graph::NodeMap<T> { 1123 // public: 1124 // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) 1125 // : Graph::NodeMap<T>(_G.gw) { } 1126 // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, 1127 // T a) : Graph::NodeMap<T>(_G.gw, a) { } 1232 1128 // }; 1233 1129 … … 1244 1140 template <typename T> 1245 1141 class EdgeMap { 1246 typename Graph Wrapper::EdgeMap<T> forward_map, backward_map;1247 public: 1248 EdgeMap(const ResGraphWrapper<Graph Wrapper, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.gw), backward_map(_G.gw) { }1249 EdgeMap(const ResGraphWrapper<Graph Wrapper, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.gw, a), backward_map(_G.gw, a) { }1142 typename Graph::EdgeMap<T> forward_map, backward_map; 1143 public: 1144 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { } 1145 EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { } 1250 1146 void set(Edge e, T a) { 1251 1147 if (e.out_or_in) … … 1254 1150 backward_map.set(e.in, a); 1255 1151 } 1256 T get(Edge e){1152 T operator[](Edge e) const { 1257 1153 if (e.out_or_in) 1258 return forward_map .get(e.out);1154 return forward_map[e.out]; 1259 1155 else 1260 return backward_map .get(e.in);1156 return backward_map[e.in]; 1261 1157 } 1158 // T get(Edge e) const { 1159 // if (e.out_or_in) 1160 // return forward_map.get(e.out); 1161 // else 1162 // return backward_map.get(e.in); 1163 // } 1262 1164 }; 1263 1165 }; 1264 1166 1265 // Subgraph on the same node-set and partial edge-set1266 template<typename Graph Wrapper, typename FirstOutEdgesMap>1267 class ErasingFirstGraphWrapper : public GraphWrapper Skeleton<GraphWrapper> {1167 //ErasingFirstGraphWrapper for blocking flows 1168 template<typename Graph, typename FirstOutEdgesMap> 1169 class ErasingFirstGraphWrapper : public GraphWrapper<Graph> { 1268 1170 protected: 1269 1171 FirstOutEdgesMap* first_out_edges; 1270 1172 public: 1271 typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node; 1272 typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt; 1273 typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge; 1274 typedef typename GraphWrapperSkeleton<GraphWrapper>::EdgeIt EdgeIt; 1275 typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt InEdgeIt; 1276 typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt OutEdgeIt; 1277 1278 ErasingFirstGraphWrapper(GraphWrapper _gw, FirstOutEdgesMap& _first_out_edges) : 1279 GraphWrapperSkeleton<GraphWrapper>(_gw), first_out_edges(&_first_out_edges) { } 1173 typedef typename GraphWrapper<Graph>::Node Node; 1174 typedef typename GraphWrapper<Graph>::NodeIt NodeIt; 1175 typedef typename GraphWrapper<Graph>::Edge Edge; 1176 typedef typename GraphWrapper<Graph>::EdgeIt EdgeIt; 1177 typedef typename GraphWrapper<Graph>::InEdgeIt InEdgeIt; 1178 typedef typename GraphWrapper<Graph>::OutEdgeIt OutEdgeIt; 1179 1180 ErasingFirstGraphWrapper(Graph& _graph, 1181 FirstOutEdgesMap& _first_out_edges) : 1182 GraphWrapper<Graph>(_graph), first_out_edges(&_first_out_edges) { } 1280 1183 1281 1184 template<typename I> I& first(I& i) const { 1282 gw.first(i); 1283 //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); } 1185 graph->first(i); 1284 1186 return i; 1285 1187 } 1286 1188 OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { 1287 e=first_out_edges->get(n); 1189 // e=first_out_edges->get(n); 1190 e=(*first_out_edges)[n]; 1288 1191 return e; 1289 1192 } 1290 1193 template<typename I, typename P> I& first(I& i, const P& p) const { 1291 gw.first(i, p); 1292 //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); } 1194 graph->first(i, p); 1293 1195 return i; 1294 1196 } … … 1298 1200 //} 1299 1201 template<typename I> I& next(I &i) const { 1300 gw.next(i); 1301 //while (gw.valid(i) && !filter_map->get(i)) { gw.next(i); } 1202 graph->next(i); 1302 1203 return i; 1303 1204 } … … 1315 1216 } 1316 1217 }; 1317 1318 // template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>1319 // class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {1320 // protected:1321 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;1322 // //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;1323 // public:1324 // ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow,1325 // const CapacityMap& _capacity) :1326 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity),1327 // first_out_edges(*this) /*, dist(*this)*/ {1328 // for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) {1329 // OutEdgeIt e;1330 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);1331 // first_out_edges.set(n, e);1332 // }1333 // }1334 1335 // //void setGraph(Graph& _graph) { graph = &_graph; }1336 // //Graph& getGraph() const { return (*graph); }1337 1338 // //TrivGraphWrapper() : graph(0) { }1339 // //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { }1340 1341 // //typedef Graph BaseGraph;1342 1343 // //typedef typename Graph::Node Node;1344 // //typedef typename Graph::NodeIt NodeIt;1345 1346 // //typedef typename Graph::Edge Edge;1347 // //typedef typename Graph::OutEdgeIt OutEdgeIt;1348 // //typedef typename Graph::InEdgeIt InEdgeIt;1349 // //typedef typename Graph::SymEdgeIt SymEdgeIt;1350 // //typedef typename Graph::EdgeIt EdgeIt;1351 1352 // typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;1353 // typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;1354 1355 // typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;1356 // typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;1357 // //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;1358 // //typedef typename Graph::SymEdgeIt SymEdgeIt;1359 // //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;1360 1361 // NodeIt& first(NodeIt& n) const {1362 // return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);1363 // }1364 1365 // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {1366 // e=first_out_edges.get(n);1367 // return e;1368 // }1369 1370 // //ROSSZ template<typename I> I& first(I& i) const { return first(i); }1371 // //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const {1372 // // return first(i, p); }1373 1374 // //template<typename I> I getNext(const I& i) const {1375 // // return gw.getNext(i); }1376 // //template<typename I> I& next(I &i) const { return gw.next(i); }1377 1378 // template< typename It > It first() const {1379 // It e; first(e); return e; }1380 1381 // template< typename It > It first(const Node& v) const {1382 // It e; first(e, v); return e; }1383 1384 // //Node head(const Edge& e) const { return gw.head(e); }1385 // //Node tail(const Edge& e) const { return gw.tail(e); }1386 1387 // //template<typename I> bool valid(const I& i) const1388 // // { return gw.valid(i); }1389 1390 // //int nodeNum() const { return gw.nodeNum(); }1391 // //int edgeNum() const { return gw.edgeNum(); }1392 1393 // //template<typename I> Node aNode(const I& e) const {1394 // // return gw.aNode(e); }1395 // //template<typename I> Node bNode(const I& e) const {1396 // // return gw.bNode(e); }1397 1398 // //Node addNode() const { return gw.addNode(); }1399 // //Edge addEdge(const Node& tail, const Node& head) const {1400 // // return gw.addEdge(tail, head); }1401 1402 // //void erase(const OutEdgeIt& e) {1403 // // first_out_edge(this->tail(e))=e;1404 // //}1405 // void erase(const Edge& e) {1406 // OutEdgeIt f(e);1407 // next(f);1408 // first_out_edges.set(this->tail(e), f);1409 // }1410 // //template<typename I> void erase(const I& i) const { gw.erase(i); }1411 1412 // //void clear() const { gw.clear(); }1413 1414 // template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {1415 // public:1416 // NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :1417 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }1418 // NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :1419 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }1420 // };1421 1422 // template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {1423 // public:1424 // EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) :1425 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }1426 // EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) :1427 // ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }1428 // };1429 // };1430 1431 // template<typename GraphWrapper>1432 // class FilterGraphWrapper {1433 // };1434 1435 // template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>1436 // class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> {1437 1438 // //Graph* graph;1439 1440 // public:1441 // //typedef Graph BaseGraph;1442 1443 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node;1444 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt;1445 1446 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge;1447 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt;1448 // //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt;1449 // //typedef typename Graph::SymEdgeIt SymEdgeIt;1450 // typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt;1451 1452 // //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges;1453 1454 // public:1455 // FilterGraphWrapper(const Graph& _G, FlowMap& _flow,1456 // const CapacityMap& _capacity) :1457 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, gw.nodeNum()) {1458 // }1459 1460 // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const {1461 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n);1462 // while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e))))1463 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);1464 // return e;1465 // }1466 1467 // NodeIt& next(NodeIt& e) const {1468 // return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);1469 // }1470 1471 // OutEdgeIt& next(OutEdgeIt& e) const {1472 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);1473 // while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e))))1474 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e);1475 // return e;1476 // }1477 1478 // NodeIt& first(NodeIt& n) const {1479 // return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n);1480 // }1481 1482 // void erase(const Edge& e) {1483 // OutEdgeIt f(e);1484 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);1485 // while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f))))1486 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f);1487 // first_out_edges.set(this->tail(e), f);1488 // }1489 1490 // //TrivGraphWrapper() : graph(0) { }1491 // //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }1492 1493 // //void setGraph(Graph& _graph) { graph = &_graph; }1494 // //Graph& getGraph() const { return (*graph); }1495 1496 // //template<typename I> I& first(I& i) const { return gw.first(i); }1497 // //template<typename I, typename P> I& first(I& i, const P& p) const {1498 // // return gw.first(i, p); }1499 1500 // //template<typename I> I getNext(const I& i) const {1501 // // return gw.getNext(i); }1502 // //template<typename I> I& next(I &i) const { return gw.next(i); }1503 1504 // template< typename It > It first() const {1505 // It e; first(e); return e; }1506 1507 // template< typename It > It first(const Node& v) const {1508 // It e; first(e, v); return e; }1509 1510 // //Node head(const Edge& e) const { return gw.head(e); }1511 // //Node tail(const Edge& e) const { return gw.tail(e); }1512 1513 // //template<typename I> bool valid(const I& i) const1514 // // { return gw.valid(i); }1515 1516 // //template<typename I> void setInvalid(const I &i);1517 // //{ return gw.setInvalid(i); }1518 1519 // //int nodeNum() const { return gw.nodeNum(); }1520 // //int edgeNum() const { return gw.edgeNum(); }1521 1522 // //template<typename I> Node aNode(const I& e) const {1523 // // return gw.aNode(e); }1524 // //template<typename I> Node bNode(const I& e) const {1525 // // return gw.bNode(e); }1526 1527 // //Node addNode() const { return gw.addNode(); }1528 // //Edge addEdge(const Node& tail, const Node& head) const {1529 // // return gw.addEdge(tail, head); }1530 1531 // //template<typename I> void erase(const I& i) const { gw.erase(i); }1532 1533 // //void clear() const { gw.clear(); }1534 1535 // template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> {1536 // public:1537 // NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :1538 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { }1539 // NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :1540 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { }1541 // };1542 1543 // template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> {1544 // public:1545 // EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) :1546 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { }1547 // EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) :1548 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { }1549 // };1550 1551 // public:1552 // ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist;1553 1554 // };1555 1556 1557 1218 1558 1219 // // FIXME: comparison should be made better!!! … … 1563 1224 1564 1225 // public: 1565 // typedef Graph BaseGraph;1226 // typedef Graph ParentGraph; 1566 1227 1567 1228 // typedef typename Graph::Node Node;
Note: See TracChangeset
for help on using the changeset viewer.