[174] | 1 | // -*- c++ -*- |
---|
[76] | 2 | #ifndef GRAPH_WRAPPER_H |
---|
| 3 | #define GRAPH_WRAPPER_H |
---|
| 4 | |
---|
[174] | 5 | #include <invalid.h> |
---|
| 6 | |
---|
[105] | 7 | namespace hugo { |
---|
[76] | 8 | |
---|
| 9 | template<typename Graph> |
---|
| 10 | class TrivGraphWrapper { |
---|
[199] | 11 | protected: |
---|
[76] | 12 | Graph* graph; |
---|
| 13 | |
---|
| 14 | public: |
---|
| 15 | typedef Graph BaseGraph; |
---|
| 16 | |
---|
[174] | 17 | typedef typename Graph::Node Node; |
---|
[76] | 18 | typedef typename Graph::NodeIt NodeIt; |
---|
| 19 | |
---|
[174] | 20 | typedef typename Graph::Edge Edge; |
---|
[76] | 21 | typedef typename Graph::OutEdgeIt OutEdgeIt; |
---|
| 22 | typedef typename Graph::InEdgeIt InEdgeIt; |
---|
[155] | 23 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 24 | typedef typename Graph::EdgeIt EdgeIt; |
---|
[168] | 25 | |
---|
| 26 | //TrivGraphWrapper() : graph(0) { } |
---|
| 27 | TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 28 | |
---|
| 29 | void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 30 | Graph& getGraph() const { return (*graph); } |
---|
[76] | 31 | |
---|
[174] | 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); } |
---|
[155] | 35 | |
---|
| 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); } |
---|
[76] | 39 | |
---|
| 40 | template< typename It > It first() const { |
---|
[174] | 41 | It e; /*getF*/first(e); return e; } |
---|
[76] | 42 | |
---|
[174] | 43 | template< typename It > It first(const Node& v) const { |
---|
| 44 | It e; /*getF*/first(e, v); return e; } |
---|
[76] | 45 | |
---|
[174] | 46 | Node head(const Edge& e) const { return graph->head(e); } |
---|
| 47 | Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[155] | 48 | |
---|
| 49 | template<typename I> bool valid(const I& i) const |
---|
| 50 | { return graph->valid(i); } |
---|
| 51 | |
---|
| 52 | //template<typename I> void setInvalid(const I &i); |
---|
| 53 | //{ return graph->setInvalid(i); } |
---|
| 54 | |
---|
| 55 | int nodeNum() const { return graph->nodeNum(); } |
---|
| 56 | int edgeNum() const { return graph->edgeNum(); } |
---|
[76] | 57 | |
---|
[174] | 58 | template<typename I> Node aNode(const I& e) const { |
---|
[76] | 59 | return graph->aNode(e); } |
---|
[174] | 60 | template<typename I> Node bNode(const I& e) const { |
---|
[76] | 61 | return graph->bNode(e); } |
---|
| 62 | |
---|
[174] | 63 | Node addNode() const { return graph->addNode(); } |
---|
| 64 | Edge addEdge(const Node& tail, const Node& head) const { |
---|
[76] | 65 | return graph->addEdge(tail, head); } |
---|
| 66 | |
---|
| 67 | template<typename I> void erase(const I& i) const { graph->erase(i); } |
---|
| 68 | |
---|
| 69 | void clear() const { graph->clear(); } |
---|
[155] | 70 | |
---|
[76] | 71 | template<typename T> class NodeMap : public Graph::NodeMap<T> { |
---|
| 72 | public: |
---|
[155] | 73 | NodeMap(const TrivGraphWrapper<Graph>& _G) : |
---|
[158] | 74 | Graph::NodeMap<T>(_G.getGraph()) { } |
---|
[155] | 75 | NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : |
---|
[158] | 76 | Graph::NodeMap<T>(_G.getGraph(), a) { } |
---|
[76] | 77 | }; |
---|
[168] | 78 | |
---|
[155] | 79 | template<typename T> class EdgeMap : public Graph::EdgeMap<T> { |
---|
| 80 | public: |
---|
| 81 | EdgeMap(const TrivGraphWrapper<Graph>& _G) : |
---|
[158] | 82 | Graph::EdgeMap<T>(_G.getGraph()) { } |
---|
[155] | 83 | EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : |
---|
[158] | 84 | Graph::EdgeMap<T>(_G.getGraph(), a) { } |
---|
[155] | 85 | }; |
---|
[76] | 86 | }; |
---|
| 87 | |
---|
| 88 | template<typename Graph> |
---|
| 89 | class RevGraphWrapper |
---|
| 90 | { |
---|
[199] | 91 | protected: |
---|
[76] | 92 | Graph* graph; |
---|
| 93 | |
---|
| 94 | public: |
---|
| 95 | typedef Graph BaseGraph; |
---|
| 96 | |
---|
[174] | 97 | typedef typename Graph::Node Node; |
---|
| 98 | typedef typename Graph::NodeIt NodeIt; |
---|
[76] | 99 | |
---|
[174] | 100 | typedef typename Graph::Edge Edge; |
---|
[76] | 101 | typedef typename Graph::OutEdgeIt InEdgeIt; |
---|
| 102 | typedef typename Graph::InEdgeIt OutEdgeIt; |
---|
[155] | 103 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 104 | typedef typename Graph::EdgeIt EdgeIt; |
---|
[168] | 105 | |
---|
| 106 | //RevGraphWrapper() : graph(0) { } |
---|
| 107 | RevGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 108 | |
---|
| 109 | void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 110 | Graph& getGraph() const { return (*graph); } |
---|
[76] | 111 | |
---|
[174] | 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); } |
---|
[155] | 115 | |
---|
| 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); } |
---|
[76] | 119 | |
---|
| 120 | template< typename It > It first() const { |
---|
[174] | 121 | It e; /*getF*/first(e); return e; } |
---|
[76] | 122 | |
---|
[174] | 123 | template< typename It > It first(const Node& v) const { |
---|
| 124 | It e; /*getF*/first(e, v); return e; } |
---|
[76] | 125 | |
---|
[174] | 126 | Node head(const Edge& e) const { return graph->tail(e); } |
---|
| 127 | Node tail(const Edge& e) const { return graph->head(e); } |
---|
[76] | 128 | |
---|
[155] | 129 | template<typename I> bool valid(const I& i) const |
---|
| 130 | { return graph->valid(i); } |
---|
| 131 | |
---|
| 132 | //template<typename I> void setInvalid(const I &i); |
---|
| 133 | //{ return graph->setInvalid(i); } |
---|
| 134 | |
---|
[174] | 135 | template<typename I> Node aNode(const I& e) const { |
---|
[76] | 136 | return graph->aNode(e); } |
---|
[174] | 137 | template<typename I> Node bNode(const I& e) const { |
---|
[76] | 138 | return graph->bNode(e); } |
---|
[155] | 139 | |
---|
[174] | 140 | Node addNode() const { return graph->addNode(); } |
---|
| 141 | Edge addEdge(const Node& tail, const Node& head) const { |
---|
[76] | 142 | return graph->addEdge(tail, head); } |
---|
| 143 | |
---|
[155] | 144 | int nodeNum() const { return graph->nodeNum(); } |
---|
| 145 | int edgeNum() const { return graph->edgeNum(); } |
---|
[76] | 146 | |
---|
[155] | 147 | template<typename I> void erase(const I& i) const { graph->erase(i); } |
---|
[76] | 148 | |
---|
[155] | 149 | void clear() const { graph->clear(); } |
---|
| 150 | |
---|
| 151 | template<typename T> class NodeMap : public Graph::NodeMap<T> { |
---|
| 152 | public: |
---|
| 153 | NodeMap(const RevGraphWrapper<Graph>& _G) : |
---|
[158] | 154 | Graph::NodeMap<T>(_G.getGraph()) { } |
---|
[155] | 155 | NodeMap(const RevGraphWrapper<Graph>& _G, T a) : |
---|
[158] | 156 | Graph::NodeMap<T>(_G.getGraph(), a) { } |
---|
[155] | 157 | }; |
---|
[168] | 158 | |
---|
[155] | 159 | template<typename T> class EdgeMap : public Graph::EdgeMap<T> { |
---|
| 160 | public: |
---|
| 161 | EdgeMap(const RevGraphWrapper<Graph>& _G) : |
---|
[158] | 162 | Graph::EdgeMap<T>(_G.getGraph()) { } |
---|
[155] | 163 | EdgeMap(const RevGraphWrapper<Graph>& _G, T a) : |
---|
[158] | 164 | Graph::EdgeMap<T>(_G.getGraph(), a) { } |
---|
[155] | 165 | }; |
---|
[76] | 166 | }; |
---|
| 167 | |
---|
[155] | 168 | |
---|
[158] | 169 | template<typename Graph> |
---|
| 170 | class UndirGraphWrapper { |
---|
[199] | 171 | protected: |
---|
[158] | 172 | Graph* graph; |
---|
| 173 | |
---|
| 174 | public: |
---|
| 175 | typedef Graph BaseGraph; |
---|
| 176 | |
---|
[174] | 177 | typedef typename Graph::Node Node; |
---|
[158] | 178 | typedef typename Graph::NodeIt NodeIt; |
---|
| 179 | |
---|
[174] | 180 | //typedef typename Graph::Edge Edge; |
---|
[158] | 181 | //typedef typename Graph::OutEdgeIt OutEdgeIt; |
---|
| 182 | //typedef typename Graph::InEdgeIt InEdgeIt; |
---|
| 183 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 184 | //typedef typename Graph::EdgeIt EdgeIt; |
---|
[158] | 185 | |
---|
| 186 | //private: |
---|
[174] | 187 | typedef typename Graph::Edge GraphEdge; |
---|
[158] | 188 | typedef typename Graph::OutEdgeIt GraphOutEdgeIt; |
---|
| 189 | typedef typename Graph::InEdgeIt GraphInEdgeIt; |
---|
| 190 | //public: |
---|
| 191 | |
---|
[168] | 192 | //UndirGraphWrapper() : graph(0) { } |
---|
| 193 | UndirGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 194 | |
---|
| 195 | void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 196 | Graph& getGraph() const { return (*graph); } |
---|
| 197 | |
---|
[174] | 198 | class Edge { |
---|
[158] | 199 | friend class UndirGraphWrapper<Graph>; |
---|
| 200 | bool out_or_in; //true iff out |
---|
| 201 | GraphOutEdgeIt out; |
---|
| 202 | GraphInEdgeIt in; |
---|
| 203 | public: |
---|
[174] | 204 | Edge() : out_or_in(), out(), in() { } |
---|
| 205 | Edge(const Invalid& i) : out_or_in(false), out(), in(i) { } |
---|
| 206 | operator GraphEdge() const { |
---|
[158] | 207 | if (out_or_in) return(out); else return(in); |
---|
| 208 | } |
---|
[174] | 209 | friend bool operator==(const Edge& u, const Edge& v) { |
---|
| 210 | if (v.out_or_in) |
---|
| 211 | return (u.out_or_in && u.out==v.out); |
---|
| 212 | else |
---|
| 213 | return (!u.out_or_in && u.in==v.in); |
---|
| 214 | } |
---|
| 215 | friend bool operator!=(const Edge& u, const Edge& v) { |
---|
| 216 | if (v.out_or_in) |
---|
| 217 | return (!u.out_or_in || u.out!=v.out); |
---|
| 218 | else |
---|
| 219 | return (u.out_or_in || u.in!=v.in); |
---|
| 220 | } |
---|
[158] | 221 | }; |
---|
| 222 | |
---|
[174] | 223 | class OutEdgeIt : public Edge { |
---|
[158] | 224 | friend class UndirGraphWrapper<Graph>; |
---|
| 225 | public: |
---|
[174] | 226 | OutEdgeIt() : Edge() { } |
---|
| 227 | OutEdgeIt(const Invalid& i) : Edge(i) { } |
---|
| 228 | OutEdgeIt(const UndirGraphWrapper& _G, const Node& n) : Edge() { |
---|
| 229 | out_or_in=true; |
---|
| 230 | _G.graph->/*getF*/first(out, n); |
---|
[158] | 231 | if (!(_G.graph->valid(out))) { |
---|
| 232 | out_or_in=false; |
---|
[174] | 233 | _G.graph->/*getF*/first(in, n); |
---|
[158] | 234 | } |
---|
| 235 | } |
---|
| 236 | }; |
---|
| 237 | |
---|
[174] | 238 | OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const { |
---|
[158] | 239 | e.out_or_in=true; |
---|
[174] | 240 | graph->/*getF*/first(e.out, n); |
---|
[158] | 241 | if (!(graph->valid(e.out))) { |
---|
| 242 | e.out_or_in=false; |
---|
[174] | 243 | graph->/*getF*/first(e.in, n); |
---|
[158] | 244 | } |
---|
| 245 | return e; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 249 | if (e.out_or_in) { |
---|
[174] | 250 | Node n=graph->tail(e.out); |
---|
[158] | 251 | graph->next(e.out); |
---|
| 252 | if (!graph->valid(e.out)) { |
---|
| 253 | e.out_or_in=false; |
---|
[174] | 254 | graph->/*getF*/first(e.in, n); |
---|
[158] | 255 | } |
---|
| 256 | } else { |
---|
| 257 | graph->next(e.in); |
---|
| 258 | } |
---|
| 259 | return e; |
---|
| 260 | } |
---|
| 261 | |
---|
[174] | 262 | Node aNode(const OutEdgeIt& e) const { |
---|
[158] | 263 | if (e.out_or_in) return graph->tail(e); else return graph->head(e); } |
---|
[174] | 264 | Node bNode(const OutEdgeIt& e) const { |
---|
[158] | 265 | if (e.out_or_in) return graph->head(e); else return graph->tail(e); } |
---|
| 266 | |
---|
| 267 | typedef OutEdgeIt InEdgeIt; |
---|
| 268 | |
---|
[174] | 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); } |
---|
[158] | 272 | |
---|
| 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); } |
---|
| 276 | |
---|
| 277 | template< typename It > It first() const { |
---|
[174] | 278 | It e; /*getF*/first(e); return e; } |
---|
[158] | 279 | |
---|
[174] | 280 | template< typename It > It first(const Node& v) const { |
---|
| 281 | It e; /*getF*/first(e, v); return e; } |
---|
[158] | 282 | |
---|
[174] | 283 | Node head(const Edge& e) const { return graph->head(e); } |
---|
| 284 | Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[158] | 285 | |
---|
| 286 | template<typename I> bool valid(const I& i) const |
---|
| 287 | { return graph->valid(i); } |
---|
| 288 | |
---|
| 289 | //template<typename I> void setInvalid(const I &i); |
---|
| 290 | //{ return graph->setInvalid(i); } |
---|
| 291 | |
---|
| 292 | int nodeNum() const { return graph->nodeNum(); } |
---|
| 293 | int edgeNum() const { return graph->edgeNum(); } |
---|
| 294 | |
---|
[174] | 295 | // template<typename I> Node aNode(const I& e) const { |
---|
[158] | 296 | // return graph->aNode(e); } |
---|
[174] | 297 | // template<typename I> Node bNode(const I& e) const { |
---|
[158] | 298 | // return graph->bNode(e); } |
---|
| 299 | |
---|
[174] | 300 | Node addNode() const { return graph->addNode(); } |
---|
| 301 | Edge addEdge(const Node& tail, const Node& head) const { |
---|
[158] | 302 | return graph->addEdge(tail, head); } |
---|
| 303 | |
---|
| 304 | template<typename I> void erase(const I& i) const { graph->erase(i); } |
---|
| 305 | |
---|
| 306 | void clear() const { graph->clear(); } |
---|
| 307 | |
---|
| 308 | template<typename T> class NodeMap : public Graph::NodeMap<T> { |
---|
| 309 | public: |
---|
| 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) { } |
---|
| 314 | }; |
---|
[168] | 315 | |
---|
[158] | 316 | template<typename T> class EdgeMap : public Graph::EdgeMap<T> { |
---|
| 317 | public: |
---|
| 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) { } |
---|
| 322 | }; |
---|
| 323 | }; |
---|
| 324 | |
---|
| 325 | |
---|
| 326 | |
---|
[155] | 327 | // template<typename Graph> |
---|
| 328 | // class SymGraphWrapper |
---|
| 329 | // { |
---|
| 330 | // Graph* graph; |
---|
[76] | 331 | |
---|
[155] | 332 | // public: |
---|
| 333 | // typedef Graph BaseGraph; |
---|
| 334 | |
---|
[174] | 335 | // typedef typename Graph::Node Node; |
---|
| 336 | // typedef typename Graph::Edge Edge; |
---|
| 337 | |
---|
[155] | 338 | // typedef typename Graph::NodeIt NodeIt; |
---|
| 339 | |
---|
| 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; |
---|
[174] | 346 | // typedef typename Graph::EdgeIt EdgeIt; |
---|
[155] | 347 | |
---|
| 348 | // int nodeNum() const { return graph->nodeNum(); } |
---|
| 349 | // int edgeNum() const { return graph->edgeNum(); } |
---|
| 350 | |
---|
[174] | 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); } |
---|
[155] | 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); } |
---|
| 356 | |
---|
| 357 | // template< typename It > It first() const { |
---|
[174] | 358 | // It e; /*getF*/first(e); return e; } |
---|
[155] | 359 | |
---|
[174] | 360 | // template< typename It > It first(Node v) const { |
---|
| 361 | // It e; /*getF*/first(e, v); return e; } |
---|
[155] | 362 | |
---|
[174] | 363 | // Node head(const Edge& e) const { return graph->head(e); } |
---|
| 364 | // Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[155] | 365 | |
---|
[174] | 366 | // template<typename I> Node aNode(const I& e) const { |
---|
[155] | 367 | // return graph->aNode(e); } |
---|
[174] | 368 | // template<typename I> Node bNode(const I& e) const { |
---|
[155] | 369 | // return graph->bNode(e); } |
---|
| 370 | |
---|
| 371 | // //template<typename I> bool valid(const I i); |
---|
| 372 | // //{ return graph->valid(i); } |
---|
| 373 | |
---|
| 374 | // //template<typename I> void setInvalid(const I &i); |
---|
| 375 | // //{ return graph->setInvalid(i); } |
---|
| 376 | |
---|
[174] | 377 | // Node addNode() { return graph->addNode(); } |
---|
| 378 | // Edge addEdge(const Node& tail, const Node& head) { |
---|
[155] | 379 | // return graph->addEdge(tail, head); } |
---|
| 380 | |
---|
| 381 | // template<typename I> void erase(const I& i) { graph->erase(i); } |
---|
| 382 | |
---|
| 383 | // void clear() { graph->clear(); } |
---|
| 384 | |
---|
| 385 | // template<typename T> class NodeMap : public Graph::NodeMap<T> { }; |
---|
| 386 | // template<typename T> class EdgeMap : public Graph::EdgeMap<T> { }; |
---|
| 387 | |
---|
| 388 | // void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 389 | // Graph& getGraph() { return (*graph); } |
---|
| 390 | |
---|
| 391 | // //SymGraphWrapper() : graph(0) { } |
---|
| 392 | // SymGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 393 | // }; |
---|
| 394 | |
---|
| 395 | |
---|
| 396 | template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
---|
| 397 | class ResGraphWrapper { |
---|
[76] | 398 | public: |
---|
| 399 | typedef Graph BaseGraph; |
---|
[174] | 400 | typedef typename Graph::Node Node; |
---|
[155] | 401 | typedef typename Graph::NodeIt NodeIt; |
---|
| 402 | private: |
---|
| 403 | typedef typename Graph::OutEdgeIt OldOutEdgeIt; |
---|
| 404 | typedef typename Graph::InEdgeIt OldInEdgeIt; |
---|
[199] | 405 | protected: |
---|
[174] | 406 | const Graph* graph; |
---|
[155] | 407 | FlowMap* flow; |
---|
| 408 | const CapacityMap* capacity; |
---|
| 409 | public: |
---|
[168] | 410 | |
---|
[155] | 411 | ResGraphWrapper(const Graph& _G, FlowMap& _flow, |
---|
| 412 | const CapacityMap& _capacity) : |
---|
[174] | 413 | graph(&_G), flow(&_flow), capacity(&_capacity) { } |
---|
[168] | 414 | |
---|
| 415 | void setGraph(const Graph& _graph) { graph = &_graph; } |
---|
[174] | 416 | const Graph& getGraph() const { return (*graph); } |
---|
[168] | 417 | |
---|
[174] | 418 | class Edge; |
---|
[155] | 419 | class OutEdgeIt; |
---|
[174] | 420 | friend class Edge; |
---|
[155] | 421 | friend class OutEdgeIt; |
---|
[76] | 422 | |
---|
[174] | 423 | class Edge { |
---|
[155] | 424 | friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; |
---|
| 425 | protected: |
---|
[168] | 426 | bool out_or_in; //true, iff out |
---|
[155] | 427 | OldOutEdgeIt out; |
---|
| 428 | OldInEdgeIt in; |
---|
| 429 | public: |
---|
[174] | 430 | Edge() : out_or_in(true) { } |
---|
| 431 | Edge(const Invalid& i) : out_or_in(false), out(), in(i) { } |
---|
[168] | 432 | // bool valid() const { |
---|
| 433 | // return out_or_in && out.valid() || in.valid(); } |
---|
[174] | 434 | friend bool operator==(const Edge& u, const Edge& v) { |
---|
| 435 | if (v.out_or_in) |
---|
| 436 | return (u.out_or_in && u.out==v.out); |
---|
| 437 | else |
---|
| 438 | return (!u.out_or_in && u.in==v.in); |
---|
| 439 | } |
---|
| 440 | friend bool operator!=(const Edge& u, const Edge& v) { |
---|
| 441 | if (v.out_or_in) |
---|
| 442 | return (!u.out_or_in || u.out!=v.out); |
---|
| 443 | else |
---|
| 444 | return (u.out_or_in || u.in!=v.in); |
---|
| 445 | } |
---|
[155] | 446 | }; |
---|
| 447 | |
---|
| 448 | |
---|
[174] | 449 | class OutEdgeIt : public Edge { |
---|
[155] | 450 | friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; |
---|
| 451 | public: |
---|
| 452 | OutEdgeIt() { } |
---|
[168] | 453 | //FIXME |
---|
[174] | 454 | OutEdgeIt(const Edge& e) : Edge(e) { } |
---|
| 455 | OutEdgeIt(const Invalid& i) : Edge(i) { } |
---|
[155] | 456 | private: |
---|
[174] | 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)) { |
---|
[155] | 461 | out_or_in=0; |
---|
[174] | 462 | resG.graph->/*getF*/first(in, v); |
---|
| 463 | while( resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); } |
---|
[155] | 464 | } |
---|
| 465 | } |
---|
[168] | 466 | // public: |
---|
| 467 | // OutEdgeIt& operator++() { |
---|
| 468 | // if (out_or_in) { |
---|
[174] | 469 | // Node v=/*resG->*/G->aNode(out); |
---|
[168] | 470 | // ++out; |
---|
[174] | 471 | // while( out.valid() && !(Edge::free()>0) ) { ++out; } |
---|
[168] | 472 | // if (!out.valid()) { |
---|
| 473 | // out_or_in=0; |
---|
[174] | 474 | // G->/*getF*/first(in, v); |
---|
| 475 | // while( in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 476 | // } |
---|
| 477 | // } else { |
---|
| 478 | // ++in; |
---|
[174] | 479 | // while( in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 480 | // } |
---|
| 481 | // return *this; |
---|
| 482 | // } |
---|
[155] | 483 | }; |
---|
| 484 | |
---|
[174] | 485 | class EdgeIt : public Edge { |
---|
[155] | 486 | friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; |
---|
[174] | 487 | typename Graph::NodeIt v; |
---|
[155] | 488 | public: |
---|
[174] | 489 | EdgeIt() { } |
---|
| 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)) { |
---|
| 497 | resG.graph->next(v); |
---|
| 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); } |
---|
[155] | 500 | } |
---|
[174] | 501 | if (!resG.graph->valid(out)) { |
---|
[155] | 502 | out_or_in=0; |
---|
[174] | 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)) { |
---|
| 507 | resG.graph->next(v); |
---|
| 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); } |
---|
[155] | 510 | } |
---|
| 511 | } |
---|
| 512 | } |
---|
[174] | 513 | // EdgeIt& operator++() { |
---|
[168] | 514 | // if (out_or_in) { |
---|
| 515 | // ++out; |
---|
[174] | 516 | // while (out.valid() && !(Edge::free()>0) ) { ++out; } |
---|
[168] | 517 | // while (v.valid() && !out.valid()) { |
---|
| 518 | // ++v; |
---|
[174] | 519 | // if (v.valid()) G->/*getF*/first(out, v); |
---|
| 520 | // while (out.valid() && !(Edge::free()>0) ) { ++out; } |
---|
[168] | 521 | // } |
---|
| 522 | // if (!out.valid()) { |
---|
| 523 | // out_or_in=0; |
---|
[174] | 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; } |
---|
[168] | 527 | // while (v.valid() && !in.valid()) { |
---|
| 528 | // ++v; |
---|
[174] | 529 | // if (v.valid()) G->/*getF*/first(in, v); |
---|
| 530 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 531 | // } |
---|
| 532 | // } |
---|
| 533 | // } else { |
---|
| 534 | // ++in; |
---|
[174] | 535 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 536 | // while (v.valid() && !in.valid()) { |
---|
| 537 | // ++v; |
---|
[174] | 538 | // if (v.valid()) G->/*getF*/first(in, v); |
---|
| 539 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 540 | // } |
---|
| 541 | // } |
---|
| 542 | // return *this; |
---|
| 543 | // } |
---|
[155] | 544 | }; |
---|
| 545 | |
---|
[174] | 546 | NodeIt& /*getF*/first(NodeIt& v) const { return graph->/*getF*/first(v); } |
---|
| 547 | OutEdgeIt& /*getF*/first(OutEdgeIt& e, Node v) const { |
---|
[168] | 548 | e=OutEdgeIt(*this, v); |
---|
[174] | 549 | return e; |
---|
[155] | 550 | } |
---|
[174] | 551 | EdgeIt& /*getF*/first(EdgeIt& e) const { |
---|
| 552 | e=EdgeIt(*this); |
---|
| 553 | return e; |
---|
[155] | 554 | } |
---|
| 555 | |
---|
[174] | 556 | NodeIt& next(NodeIt& n) const { return graph->next(n); } |
---|
[155] | 557 | |
---|
| 558 | OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 559 | if (e.out_or_in) { |
---|
[174] | 560 | Node v=graph->aNode(e.out); |
---|
| 561 | graph->next(e.out); |
---|
| 562 | while( graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); } |
---|
| 563 | if (!graph->valid(e.out)) { |
---|
[155] | 564 | e.out_or_in=0; |
---|
[174] | 565 | graph->/*getF*/first(e.in, v); |
---|
| 566 | while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } |
---|
[155] | 567 | } |
---|
| 568 | } else { |
---|
[174] | 569 | graph->next(e.in); |
---|
| 570 | while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } |
---|
[155] | 571 | } |
---|
| 572 | return e; |
---|
| 573 | } |
---|
| 574 | |
---|
[174] | 575 | EdgeIt& next(EdgeIt& e) const { |
---|
[155] | 576 | if (e.out_or_in) { |
---|
[174] | 577 | graph->next(e.out); |
---|
| 578 | while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); } |
---|
| 579 | while (graph->valid(e.v) && !graph->valid(e.out)) { |
---|
| 580 | graph->next(e.v); |
---|
| 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); } |
---|
[155] | 583 | } |
---|
[174] | 584 | if (!graph->valid(e.out)) { |
---|
[155] | 585 | e.out_or_in=0; |
---|
[174] | 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)) { |
---|
| 590 | graph->next(e.v); |
---|
| 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); } |
---|
[155] | 593 | } |
---|
| 594 | } |
---|
| 595 | } else { |
---|
[174] | 596 | 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)) { |
---|
| 599 | graph->next(e.v); |
---|
| 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); } |
---|
[155] | 602 | } |
---|
| 603 | } |
---|
| 604 | return e; |
---|
| 605 | } |
---|
[76] | 606 | |
---|
| 607 | |
---|
[155] | 608 | template< typename It > |
---|
| 609 | It first() const { |
---|
| 610 | It e; |
---|
[174] | 611 | /*getF*/first(e); |
---|
[155] | 612 | return e; |
---|
| 613 | } |
---|
[76] | 614 | |
---|
[155] | 615 | template< typename It > |
---|
[174] | 616 | It first(Node v) const { |
---|
[155] | 617 | It e; |
---|
[174] | 618 | /*getF*/first(e, v); |
---|
[155] | 619 | return e; |
---|
| 620 | } |
---|
[76] | 621 | |
---|
[174] | 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)); } |
---|
[76] | 626 | |
---|
[174] | 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)); } |
---|
[76] | 631 | |
---|
[174] | 632 | int id(Node v) const { return graph->id(v); } |
---|
[155] | 633 | |
---|
[174] | 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); } |
---|
[155] | 637 | |
---|
[174] | 638 | void augment(const Edge& e, Number a) const { |
---|
[168] | 639 | if (e.out_or_in) |
---|
| 640 | flow->set(e.out, flow->get(e.out)+a); |
---|
| 641 | else |
---|
| 642 | flow->set(e.in, flow->get(e.in)-a); |
---|
| 643 | } |
---|
| 644 | |
---|
[174] | 645 | Number free(const Edge& e) const { |
---|
[168] | 646 | if (e.out_or_in) |
---|
| 647 | return (capacity->get(e.out)-flow->get(e.out)); |
---|
| 648 | else |
---|
| 649 | return (flow->get(e.in)); |
---|
| 650 | } |
---|
| 651 | |
---|
| 652 | Number free(OldOutEdgeIt out) const { |
---|
| 653 | return (capacity->get(out)-flow->get(out)); |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | Number free(OldInEdgeIt in) const { |
---|
| 657 | return (flow->get(in)); |
---|
| 658 | } |
---|
| 659 | |
---|
[155] | 660 | template<typename T> class NodeMap : public Graph::NodeMap<T> { |
---|
| 661 | public: |
---|
| 662 | NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) |
---|
[158] | 663 | : Graph::NodeMap<T>(_G.getGraph()) { } |
---|
[155] | 664 | NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, |
---|
[158] | 665 | T a) : Graph::NodeMap<T>(_G.getGraph(), a) { } |
---|
[155] | 666 | }; |
---|
| 667 | |
---|
| 668 | // template <typename T> |
---|
| 669 | // class NodeMap { |
---|
| 670 | // typename Graph::NodeMap<T> node_map; |
---|
| 671 | // public: |
---|
[174] | 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); } |
---|
[155] | 676 | // }; |
---|
| 677 | |
---|
| 678 | template <typename T> |
---|
| 679 | class EdgeMap { |
---|
| 680 | typename Graph::EdgeMap<T> forward_map, backward_map; |
---|
| 681 | public: |
---|
[158] | 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) { } |
---|
[174] | 684 | void set(Edge e, T a) { |
---|
[155] | 685 | if (e.out_or_in) |
---|
| 686 | forward_map.set(e.out, a); |
---|
| 687 | else |
---|
| 688 | backward_map.set(e.in, a); |
---|
| 689 | } |
---|
[174] | 690 | T get(Edge e) { |
---|
[155] | 691 | if (e.out_or_in) |
---|
| 692 | return forward_map.get(e.out); |
---|
| 693 | else |
---|
| 694 | return backward_map.get(e.in); |
---|
| 695 | } |
---|
| 696 | }; |
---|
[168] | 697 | }; |
---|
| 698 | |
---|
| 699 | template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
---|
| 700 | class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> { |
---|
| 701 | protected: |
---|
| 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; |
---|
| 704 | public: |
---|
| 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)*/ { |
---|
[174] | 709 | for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) { |
---|
[168] | 710 | OutEdgeIt e; |
---|
[174] | 711 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::/*getF*/first(e, n); |
---|
[168] | 712 | first_out_edges.set(n, e); |
---|
| 713 | } |
---|
| 714 | } |
---|
| 715 | |
---|
| 716 | //void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 717 | //Graph& getGraph() const { return (*graph); } |
---|
| 718 | |
---|
| 719 | //TrivGraphWrapper() : graph(0) { } |
---|
| 720 | //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 721 | |
---|
| 722 | //typedef Graph BaseGraph; |
---|
| 723 | |
---|
[174] | 724 | //typedef typename Graph::Node Node; |
---|
[168] | 725 | //typedef typename Graph::NodeIt NodeIt; |
---|
| 726 | |
---|
[174] | 727 | //typedef typename Graph::Edge Edge; |
---|
[168] | 728 | //typedef typename Graph::OutEdgeIt OutEdgeIt; |
---|
| 729 | //typedef typename Graph::InEdgeIt InEdgeIt; |
---|
| 730 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 731 | //typedef typename Graph::EdgeIt EdgeIt; |
---|
[168] | 732 | |
---|
[174] | 733 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node; |
---|
[168] | 734 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt; |
---|
| 735 | |
---|
[174] | 736 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge; |
---|
[168] | 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; |
---|
[174] | 740 | //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt; |
---|
[168] | 741 | |
---|
[174] | 742 | NodeIt& /*getF*/first(NodeIt& n) const { |
---|
| 743 | return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::/*getF*/first(n); |
---|
[168] | 744 | } |
---|
| 745 | |
---|
[174] | 746 | OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const { |
---|
[168] | 747 | e=first_out_edges.get(n); |
---|
| 748 | return e; |
---|
| 749 | } |
---|
| 750 | |
---|
[174] | 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); } |
---|
[168] | 754 | |
---|
| 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); } |
---|
| 758 | |
---|
| 759 | template< typename It > It first() const { |
---|
[174] | 760 | It e; /*getF*/first(e); return e; } |
---|
[168] | 761 | |
---|
[174] | 762 | template< typename It > It first(const Node& v) const { |
---|
| 763 | It e; /*getF*/first(e, v); return e; } |
---|
[168] | 764 | |
---|
[174] | 765 | //Node head(const Edge& e) const { return graph->head(e); } |
---|
| 766 | //Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[168] | 767 | |
---|
| 768 | //template<typename I> bool valid(const I& i) const |
---|
| 769 | // { return graph->valid(i); } |
---|
| 770 | |
---|
| 771 | //int nodeNum() const { return graph->nodeNum(); } |
---|
| 772 | //int edgeNum() const { return graph->edgeNum(); } |
---|
| 773 | |
---|
[174] | 774 | //template<typename I> Node aNode(const I& e) const { |
---|
[168] | 775 | // return graph->aNode(e); } |
---|
[174] | 776 | //template<typename I> Node bNode(const I& e) const { |
---|
[168] | 777 | // return graph->bNode(e); } |
---|
| 778 | |
---|
[174] | 779 | //Node addNode() const { return graph->addNode(); } |
---|
| 780 | //Edge addEdge(const Node& tail, const Node& head) const { |
---|
[168] | 781 | // return graph->addEdge(tail, head); } |
---|
| 782 | |
---|
| 783 | //void erase(const OutEdgeIt& e) { |
---|
| 784 | // first_out_edge(this->tail(e))=e; |
---|
| 785 | //} |
---|
[174] | 786 | void erase(const Edge& e) { |
---|
[168] | 787 | OutEdgeIt f(e); |
---|
| 788 | next(f); |
---|
| 789 | first_out_edges.set(this->tail(e), f); |
---|
| 790 | } |
---|
| 791 | //template<typename I> void erase(const I& i) const { graph->erase(i); } |
---|
| 792 | |
---|
| 793 | //void clear() const { graph->clear(); } |
---|
| 794 | |
---|
| 795 | template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { |
---|
| 796 | public: |
---|
| 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) { } |
---|
| 801 | }; |
---|
| 802 | |
---|
| 803 | template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { |
---|
| 804 | public: |
---|
| 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) { } |
---|
| 809 | }; |
---|
| 810 | }; |
---|
| 811 | |
---|
| 812 | template<typename GraphWrapper> |
---|
| 813 | class FilterGraphWrapper { |
---|
| 814 | }; |
---|
| 815 | |
---|
| 816 | template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
---|
| 817 | class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> { |
---|
| 818 | |
---|
| 819 | //Graph* graph; |
---|
| 820 | |
---|
| 821 | public: |
---|
| 822 | //typedef Graph BaseGraph; |
---|
| 823 | |
---|
[174] | 824 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node; |
---|
[168] | 825 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt; |
---|
| 826 | |
---|
[174] | 827 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge; |
---|
[168] | 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; |
---|
[174] | 831 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt; |
---|
[168] | 832 | |
---|
| 833 | //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges; |
---|
| 834 | |
---|
| 835 | public: |
---|
| 836 | FilterGraphWrapper(const Graph& _G, FlowMap& _flow, |
---|
| 837 | const CapacityMap& _capacity) : |
---|
[199] | 838 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, graph->nodeNum()) { |
---|
[168] | 839 | } |
---|
| 840 | |
---|
[174] | 841 | OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const { |
---|
| 842 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::/*getF*/first(e, n); |
---|
[199] | 843 | while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e)))) |
---|
[168] | 844 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
| 845 | return e; |
---|
| 846 | } |
---|
| 847 | |
---|
[174] | 848 | NodeIt& next(NodeIt& e) const { |
---|
[168] | 849 | return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
| 850 | } |
---|
| 851 | |
---|
| 852 | OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 853 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
[199] | 854 | while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e)))) |
---|
[168] | 855 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
| 856 | return e; |
---|
| 857 | } |
---|
| 858 | |
---|
[174] | 859 | NodeIt& /*getF*/first(NodeIt& n) const { |
---|
| 860 | return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::/*getF*/first(n); |
---|
[168] | 861 | } |
---|
| 862 | |
---|
[174] | 863 | void erase(const Edge& e) { |
---|
[168] | 864 | OutEdgeIt f(e); |
---|
| 865 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f); |
---|
[199] | 866 | while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f)))) |
---|
[168] | 867 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f); |
---|
| 868 | first_out_edges.set(this->tail(e), f); |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | //TrivGraphWrapper() : graph(0) { } |
---|
| 872 | //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 873 | |
---|
| 874 | //void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 875 | //Graph& getGraph() const { return (*graph); } |
---|
| 876 | |
---|
[174] | 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); } |
---|
[168] | 880 | |
---|
| 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); } |
---|
| 884 | |
---|
| 885 | template< typename It > It first() const { |
---|
[174] | 886 | It e; /*getF*/first(e); return e; } |
---|
[168] | 887 | |
---|
[174] | 888 | template< typename It > It first(const Node& v) const { |
---|
| 889 | It e; /*getF*/first(e, v); return e; } |
---|
[168] | 890 | |
---|
[174] | 891 | //Node head(const Edge& e) const { return graph->head(e); } |
---|
| 892 | //Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[168] | 893 | |
---|
| 894 | //template<typename I> bool valid(const I& i) const |
---|
| 895 | // { return graph->valid(i); } |
---|
| 896 | |
---|
| 897 | //template<typename I> void setInvalid(const I &i); |
---|
| 898 | //{ return graph->setInvalid(i); } |
---|
| 899 | |
---|
| 900 | //int nodeNum() const { return graph->nodeNum(); } |
---|
| 901 | //int edgeNum() const { return graph->edgeNum(); } |
---|
| 902 | |
---|
[174] | 903 | //template<typename I> Node aNode(const I& e) const { |
---|
[168] | 904 | // return graph->aNode(e); } |
---|
[174] | 905 | //template<typename I> Node bNode(const I& e) const { |
---|
[168] | 906 | // return graph->bNode(e); } |
---|
| 907 | |
---|
[174] | 908 | //Node addNode() const { return graph->addNode(); } |
---|
| 909 | //Edge addEdge(const Node& tail, const Node& head) const { |
---|
[168] | 910 | // return graph->addEdge(tail, head); } |
---|
| 911 | |
---|
| 912 | //template<typename I> void erase(const I& i) const { graph->erase(i); } |
---|
| 913 | |
---|
| 914 | //void clear() const { graph->clear(); } |
---|
| 915 | |
---|
| 916 | template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { |
---|
| 917 | public: |
---|
| 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) { } |
---|
| 922 | }; |
---|
| 923 | |
---|
| 924 | template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { |
---|
| 925 | public: |
---|
| 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) { } |
---|
| 930 | }; |
---|
| 931 | |
---|
| 932 | public: |
---|
| 933 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist; |
---|
[155] | 934 | |
---|
[76] | 935 | }; |
---|
| 936 | |
---|
| 937 | |
---|
[148] | 938 | |
---|
| 939 | // // FIXME: comparison should be made better!!! |
---|
| 940 | // template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap> |
---|
| 941 | // class ResGraphWrapper |
---|
| 942 | // { |
---|
| 943 | // Graph* graph; |
---|
[76] | 944 | |
---|
[148] | 945 | // public: |
---|
| 946 | // typedef Graph BaseGraph; |
---|
[76] | 947 | |
---|
[174] | 948 | // typedef typename Graph::Node Node; |
---|
| 949 | // typedef typename Graph::Edge Edge; |
---|
| 950 | |
---|
[148] | 951 | // typedef typename Graph::NodeIt NodeIt; |
---|
[76] | 952 | |
---|
[148] | 953 | // class OutEdgeIt { |
---|
| 954 | // public: |
---|
[174] | 955 | // //Graph::Node n; |
---|
[148] | 956 | // bool out_or_in; |
---|
| 957 | // typename Graph::OutEdgeIt o; |
---|
| 958 | // typename Graph::InEdgeIt i; |
---|
| 959 | // }; |
---|
| 960 | // class InEdgeIt { |
---|
| 961 | // public: |
---|
[174] | 962 | // //Graph::Node n; |
---|
[148] | 963 | // bool out_or_in; |
---|
| 964 | // typename Graph::OutEdgeIt o; |
---|
| 965 | // typename Graph::InEdgeIt i; |
---|
| 966 | // }; |
---|
| 967 | // typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 968 | // typedef typename Graph::EdgeIt EdgeIt; |
---|
[76] | 969 | |
---|
[148] | 970 | // int nodeNum() const { return graph->nodeNum(); } |
---|
| 971 | // int edgeNum() const { return graph->edgeNum(); } |
---|
[76] | 972 | |
---|
[174] | 973 | // Node& /*getF*/first(Node& n) const { return graph->/*getF*/first(n); } |
---|
[76] | 974 | |
---|
[174] | 975 | // // Edge and SymEdge is missing!!!! |
---|
| 976 | // // Edge <-> In/OutEdgeIt conversion is missing!!!! |
---|
[76] | 977 | |
---|
[148] | 978 | // //FIXME |
---|
[174] | 979 | // OutEdgeIt& /*getF*/first(OutEdgeIt& e, const Node& n) const |
---|
[148] | 980 | // { |
---|
| 981 | // e.n=n; |
---|
[174] | 982 | // graph->/*getF*/first(e.o,n); |
---|
[148] | 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)) { |
---|
[174] | 986 | // graph->/*getF*/first(e.i,n); |
---|
[148] | 987 | // while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i)) |
---|
| 988 | // graph->goNext(e.i); |
---|
| 989 | // } |
---|
| 990 | // return e; |
---|
| 991 | // } |
---|
| 992 | // /* |
---|
| 993 | // OutEdgeIt &goNext(OutEdgeIt &e) |
---|
| 994 | // { |
---|
| 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; |
---|
[174] | 999 | // else graph->/*getF*/first(e.i,e.n); |
---|
[148] | 1000 | // } |
---|
| 1001 | // else { |
---|
| 1002 | // while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i)) |
---|
| 1003 | // graph->goNext(e.i); |
---|
| 1004 | // return e; |
---|
| 1005 | // } |
---|
| 1006 | // } |
---|
| 1007 | // OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);} |
---|
| 1008 | // */ |
---|
| 1009 | // //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);} |
---|
[76] | 1010 | |
---|
[148] | 1011 | // //FIXME |
---|
[174] | 1012 | // InEdgeIt& /*getF*/first(InEdgeIt& e, const Node& n) const |
---|
[148] | 1013 | // { |
---|
| 1014 | // e.n=n; |
---|
[174] | 1015 | // graph->/*getF*/first(e.i,n); |
---|
[148] | 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)) { |
---|
[174] | 1019 | // graph->/*getF*/first(e.o,n); |
---|
[148] | 1020 | // while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o)) |
---|
| 1021 | // graph->goNext(e.o); |
---|
| 1022 | // } |
---|
| 1023 | // return e; |
---|
| 1024 | // } |
---|
| 1025 | // /* |
---|
| 1026 | // InEdgeIt &goNext(InEdgeIt &e) |
---|
| 1027 | // { |
---|
| 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; |
---|
[174] | 1032 | // else graph->/*getF*/first(e.o,e.n); |
---|
[148] | 1033 | // } |
---|
| 1034 | // else { |
---|
| 1035 | // while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o)) |
---|
| 1036 | // graph->goNext(e.o); |
---|
| 1037 | // return e; |
---|
| 1038 | // } |
---|
| 1039 | // } |
---|
| 1040 | // InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);} |
---|
| 1041 | // */ |
---|
| 1042 | // //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);} |
---|
[76] | 1043 | |
---|
[148] | 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); } |
---|
[76] | 1046 | |
---|
[148] | 1047 | // template< typename It > It first() const { |
---|
[174] | 1048 | // It e; /*getF*/first(e); return e; } |
---|
[76] | 1049 | |
---|
[174] | 1050 | // template< typename It > It first(Node v) const { |
---|
| 1051 | // It e; /*getF*/first(e, v); return e; } |
---|
[76] | 1052 | |
---|
[174] | 1053 | // Node head(const Edge& e) const { return graph->head(e); } |
---|
| 1054 | // Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[76] | 1055 | |
---|
[174] | 1056 | // template<typename I> Node aNode(const I& e) const { |
---|
[148] | 1057 | // return graph->aNode(e); } |
---|
[174] | 1058 | // template<typename I> Node bNode(const I& e) const { |
---|
[148] | 1059 | // return graph->bNode(e); } |
---|
[76] | 1060 | |
---|
[148] | 1061 | // //template<typename I> bool valid(const I i); |
---|
| 1062 | // //{ return graph->valid(i); } |
---|
[76] | 1063 | |
---|
[148] | 1064 | // //template<typename I> void setInvalid(const I &i); |
---|
| 1065 | // //{ return graph->setInvalid(i); } |
---|
[76] | 1066 | |
---|
[174] | 1067 | // Node addNode() { return graph->addNode(); } |
---|
| 1068 | // Edge addEdge(const Node& tail, const Node& head) { |
---|
[148] | 1069 | // return graph->addEdge(tail, head); } |
---|
[76] | 1070 | |
---|
[148] | 1071 | // template<typename I> void erase(const I& i) { graph->erase(i); } |
---|
[76] | 1072 | |
---|
[148] | 1073 | // void clear() { graph->clear(); } |
---|
[76] | 1074 | |
---|
[148] | 1075 | // template<typename S> class NodeMap : public Graph::NodeMap<S> { }; |
---|
| 1076 | // template<typename S> class EdgeMap : public Graph::EdgeMap<S> { }; |
---|
[76] | 1077 | |
---|
[148] | 1078 | // void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 1079 | // Graph& getGraph() { return (*graph); } |
---|
[76] | 1080 | |
---|
[148] | 1081 | // //ResGraphWrapper() : graph(0) { } |
---|
| 1082 | // ResGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 1083 | // }; |
---|
[76] | 1084 | |
---|
[105] | 1085 | } //namespace hugo |
---|
[76] | 1086 | |
---|
| 1087 | #endif //GRAPH_WRAPPER_H |
---|
| 1088 | |
---|