[174] | 1 | // -*- c++ -*- |
---|
[259] | 2 | #ifndef HUGO_GRAPH_WRAPPER_H |
---|
| 3 | #define HUGO_GRAPH_WRAPPER_H |
---|
[76] | 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 | |
---|
[212] | 32 | template<typename I> I& first(I& i) const { return graph->first(i); } |
---|
| 33 | template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 34 | return graph->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 { |
---|
[212] | 41 | It e; first(e); return e; } |
---|
[76] | 42 | |
---|
[174] | 43 | template< typename It > It first(const Node& v) const { |
---|
[212] | 44 | It e; 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 | |
---|
[212] | 88 | template<typename GraphWrapper> |
---|
| 89 | class GraphWrapperSkeleton { |
---|
| 90 | protected: |
---|
| 91 | GraphWrapper gw; |
---|
| 92 | |
---|
| 93 | public: |
---|
| 94 | typedef typename GraphWrapper::BaseGraph BaseGraph; |
---|
| 95 | |
---|
| 96 | typedef typename GraphWrapper::Node Node; |
---|
| 97 | typedef typename GraphWrapper::NodeIt NodeIt; |
---|
| 98 | |
---|
| 99 | typedef typename GraphWrapper::Edge Edge; |
---|
| 100 | typedef typename GraphWrapper::OutEdgeIt OutEdgeIt; |
---|
| 101 | typedef typename GraphWrapper::InEdgeIt InEdgeIt; |
---|
| 102 | //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt; |
---|
| 103 | typedef typename GraphWrapper::EdgeIt EdgeIt; |
---|
| 104 | |
---|
| 105 | //GraphWrapperSkeleton() : gw() { } |
---|
[230] | 106 | GraphWrapperSkeleton(GraphWrapper _gw) : gw(_gw) { } |
---|
[212] | 107 | |
---|
| 108 | void setGraph(BaseGraph& _graph) { gw.setGraph(_graph); } |
---|
| 109 | BaseGraph& getGraph() const { return gw.getGraph(); } |
---|
| 110 | |
---|
| 111 | template<typename I> I& first(I& i) const { return gw.first(i); } |
---|
| 112 | template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 113 | return gw.first(i, p); } |
---|
| 114 | |
---|
| 115 | template<typename I> I getNext(const I& i) const { return gw.getNext(i); } |
---|
| 116 | template<typename I> I& next(I &i) const { return gw.next(i); } |
---|
| 117 | |
---|
| 118 | template< typename It > It first() const { |
---|
| 119 | It e; this->first(e); return e; } |
---|
| 120 | |
---|
| 121 | template< typename It > It first(const Node& v) const { |
---|
| 122 | It e; this->first(e, v); return e; } |
---|
| 123 | |
---|
| 124 | Node head(const Edge& e) const { return gw.head(e); } |
---|
| 125 | Node tail(const Edge& e) const { return gw.tail(e); } |
---|
| 126 | |
---|
| 127 | template<typename I> bool valid(const I& i) const { return gw.valid(i); } |
---|
| 128 | |
---|
| 129 | //template<typename I> void setInvalid(const I &i); |
---|
| 130 | //{ return graph->setInvalid(i); } |
---|
| 131 | |
---|
| 132 | int nodeNum() const { return gw.nodeNum(); } |
---|
| 133 | int edgeNum() const { return gw.edgeNum(); } |
---|
| 134 | |
---|
| 135 | template<typename I> Node aNode(const I& e) const { return gw.aNode(e); } |
---|
| 136 | template<typename I> Node bNode(const I& e) const { return gw.bNode(e); } |
---|
| 137 | |
---|
| 138 | Node addNode() const { return gw.addNode(); } |
---|
| 139 | Edge addEdge(const Node& tail, const Node& head) const { |
---|
| 140 | return gw.addEdge(tail, head); } |
---|
| 141 | |
---|
| 142 | template<typename I> void erase(const I& i) const { gw.erase(i); } |
---|
| 143 | |
---|
| 144 | void clear() const { gw.clear(); } |
---|
| 145 | |
---|
| 146 | template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { |
---|
| 147 | public: |
---|
| 148 | NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) : |
---|
| 149 | GraphWrapper::NodeMap<T>(_G.gw) { } |
---|
| 150 | NodeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) : |
---|
| 151 | GraphWrapper::NodeMap<T>(_G.gw, a) { } |
---|
| 152 | }; |
---|
| 153 | |
---|
| 154 | template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { |
---|
| 155 | public: |
---|
| 156 | EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G) : |
---|
| 157 | GraphWrapper::EdgeMap<T>(_G.gw) { } |
---|
| 158 | EdgeMap(const GraphWrapperSkeleton<GraphWrapper>& _G, T a) : |
---|
| 159 | GraphWrapper::EdgeMap<T>(_G.gw, a) { } |
---|
| 160 | }; |
---|
| 161 | }; |
---|
| 162 | |
---|
[230] | 163 | // template<typename Graph> |
---|
| 164 | // class RevGraphWrapper |
---|
| 165 | // { |
---|
| 166 | // protected: |
---|
| 167 | // Graph* graph; |
---|
| 168 | |
---|
| 169 | // public: |
---|
| 170 | // typedef Graph BaseGraph; |
---|
| 171 | |
---|
| 172 | // typedef typename Graph::Node Node; |
---|
| 173 | // typedef typename Graph::NodeIt NodeIt; |
---|
| 174 | |
---|
| 175 | // typedef typename Graph::Edge Edge; |
---|
| 176 | // typedef typename Graph::OutEdgeIt InEdgeIt; |
---|
| 177 | // typedef typename Graph::InEdgeIt OutEdgeIt; |
---|
| 178 | // //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
| 179 | // typedef typename Graph::EdgeIt EdgeIt; |
---|
| 180 | |
---|
| 181 | // //RevGraphWrapper() : graph(0) { } |
---|
| 182 | // RevGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 183 | |
---|
| 184 | // void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 185 | // Graph& getGraph() const { return (*graph); } |
---|
| 186 | |
---|
| 187 | // template<typename I> I& first(I& i) const { return graph->first(i); } |
---|
| 188 | // template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 189 | // return graph->first(i, p); } |
---|
| 190 | |
---|
| 191 | // template<typename I> I getNext(const I& i) const { |
---|
| 192 | // return graph->getNext(i); } |
---|
| 193 | // template<typename I> I& next(I &i) const { return graph->next(i); } |
---|
| 194 | |
---|
| 195 | // template< typename It > It first() const { |
---|
| 196 | // It e; first(e); return e; } |
---|
| 197 | |
---|
| 198 | // template< typename It > It first(const Node& v) const { |
---|
| 199 | // It e; first(e, v); return e; } |
---|
| 200 | |
---|
| 201 | // Node head(const Edge& e) const { return graph->tail(e); } |
---|
| 202 | // Node tail(const Edge& e) const { return graph->head(e); } |
---|
| 203 | |
---|
| 204 | // template<typename I> bool valid(const I& i) const |
---|
| 205 | // { return graph->valid(i); } |
---|
| 206 | |
---|
| 207 | // //template<typename I> void setInvalid(const I &i); |
---|
| 208 | // //{ return graph->setInvalid(i); } |
---|
| 209 | |
---|
| 210 | // template<typename I> Node aNode(const I& e) const { |
---|
| 211 | // return graph->aNode(e); } |
---|
| 212 | // template<typename I> Node bNode(const I& e) const { |
---|
| 213 | // return graph->bNode(e); } |
---|
| 214 | |
---|
| 215 | // Node addNode() const { return graph->addNode(); } |
---|
| 216 | // Edge addEdge(const Node& tail, const Node& head) const { |
---|
| 217 | // return graph->addEdge(tail, head); } |
---|
| 218 | |
---|
| 219 | // int nodeNum() const { return graph->nodeNum(); } |
---|
| 220 | // int edgeNum() const { return graph->edgeNum(); } |
---|
| 221 | |
---|
| 222 | // template<typename I> void erase(const I& i) const { graph->erase(i); } |
---|
| 223 | |
---|
| 224 | // void clear() const { graph->clear(); } |
---|
| 225 | |
---|
| 226 | // template<typename T> class NodeMap : public Graph::NodeMap<T> { |
---|
| 227 | // public: |
---|
| 228 | // NodeMap(const RevGraphWrapper<Graph>& _G) : |
---|
| 229 | // Graph::NodeMap<T>(_G.getGraph()) { } |
---|
| 230 | // NodeMap(const RevGraphWrapper<Graph>& _G, T a) : |
---|
| 231 | // Graph::NodeMap<T>(_G.getGraph(), a) { } |
---|
| 232 | // }; |
---|
| 233 | |
---|
| 234 | // template<typename T> class EdgeMap : public Graph::EdgeMap<T> { |
---|
| 235 | // public: |
---|
| 236 | // EdgeMap(const RevGraphWrapper<Graph>& _G) : |
---|
| 237 | // Graph::EdgeMap<T>(_G.getGraph()) { } |
---|
| 238 | // EdgeMap(const RevGraphWrapper<Graph>& _G, T a) : |
---|
| 239 | // Graph::EdgeMap<T>(_G.getGraph(), a) { } |
---|
| 240 | // }; |
---|
| 241 | // }; |
---|
| 242 | |
---|
[235] | 243 | // template<typename /*Graph*/GraphWrapper |
---|
| 244 | // /*=typename GraphWrapperSkeleton< TrivGraphWrapper<Graph>*/ > |
---|
| 245 | // class RevGraphWrapper : |
---|
| 246 | // public GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/ { |
---|
| 247 | // protected: |
---|
| 248 | // //Graph* graph; |
---|
[230] | 249 | |
---|
[235] | 250 | // public: |
---|
| 251 | // //typedef Graph BaseGraph; |
---|
| 252 | |
---|
| 253 | // //typedef typename Graph::Node Node; |
---|
| 254 | // //typedef typename Graph::NodeIt NodeIt; |
---|
| 255 | |
---|
| 256 | // //typedef typename Graph::Edge Edge; |
---|
| 257 | // typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::OutEdgeIt InEdgeIt; |
---|
| 258 | // typedef typename GraphWrapper/*typename GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/::InEdgeIt OutEdgeIt; |
---|
| 259 | // //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
| 260 | // //typedef typename Graph::EdgeIt EdgeIt; |
---|
| 261 | |
---|
| 262 | // //RevGraphWrapper() : graph(0) { } |
---|
| 263 | // RevGraphWrapper(GraphWrapper _gw/*BaseGraph& _graph*/) : GraphWrapper/*GraphWrapperSkeleton< TrivGraphWrapper<Graph> >*/(_gw/*TrivGraphWrapper<Graph>(_graph)*/) { } |
---|
| 264 | |
---|
| 265 | // //void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 266 | // //Graph& getGraph() const { return (*graph); } |
---|
| 267 | |
---|
| 268 | // //template<typename I> I& first(I& i) const { return graph->first(i); } |
---|
| 269 | // //template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 270 | // // return graph->first(i, p); } |
---|
| 271 | |
---|
| 272 | // //template<typename I> I getNext(const I& i) const { |
---|
| 273 | // // return graph->getNext(i); } |
---|
| 274 | // //template<typename I> I& next(I &i) const { return graph->next(i); } |
---|
| 275 | |
---|
| 276 | // //template< typename It > It first() const { |
---|
| 277 | // // It e; first(e); return e; } |
---|
| 278 | |
---|
| 279 | // //template< typename It > It first(const Node& v) const { |
---|
| 280 | // // It e; first(e, v); return e; } |
---|
| 281 | |
---|
| 282 | // //Node head(const Edge& e) const { return graph->tail(e); } |
---|
| 283 | // //Node tail(const Edge& e) const { return graph->head(e); } |
---|
| 284 | |
---|
| 285 | // //template<typename I> bool valid(const I& i) const |
---|
| 286 | // // { return graph->valid(i); } |
---|
| 287 | |
---|
| 288 | // //template<typename I> void setInvalid(const I &i); |
---|
| 289 | // //{ return graph->setInvalid(i); } |
---|
| 290 | |
---|
| 291 | // //template<typename I> Node aNode(const I& e) const { |
---|
| 292 | // // return graph->aNode(e); } |
---|
| 293 | // //template<typename I> Node bNode(const I& e) const { |
---|
| 294 | // // return graph->bNode(e); } |
---|
| 295 | |
---|
| 296 | // //Node addNode() const { return graph->addNode(); } |
---|
| 297 | // //Edge addEdge(const Node& tail, const Node& head) const { |
---|
| 298 | // // return graph->addEdge(tail, head); } |
---|
| 299 | |
---|
| 300 | // //int nodeNum() const { return graph->nodeNum(); } |
---|
| 301 | // //int edgeNum() const { return graph->edgeNum(); } |
---|
| 302 | |
---|
| 303 | // //template<typename I> void erase(const I& i) const { graph->erase(i); } |
---|
| 304 | |
---|
| 305 | // //void clear() const { graph->clear(); } |
---|
| 306 | |
---|
| 307 | // template<typename T> class NodeMap : |
---|
| 308 | // public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T> |
---|
| 309 | // { |
---|
| 310 | // public: |
---|
| 311 | // NodeMap(const RevGraphWrapper<GraphWrapper>& _gw) : |
---|
| 312 | // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw) { } |
---|
| 313 | // NodeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : |
---|
| 314 | // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::NodeMap<T>(_gw, a) { } |
---|
| 315 | // }; |
---|
| 316 | |
---|
| 317 | // template<typename T> class EdgeMap : |
---|
| 318 | // public GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T> { |
---|
| 319 | // public: |
---|
| 320 | // EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw) : |
---|
| 321 | // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw) { } |
---|
| 322 | // EdgeMap(const RevGraphWrapper<GraphWrapper>& _gw, T a) : |
---|
| 323 | // GraphWrapper/*Skeleton< TrivGraphWrapper<Graph> >*/::EdgeMap<T>(_gw, a) { } |
---|
| 324 | // }; |
---|
| 325 | // }; |
---|
| 326 | |
---|
| 327 | |
---|
| 328 | template<typename GraphWrapper> |
---|
| 329 | class RevGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> { |
---|
[230] | 330 | public: |
---|
[237] | 331 | typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node; |
---|
| 332 | typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge Edge; |
---|
[235] | 333 | typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt InEdgeIt; |
---|
| 334 | typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt OutEdgeIt; |
---|
[237] | 335 | |
---|
[238] | 336 | RevGraphWrapper(GraphWrapper _gw) : |
---|
| 337 | GraphWrapperSkeleton<GraphWrapper>(_gw) { } |
---|
| 338 | |
---|
[237] | 339 | Node head(const Edge& e) const |
---|
| 340 | { return GraphWrapperSkeleton<GraphWrapper>::tail(e); } |
---|
| 341 | Node tail(const Edge& e) const |
---|
| 342 | { return GraphWrapperSkeleton<GraphWrapper>::head(e); } |
---|
[76] | 343 | }; |
---|
| 344 | |
---|
[155] | 345 | |
---|
[238] | 346 | // template<typename GraphWrapper> |
---|
[236] | 347 | // class UndirGraphWrapper { |
---|
| 348 | // protected: |
---|
[238] | 349 | // //Graph* graph; |
---|
| 350 | // GraphWrapper gw; |
---|
| 351 | |
---|
[236] | 352 | // public: |
---|
[238] | 353 | // typedef GraphWrapper BaseGraph; |
---|
[236] | 354 | |
---|
[238] | 355 | // typedef typename GraphWrapper::Node Node; |
---|
| 356 | // typedef typename GraphWrapper::NodeIt NodeIt; |
---|
[236] | 357 | |
---|
| 358 | // //typedef typename Graph::Edge Edge; |
---|
| 359 | // //typedef typename Graph::OutEdgeIt OutEdgeIt; |
---|
| 360 | // //typedef typename Graph::InEdgeIt InEdgeIt; |
---|
| 361 | // //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
| 362 | // //typedef typename Graph::EdgeIt EdgeIt; |
---|
| 363 | |
---|
| 364 | // //private: |
---|
[238] | 365 | // typedef typename GraphWrapper::Edge GraphEdge; |
---|
| 366 | // typedef typename GraphWrapper::OutEdgeIt GraphOutEdgeIt; |
---|
| 367 | // typedef typename GraphWrapper::InEdgeIt GraphInEdgeIt; |
---|
[236] | 368 | // //public: |
---|
| 369 | |
---|
| 370 | // //UndirGraphWrapper() : graph(0) { } |
---|
[238] | 371 | // UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { } |
---|
[236] | 372 | |
---|
[238] | 373 | // //void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 374 | // //Graph& getGraph() const { return (*graph); } |
---|
[236] | 375 | |
---|
| 376 | // class Edge { |
---|
[238] | 377 | // friend class UndirGraphWrapper<GraphWrapper>; |
---|
[236] | 378 | // bool out_or_in; //true iff out |
---|
| 379 | // GraphOutEdgeIt out; |
---|
| 380 | // GraphInEdgeIt in; |
---|
| 381 | // public: |
---|
| 382 | // Edge() : out_or_in(), out(), in() { } |
---|
| 383 | // Edge(const Invalid& i) : out_or_in(false), out(), in(i) { } |
---|
| 384 | // operator GraphEdge() const { |
---|
| 385 | // if (out_or_in) return(out); else return(in); |
---|
| 386 | // } |
---|
| 387 | // friend bool operator==(const Edge& u, const Edge& v) { |
---|
| 388 | // if (v.out_or_in) |
---|
| 389 | // return (u.out_or_in && u.out==v.out); |
---|
| 390 | // else |
---|
| 391 | // return (!u.out_or_in && u.in==v.in); |
---|
| 392 | // } |
---|
| 393 | // friend bool operator!=(const Edge& u, const Edge& v) { |
---|
| 394 | // if (v.out_or_in) |
---|
| 395 | // return (!u.out_or_in || u.out!=v.out); |
---|
| 396 | // else |
---|
| 397 | // return (u.out_or_in || u.in!=v.in); |
---|
| 398 | // } |
---|
| 399 | // }; |
---|
| 400 | |
---|
| 401 | // class OutEdgeIt : public Edge { |
---|
[238] | 402 | // friend class UndirGraphWrapper<GraphWrapper>; |
---|
[236] | 403 | // public: |
---|
| 404 | // OutEdgeIt() : Edge() { } |
---|
| 405 | // OutEdgeIt(const Invalid& i) : Edge(i) { } |
---|
[238] | 406 | // OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) |
---|
| 407 | // : Edge() { |
---|
[236] | 408 | // out_or_in=true; |
---|
[238] | 409 | // _G.gw.first(out, n); |
---|
| 410 | // if (!(_G.gw.valid(out))) { |
---|
[236] | 411 | // out_or_in=false; |
---|
[238] | 412 | // _G.gw.first(in, n); |
---|
[236] | 413 | // } |
---|
| 414 | // } |
---|
| 415 | // }; |
---|
| 416 | |
---|
| 417 | // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { |
---|
| 418 | // e.out_or_in=true; |
---|
[238] | 419 | // gw.first(e.out, n); |
---|
| 420 | // if (!(gw.valid(e.out))) { |
---|
[236] | 421 | // e.out_or_in=false; |
---|
[238] | 422 | // gw.first(e.in, n); |
---|
[236] | 423 | // } |
---|
| 424 | // return e; |
---|
| 425 | // } |
---|
| 426 | |
---|
| 427 | // OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 428 | // if (e.out_or_in) { |
---|
[238] | 429 | // Node n=gw.tail(e.out); |
---|
| 430 | // gw.next(e.out); |
---|
| 431 | // if (!gw.valid(e.out)) { |
---|
[236] | 432 | // e.out_or_in=false; |
---|
[238] | 433 | // gw.first(e.in, n); |
---|
[236] | 434 | // } |
---|
| 435 | // } else { |
---|
[238] | 436 | // gw.next(e.in); |
---|
[236] | 437 | // } |
---|
| 438 | // return e; |
---|
| 439 | // } |
---|
| 440 | |
---|
| 441 | // Node aNode(const OutEdgeIt& e) const { |
---|
[238] | 442 | // if (e.out_or_in) return gw.tail(e); else return gw.head(e); } |
---|
[236] | 443 | // Node bNode(const OutEdgeIt& e) const { |
---|
[238] | 444 | // if (e.out_or_in) return gw.head(e); else return gw.tail(e); } |
---|
[236] | 445 | |
---|
| 446 | // typedef OutEdgeIt InEdgeIt; |
---|
| 447 | |
---|
[238] | 448 | // template<typename I> I& first(I& i) const { return gw.first(i); } |
---|
[236] | 449 | // // template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 450 | // // return graph->first(i, p); } |
---|
| 451 | |
---|
| 452 | // template<typename I> I getNext(const I& i) const { |
---|
[238] | 453 | // return gw.getNext(i); } |
---|
| 454 | // template<typename I> I& next(I &i) const { return gw.next(i); } |
---|
[236] | 455 | |
---|
| 456 | // template< typename It > It first() const { |
---|
| 457 | // It e; first(e); return e; } |
---|
| 458 | |
---|
| 459 | // template< typename It > It first(const Node& v) const { |
---|
| 460 | // It e; first(e, v); return e; } |
---|
| 461 | |
---|
[238] | 462 | // Node head(const Edge& e) const { return gw.head(e); } |
---|
| 463 | // Node tail(const Edge& e) const { return gw.tail(e); } |
---|
[236] | 464 | |
---|
| 465 | // template<typename I> bool valid(const I& i) const |
---|
[238] | 466 | // { return gw.valid(i); } |
---|
[236] | 467 | |
---|
| 468 | // //template<typename I> void setInvalid(const I &i); |
---|
| 469 | // //{ return graph->setInvalid(i); } |
---|
| 470 | |
---|
[238] | 471 | // int nodeNum() const { return gw.nodeNum(); } |
---|
| 472 | // int edgeNum() const { return gw.edgeNum(); } |
---|
[236] | 473 | |
---|
| 474 | // // template<typename I> Node aNode(const I& e) const { |
---|
| 475 | // // return graph->aNode(e); } |
---|
| 476 | // // template<typename I> Node bNode(const I& e) const { |
---|
| 477 | // // return graph->bNode(e); } |
---|
| 478 | |
---|
[238] | 479 | // Node addNode() const { return gw.addNode(); } |
---|
[236] | 480 | // // FIXME: ez igy nem jo, mert nem |
---|
| 481 | // // Edge addEdge(const Node& tail, const Node& head) const { |
---|
| 482 | // // return graph->addEdge(tail, head); } |
---|
| 483 | |
---|
[238] | 484 | // template<typename I> void erase(const I& i) const { gw.erase(i); } |
---|
[236] | 485 | |
---|
[238] | 486 | // void clear() const { gw.clear(); } |
---|
[236] | 487 | |
---|
[238] | 488 | // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { |
---|
[236] | 489 | // public: |
---|
[238] | 490 | // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : |
---|
| 491 | // GraphWrapper::NodeMap<T>(_G.gw) { } |
---|
| 492 | // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : |
---|
| 493 | // GraphWrapper::NodeMap<T>(_G.gw, a) { } |
---|
[236] | 494 | // }; |
---|
| 495 | |
---|
[238] | 496 | // template<typename T> class EdgeMap : public GraphWrapper::EdgeMap<T> { |
---|
[236] | 497 | // public: |
---|
[238] | 498 | // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : |
---|
| 499 | // GraphWrapper::EdgeMap<T>(_G.gw) { } |
---|
| 500 | // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : |
---|
| 501 | // GraphWrapper::EdgeMap<T>(_G.gw, a) { } |
---|
[236] | 502 | // }; |
---|
| 503 | // }; |
---|
| 504 | |
---|
| 505 | |
---|
| 506 | template<typename GraphWrapper> |
---|
[238] | 507 | class UndirGraphWrapper : public GraphWrapperSkeleton<GraphWrapper> { |
---|
[199] | 508 | protected: |
---|
[238] | 509 | // GraphWrapper gw; |
---|
[236] | 510 | |
---|
[158] | 511 | public: |
---|
[238] | 512 | //typedef GraphWrapper BaseGraph; |
---|
[158] | 513 | |
---|
[238] | 514 | typedef typename GraphWrapperSkeleton<GraphWrapper>::Node Node; |
---|
| 515 | typedef typename GraphWrapperSkeleton<GraphWrapper>::NodeIt NodeIt; |
---|
[158] | 516 | |
---|
| 517 | //private: |
---|
[238] | 518 | typedef typename GraphWrapperSkeleton<GraphWrapper>::Edge GraphEdge; |
---|
| 519 | typedef typename GraphWrapperSkeleton<GraphWrapper>::OutEdgeIt GraphOutEdgeIt; |
---|
| 520 | typedef typename GraphWrapperSkeleton<GraphWrapper>::InEdgeIt GraphInEdgeIt; |
---|
[158] | 521 | //public: |
---|
| 522 | |
---|
[168] | 523 | //UndirGraphWrapper() : graph(0) { } |
---|
[238] | 524 | UndirGraphWrapper(GraphWrapper _gw) : |
---|
| 525 | GraphWrapperSkeleton<GraphWrapper>(_gw) { } |
---|
| 526 | |
---|
| 527 | //UndirGraphWrapper(GraphWrapper _gw) : gw(_gw) { } |
---|
[168] | 528 | |
---|
[236] | 529 | //void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 530 | //Graph& getGraph() const { return (*graph); } |
---|
[168] | 531 | |
---|
[174] | 532 | class Edge { |
---|
[236] | 533 | friend class UndirGraphWrapper<GraphWrapper>; |
---|
[158] | 534 | bool out_or_in; //true iff out |
---|
| 535 | GraphOutEdgeIt out; |
---|
| 536 | GraphInEdgeIt in; |
---|
| 537 | public: |
---|
[174] | 538 | Edge() : out_or_in(), out(), in() { } |
---|
| 539 | Edge(const Invalid& i) : out_or_in(false), out(), in(i) { } |
---|
| 540 | operator GraphEdge() const { |
---|
[158] | 541 | if (out_or_in) return(out); else return(in); |
---|
| 542 | } |
---|
[239] | 543 | //FIXME |
---|
| 544 | //2 edges are equal if they "refer" to the same physical edge |
---|
| 545 | //is it good? |
---|
[174] | 546 | friend bool operator==(const Edge& u, const Edge& v) { |
---|
| 547 | if (v.out_or_in) |
---|
[239] | 548 | if (u.out_or_in) return (u.out==v.out); else return (u.out==v.in); |
---|
| 549 | //return (u.out_or_in && u.out==v.out); |
---|
[174] | 550 | else |
---|
[239] | 551 | if (u.out_or_in) return (u.out==v.in); else return (u.in==v.in); |
---|
| 552 | //return (!u.out_or_in && u.in==v.in); |
---|
[174] | 553 | } |
---|
| 554 | friend bool operator!=(const Edge& u, const Edge& v) { |
---|
| 555 | if (v.out_or_in) |
---|
[239] | 556 | if (u.out_or_in) return (u.out!=v.out); else return (u.out!=v.in); |
---|
| 557 | //return (!u.out_or_in || u.out!=v.out); |
---|
[174] | 558 | else |
---|
[239] | 559 | if (u.out_or_in) return (u.out!=v.in); else return (u.in!=v.in); |
---|
| 560 | //return (u.out_or_in || u.in!=v.in); |
---|
[174] | 561 | } |
---|
[158] | 562 | }; |
---|
| 563 | |
---|
[174] | 564 | class OutEdgeIt : public Edge { |
---|
[236] | 565 | friend class UndirGraphWrapper<GraphWrapper>; |
---|
[158] | 566 | public: |
---|
[174] | 567 | OutEdgeIt() : Edge() { } |
---|
| 568 | OutEdgeIt(const Invalid& i) : Edge(i) { } |
---|
[236] | 569 | OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) |
---|
| 570 | : Edge() { |
---|
[239] | 571 | out_or_in=true; _G.gw.first(out, n); |
---|
| 572 | if (!(_G.gw.valid(out))) { out_or_in=false; _G.gw.first(in, n); } |
---|
[158] | 573 | } |
---|
| 574 | }; |
---|
| 575 | |
---|
[238] | 576 | typedef OutEdgeIt InEdgeIt; |
---|
| 577 | |
---|
| 578 | class EdgeIt : public Edge { |
---|
| 579 | friend class UndirGraphWrapper<GraphWrapper>; |
---|
| 580 | protected: |
---|
| 581 | NodeIt v; |
---|
| 582 | public: |
---|
| 583 | EdgeIt() : Edge() { } |
---|
| 584 | EdgeIt(const Invalid& i) : Edge(i) { } |
---|
| 585 | EdgeIt(const UndirGraphWrapper<GraphWrapper>& _G) |
---|
| 586 | : Edge() { |
---|
| 587 | out_or_in=true; |
---|
| 588 | //Node v; |
---|
| 589 | _G.first(v); |
---|
| 590 | if (_G.valid(v)) _G.gw.first(out); else out=INVALID; |
---|
| 591 | while (_G.valid(v) && !_G.gw.valid(out)) { |
---|
| 592 | _G.gw.next(v); |
---|
| 593 | if (_G.valid(v)) _G.gw.first(out); |
---|
| 594 | } |
---|
| 595 | } |
---|
| 596 | }; |
---|
| 597 | |
---|
[212] | 598 | OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { |
---|
[239] | 599 | e.out_or_in=true; gw.first(e.out, n); |
---|
| 600 | if (!(gw.valid(e.out))) { e.out_or_in=false; gw.first(e.in, n); } |
---|
[158] | 601 | return e; |
---|
| 602 | } |
---|
| 603 | |
---|
[238] | 604 | EdgeIt& first(EdgeIt& e) const { |
---|
| 605 | e.out_or_in=true; |
---|
| 606 | //NodeIt v; |
---|
| 607 | first(e.v); |
---|
| 608 | if (valid(e.v)) gw.first(e.out, e.v); else e.out=INVALID; |
---|
| 609 | while (valid(e.v) && !gw.valid(e.out)) { |
---|
| 610 | gw.next(e.v); |
---|
| 611 | if (valid(e.v)) gw.first(e.out, e.v); |
---|
| 612 | } |
---|
| 613 | return e; |
---|
| 614 | } |
---|
| 615 | |
---|
| 616 | template<typename I> I& first(I& i) const { return gw.first(i); } |
---|
| 617 | template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 618 | return graph->first(i, p); } |
---|
| 619 | |
---|
[158] | 620 | OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 621 | if (e.out_or_in) { |
---|
[236] | 622 | Node n=gw.tail(e.out); |
---|
| 623 | gw.next(e.out); |
---|
[239] | 624 | if (!gw.valid(e.out)) { e.out_or_in=false; gw.first(e.in, n); } |
---|
[158] | 625 | } else { |
---|
[236] | 626 | gw.next(e.in); |
---|
[158] | 627 | } |
---|
| 628 | return e; |
---|
| 629 | } |
---|
| 630 | |
---|
[238] | 631 | EdgeIt& next(EdgeIt& e) const { |
---|
| 632 | //NodeIt v=tail(e); |
---|
| 633 | gw.next(e.out); |
---|
| 634 | while (valid(e.v) && !gw.valid(e.out)) { |
---|
| 635 | next(e.v); |
---|
| 636 | if (valid(e.v)) gw.first(e.out, e.v); |
---|
| 637 | } |
---|
| 638 | return e; |
---|
| 639 | } |
---|
[158] | 640 | |
---|
[238] | 641 | template<typename I> I& next(I &i) const { return gw.next(i); } |
---|
[239] | 642 | template<typename I> I getNext(const I& i) const { return gw.getNext(i); } |
---|
[158] | 643 | |
---|
| 644 | template< typename It > It first() const { |
---|
[212] | 645 | It e; first(e); return e; } |
---|
[158] | 646 | |
---|
[174] | 647 | template< typename It > It first(const Node& v) const { |
---|
[212] | 648 | It e; first(e, v); return e; } |
---|
[158] | 649 | |
---|
[238] | 650 | // Node head(const Edge& e) const { return gw.head(e); } |
---|
| 651 | // Node tail(const Edge& e) const { return gw.tail(e); } |
---|
[158] | 652 | |
---|
[238] | 653 | // template<typename I> bool valid(const I& i) const |
---|
| 654 | // { return gw.valid(i); } |
---|
[158] | 655 | |
---|
[238] | 656 | // int nodeNum() const { return gw.nodeNum(); } |
---|
| 657 | // int edgeNum() const { return gw.edgeNum(); } |
---|
[158] | 658 | |
---|
[174] | 659 | // template<typename I> Node aNode(const I& e) const { |
---|
[158] | 660 | // return graph->aNode(e); } |
---|
[174] | 661 | // template<typename I> Node bNode(const I& e) const { |
---|
[158] | 662 | // return graph->bNode(e); } |
---|
[238] | 663 | |
---|
| 664 | Node aNode(const OutEdgeIt& e) const { |
---|
| 665 | if (e.out_or_in) return gw.tail(e); else return gw.head(e); } |
---|
| 666 | Node bNode(const OutEdgeIt& e) const { |
---|
| 667 | if (e.out_or_in) return gw.head(e); else return gw.tail(e); } |
---|
[158] | 668 | |
---|
[238] | 669 | // Node addNode() const { return gw.addNode(); } |
---|
| 670 | |
---|
[231] | 671 | // FIXME: ez igy nem jo, mert nem |
---|
| 672 | // Edge addEdge(const Node& tail, const Node& head) const { |
---|
| 673 | // return graph->addEdge(tail, head); } |
---|
[158] | 674 | |
---|
[238] | 675 | // template<typename I> void erase(const I& i) const { gw.erase(i); } |
---|
[158] | 676 | |
---|
[238] | 677 | // void clear() const { gw.clear(); } |
---|
[158] | 678 | |
---|
[238] | 679 | // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { |
---|
| 680 | // public: |
---|
| 681 | // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : |
---|
| 682 | // GraphWrapper::NodeMap<T>(_G.gw) { } |
---|
| 683 | // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : |
---|
| 684 | // GraphWrapper::NodeMap<T>(_G.gw, a) { } |
---|
| 685 | // }; |
---|
[168] | 686 | |
---|
[238] | 687 | // template<typename T> class EdgeMap : |
---|
| 688 | // public GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T> { |
---|
| 689 | // public: |
---|
| 690 | // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : |
---|
| 691 | // GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T>(_G.gw) { } |
---|
| 692 | // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : |
---|
| 693 | // GraphWrapper::EdgeMap<T>(_G.gw, a) { } |
---|
| 694 | // }; |
---|
| 695 | }; |
---|
[158] | 696 | |
---|
| 697 | |
---|
| 698 | |
---|
[236] | 699 | |
---|
| 700 | |
---|
[155] | 701 | // template<typename Graph> |
---|
| 702 | // class SymGraphWrapper |
---|
| 703 | // { |
---|
| 704 | // Graph* graph; |
---|
[76] | 705 | |
---|
[155] | 706 | // public: |
---|
| 707 | // typedef Graph BaseGraph; |
---|
| 708 | |
---|
[174] | 709 | // typedef typename Graph::Node Node; |
---|
| 710 | // typedef typename Graph::Edge Edge; |
---|
| 711 | |
---|
[155] | 712 | // typedef typename Graph::NodeIt NodeIt; |
---|
| 713 | |
---|
| 714 | // //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon |
---|
| 715 | // //iranyitatlant, ami van |
---|
| 716 | // //mert csak 1 dolgot lehet be typedef-elni |
---|
| 717 | // typedef typename Graph::OutEdgeIt SymEdgeIt; |
---|
| 718 | // //typedef typename Graph::InEdgeIt SymEdgeIt; |
---|
| 719 | // //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 720 | // typedef typename Graph::EdgeIt EdgeIt; |
---|
[155] | 721 | |
---|
| 722 | // int nodeNum() const { return graph->nodeNum(); } |
---|
| 723 | // int edgeNum() const { return graph->edgeNum(); } |
---|
| 724 | |
---|
[212] | 725 | // template<typename I> I& first(I& i) const { return graph->first(i); } |
---|
| 726 | // template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 727 | // return graph->first(i, p); } |
---|
[155] | 728 | // //template<typename I> I next(const I i); { return graph->goNext(i); } |
---|
| 729 | // //template<typename I> I &goNext(I &i); { return graph->goNext(i); } |
---|
| 730 | |
---|
| 731 | // template< typename It > It first() const { |
---|
[212] | 732 | // It e; first(e); return e; } |
---|
[155] | 733 | |
---|
[174] | 734 | // template< typename It > It first(Node v) const { |
---|
[212] | 735 | // It e; first(e, v); return e; } |
---|
[155] | 736 | |
---|
[174] | 737 | // Node head(const Edge& e) const { return graph->head(e); } |
---|
| 738 | // Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[155] | 739 | |
---|
[174] | 740 | // template<typename I> Node aNode(const I& e) const { |
---|
[155] | 741 | // return graph->aNode(e); } |
---|
[174] | 742 | // template<typename I> Node bNode(const I& e) const { |
---|
[155] | 743 | // return graph->bNode(e); } |
---|
| 744 | |
---|
| 745 | // //template<typename I> bool valid(const I i); |
---|
| 746 | // //{ return graph->valid(i); } |
---|
| 747 | |
---|
| 748 | // //template<typename I> void setInvalid(const I &i); |
---|
| 749 | // //{ return graph->setInvalid(i); } |
---|
| 750 | |
---|
[174] | 751 | // Node addNode() { return graph->addNode(); } |
---|
| 752 | // Edge addEdge(const Node& tail, const Node& head) { |
---|
[155] | 753 | // return graph->addEdge(tail, head); } |
---|
| 754 | |
---|
| 755 | // template<typename I> void erase(const I& i) { graph->erase(i); } |
---|
| 756 | |
---|
| 757 | // void clear() { graph->clear(); } |
---|
| 758 | |
---|
| 759 | // template<typename T> class NodeMap : public Graph::NodeMap<T> { }; |
---|
| 760 | // template<typename T> class EdgeMap : public Graph::EdgeMap<T> { }; |
---|
| 761 | |
---|
| 762 | // void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 763 | // Graph& getGraph() { return (*graph); } |
---|
| 764 | |
---|
| 765 | // //SymGraphWrapper() : graph(0) { } |
---|
| 766 | // SymGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 767 | // }; |
---|
| 768 | |
---|
| 769 | |
---|
| 770 | template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
---|
| 771 | class ResGraphWrapper { |
---|
[76] | 772 | public: |
---|
[259] | 773 | //typedef Graph BaseGraph; |
---|
[174] | 774 | typedef typename Graph::Node Node; |
---|
[155] | 775 | typedef typename Graph::NodeIt NodeIt; |
---|
| 776 | private: |
---|
| 777 | typedef typename Graph::OutEdgeIt OldOutEdgeIt; |
---|
| 778 | typedef typename Graph::InEdgeIt OldInEdgeIt; |
---|
[199] | 779 | protected: |
---|
[259] | 780 | //const Graph* graph; |
---|
| 781 | typedef TrivGraphWrapper<const Graph> GraphWrapper; |
---|
| 782 | GraphWrapper gw; |
---|
[155] | 783 | FlowMap* flow; |
---|
| 784 | const CapacityMap* capacity; |
---|
| 785 | public: |
---|
[168] | 786 | |
---|
[155] | 787 | ResGraphWrapper(const Graph& _G, FlowMap& _flow, |
---|
| 788 | const CapacityMap& _capacity) : |
---|
[259] | 789 | gw(_G), flow(&_flow), capacity(&_capacity) { } |
---|
[168] | 790 | |
---|
[259] | 791 | //void setGraph(const Graph& _graph) { graph = &_graph; } |
---|
| 792 | //const Graph& getGraph() const { return (*graph); } |
---|
[168] | 793 | |
---|
[174] | 794 | class Edge; |
---|
[155] | 795 | class OutEdgeIt; |
---|
[174] | 796 | friend class Edge; |
---|
[155] | 797 | friend class OutEdgeIt; |
---|
[76] | 798 | |
---|
[174] | 799 | class Edge { |
---|
[155] | 800 | friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; |
---|
| 801 | protected: |
---|
[168] | 802 | bool out_or_in; //true, iff out |
---|
[155] | 803 | OldOutEdgeIt out; |
---|
| 804 | OldInEdgeIt in; |
---|
| 805 | public: |
---|
[174] | 806 | Edge() : out_or_in(true) { } |
---|
| 807 | Edge(const Invalid& i) : out_or_in(false), out(), in(i) { } |
---|
[168] | 808 | // bool valid() const { |
---|
| 809 | // return out_or_in && out.valid() || in.valid(); } |
---|
[174] | 810 | friend bool operator==(const Edge& u, const Edge& v) { |
---|
| 811 | if (v.out_or_in) |
---|
| 812 | return (u.out_or_in && u.out==v.out); |
---|
| 813 | else |
---|
| 814 | return (!u.out_or_in && u.in==v.in); |
---|
| 815 | } |
---|
| 816 | friend bool operator!=(const Edge& u, const Edge& v) { |
---|
| 817 | if (v.out_or_in) |
---|
| 818 | return (!u.out_or_in || u.out!=v.out); |
---|
| 819 | else |
---|
| 820 | return (u.out_or_in || u.in!=v.in); |
---|
| 821 | } |
---|
[155] | 822 | }; |
---|
| 823 | |
---|
| 824 | |
---|
[174] | 825 | class OutEdgeIt : public Edge { |
---|
[155] | 826 | friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; |
---|
| 827 | public: |
---|
| 828 | OutEdgeIt() { } |
---|
[168] | 829 | //FIXME |
---|
[174] | 830 | OutEdgeIt(const Edge& e) : Edge(e) { } |
---|
| 831 | OutEdgeIt(const Invalid& i) : Edge(i) { } |
---|
[155] | 832 | private: |
---|
[174] | 833 | OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { |
---|
[259] | 834 | resG.gw.first(out, v); |
---|
| 835 | while( resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); } |
---|
| 836 | if (!resG.gw.valid(out)) { |
---|
[155] | 837 | out_or_in=0; |
---|
[259] | 838 | resG.gw.first(in, v); |
---|
| 839 | while( resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); } |
---|
[155] | 840 | } |
---|
| 841 | } |
---|
[168] | 842 | // public: |
---|
| 843 | // OutEdgeIt& operator++() { |
---|
| 844 | // if (out_or_in) { |
---|
[174] | 845 | // Node v=/*resG->*/G->aNode(out); |
---|
[168] | 846 | // ++out; |
---|
[174] | 847 | // while( out.valid() && !(Edge::free()>0) ) { ++out; } |
---|
[168] | 848 | // if (!out.valid()) { |
---|
| 849 | // out_or_in=0; |
---|
[212] | 850 | // G->first(in, v); |
---|
[174] | 851 | // while( in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 852 | // } |
---|
| 853 | // } else { |
---|
| 854 | // ++in; |
---|
[174] | 855 | // while( in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 856 | // } |
---|
| 857 | // return *this; |
---|
| 858 | // } |
---|
[155] | 859 | }; |
---|
| 860 | |
---|
[174] | 861 | class EdgeIt : public Edge { |
---|
[155] | 862 | friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; |
---|
[174] | 863 | typename Graph::NodeIt v; |
---|
[155] | 864 | public: |
---|
[174] | 865 | EdgeIt() { } |
---|
| 866 | //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { } |
---|
| 867 | EdgeIt(const Invalid& i) : Edge(i) { } |
---|
| 868 | EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() { |
---|
[259] | 869 | resG.gw.first(v); |
---|
| 870 | if (resG.gw.valid(v)) resG.gw.first(out, v); else out=/*OldOutEdgeIt*/(INVALID); |
---|
| 871 | while (resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); } |
---|
| 872 | while (resG.gw.valid(v) && !resG.gw.valid(out)) { |
---|
| 873 | resG.gw.next(v); |
---|
| 874 | if (resG.gw.valid(v)) resG.gw.first(out, v); |
---|
| 875 | while (resG.gw.valid(out) && !(resG.free(out)>0) ) { resG.gw.next(out); } |
---|
[155] | 876 | } |
---|
[259] | 877 | if (!resG.gw.valid(out)) { |
---|
[155] | 878 | out_or_in=0; |
---|
[259] | 879 | resG.gw.first(v); |
---|
| 880 | if (resG.gw.valid(v)) resG.gw.first(in, v); else in=/*OldInEdgeIt*/(INVALID); |
---|
| 881 | while (resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); } |
---|
| 882 | while (resG.gw.valid(v) && !resG.gw.valid(in)) { |
---|
| 883 | resG.gw.next(v); |
---|
| 884 | if (resG.gw.valid(v)) resG.gw.first(in, v); |
---|
| 885 | while (resG.gw.valid(in) && !(resG.free(in)>0) ) { resG.gw.next(in); } |
---|
[155] | 886 | } |
---|
| 887 | } |
---|
| 888 | } |
---|
[174] | 889 | // EdgeIt& operator++() { |
---|
[168] | 890 | // if (out_or_in) { |
---|
| 891 | // ++out; |
---|
[174] | 892 | // while (out.valid() && !(Edge::free()>0) ) { ++out; } |
---|
[168] | 893 | // while (v.valid() && !out.valid()) { |
---|
| 894 | // ++v; |
---|
[212] | 895 | // if (v.valid()) G->first(out, v); |
---|
[174] | 896 | // while (out.valid() && !(Edge::free()>0) ) { ++out; } |
---|
[168] | 897 | // } |
---|
| 898 | // if (!out.valid()) { |
---|
| 899 | // out_or_in=0; |
---|
[212] | 900 | // G->first(v); |
---|
| 901 | // if (v.valid()) G->first(in, v); else in=OldInEdgeIt(); |
---|
[174] | 902 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 903 | // while (v.valid() && !in.valid()) { |
---|
| 904 | // ++v; |
---|
[212] | 905 | // if (v.valid()) G->first(in, v); |
---|
[174] | 906 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 907 | // } |
---|
| 908 | // } |
---|
| 909 | // } else { |
---|
| 910 | // ++in; |
---|
[174] | 911 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 912 | // while (v.valid() && !in.valid()) { |
---|
| 913 | // ++v; |
---|
[212] | 914 | // if (v.valid()) G->first(in, v); |
---|
[174] | 915 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 916 | // } |
---|
| 917 | // } |
---|
| 918 | // return *this; |
---|
| 919 | // } |
---|
[155] | 920 | }; |
---|
| 921 | |
---|
[259] | 922 | NodeIt& first(NodeIt& v) const { return gw.first(v); } |
---|
[212] | 923 | OutEdgeIt& first(OutEdgeIt& e, Node v) const { |
---|
[168] | 924 | e=OutEdgeIt(*this, v); |
---|
[174] | 925 | return e; |
---|
[155] | 926 | } |
---|
[212] | 927 | EdgeIt& first(EdgeIt& e) const { |
---|
[174] | 928 | e=EdgeIt(*this); |
---|
| 929 | return e; |
---|
[155] | 930 | } |
---|
| 931 | |
---|
[259] | 932 | NodeIt& next(NodeIt& n) const { return gw.next(n); } |
---|
[155] | 933 | |
---|
| 934 | OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 935 | if (e.out_or_in) { |
---|
[259] | 936 | Node v=gw.aNode(e.out); |
---|
| 937 | gw.next(e.out); |
---|
| 938 | while( gw.valid(e.out) && !(free(e.out)>0) ) { gw.next(e.out); } |
---|
| 939 | if (!gw.valid(e.out)) { |
---|
[155] | 940 | e.out_or_in=0; |
---|
[259] | 941 | gw.first(e.in, v); |
---|
| 942 | while( gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
---|
[155] | 943 | } |
---|
| 944 | } else { |
---|
[259] | 945 | gw.next(e.in); |
---|
| 946 | while( gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
---|
[155] | 947 | } |
---|
| 948 | return e; |
---|
| 949 | } |
---|
| 950 | |
---|
[174] | 951 | EdgeIt& next(EdgeIt& e) const { |
---|
[155] | 952 | if (e.out_or_in) { |
---|
[259] | 953 | gw.next(e.out); |
---|
| 954 | while (gw.valid(e.out) && !(free(e.out)>0) ) { gw.next(e.out); } |
---|
| 955 | while (gw.valid(e.v) && !gw.valid(e.out)) { |
---|
| 956 | gw.next(e.v); |
---|
| 957 | if (gw.valid(e.v)) gw.first(e.out, e.v); |
---|
| 958 | while (gw.valid(e.out) && !(free(e.out)>0) ) { gw.next(e.out); } |
---|
[155] | 959 | } |
---|
[259] | 960 | if (!gw.valid(e.out)) { |
---|
[155] | 961 | e.out_or_in=0; |
---|
[259] | 962 | gw.first(e.v); |
---|
| 963 | if (gw.valid(e.v)) gw.first(e.in, e.v); else e.in=/*OldInEdgeIt*/(INVALID); |
---|
| 964 | while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
---|
| 965 | while (gw.valid(e.v) && !gw.valid(e.in)) { |
---|
| 966 | gw.next(e.v); |
---|
| 967 | if (gw.valid(e.v)) gw.first(e.in, e.v); |
---|
| 968 | while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
---|
[155] | 969 | } |
---|
| 970 | } |
---|
| 971 | } else { |
---|
[259] | 972 | gw.next(e.in); |
---|
| 973 | while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
---|
| 974 | while (gw.valid(e.v) && !gw.valid(e.in)) { |
---|
| 975 | gw.next(e.v); |
---|
| 976 | if (gw.valid(e.v)) gw.first(e.in, e.v); |
---|
| 977 | while (gw.valid(e.in) && !(free(e.in)>0) ) { gw.next(e.in); } |
---|
[155] | 978 | } |
---|
| 979 | } |
---|
| 980 | return e; |
---|
| 981 | } |
---|
[76] | 982 | |
---|
| 983 | |
---|
[155] | 984 | template< typename It > |
---|
| 985 | It first() const { |
---|
| 986 | It e; |
---|
[212] | 987 | first(e); |
---|
[155] | 988 | return e; |
---|
| 989 | } |
---|
[76] | 990 | |
---|
[155] | 991 | template< typename It > |
---|
[174] | 992 | It first(Node v) const { |
---|
[155] | 993 | It e; |
---|
[212] | 994 | first(e, v); |
---|
[155] | 995 | return e; |
---|
| 996 | } |
---|
[76] | 997 | |
---|
[174] | 998 | Node tail(Edge e) const { |
---|
[259] | 999 | return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); } |
---|
[174] | 1000 | Node head(Edge e) const { |
---|
[259] | 1001 | return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); } |
---|
[76] | 1002 | |
---|
[174] | 1003 | Node aNode(OutEdgeIt e) const { |
---|
[259] | 1004 | return ((e.out_or_in) ? gw.aNode(e.out) : gw.aNode(e.in)); } |
---|
[174] | 1005 | Node bNode(OutEdgeIt e) const { |
---|
[259] | 1006 | return ((e.out_or_in) ? gw.bNode(e.out) : gw.bNode(e.in)); } |
---|
[76] | 1007 | |
---|
[259] | 1008 | int id(Node v) const { return gw.id(v); } |
---|
[155] | 1009 | |
---|
[259] | 1010 | bool valid(Node n) const { return gw.valid(n); } |
---|
[174] | 1011 | bool valid(Edge e) const { |
---|
[259] | 1012 | return e.out_or_in ? gw.valid(e.out) : gw.valid(e.in); } |
---|
[155] | 1013 | |
---|
[174] | 1014 | void augment(const Edge& e, Number a) const { |
---|
[168] | 1015 | if (e.out_or_in) |
---|
| 1016 | flow->set(e.out, flow->get(e.out)+a); |
---|
| 1017 | else |
---|
| 1018 | flow->set(e.in, flow->get(e.in)-a); |
---|
| 1019 | } |
---|
| 1020 | |
---|
[174] | 1021 | Number free(const Edge& e) const { |
---|
[168] | 1022 | if (e.out_or_in) |
---|
| 1023 | return (capacity->get(e.out)-flow->get(e.out)); |
---|
| 1024 | else |
---|
| 1025 | return (flow->get(e.in)); |
---|
| 1026 | } |
---|
| 1027 | |
---|
| 1028 | Number free(OldOutEdgeIt out) const { |
---|
| 1029 | return (capacity->get(out)-flow->get(out)); |
---|
| 1030 | } |
---|
| 1031 | |
---|
| 1032 | Number free(OldInEdgeIt in) const { |
---|
| 1033 | return (flow->get(in)); |
---|
| 1034 | } |
---|
| 1035 | |
---|
[259] | 1036 | template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { |
---|
[155] | 1037 | public: |
---|
| 1038 | NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) |
---|
[259] | 1039 | : GraphWrapper::NodeMap<T>(_G.gw) { } |
---|
[155] | 1040 | NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, |
---|
[259] | 1041 | T a) : GraphWrapper::NodeMap<T>(_G.gw, a) { } |
---|
[155] | 1042 | }; |
---|
| 1043 | |
---|
| 1044 | // template <typename T> |
---|
| 1045 | // class NodeMap { |
---|
| 1046 | // typename Graph::NodeMap<T> node_map; |
---|
| 1047 | // public: |
---|
[174] | 1048 | // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { } |
---|
| 1049 | // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { } |
---|
| 1050 | // void set(Node nit, T a) { node_map.set(nit, a); } |
---|
| 1051 | // T get(Node nit) const { return node_map.get(nit); } |
---|
[155] | 1052 | // }; |
---|
| 1053 | |
---|
| 1054 | template <typename T> |
---|
| 1055 | class EdgeMap { |
---|
[259] | 1056 | typename GraphWrapper::EdgeMap<T> forward_map, backward_map; |
---|
[155] | 1057 | public: |
---|
[259] | 1058 | EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.gw), backward_map(_G.gw) { } |
---|
| 1059 | EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.gw, a), backward_map(_G.gw, a) { } |
---|
[174] | 1060 | void set(Edge e, T a) { |
---|
[155] | 1061 | if (e.out_or_in) |
---|
| 1062 | forward_map.set(e.out, a); |
---|
| 1063 | else |
---|
| 1064 | backward_map.set(e.in, a); |
---|
| 1065 | } |
---|
[174] | 1066 | T get(Edge e) { |
---|
[155] | 1067 | if (e.out_or_in) |
---|
| 1068 | return forward_map.get(e.out); |
---|
| 1069 | else |
---|
| 1070 | return backward_map.get(e.in); |
---|
| 1071 | } |
---|
| 1072 | }; |
---|
[168] | 1073 | }; |
---|
| 1074 | |
---|
| 1075 | template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
---|
| 1076 | class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> { |
---|
| 1077 | protected: |
---|
| 1078 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges; |
---|
| 1079 | //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist; |
---|
| 1080 | public: |
---|
| 1081 | ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow, |
---|
| 1082 | const CapacityMap& _capacity) : |
---|
| 1083 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), |
---|
| 1084 | first_out_edges(*this) /*, dist(*this)*/ { |
---|
[174] | 1085 | for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) { |
---|
[168] | 1086 | OutEdgeIt e; |
---|
[212] | 1087 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n); |
---|
[168] | 1088 | first_out_edges.set(n, e); |
---|
| 1089 | } |
---|
| 1090 | } |
---|
| 1091 | |
---|
| 1092 | //void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 1093 | //Graph& getGraph() const { return (*graph); } |
---|
| 1094 | |
---|
| 1095 | //TrivGraphWrapper() : graph(0) { } |
---|
| 1096 | //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 1097 | |
---|
| 1098 | //typedef Graph BaseGraph; |
---|
| 1099 | |
---|
[174] | 1100 | //typedef typename Graph::Node Node; |
---|
[168] | 1101 | //typedef typename Graph::NodeIt NodeIt; |
---|
| 1102 | |
---|
[174] | 1103 | //typedef typename Graph::Edge Edge; |
---|
[168] | 1104 | //typedef typename Graph::OutEdgeIt OutEdgeIt; |
---|
| 1105 | //typedef typename Graph::InEdgeIt InEdgeIt; |
---|
| 1106 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 1107 | //typedef typename Graph::EdgeIt EdgeIt; |
---|
[168] | 1108 | |
---|
[174] | 1109 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node; |
---|
[168] | 1110 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt; |
---|
| 1111 | |
---|
[174] | 1112 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge; |
---|
[168] | 1113 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt; |
---|
| 1114 | //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt; |
---|
| 1115 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 1116 | //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt; |
---|
[168] | 1117 | |
---|
[212] | 1118 | NodeIt& first(NodeIt& n) const { |
---|
| 1119 | return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n); |
---|
[168] | 1120 | } |
---|
| 1121 | |
---|
[212] | 1122 | OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { |
---|
[168] | 1123 | e=first_out_edges.get(n); |
---|
| 1124 | return e; |
---|
| 1125 | } |
---|
| 1126 | |
---|
[212] | 1127 | //ROSSZ template<typename I> I& first(I& i) const { return first(i); } |
---|
| 1128 | //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 1129 | // return first(i, p); } |
---|
[168] | 1130 | |
---|
| 1131 | //template<typename I> I getNext(const I& i) const { |
---|
[259] | 1132 | // return gw.getNext(i); } |
---|
| 1133 | //template<typename I> I& next(I &i) const { return gw.next(i); } |
---|
[168] | 1134 | |
---|
| 1135 | template< typename It > It first() const { |
---|
[212] | 1136 | It e; first(e); return e; } |
---|
[168] | 1137 | |
---|
[174] | 1138 | template< typename It > It first(const Node& v) const { |
---|
[212] | 1139 | It e; first(e, v); return e; } |
---|
[168] | 1140 | |
---|
[259] | 1141 | //Node head(const Edge& e) const { return gw.head(e); } |
---|
| 1142 | //Node tail(const Edge& e) const { return gw.tail(e); } |
---|
[168] | 1143 | |
---|
| 1144 | //template<typename I> bool valid(const I& i) const |
---|
[259] | 1145 | // { return gw.valid(i); } |
---|
[168] | 1146 | |
---|
[259] | 1147 | //int nodeNum() const { return gw.nodeNum(); } |
---|
| 1148 | //int edgeNum() const { return gw.edgeNum(); } |
---|
[168] | 1149 | |
---|
[174] | 1150 | //template<typename I> Node aNode(const I& e) const { |
---|
[259] | 1151 | // return gw.aNode(e); } |
---|
[174] | 1152 | //template<typename I> Node bNode(const I& e) const { |
---|
[259] | 1153 | // return gw.bNode(e); } |
---|
[168] | 1154 | |
---|
[259] | 1155 | //Node addNode() const { return gw.addNode(); } |
---|
[174] | 1156 | //Edge addEdge(const Node& tail, const Node& head) const { |
---|
[259] | 1157 | // return gw.addEdge(tail, head); } |
---|
[168] | 1158 | |
---|
| 1159 | //void erase(const OutEdgeIt& e) { |
---|
| 1160 | // first_out_edge(this->tail(e))=e; |
---|
| 1161 | //} |
---|
[174] | 1162 | void erase(const Edge& e) { |
---|
[168] | 1163 | OutEdgeIt f(e); |
---|
| 1164 | next(f); |
---|
| 1165 | first_out_edges.set(this->tail(e), f); |
---|
| 1166 | } |
---|
[259] | 1167 | //template<typename I> void erase(const I& i) const { gw.erase(i); } |
---|
[168] | 1168 | |
---|
[259] | 1169 | //void clear() const { gw.clear(); } |
---|
[168] | 1170 | |
---|
| 1171 | template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { |
---|
| 1172 | public: |
---|
| 1173 | NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : |
---|
| 1174 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { } |
---|
| 1175 | NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : |
---|
| 1176 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { } |
---|
| 1177 | }; |
---|
| 1178 | |
---|
| 1179 | template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { |
---|
| 1180 | public: |
---|
| 1181 | EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : |
---|
| 1182 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { } |
---|
| 1183 | EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : |
---|
| 1184 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { } |
---|
| 1185 | }; |
---|
| 1186 | }; |
---|
| 1187 | |
---|
| 1188 | template<typename GraphWrapper> |
---|
| 1189 | class FilterGraphWrapper { |
---|
| 1190 | }; |
---|
| 1191 | |
---|
| 1192 | template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
---|
| 1193 | class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> { |
---|
| 1194 | |
---|
| 1195 | //Graph* graph; |
---|
| 1196 | |
---|
| 1197 | public: |
---|
| 1198 | //typedef Graph BaseGraph; |
---|
| 1199 | |
---|
[174] | 1200 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node; |
---|
[168] | 1201 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt; |
---|
| 1202 | |
---|
[174] | 1203 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge; |
---|
[168] | 1204 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt; |
---|
| 1205 | //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt; |
---|
| 1206 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 1207 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt; |
---|
[168] | 1208 | |
---|
| 1209 | //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges; |
---|
| 1210 | |
---|
| 1211 | public: |
---|
| 1212 | FilterGraphWrapper(const Graph& _G, FlowMap& _flow, |
---|
| 1213 | const CapacityMap& _capacity) : |
---|
[259] | 1214 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, gw.nodeNum()) { |
---|
[168] | 1215 | } |
---|
| 1216 | |
---|
[212] | 1217 | OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { |
---|
| 1218 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n); |
---|
[199] | 1219 | while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e)))) |
---|
[168] | 1220 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
| 1221 | return e; |
---|
| 1222 | } |
---|
| 1223 | |
---|
[174] | 1224 | NodeIt& next(NodeIt& e) const { |
---|
[168] | 1225 | return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
| 1226 | } |
---|
| 1227 | |
---|
| 1228 | OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 1229 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
[199] | 1230 | while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e)))) |
---|
[168] | 1231 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
| 1232 | return e; |
---|
| 1233 | } |
---|
| 1234 | |
---|
[212] | 1235 | NodeIt& first(NodeIt& n) const { |
---|
| 1236 | return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n); |
---|
[168] | 1237 | } |
---|
| 1238 | |
---|
[174] | 1239 | void erase(const Edge& e) { |
---|
[168] | 1240 | OutEdgeIt f(e); |
---|
| 1241 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f); |
---|
[199] | 1242 | while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f)))) |
---|
[168] | 1243 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f); |
---|
| 1244 | first_out_edges.set(this->tail(e), f); |
---|
| 1245 | } |
---|
| 1246 | |
---|
| 1247 | //TrivGraphWrapper() : graph(0) { } |
---|
| 1248 | //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 1249 | |
---|
| 1250 | //void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 1251 | //Graph& getGraph() const { return (*graph); } |
---|
| 1252 | |
---|
[259] | 1253 | //template<typename I> I& first(I& i) const { return gw.first(i); } |
---|
[212] | 1254 | //template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
[259] | 1255 | // return gw.first(i, p); } |
---|
[168] | 1256 | |
---|
| 1257 | //template<typename I> I getNext(const I& i) const { |
---|
[259] | 1258 | // return gw.getNext(i); } |
---|
| 1259 | //template<typename I> I& next(I &i) const { return gw.next(i); } |
---|
[168] | 1260 | |
---|
| 1261 | template< typename It > It first() const { |
---|
[212] | 1262 | It e; first(e); return e; } |
---|
[168] | 1263 | |
---|
[174] | 1264 | template< typename It > It first(const Node& v) const { |
---|
[212] | 1265 | It e; first(e, v); return e; } |
---|
[168] | 1266 | |
---|
[259] | 1267 | //Node head(const Edge& e) const { return gw.head(e); } |
---|
| 1268 | //Node tail(const Edge& e) const { return gw.tail(e); } |
---|
[168] | 1269 | |
---|
| 1270 | //template<typename I> bool valid(const I& i) const |
---|
[259] | 1271 | // { return gw.valid(i); } |
---|
[168] | 1272 | |
---|
| 1273 | //template<typename I> void setInvalid(const I &i); |
---|
[259] | 1274 | //{ return gw.setInvalid(i); } |
---|
[168] | 1275 | |
---|
[259] | 1276 | //int nodeNum() const { return gw.nodeNum(); } |
---|
| 1277 | //int edgeNum() const { return gw.edgeNum(); } |
---|
[168] | 1278 | |
---|
[174] | 1279 | //template<typename I> Node aNode(const I& e) const { |
---|
[259] | 1280 | // return gw.aNode(e); } |
---|
[174] | 1281 | //template<typename I> Node bNode(const I& e) const { |
---|
[259] | 1282 | // return gw.bNode(e); } |
---|
[168] | 1283 | |
---|
[259] | 1284 | //Node addNode() const { return gw.addNode(); } |
---|
[174] | 1285 | //Edge addEdge(const Node& tail, const Node& head) const { |
---|
[259] | 1286 | // return gw.addEdge(tail, head); } |
---|
[168] | 1287 | |
---|
[259] | 1288 | //template<typename I> void erase(const I& i) const { gw.erase(i); } |
---|
[168] | 1289 | |
---|
[259] | 1290 | //void clear() const { gw.clear(); } |
---|
[168] | 1291 | |
---|
| 1292 | template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { |
---|
| 1293 | public: |
---|
| 1294 | NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : |
---|
| 1295 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { } |
---|
| 1296 | NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : |
---|
| 1297 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { } |
---|
| 1298 | }; |
---|
| 1299 | |
---|
| 1300 | template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { |
---|
| 1301 | public: |
---|
| 1302 | EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : |
---|
| 1303 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { } |
---|
| 1304 | EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : |
---|
| 1305 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { } |
---|
| 1306 | }; |
---|
| 1307 | |
---|
| 1308 | public: |
---|
| 1309 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist; |
---|
[155] | 1310 | |
---|
[76] | 1311 | }; |
---|
| 1312 | |
---|
| 1313 | |
---|
[148] | 1314 | |
---|
| 1315 | // // FIXME: comparison should be made better!!! |
---|
| 1316 | // template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap> |
---|
| 1317 | // class ResGraphWrapper |
---|
| 1318 | // { |
---|
| 1319 | // Graph* graph; |
---|
[76] | 1320 | |
---|
[148] | 1321 | // public: |
---|
| 1322 | // typedef Graph BaseGraph; |
---|
[76] | 1323 | |
---|
[174] | 1324 | // typedef typename Graph::Node Node; |
---|
| 1325 | // typedef typename Graph::Edge Edge; |
---|
| 1326 | |
---|
[148] | 1327 | // typedef typename Graph::NodeIt NodeIt; |
---|
[76] | 1328 | |
---|
[148] | 1329 | // class OutEdgeIt { |
---|
| 1330 | // public: |
---|
[174] | 1331 | // //Graph::Node n; |
---|
[148] | 1332 | // bool out_or_in; |
---|
| 1333 | // typename Graph::OutEdgeIt o; |
---|
| 1334 | // typename Graph::InEdgeIt i; |
---|
| 1335 | // }; |
---|
| 1336 | // class InEdgeIt { |
---|
| 1337 | // public: |
---|
[174] | 1338 | // //Graph::Node n; |
---|
[148] | 1339 | // bool out_or_in; |
---|
| 1340 | // typename Graph::OutEdgeIt o; |
---|
| 1341 | // typename Graph::InEdgeIt i; |
---|
| 1342 | // }; |
---|
| 1343 | // typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 1344 | // typedef typename Graph::EdgeIt EdgeIt; |
---|
[76] | 1345 | |
---|
[259] | 1346 | // int nodeNum() const { return gw.nodeNum(); } |
---|
| 1347 | // int edgeNum() const { return gw.edgeNum(); } |
---|
[76] | 1348 | |
---|
[259] | 1349 | // Node& first(Node& n) const { return gw.first(n); } |
---|
[76] | 1350 | |
---|
[174] | 1351 | // // Edge and SymEdge is missing!!!! |
---|
| 1352 | // // Edge <-> In/OutEdgeIt conversion is missing!!!! |
---|
[76] | 1353 | |
---|
[148] | 1354 | // //FIXME |
---|
[212] | 1355 | // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const |
---|
[148] | 1356 | // { |
---|
| 1357 | // e.n=n; |
---|
[259] | 1358 | // gw.first(e.o,n); |
---|
| 1359 | // while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o)) |
---|
| 1360 | // gw.goNext(e.o); |
---|
| 1361 | // if(!gw.valid(e.o)) { |
---|
| 1362 | // gw.first(e.i,n); |
---|
| 1363 | // while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i)) |
---|
| 1364 | // gw.goNext(e.i); |
---|
[148] | 1365 | // } |
---|
| 1366 | // return e; |
---|
| 1367 | // } |
---|
| 1368 | // /* |
---|
| 1369 | // OutEdgeIt &goNext(OutEdgeIt &e) |
---|
| 1370 | // { |
---|
[259] | 1371 | // if(gw.valid(e.o)) { |
---|
| 1372 | // while(gw.valid(e.o) && fmap.get(e.o)>=himap.get(e.o)) |
---|
| 1373 | // gw.goNext(e.o); |
---|
| 1374 | // if(gw.valid(e.o)) return e; |
---|
| 1375 | // else gw.first(e.i,e.n); |
---|
[148] | 1376 | // } |
---|
| 1377 | // else { |
---|
[259] | 1378 | // while(gw.valid(e.i) && fmap.get(e.i)<=lomap.get(e.i)) |
---|
| 1379 | // gw.goNext(e.i); |
---|
[148] | 1380 | // return e; |
---|
| 1381 | // } |
---|
| 1382 | // } |
---|
| 1383 | // OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);} |
---|
| 1384 | // */ |
---|
[259] | 1385 | // //bool valid(const OutEdgeIt e) { return gw.valid(e.o)||gw.valid(e.i);} |
---|
[76] | 1386 | |
---|
[148] | 1387 | // //FIXME |
---|
[212] | 1388 | // InEdgeIt& first(InEdgeIt& e, const Node& n) const |
---|
[148] | 1389 | // { |
---|
| 1390 | // e.n=n; |
---|
[259] | 1391 | // gw.first(e.i,n); |
---|
| 1392 | // while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i)) |
---|
| 1393 | // gw.goNext(e.i); |
---|
| 1394 | // if(!gw.valid(e.i)) { |
---|
| 1395 | // gw.first(e.o,n); |
---|
| 1396 | // while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o)) |
---|
| 1397 | // gw.goNext(e.o); |
---|
[148] | 1398 | // } |
---|
| 1399 | // return e; |
---|
| 1400 | // } |
---|
| 1401 | // /* |
---|
| 1402 | // InEdgeIt &goNext(InEdgeIt &e) |
---|
| 1403 | // { |
---|
[259] | 1404 | // if(gw.valid(e.i)) { |
---|
| 1405 | // while(gw.valid(e.i) && fmap.get(e.i)>=himap.get(e.i)) |
---|
| 1406 | // gw.goNext(e.i); |
---|
| 1407 | // if(gw.valid(e.i)) return e; |
---|
| 1408 | // else gw.first(e.o,e.n); |
---|
[148] | 1409 | // } |
---|
| 1410 | // else { |
---|
[259] | 1411 | // while(gw.valid(e.o) && fmap.get(e.o)<=lomap.get(e.o)) |
---|
| 1412 | // gw.goNext(e.o); |
---|
[148] | 1413 | // return e; |
---|
| 1414 | // } |
---|
| 1415 | // } |
---|
| 1416 | // InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);} |
---|
| 1417 | // */ |
---|
[259] | 1418 | // //bool valid(const InEdgeIt e) { return gw.valid(e.i)||gw.valid(e.o);} |
---|
[76] | 1419 | |
---|
[259] | 1420 | // //template<typename I> I &goNext(I &i); { return gw.goNext(i); } |
---|
| 1421 | // //template<typename I> I next(const I i); { return gw.goNext(i); } |
---|
[76] | 1422 | |
---|
[148] | 1423 | // template< typename It > It first() const { |
---|
[212] | 1424 | // It e; first(e); return e; } |
---|
[76] | 1425 | |
---|
[174] | 1426 | // template< typename It > It first(Node v) const { |
---|
[212] | 1427 | // It e; first(e, v); return e; } |
---|
[76] | 1428 | |
---|
[259] | 1429 | // Node head(const Edge& e) const { return gw.head(e); } |
---|
| 1430 | // Node tail(const Edge& e) const { return gw.tail(e); } |
---|
[76] | 1431 | |
---|
[174] | 1432 | // template<typename I> Node aNode(const I& e) const { |
---|
[259] | 1433 | // return gw.aNode(e); } |
---|
[174] | 1434 | // template<typename I> Node bNode(const I& e) const { |
---|
[259] | 1435 | // return gw.bNode(e); } |
---|
[76] | 1436 | |
---|
[148] | 1437 | // //template<typename I> bool valid(const I i); |
---|
[259] | 1438 | // //{ return gw.valid(i); } |
---|
[76] | 1439 | |
---|
[148] | 1440 | // //template<typename I> void setInvalid(const I &i); |
---|
[259] | 1441 | // //{ return gw.setInvalid(i); } |
---|
[76] | 1442 | |
---|
[259] | 1443 | // Node addNode() { return gw.addNode(); } |
---|
[174] | 1444 | // Edge addEdge(const Node& tail, const Node& head) { |
---|
[259] | 1445 | // return gw.addEdge(tail, head); } |
---|
[76] | 1446 | |
---|
[259] | 1447 | // template<typename I> void erase(const I& i) { gw.erase(i); } |
---|
[76] | 1448 | |
---|
[259] | 1449 | // void clear() { gw.clear(); } |
---|
[76] | 1450 | |
---|
[148] | 1451 | // template<typename S> class NodeMap : public Graph::NodeMap<S> { }; |
---|
| 1452 | // template<typename S> class EdgeMap : public Graph::EdgeMap<S> { }; |
---|
[76] | 1453 | |
---|
[148] | 1454 | // void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 1455 | // Graph& getGraph() { return (*graph); } |
---|
[76] | 1456 | |
---|
[148] | 1457 | // //ResGraphWrapper() : graph(0) { } |
---|
| 1458 | // ResGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 1459 | // }; |
---|
[76] | 1460 | |
---|
[105] | 1461 | } //namespace hugo |
---|
[76] | 1462 | |
---|
[259] | 1463 | #endif //HUGO_GRAPH_WRAPPER_H |
---|
[76] | 1464 | |
---|