[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 | |
---|
[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 | } |
---|
[174] | 543 | friend bool operator==(const Edge& u, const Edge& v) { |
---|
| 544 | if (v.out_or_in) |
---|
| 545 | return (u.out_or_in && u.out==v.out); |
---|
| 546 | else |
---|
| 547 | return (!u.out_or_in && u.in==v.in); |
---|
| 548 | } |
---|
| 549 | friend bool operator!=(const Edge& u, const Edge& v) { |
---|
| 550 | if (v.out_or_in) |
---|
| 551 | return (!u.out_or_in || u.out!=v.out); |
---|
| 552 | else |
---|
| 553 | return (u.out_or_in || u.in!=v.in); |
---|
| 554 | } |
---|
[158] | 555 | }; |
---|
| 556 | |
---|
[174] | 557 | class OutEdgeIt : public Edge { |
---|
[236] | 558 | friend class UndirGraphWrapper<GraphWrapper>; |
---|
[158] | 559 | public: |
---|
[174] | 560 | OutEdgeIt() : Edge() { } |
---|
| 561 | OutEdgeIt(const Invalid& i) : Edge(i) { } |
---|
[236] | 562 | OutEdgeIt(const UndirGraphWrapper<GraphWrapper>& _G, const Node& n) |
---|
| 563 | : Edge() { |
---|
[174] | 564 | out_or_in=true; |
---|
[236] | 565 | _G.gw.first(out, n); |
---|
| 566 | if (!(_G.gw.valid(out))) { |
---|
[158] | 567 | out_or_in=false; |
---|
[236] | 568 | _G.gw.first(in, n); |
---|
[158] | 569 | } |
---|
| 570 | } |
---|
| 571 | }; |
---|
| 572 | |
---|
[238] | 573 | typedef OutEdgeIt InEdgeIt; |
---|
| 574 | |
---|
| 575 | class EdgeIt : public Edge { |
---|
| 576 | friend class UndirGraphWrapper<GraphWrapper>; |
---|
| 577 | protected: |
---|
| 578 | NodeIt v; |
---|
| 579 | public: |
---|
| 580 | EdgeIt() : Edge() { } |
---|
| 581 | EdgeIt(const Invalid& i) : Edge(i) { } |
---|
| 582 | EdgeIt(const UndirGraphWrapper<GraphWrapper>& _G) |
---|
| 583 | : Edge() { |
---|
| 584 | out_or_in=true; |
---|
| 585 | //Node v; |
---|
| 586 | _G.first(v); |
---|
| 587 | if (_G.valid(v)) _G.gw.first(out); else out=INVALID; |
---|
| 588 | while (_G.valid(v) && !_G.gw.valid(out)) { |
---|
| 589 | _G.gw.next(v); |
---|
| 590 | if (_G.valid(v)) _G.gw.first(out); |
---|
| 591 | } |
---|
| 592 | } |
---|
| 593 | }; |
---|
| 594 | |
---|
[212] | 595 | OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { |
---|
[158] | 596 | e.out_or_in=true; |
---|
[236] | 597 | gw.first(e.out, n); |
---|
| 598 | if (!(gw.valid(e.out))) { |
---|
[158] | 599 | e.out_or_in=false; |
---|
[236] | 600 | gw.first(e.in, n); |
---|
[158] | 601 | } |
---|
| 602 | return e; |
---|
| 603 | } |
---|
| 604 | |
---|
[238] | 605 | EdgeIt& first(EdgeIt& e) const { |
---|
| 606 | e.out_or_in=true; |
---|
| 607 | //NodeIt v; |
---|
| 608 | first(e.v); |
---|
| 609 | if (valid(e.v)) gw.first(e.out, e.v); else e.out=INVALID; |
---|
| 610 | while (valid(e.v) && !gw.valid(e.out)) { |
---|
| 611 | gw.next(e.v); |
---|
| 612 | if (valid(e.v)) gw.first(e.out, e.v); |
---|
| 613 | } |
---|
| 614 | return e; |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | template<typename I> I& first(I& i) const { return gw.first(i); } |
---|
| 618 | template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 619 | return graph->first(i, p); } |
---|
| 620 | |
---|
[158] | 621 | OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 622 | if (e.out_or_in) { |
---|
[236] | 623 | Node n=gw.tail(e.out); |
---|
| 624 | gw.next(e.out); |
---|
| 625 | if (!gw.valid(e.out)) { |
---|
[158] | 626 | e.out_or_in=false; |
---|
[236] | 627 | gw.first(e.in, n); |
---|
[158] | 628 | } |
---|
| 629 | } else { |
---|
[236] | 630 | gw.next(e.in); |
---|
[158] | 631 | } |
---|
| 632 | return e; |
---|
| 633 | } |
---|
| 634 | |
---|
[238] | 635 | EdgeIt& next(EdgeIt& e) const { |
---|
| 636 | //NodeIt v=tail(e); |
---|
| 637 | gw.next(e.out); |
---|
| 638 | while (valid(e.v) && !gw.valid(e.out)) { |
---|
| 639 | next(e.v); |
---|
| 640 | if (valid(e.v)) gw.first(e.out, e.v); |
---|
| 641 | } |
---|
| 642 | return e; |
---|
| 643 | } |
---|
[158] | 644 | |
---|
[238] | 645 | template<typename I> I& next(I &i) const { return gw.next(i); } |
---|
[158] | 646 | |
---|
| 647 | template<typename I> I getNext(const I& i) const { |
---|
[236] | 648 | return gw.getNext(i); } |
---|
[158] | 649 | |
---|
| 650 | template< typename It > It first() const { |
---|
[212] | 651 | It e; first(e); return e; } |
---|
[158] | 652 | |
---|
[174] | 653 | template< typename It > It first(const Node& v) const { |
---|
[212] | 654 | It e; first(e, v); return e; } |
---|
[158] | 655 | |
---|
[238] | 656 | // Node head(const Edge& e) const { return gw.head(e); } |
---|
| 657 | // Node tail(const Edge& e) const { return gw.tail(e); } |
---|
[158] | 658 | |
---|
[238] | 659 | // template<typename I> bool valid(const I& i) const |
---|
| 660 | // { return gw.valid(i); } |
---|
[158] | 661 | |
---|
[238] | 662 | // int nodeNum() const { return gw.nodeNum(); } |
---|
| 663 | // int edgeNum() const { return gw.edgeNum(); } |
---|
[158] | 664 | |
---|
[174] | 665 | // template<typename I> Node aNode(const I& e) const { |
---|
[158] | 666 | // return graph->aNode(e); } |
---|
[174] | 667 | // template<typename I> Node bNode(const I& e) const { |
---|
[158] | 668 | // return graph->bNode(e); } |
---|
[238] | 669 | |
---|
| 670 | Node aNode(const OutEdgeIt& e) const { |
---|
| 671 | if (e.out_or_in) return gw.tail(e); else return gw.head(e); } |
---|
| 672 | Node bNode(const OutEdgeIt& e) const { |
---|
| 673 | if (e.out_or_in) return gw.head(e); else return gw.tail(e); } |
---|
[158] | 674 | |
---|
[238] | 675 | // Node addNode() const { return gw.addNode(); } |
---|
| 676 | |
---|
[231] | 677 | // FIXME: ez igy nem jo, mert nem |
---|
| 678 | // Edge addEdge(const Node& tail, const Node& head) const { |
---|
| 679 | // return graph->addEdge(tail, head); } |
---|
[158] | 680 | |
---|
[238] | 681 | // template<typename I> void erase(const I& i) const { gw.erase(i); } |
---|
[158] | 682 | |
---|
[238] | 683 | // void clear() const { gw.clear(); } |
---|
[158] | 684 | |
---|
[238] | 685 | // template<typename T> class NodeMap : public GraphWrapper::NodeMap<T> { |
---|
| 686 | // public: |
---|
| 687 | // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G) : |
---|
| 688 | // GraphWrapper::NodeMap<T>(_G.gw) { } |
---|
| 689 | // NodeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : |
---|
| 690 | // GraphWrapper::NodeMap<T>(_G.gw, a) { } |
---|
| 691 | // }; |
---|
[168] | 692 | |
---|
[238] | 693 | // template<typename T> class EdgeMap : |
---|
| 694 | // public GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T> { |
---|
| 695 | // public: |
---|
| 696 | // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G) : |
---|
| 697 | // GraphWrapperSkeleton<GraphWrapper>::EdgeMap<T>(_G.gw) { } |
---|
| 698 | // EdgeMap(const UndirGraphWrapper<GraphWrapper>& _G, T a) : |
---|
| 699 | // GraphWrapper::EdgeMap<T>(_G.gw, a) { } |
---|
| 700 | // }; |
---|
| 701 | }; |
---|
[158] | 702 | |
---|
| 703 | |
---|
| 704 | |
---|
[236] | 705 | |
---|
| 706 | |
---|
[155] | 707 | // template<typename Graph> |
---|
| 708 | // class SymGraphWrapper |
---|
| 709 | // { |
---|
| 710 | // Graph* graph; |
---|
[76] | 711 | |
---|
[155] | 712 | // public: |
---|
| 713 | // typedef Graph BaseGraph; |
---|
| 714 | |
---|
[174] | 715 | // typedef typename Graph::Node Node; |
---|
| 716 | // typedef typename Graph::Edge Edge; |
---|
| 717 | |
---|
[155] | 718 | // typedef typename Graph::NodeIt NodeIt; |
---|
| 719 | |
---|
| 720 | // //FIXME tag-ekkel megcsinalni, hogy abbol csinaljon |
---|
| 721 | // //iranyitatlant, ami van |
---|
| 722 | // //mert csak 1 dolgot lehet be typedef-elni |
---|
| 723 | // typedef typename Graph::OutEdgeIt SymEdgeIt; |
---|
| 724 | // //typedef typename Graph::InEdgeIt SymEdgeIt; |
---|
| 725 | // //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 726 | // typedef typename Graph::EdgeIt EdgeIt; |
---|
[155] | 727 | |
---|
| 728 | // int nodeNum() const { return graph->nodeNum(); } |
---|
| 729 | // int edgeNum() const { return graph->edgeNum(); } |
---|
| 730 | |
---|
[212] | 731 | // template<typename I> I& first(I& i) const { return graph->first(i); } |
---|
| 732 | // template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 733 | // return graph->first(i, p); } |
---|
[155] | 734 | // //template<typename I> I next(const I i); { return graph->goNext(i); } |
---|
| 735 | // //template<typename I> I &goNext(I &i); { return graph->goNext(i); } |
---|
| 736 | |
---|
| 737 | // template< typename It > It first() const { |
---|
[212] | 738 | // It e; first(e); return e; } |
---|
[155] | 739 | |
---|
[174] | 740 | // template< typename It > It first(Node v) const { |
---|
[212] | 741 | // It e; first(e, v); return e; } |
---|
[155] | 742 | |
---|
[174] | 743 | // Node head(const Edge& e) const { return graph->head(e); } |
---|
| 744 | // Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[155] | 745 | |
---|
[174] | 746 | // template<typename I> Node aNode(const I& e) const { |
---|
[155] | 747 | // return graph->aNode(e); } |
---|
[174] | 748 | // template<typename I> Node bNode(const I& e) const { |
---|
[155] | 749 | // return graph->bNode(e); } |
---|
| 750 | |
---|
| 751 | // //template<typename I> bool valid(const I i); |
---|
| 752 | // //{ return graph->valid(i); } |
---|
| 753 | |
---|
| 754 | // //template<typename I> void setInvalid(const I &i); |
---|
| 755 | // //{ return graph->setInvalid(i); } |
---|
| 756 | |
---|
[174] | 757 | // Node addNode() { return graph->addNode(); } |
---|
| 758 | // Edge addEdge(const Node& tail, const Node& head) { |
---|
[155] | 759 | // return graph->addEdge(tail, head); } |
---|
| 760 | |
---|
| 761 | // template<typename I> void erase(const I& i) { graph->erase(i); } |
---|
| 762 | |
---|
| 763 | // void clear() { graph->clear(); } |
---|
| 764 | |
---|
| 765 | // template<typename T> class NodeMap : public Graph::NodeMap<T> { }; |
---|
| 766 | // template<typename T> class EdgeMap : public Graph::EdgeMap<T> { }; |
---|
| 767 | |
---|
| 768 | // void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 769 | // Graph& getGraph() { return (*graph); } |
---|
| 770 | |
---|
| 771 | // //SymGraphWrapper() : graph(0) { } |
---|
| 772 | // SymGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 773 | // }; |
---|
| 774 | |
---|
| 775 | |
---|
| 776 | template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
---|
| 777 | class ResGraphWrapper { |
---|
[76] | 778 | public: |
---|
| 779 | typedef Graph BaseGraph; |
---|
[174] | 780 | typedef typename Graph::Node Node; |
---|
[155] | 781 | typedef typename Graph::NodeIt NodeIt; |
---|
| 782 | private: |
---|
| 783 | typedef typename Graph::OutEdgeIt OldOutEdgeIt; |
---|
| 784 | typedef typename Graph::InEdgeIt OldInEdgeIt; |
---|
[199] | 785 | protected: |
---|
[174] | 786 | const Graph* graph; |
---|
[155] | 787 | FlowMap* flow; |
---|
| 788 | const CapacityMap* capacity; |
---|
| 789 | public: |
---|
[168] | 790 | |
---|
[155] | 791 | ResGraphWrapper(const Graph& _G, FlowMap& _flow, |
---|
| 792 | const CapacityMap& _capacity) : |
---|
[174] | 793 | graph(&_G), flow(&_flow), capacity(&_capacity) { } |
---|
[168] | 794 | |
---|
| 795 | void setGraph(const Graph& _graph) { graph = &_graph; } |
---|
[174] | 796 | const Graph& getGraph() const { return (*graph); } |
---|
[168] | 797 | |
---|
[174] | 798 | class Edge; |
---|
[155] | 799 | class OutEdgeIt; |
---|
[174] | 800 | friend class Edge; |
---|
[155] | 801 | friend class OutEdgeIt; |
---|
[76] | 802 | |
---|
[174] | 803 | class Edge { |
---|
[155] | 804 | friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; |
---|
| 805 | protected: |
---|
[168] | 806 | bool out_or_in; //true, iff out |
---|
[155] | 807 | OldOutEdgeIt out; |
---|
| 808 | OldInEdgeIt in; |
---|
| 809 | public: |
---|
[174] | 810 | Edge() : out_or_in(true) { } |
---|
| 811 | Edge(const Invalid& i) : out_or_in(false), out(), in(i) { } |
---|
[168] | 812 | // bool valid() const { |
---|
| 813 | // return out_or_in && out.valid() || in.valid(); } |
---|
[174] | 814 | friend bool operator==(const Edge& u, const Edge& v) { |
---|
| 815 | if (v.out_or_in) |
---|
| 816 | return (u.out_or_in && u.out==v.out); |
---|
| 817 | else |
---|
| 818 | return (!u.out_or_in && u.in==v.in); |
---|
| 819 | } |
---|
| 820 | friend bool operator!=(const Edge& u, const Edge& v) { |
---|
| 821 | if (v.out_or_in) |
---|
| 822 | return (!u.out_or_in || u.out!=v.out); |
---|
| 823 | else |
---|
| 824 | return (u.out_or_in || u.in!=v.in); |
---|
| 825 | } |
---|
[155] | 826 | }; |
---|
| 827 | |
---|
| 828 | |
---|
[174] | 829 | class OutEdgeIt : public Edge { |
---|
[155] | 830 | friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; |
---|
| 831 | public: |
---|
| 832 | OutEdgeIt() { } |
---|
[168] | 833 | //FIXME |
---|
[174] | 834 | OutEdgeIt(const Edge& e) : Edge(e) { } |
---|
| 835 | OutEdgeIt(const Invalid& i) : Edge(i) { } |
---|
[155] | 836 | private: |
---|
[174] | 837 | OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { |
---|
[212] | 838 | resG.graph->first(out, v); |
---|
[174] | 839 | while( resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); } |
---|
| 840 | if (!resG.graph->valid(out)) { |
---|
[155] | 841 | out_or_in=0; |
---|
[212] | 842 | resG.graph->first(in, v); |
---|
[174] | 843 | while( resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); } |
---|
[155] | 844 | } |
---|
| 845 | } |
---|
[168] | 846 | // public: |
---|
| 847 | // OutEdgeIt& operator++() { |
---|
| 848 | // if (out_or_in) { |
---|
[174] | 849 | // Node v=/*resG->*/G->aNode(out); |
---|
[168] | 850 | // ++out; |
---|
[174] | 851 | // while( out.valid() && !(Edge::free()>0) ) { ++out; } |
---|
[168] | 852 | // if (!out.valid()) { |
---|
| 853 | // out_or_in=0; |
---|
[212] | 854 | // G->first(in, v); |
---|
[174] | 855 | // while( in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 856 | // } |
---|
| 857 | // } else { |
---|
| 858 | // ++in; |
---|
[174] | 859 | // while( in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 860 | // } |
---|
| 861 | // return *this; |
---|
| 862 | // } |
---|
[155] | 863 | }; |
---|
| 864 | |
---|
[174] | 865 | class EdgeIt : public Edge { |
---|
[155] | 866 | friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>; |
---|
[174] | 867 | typename Graph::NodeIt v; |
---|
[155] | 868 | public: |
---|
[174] | 869 | EdgeIt() { } |
---|
| 870 | //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { } |
---|
| 871 | EdgeIt(const Invalid& i) : Edge(i) { } |
---|
| 872 | EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() { |
---|
[212] | 873 | resG.graph->first(v); |
---|
| 874 | if (resG.graph->valid(v)) resG.graph->first(out, v); else out=OldOutEdgeIt(INVALID); |
---|
[174] | 875 | while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); } |
---|
| 876 | while (resG.graph->valid(v) && !resG.graph->valid(out)) { |
---|
| 877 | resG.graph->next(v); |
---|
[212] | 878 | if (resG.graph->valid(v)) resG.graph->first(out, v); |
---|
[174] | 879 | while (resG.graph->valid(out) && !(resG.free(out)>0) ) { resG.graph->next(out); } |
---|
[155] | 880 | } |
---|
[174] | 881 | if (!resG.graph->valid(out)) { |
---|
[155] | 882 | out_or_in=0; |
---|
[212] | 883 | resG.graph->first(v); |
---|
| 884 | if (resG.graph->valid(v)) resG.graph->first(in, v); else in=OldInEdgeIt(INVALID); |
---|
[174] | 885 | while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); } |
---|
| 886 | while (resG.graph->valid(v) && !resG.graph->valid(in)) { |
---|
| 887 | resG.graph->next(v); |
---|
[212] | 888 | if (resG.graph->valid(v)) resG.graph->first(in, v); |
---|
[174] | 889 | while (resG.graph->valid(in) && !(resG.free(in)>0) ) { resG.graph->next(in); } |
---|
[155] | 890 | } |
---|
| 891 | } |
---|
| 892 | } |
---|
[174] | 893 | // EdgeIt& operator++() { |
---|
[168] | 894 | // if (out_or_in) { |
---|
| 895 | // ++out; |
---|
[174] | 896 | // while (out.valid() && !(Edge::free()>0) ) { ++out; } |
---|
[168] | 897 | // while (v.valid() && !out.valid()) { |
---|
| 898 | // ++v; |
---|
[212] | 899 | // if (v.valid()) G->first(out, v); |
---|
[174] | 900 | // while (out.valid() && !(Edge::free()>0) ) { ++out; } |
---|
[168] | 901 | // } |
---|
| 902 | // if (!out.valid()) { |
---|
| 903 | // out_or_in=0; |
---|
[212] | 904 | // G->first(v); |
---|
| 905 | // if (v.valid()) G->first(in, v); else in=OldInEdgeIt(); |
---|
[174] | 906 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 907 | // while (v.valid() && !in.valid()) { |
---|
| 908 | // ++v; |
---|
[212] | 909 | // if (v.valid()) G->first(in, v); |
---|
[174] | 910 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 911 | // } |
---|
| 912 | // } |
---|
| 913 | // } else { |
---|
| 914 | // ++in; |
---|
[174] | 915 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 916 | // while (v.valid() && !in.valid()) { |
---|
| 917 | // ++v; |
---|
[212] | 918 | // if (v.valid()) G->first(in, v); |
---|
[174] | 919 | // while (in.valid() && !(Edge::free()>0) ) { ++in; } |
---|
[168] | 920 | // } |
---|
| 921 | // } |
---|
| 922 | // return *this; |
---|
| 923 | // } |
---|
[155] | 924 | }; |
---|
| 925 | |
---|
[212] | 926 | NodeIt& first(NodeIt& v) const { return graph->first(v); } |
---|
| 927 | OutEdgeIt& first(OutEdgeIt& e, Node v) const { |
---|
[168] | 928 | e=OutEdgeIt(*this, v); |
---|
[174] | 929 | return e; |
---|
[155] | 930 | } |
---|
[212] | 931 | EdgeIt& first(EdgeIt& e) const { |
---|
[174] | 932 | e=EdgeIt(*this); |
---|
| 933 | return e; |
---|
[155] | 934 | } |
---|
| 935 | |
---|
[174] | 936 | NodeIt& next(NodeIt& n) const { return graph->next(n); } |
---|
[155] | 937 | |
---|
| 938 | OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 939 | if (e.out_or_in) { |
---|
[174] | 940 | Node v=graph->aNode(e.out); |
---|
| 941 | graph->next(e.out); |
---|
| 942 | while( graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); } |
---|
| 943 | if (!graph->valid(e.out)) { |
---|
[155] | 944 | e.out_or_in=0; |
---|
[212] | 945 | graph->first(e.in, v); |
---|
[174] | 946 | while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } |
---|
[155] | 947 | } |
---|
| 948 | } else { |
---|
[174] | 949 | graph->next(e.in); |
---|
| 950 | while( graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } |
---|
[155] | 951 | } |
---|
| 952 | return e; |
---|
| 953 | } |
---|
| 954 | |
---|
[174] | 955 | EdgeIt& next(EdgeIt& e) const { |
---|
[155] | 956 | if (e.out_or_in) { |
---|
[174] | 957 | graph->next(e.out); |
---|
| 958 | while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); } |
---|
| 959 | while (graph->valid(e.v) && !graph->valid(e.out)) { |
---|
| 960 | graph->next(e.v); |
---|
[212] | 961 | if (graph->valid(e.v)) graph->first(e.out, e.v); |
---|
[174] | 962 | while (graph->valid(e.out) && !(free(e.out)>0) ) { graph->next(e.out); } |
---|
[155] | 963 | } |
---|
[174] | 964 | if (!graph->valid(e.out)) { |
---|
[155] | 965 | e.out_or_in=0; |
---|
[212] | 966 | graph->first(e.v); |
---|
| 967 | if (graph->valid(e.v)) graph->first(e.in, e.v); else e.in=OldInEdgeIt(INVALID); |
---|
[174] | 968 | while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } |
---|
| 969 | while (graph->valid(e.v) && !graph->valid(e.in)) { |
---|
| 970 | graph->next(e.v); |
---|
[212] | 971 | if (graph->valid(e.v)) graph->first(e.in, e.v); |
---|
[174] | 972 | while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } |
---|
[155] | 973 | } |
---|
| 974 | } |
---|
| 975 | } else { |
---|
[174] | 976 | graph->next(e.in); |
---|
| 977 | while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } |
---|
| 978 | while (graph->valid(e.v) && !graph->valid(e.in)) { |
---|
| 979 | graph->next(e.v); |
---|
[212] | 980 | if (graph->valid(e.v)) graph->first(e.in, e.v); |
---|
[174] | 981 | while (graph->valid(e.in) && !(free(e.in)>0) ) { graph->next(e.in); } |
---|
[155] | 982 | } |
---|
| 983 | } |
---|
| 984 | return e; |
---|
| 985 | } |
---|
[76] | 986 | |
---|
| 987 | |
---|
[155] | 988 | template< typename It > |
---|
| 989 | It first() const { |
---|
| 990 | It e; |
---|
[212] | 991 | first(e); |
---|
[155] | 992 | return e; |
---|
| 993 | } |
---|
[76] | 994 | |
---|
[155] | 995 | template< typename It > |
---|
[174] | 996 | It first(Node v) const { |
---|
[155] | 997 | It e; |
---|
[212] | 998 | first(e, v); |
---|
[155] | 999 | return e; |
---|
| 1000 | } |
---|
[76] | 1001 | |
---|
[174] | 1002 | Node tail(Edge e) const { |
---|
| 1003 | return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); } |
---|
| 1004 | Node head(Edge e) const { |
---|
| 1005 | return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); } |
---|
[76] | 1006 | |
---|
[174] | 1007 | Node aNode(OutEdgeIt e) const { |
---|
| 1008 | return ((e.out_or_in) ? graph->aNode(e.out) : graph->aNode(e.in)); } |
---|
| 1009 | Node bNode(OutEdgeIt e) const { |
---|
| 1010 | return ((e.out_or_in) ? graph->bNode(e.out) : graph->bNode(e.in)); } |
---|
[76] | 1011 | |
---|
[174] | 1012 | int id(Node v) const { return graph->id(v); } |
---|
[155] | 1013 | |
---|
[174] | 1014 | bool valid(Node n) const { return graph->valid(n); } |
---|
| 1015 | bool valid(Edge e) const { |
---|
| 1016 | return e.out_or_in ? graph->valid(e.out) : graph->valid(e.in); } |
---|
[155] | 1017 | |
---|
[174] | 1018 | void augment(const Edge& e, Number a) const { |
---|
[168] | 1019 | if (e.out_or_in) |
---|
| 1020 | flow->set(e.out, flow->get(e.out)+a); |
---|
| 1021 | else |
---|
| 1022 | flow->set(e.in, flow->get(e.in)-a); |
---|
| 1023 | } |
---|
| 1024 | |
---|
[174] | 1025 | Number free(const Edge& e) const { |
---|
[168] | 1026 | if (e.out_or_in) |
---|
| 1027 | return (capacity->get(e.out)-flow->get(e.out)); |
---|
| 1028 | else |
---|
| 1029 | return (flow->get(e.in)); |
---|
| 1030 | } |
---|
| 1031 | |
---|
| 1032 | Number free(OldOutEdgeIt out) const { |
---|
| 1033 | return (capacity->get(out)-flow->get(out)); |
---|
| 1034 | } |
---|
| 1035 | |
---|
| 1036 | Number free(OldInEdgeIt in) const { |
---|
| 1037 | return (flow->get(in)); |
---|
| 1038 | } |
---|
| 1039 | |
---|
[155] | 1040 | template<typename T> class NodeMap : public Graph::NodeMap<T> { |
---|
| 1041 | public: |
---|
| 1042 | NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) |
---|
[158] | 1043 | : Graph::NodeMap<T>(_G.getGraph()) { } |
---|
[155] | 1044 | NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, |
---|
[158] | 1045 | T a) : Graph::NodeMap<T>(_G.getGraph(), a) { } |
---|
[155] | 1046 | }; |
---|
| 1047 | |
---|
| 1048 | // template <typename T> |
---|
| 1049 | // class NodeMap { |
---|
| 1050 | // typename Graph::NodeMap<T> node_map; |
---|
| 1051 | // public: |
---|
[174] | 1052 | // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(*(_G.graph)) { } |
---|
| 1053 | // NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : node_map(*(_G.graph), a) { } |
---|
| 1054 | // void set(Node nit, T a) { node_map.set(nit, a); } |
---|
| 1055 | // T get(Node nit) const { return node_map.get(nit); } |
---|
[155] | 1056 | // }; |
---|
| 1057 | |
---|
| 1058 | template <typename T> |
---|
| 1059 | class EdgeMap { |
---|
| 1060 | typename Graph::EdgeMap<T> forward_map, backward_map; |
---|
| 1061 | public: |
---|
[158] | 1062 | EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(_G.getGraph()), backward_map(_G.getGraph()) { } |
---|
| 1063 | EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(_G.getGraph(), a), backward_map(_G.getGraph(), a) { } |
---|
[174] | 1064 | void set(Edge e, T a) { |
---|
[155] | 1065 | if (e.out_or_in) |
---|
| 1066 | forward_map.set(e.out, a); |
---|
| 1067 | else |
---|
| 1068 | backward_map.set(e.in, a); |
---|
| 1069 | } |
---|
[174] | 1070 | T get(Edge e) { |
---|
[155] | 1071 | if (e.out_or_in) |
---|
| 1072 | return forward_map.get(e.out); |
---|
| 1073 | else |
---|
| 1074 | return backward_map.get(e.in); |
---|
| 1075 | } |
---|
| 1076 | }; |
---|
[168] | 1077 | }; |
---|
| 1078 | |
---|
| 1079 | template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
---|
| 1080 | class ErasingResGraphWrapper : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap> { |
---|
| 1081 | protected: |
---|
| 1082 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges; |
---|
| 1083 | //ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist; |
---|
| 1084 | public: |
---|
| 1085 | ErasingResGraphWrapper(const Graph& _G, FlowMap& _flow, |
---|
| 1086 | const CapacityMap& _capacity) : |
---|
| 1087 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), |
---|
| 1088 | first_out_edges(*this) /*, dist(*this)*/ { |
---|
[174] | 1089 | for(NodeIt n=this->template first<NodeIt>(); this->valid(n); this->next(n)) { |
---|
[168] | 1090 | OutEdgeIt e; |
---|
[212] | 1091 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n); |
---|
[168] | 1092 | first_out_edges.set(n, e); |
---|
| 1093 | } |
---|
| 1094 | } |
---|
| 1095 | |
---|
| 1096 | //void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 1097 | //Graph& getGraph() const { return (*graph); } |
---|
| 1098 | |
---|
| 1099 | //TrivGraphWrapper() : graph(0) { } |
---|
| 1100 | //ErasingResGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 1101 | |
---|
| 1102 | //typedef Graph BaseGraph; |
---|
| 1103 | |
---|
[174] | 1104 | //typedef typename Graph::Node Node; |
---|
[168] | 1105 | //typedef typename Graph::NodeIt NodeIt; |
---|
| 1106 | |
---|
[174] | 1107 | //typedef typename Graph::Edge Edge; |
---|
[168] | 1108 | //typedef typename Graph::OutEdgeIt OutEdgeIt; |
---|
| 1109 | //typedef typename Graph::InEdgeIt InEdgeIt; |
---|
| 1110 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 1111 | //typedef typename Graph::EdgeIt EdgeIt; |
---|
[168] | 1112 | |
---|
[174] | 1113 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node; |
---|
[168] | 1114 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt; |
---|
| 1115 | |
---|
[174] | 1116 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge; |
---|
[168] | 1117 | typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt; |
---|
| 1118 | //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt; |
---|
| 1119 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 1120 | //typedef typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt; |
---|
[168] | 1121 | |
---|
[212] | 1122 | NodeIt& first(NodeIt& n) const { |
---|
| 1123 | return ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n); |
---|
[168] | 1124 | } |
---|
| 1125 | |
---|
[212] | 1126 | OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { |
---|
[168] | 1127 | e=first_out_edges.get(n); |
---|
| 1128 | return e; |
---|
| 1129 | } |
---|
| 1130 | |
---|
[212] | 1131 | //ROSSZ template<typename I> I& first(I& i) const { return first(i); } |
---|
| 1132 | //ROSSZ template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 1133 | // return first(i, p); } |
---|
[168] | 1134 | |
---|
| 1135 | //template<typename I> I getNext(const I& i) const { |
---|
| 1136 | // return graph->getNext(i); } |
---|
| 1137 | //template<typename I> I& next(I &i) const { return graph->next(i); } |
---|
| 1138 | |
---|
| 1139 | template< typename It > It first() const { |
---|
[212] | 1140 | It e; first(e); return e; } |
---|
[168] | 1141 | |
---|
[174] | 1142 | template< typename It > It first(const Node& v) const { |
---|
[212] | 1143 | It e; first(e, v); return e; } |
---|
[168] | 1144 | |
---|
[174] | 1145 | //Node head(const Edge& e) const { return graph->head(e); } |
---|
| 1146 | //Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[168] | 1147 | |
---|
| 1148 | //template<typename I> bool valid(const I& i) const |
---|
| 1149 | // { return graph->valid(i); } |
---|
| 1150 | |
---|
| 1151 | //int nodeNum() const { return graph->nodeNum(); } |
---|
| 1152 | //int edgeNum() const { return graph->edgeNum(); } |
---|
| 1153 | |
---|
[174] | 1154 | //template<typename I> Node aNode(const I& e) const { |
---|
[168] | 1155 | // return graph->aNode(e); } |
---|
[174] | 1156 | //template<typename I> Node bNode(const I& e) const { |
---|
[168] | 1157 | // return graph->bNode(e); } |
---|
| 1158 | |
---|
[174] | 1159 | //Node addNode() const { return graph->addNode(); } |
---|
| 1160 | //Edge addEdge(const Node& tail, const Node& head) const { |
---|
[168] | 1161 | // return graph->addEdge(tail, head); } |
---|
| 1162 | |
---|
| 1163 | //void erase(const OutEdgeIt& e) { |
---|
| 1164 | // first_out_edge(this->tail(e))=e; |
---|
| 1165 | //} |
---|
[174] | 1166 | void erase(const Edge& e) { |
---|
[168] | 1167 | OutEdgeIt f(e); |
---|
| 1168 | next(f); |
---|
| 1169 | first_out_edges.set(this->tail(e), f); |
---|
| 1170 | } |
---|
| 1171 | //template<typename I> void erase(const I& i) const { graph->erase(i); } |
---|
| 1172 | |
---|
| 1173 | //void clear() const { graph->clear(); } |
---|
| 1174 | |
---|
| 1175 | template<typename T> class NodeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { |
---|
| 1176 | public: |
---|
| 1177 | NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : |
---|
| 1178 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { } |
---|
| 1179 | NodeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : |
---|
| 1180 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { } |
---|
| 1181 | }; |
---|
| 1182 | |
---|
| 1183 | template<typename T> class EdgeMap : public ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { |
---|
| 1184 | public: |
---|
| 1185 | EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : |
---|
| 1186 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { } |
---|
| 1187 | EdgeMap(const ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : |
---|
| 1188 | ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { } |
---|
| 1189 | }; |
---|
| 1190 | }; |
---|
| 1191 | |
---|
| 1192 | template<typename GraphWrapper> |
---|
| 1193 | class FilterGraphWrapper { |
---|
| 1194 | }; |
---|
| 1195 | |
---|
| 1196 | template<typename Graph, typename Number, typename FlowMap, typename CapacityMap> |
---|
| 1197 | class FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> > : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> { |
---|
| 1198 | |
---|
| 1199 | //Graph* graph; |
---|
| 1200 | |
---|
| 1201 | public: |
---|
| 1202 | //typedef Graph BaseGraph; |
---|
| 1203 | |
---|
[174] | 1204 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Node Node; |
---|
[168] | 1205 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeIt NodeIt; |
---|
| 1206 | |
---|
[174] | 1207 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::Edge Edge; |
---|
[168] | 1208 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt OutEdgeIt; |
---|
| 1209 | //typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::InEdgeIt InEdgeIt; |
---|
| 1210 | //typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 1211 | typedef typename ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeIt EdgeIt; |
---|
[168] | 1212 | |
---|
| 1213 | //FilterGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<typename ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::OutEdgeIt> first_out_edges; |
---|
| 1214 | |
---|
| 1215 | public: |
---|
| 1216 | FilterGraphWrapper(const Graph& _G, FlowMap& _flow, |
---|
| 1217 | const CapacityMap& _capacity) : |
---|
[199] | 1218 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>(_G, _flow, _capacity), dist(*this, graph->nodeNum()) { |
---|
[168] | 1219 | } |
---|
| 1220 | |
---|
[212] | 1221 | OutEdgeIt& first(OutEdgeIt& e, const Node& n) const { |
---|
| 1222 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(e, n); |
---|
[199] | 1223 | while (valid(e) && (dist.get(tail(e))/*+1!=*/>=dist.get(head(e)))) |
---|
[168] | 1224 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
| 1225 | return e; |
---|
| 1226 | } |
---|
| 1227 | |
---|
[174] | 1228 | NodeIt& next(NodeIt& e) const { |
---|
[168] | 1229 | return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
| 1230 | } |
---|
| 1231 | |
---|
| 1232 | OutEdgeIt& next(OutEdgeIt& e) const { |
---|
| 1233 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
[199] | 1234 | while (valid(e) && (dist.get(tail(e))/*+1!*/>=dist.get(head(e)))) |
---|
[168] | 1235 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(e); |
---|
| 1236 | return e; |
---|
| 1237 | } |
---|
| 1238 | |
---|
[212] | 1239 | NodeIt& first(NodeIt& n) const { |
---|
| 1240 | return ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::first(n); |
---|
[168] | 1241 | } |
---|
| 1242 | |
---|
[174] | 1243 | void erase(const Edge& e) { |
---|
[168] | 1244 | OutEdgeIt f(e); |
---|
| 1245 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f); |
---|
[199] | 1246 | while (valid(f) && (dist.get(tail(f))/*+1!=*/>=dist.get(head(f)))) |
---|
[168] | 1247 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::next(f); |
---|
| 1248 | first_out_edges.set(this->tail(e), f); |
---|
| 1249 | } |
---|
| 1250 | |
---|
| 1251 | //TrivGraphWrapper() : graph(0) { } |
---|
| 1252 | //TrivGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 1253 | |
---|
| 1254 | //void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 1255 | //Graph& getGraph() const { return (*graph); } |
---|
| 1256 | |
---|
[212] | 1257 | //template<typename I> I& first(I& i) const { return graph->first(i); } |
---|
| 1258 | //template<typename I, typename P> I& first(I& i, const P& p) const { |
---|
| 1259 | // return graph->first(i, p); } |
---|
[168] | 1260 | |
---|
| 1261 | //template<typename I> I getNext(const I& i) const { |
---|
| 1262 | // return graph->getNext(i); } |
---|
| 1263 | //template<typename I> I& next(I &i) const { return graph->next(i); } |
---|
| 1264 | |
---|
| 1265 | template< typename It > It first() const { |
---|
[212] | 1266 | It e; first(e); return e; } |
---|
[168] | 1267 | |
---|
[174] | 1268 | template< typename It > It first(const Node& v) const { |
---|
[212] | 1269 | It e; first(e, v); return e; } |
---|
[168] | 1270 | |
---|
[174] | 1271 | //Node head(const Edge& e) const { return graph->head(e); } |
---|
| 1272 | //Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[168] | 1273 | |
---|
| 1274 | //template<typename I> bool valid(const I& i) const |
---|
| 1275 | // { return graph->valid(i); } |
---|
| 1276 | |
---|
| 1277 | //template<typename I> void setInvalid(const I &i); |
---|
| 1278 | //{ return graph->setInvalid(i); } |
---|
| 1279 | |
---|
| 1280 | //int nodeNum() const { return graph->nodeNum(); } |
---|
| 1281 | //int edgeNum() const { return graph->edgeNum(); } |
---|
| 1282 | |
---|
[174] | 1283 | //template<typename I> Node aNode(const I& e) const { |
---|
[168] | 1284 | // return graph->aNode(e); } |
---|
[174] | 1285 | //template<typename I> Node bNode(const I& e) const { |
---|
[168] | 1286 | // return graph->bNode(e); } |
---|
| 1287 | |
---|
[174] | 1288 | //Node addNode() const { return graph->addNode(); } |
---|
| 1289 | //Edge addEdge(const Node& tail, const Node& head) const { |
---|
[168] | 1290 | // return graph->addEdge(tail, head); } |
---|
| 1291 | |
---|
| 1292 | //template<typename I> void erase(const I& i) const { graph->erase(i); } |
---|
| 1293 | |
---|
| 1294 | //void clear() const { graph->clear(); } |
---|
| 1295 | |
---|
| 1296 | template<typename T> class NodeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T> { |
---|
| 1297 | public: |
---|
| 1298 | NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : |
---|
| 1299 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/) { } |
---|
| 1300 | NodeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : |
---|
| 1301 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<T>(_G /*_G.getGraph()*/, a) { } |
---|
| 1302 | }; |
---|
| 1303 | |
---|
| 1304 | template<typename T> class EdgeMap : public ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T> { |
---|
| 1305 | public: |
---|
| 1306 | EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G) : |
---|
| 1307 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/) { } |
---|
| 1308 | EdgeMap(const FilterGraphWrapper<ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap> >& _G, T a) : |
---|
| 1309 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::EdgeMap<T>(_G /*_G.getGraph()*/, a) { } |
---|
| 1310 | }; |
---|
| 1311 | |
---|
| 1312 | public: |
---|
| 1313 | ErasingResGraphWrapper<Graph, Number, FlowMap, CapacityMap>::NodeMap<int> dist; |
---|
[155] | 1314 | |
---|
[76] | 1315 | }; |
---|
| 1316 | |
---|
| 1317 | |
---|
[148] | 1318 | |
---|
| 1319 | // // FIXME: comparison should be made better!!! |
---|
| 1320 | // template<typename Graph, typename T, typename LowerMap, typename FlowMap, typename UpperMap> |
---|
| 1321 | // class ResGraphWrapper |
---|
| 1322 | // { |
---|
| 1323 | // Graph* graph; |
---|
[76] | 1324 | |
---|
[148] | 1325 | // public: |
---|
| 1326 | // typedef Graph BaseGraph; |
---|
[76] | 1327 | |
---|
[174] | 1328 | // typedef typename Graph::Node Node; |
---|
| 1329 | // typedef typename Graph::Edge Edge; |
---|
| 1330 | |
---|
[148] | 1331 | // typedef typename Graph::NodeIt NodeIt; |
---|
[76] | 1332 | |
---|
[148] | 1333 | // class OutEdgeIt { |
---|
| 1334 | // public: |
---|
[174] | 1335 | // //Graph::Node n; |
---|
[148] | 1336 | // bool out_or_in; |
---|
| 1337 | // typename Graph::OutEdgeIt o; |
---|
| 1338 | // typename Graph::InEdgeIt i; |
---|
| 1339 | // }; |
---|
| 1340 | // class InEdgeIt { |
---|
| 1341 | // public: |
---|
[174] | 1342 | // //Graph::Node n; |
---|
[148] | 1343 | // bool out_or_in; |
---|
| 1344 | // typename Graph::OutEdgeIt o; |
---|
| 1345 | // typename Graph::InEdgeIt i; |
---|
| 1346 | // }; |
---|
| 1347 | // typedef typename Graph::SymEdgeIt SymEdgeIt; |
---|
[174] | 1348 | // typedef typename Graph::EdgeIt EdgeIt; |
---|
[76] | 1349 | |
---|
[148] | 1350 | // int nodeNum() const { return graph->nodeNum(); } |
---|
| 1351 | // int edgeNum() const { return graph->edgeNum(); } |
---|
[76] | 1352 | |
---|
[212] | 1353 | // Node& first(Node& n) const { return graph->first(n); } |
---|
[76] | 1354 | |
---|
[174] | 1355 | // // Edge and SymEdge is missing!!!! |
---|
| 1356 | // // Edge <-> In/OutEdgeIt conversion is missing!!!! |
---|
[76] | 1357 | |
---|
[148] | 1358 | // //FIXME |
---|
[212] | 1359 | // OutEdgeIt& first(OutEdgeIt& e, const Node& n) const |
---|
[148] | 1360 | // { |
---|
| 1361 | // e.n=n; |
---|
[212] | 1362 | // graph->first(e.o,n); |
---|
[148] | 1363 | // while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o)) |
---|
| 1364 | // graph->goNext(e.o); |
---|
| 1365 | // if(!graph->valid(e.o)) { |
---|
[212] | 1366 | // graph->first(e.i,n); |
---|
[148] | 1367 | // while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i)) |
---|
| 1368 | // graph->goNext(e.i); |
---|
| 1369 | // } |
---|
| 1370 | // return e; |
---|
| 1371 | // } |
---|
| 1372 | // /* |
---|
| 1373 | // OutEdgeIt &goNext(OutEdgeIt &e) |
---|
| 1374 | // { |
---|
| 1375 | // if(graph->valid(e.o)) { |
---|
| 1376 | // while(graph->valid(e.o) && fmap.get(e.o)>=himap.get(e.o)) |
---|
| 1377 | // graph->goNext(e.o); |
---|
| 1378 | // if(graph->valid(e.o)) return e; |
---|
[212] | 1379 | // else graph->first(e.i,e.n); |
---|
[148] | 1380 | // } |
---|
| 1381 | // else { |
---|
| 1382 | // while(graph->valid(e.i) && fmap.get(e.i)<=lomap.get(e.i)) |
---|
| 1383 | // graph->goNext(e.i); |
---|
| 1384 | // return e; |
---|
| 1385 | // } |
---|
| 1386 | // } |
---|
| 1387 | // OutEdgeIt Next(const OutEdgeIt &e) {OutEdgeIt t(e); return goNext(t);} |
---|
| 1388 | // */ |
---|
| 1389 | // //bool valid(const OutEdgeIt e) { return graph->valid(e.o)||graph->valid(e.i);} |
---|
[76] | 1390 | |
---|
[148] | 1391 | // //FIXME |
---|
[212] | 1392 | // InEdgeIt& first(InEdgeIt& e, const Node& n) const |
---|
[148] | 1393 | // { |
---|
| 1394 | // e.n=n; |
---|
[212] | 1395 | // graph->first(e.i,n); |
---|
[148] | 1396 | // while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i)) |
---|
| 1397 | // graph->goNext(e.i); |
---|
| 1398 | // if(!graph->valid(e.i)) { |
---|
[212] | 1399 | // graph->first(e.o,n); |
---|
[148] | 1400 | // while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o)) |
---|
| 1401 | // graph->goNext(e.o); |
---|
| 1402 | // } |
---|
| 1403 | // return e; |
---|
| 1404 | // } |
---|
| 1405 | // /* |
---|
| 1406 | // InEdgeIt &goNext(InEdgeIt &e) |
---|
| 1407 | // { |
---|
| 1408 | // if(graph->valid(e.i)) { |
---|
| 1409 | // while(graph->valid(e.i) && fmap.get(e.i)>=himap.get(e.i)) |
---|
| 1410 | // graph->goNext(e.i); |
---|
| 1411 | // if(graph->valid(e.i)) return e; |
---|
[212] | 1412 | // else graph->first(e.o,e.n); |
---|
[148] | 1413 | // } |
---|
| 1414 | // else { |
---|
| 1415 | // while(graph->valid(e.o) && fmap.get(e.o)<=lomap.get(e.o)) |
---|
| 1416 | // graph->goNext(e.o); |
---|
| 1417 | // return e; |
---|
| 1418 | // } |
---|
| 1419 | // } |
---|
| 1420 | // InEdgeIt Next(const InEdgeIt &e) {InEdgeIt t(e); return goNext(t);} |
---|
| 1421 | // */ |
---|
| 1422 | // //bool valid(const InEdgeIt e) { return graph->valid(e.i)||graph->valid(e.o);} |
---|
[76] | 1423 | |
---|
[148] | 1424 | // //template<typename I> I &goNext(I &i); { return graph->goNext(i); } |
---|
| 1425 | // //template<typename I> I next(const I i); { return graph->goNext(i); } |
---|
[76] | 1426 | |
---|
[148] | 1427 | // template< typename It > It first() const { |
---|
[212] | 1428 | // It e; first(e); return e; } |
---|
[76] | 1429 | |
---|
[174] | 1430 | // template< typename It > It first(Node v) const { |
---|
[212] | 1431 | // It e; first(e, v); return e; } |
---|
[76] | 1432 | |
---|
[174] | 1433 | // Node head(const Edge& e) const { return graph->head(e); } |
---|
| 1434 | // Node tail(const Edge& e) const { return graph->tail(e); } |
---|
[76] | 1435 | |
---|
[174] | 1436 | // template<typename I> Node aNode(const I& e) const { |
---|
[148] | 1437 | // return graph->aNode(e); } |
---|
[174] | 1438 | // template<typename I> Node bNode(const I& e) const { |
---|
[148] | 1439 | // return graph->bNode(e); } |
---|
[76] | 1440 | |
---|
[148] | 1441 | // //template<typename I> bool valid(const I i); |
---|
| 1442 | // //{ return graph->valid(i); } |
---|
[76] | 1443 | |
---|
[148] | 1444 | // //template<typename I> void setInvalid(const I &i); |
---|
| 1445 | // //{ return graph->setInvalid(i); } |
---|
[76] | 1446 | |
---|
[174] | 1447 | // Node addNode() { return graph->addNode(); } |
---|
| 1448 | // Edge addEdge(const Node& tail, const Node& head) { |
---|
[148] | 1449 | // return graph->addEdge(tail, head); } |
---|
[76] | 1450 | |
---|
[148] | 1451 | // template<typename I> void erase(const I& i) { graph->erase(i); } |
---|
[76] | 1452 | |
---|
[148] | 1453 | // void clear() { graph->clear(); } |
---|
[76] | 1454 | |
---|
[148] | 1455 | // template<typename S> class NodeMap : public Graph::NodeMap<S> { }; |
---|
| 1456 | // template<typename S> class EdgeMap : public Graph::EdgeMap<S> { }; |
---|
[76] | 1457 | |
---|
[148] | 1458 | // void setGraph(Graph& _graph) { graph = &_graph; } |
---|
| 1459 | // Graph& getGraph() { return (*graph); } |
---|
[76] | 1460 | |
---|
[148] | 1461 | // //ResGraphWrapper() : graph(0) { } |
---|
| 1462 | // ResGraphWrapper(Graph& _graph) : graph(&_graph) { } |
---|
| 1463 | // }; |
---|
[76] | 1464 | |
---|
[105] | 1465 | } //namespace hugo |
---|
[76] | 1466 | |
---|
| 1467 | #endif //GRAPH_WRAPPER_H |
---|
| 1468 | |
---|