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