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