0
2
0
| ... | ... |
@@ -91,384 +91,386 @@ |
| 91 | 91 |
|
| 92 | 92 |
// Iterable extensions |
| 93 | 93 |
|
| 94 | 94 |
class NodeIt : public Node {
|
| 95 | 95 |
const Digraph* digraph; |
| 96 | 96 |
public: |
| 97 | 97 |
|
| 98 | 98 |
NodeIt() {}
|
| 99 | 99 |
|
| 100 | 100 |
NodeIt(Invalid i) : Node(i) { }
|
| 101 | 101 |
|
| 102 | 102 |
explicit NodeIt(const Digraph& _graph) : digraph(&_graph) {
|
| 103 | 103 |
_graph.first(static_cast<Node&>(*this)); |
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 | 106 |
NodeIt(const Digraph& _graph, const Node& node) |
| 107 | 107 |
: Node(node), digraph(&_graph) {}
|
| 108 | 108 |
|
| 109 | 109 |
NodeIt& operator++() {
|
| 110 | 110 |
digraph->next(*this); |
| 111 | 111 |
return *this; |
| 112 | 112 |
} |
| 113 | 113 |
|
| 114 | 114 |
}; |
| 115 | 115 |
|
| 116 | 116 |
|
| 117 | 117 |
class ArcIt : public Arc {
|
| 118 | 118 |
const Digraph* digraph; |
| 119 | 119 |
public: |
| 120 | 120 |
|
| 121 | 121 |
ArcIt() { }
|
| 122 | 122 |
|
| 123 | 123 |
ArcIt(Invalid i) : Arc(i) { }
|
| 124 | 124 |
|
| 125 | 125 |
explicit ArcIt(const Digraph& _graph) : digraph(&_graph) {
|
| 126 | 126 |
_graph.first(static_cast<Arc&>(*this)); |
| 127 | 127 |
} |
| 128 | 128 |
|
| 129 | 129 |
ArcIt(const Digraph& _graph, const Arc& e) : |
| 130 | 130 |
Arc(e), digraph(&_graph) { }
|
| 131 | 131 |
|
| 132 | 132 |
ArcIt& operator++() {
|
| 133 | 133 |
digraph->next(*this); |
| 134 | 134 |
return *this; |
| 135 | 135 |
} |
| 136 | 136 |
|
| 137 | 137 |
}; |
| 138 | 138 |
|
| 139 | 139 |
|
| 140 | 140 |
class OutArcIt : public Arc {
|
| 141 | 141 |
const Digraph* digraph; |
| 142 | 142 |
public: |
| 143 | 143 |
|
| 144 | 144 |
OutArcIt() { }
|
| 145 | 145 |
|
| 146 | 146 |
OutArcIt(Invalid i) : Arc(i) { }
|
| 147 | 147 |
|
| 148 | 148 |
OutArcIt(const Digraph& _graph, const Node& node) |
| 149 | 149 |
: digraph(&_graph) {
|
| 150 | 150 |
_graph.firstOut(*this, node); |
| 151 | 151 |
} |
| 152 | 152 |
|
| 153 | 153 |
OutArcIt(const Digraph& _graph, const Arc& arc) |
| 154 | 154 |
: Arc(arc), digraph(&_graph) {}
|
| 155 | 155 |
|
| 156 | 156 |
OutArcIt& operator++() {
|
| 157 | 157 |
digraph->nextOut(*this); |
| 158 | 158 |
return *this; |
| 159 | 159 |
} |
| 160 | 160 |
|
| 161 | 161 |
}; |
| 162 | 162 |
|
| 163 | 163 |
|
| 164 | 164 |
class InArcIt : public Arc {
|
| 165 | 165 |
const Digraph* digraph; |
| 166 | 166 |
public: |
| 167 | 167 |
|
| 168 | 168 |
InArcIt() { }
|
| 169 | 169 |
|
| 170 | 170 |
InArcIt(Invalid i) : Arc(i) { }
|
| 171 | 171 |
|
| 172 | 172 |
InArcIt(const Digraph& _graph, const Node& node) |
| 173 | 173 |
: digraph(&_graph) {
|
| 174 | 174 |
_graph.firstIn(*this, node); |
| 175 | 175 |
} |
| 176 | 176 |
|
| 177 | 177 |
InArcIt(const Digraph& _graph, const Arc& arc) : |
| 178 | 178 |
Arc(arc), digraph(&_graph) {}
|
| 179 | 179 |
|
| 180 | 180 |
InArcIt& operator++() {
|
| 181 | 181 |
digraph->nextIn(*this); |
| 182 | 182 |
return *this; |
| 183 | 183 |
} |
| 184 | 184 |
|
| 185 | 185 |
}; |
| 186 | 186 |
|
| 187 | 187 |
// \brief Base node of the iterator |
| 188 | 188 |
// |
| 189 | 189 |
// Returns the base node (ie. the source in this case) of the iterator |
| 190 | 190 |
Node baseNode(const OutArcIt &e) const {
|
| 191 | 191 |
return Parent::source(static_cast<const Arc&>(e)); |
| 192 | 192 |
} |
| 193 | 193 |
// \brief Running node of the iterator |
| 194 | 194 |
// |
| 195 | 195 |
// Returns the running node (ie. the target in this case) of the |
| 196 | 196 |
// iterator |
| 197 | 197 |
Node runningNode(const OutArcIt &e) const {
|
| 198 | 198 |
return Parent::target(static_cast<const Arc&>(e)); |
| 199 | 199 |
} |
| 200 | 200 |
|
| 201 | 201 |
// \brief Base node of the iterator |
| 202 | 202 |
// |
| 203 | 203 |
// Returns the base node (ie. the target in this case) of the iterator |
| 204 | 204 |
Node baseNode(const InArcIt &e) const {
|
| 205 | 205 |
return Parent::target(static_cast<const Arc&>(e)); |
| 206 | 206 |
} |
| 207 | 207 |
// \brief Running node of the iterator |
| 208 | 208 |
// |
| 209 | 209 |
// Returns the running node (ie. the source in this case) of the |
| 210 | 210 |
// iterator |
| 211 | 211 |
Node runningNode(const InArcIt &e) const {
|
| 212 | 212 |
return Parent::source(static_cast<const Arc&>(e)); |
| 213 | 213 |
} |
| 214 | 214 |
|
| 215 | 215 |
using Parent::first; |
| 216 | 216 |
|
| 217 | 217 |
// Mappable extension |
| 218 | 218 |
|
| 219 | 219 |
template <typename _Value> |
| 220 | 220 |
class ArcMap |
| 221 | 221 |
: public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
|
| 222 | 222 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; |
| 223 | 223 |
|
| 224 | 224 |
public: |
| 225 | 225 |
explicit ArcMap(const Digraph& _g) |
| 226 | 226 |
: Parent(_g) {}
|
| 227 | 227 |
ArcMap(const Digraph& _g, const _Value& _v) |
| 228 | 228 |
: Parent(_g, _v) {}
|
| 229 | 229 |
|
| 230 | 230 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 231 | 231 |
return operator=<ArcMap>(cmap); |
| 232 | 232 |
} |
| 233 | 233 |
|
| 234 | 234 |
template <typename CMap> |
| 235 | 235 |
ArcMap& operator=(const CMap& cmap) {
|
| 236 | 236 |
Parent::operator=(cmap); |
| 237 | 237 |
return *this; |
| 238 | 238 |
} |
| 239 | 239 |
|
| 240 | 240 |
}; |
| 241 | 241 |
|
| 242 | 242 |
|
| 243 | 243 |
// Alteration extension |
| 244 | 244 |
|
| 245 | 245 |
Arc addArc(const Node& from, const Node& to) {
|
| 246 | 246 |
Arc arc = Parent::addArc(from, to); |
| 247 | 247 |
notifier(Arc()).add(arc); |
| 248 | 248 |
return arc; |
| 249 | 249 |
} |
| 250 | 250 |
|
| 251 | 251 |
void clear() {
|
| 252 | 252 |
notifier(Arc()).clear(); |
| 253 | 253 |
Parent::clear(); |
| 254 | 254 |
} |
| 255 | 255 |
|
| 256 | 256 |
void erase(const Arc& arc) {
|
| 257 | 257 |
notifier(Arc()).erase(arc); |
| 258 | 258 |
Parent::erase(arc); |
| 259 | 259 |
} |
| 260 | 260 |
|
| 261 | 261 |
ArcSetExtender() {
|
| 262 | 262 |
arc_notifier.setContainer(*this); |
| 263 | 263 |
} |
| 264 | 264 |
|
| 265 | 265 |
~ArcSetExtender() {
|
| 266 | 266 |
arc_notifier.clear(); |
| 267 | 267 |
} |
| 268 | 268 |
|
| 269 | 269 |
}; |
| 270 | 270 |
|
| 271 | 271 |
|
| 272 | 272 |
// \ingroup digraphbits |
| 273 | 273 |
// |
| 274 | 274 |
// \brief Extender for the EdgeSets |
| 275 | 275 |
template <typename Base> |
| 276 | 276 |
class EdgeSetExtender : public Base {
|
| 277 | 277 |
typedef Base Parent; |
| 278 | 278 |
|
| 279 | 279 |
public: |
| 280 | 280 |
|
| 281 | 281 |
typedef EdgeSetExtender Graph; |
| 282 | 282 |
|
| 283 |
typedef True UndirectedTag; |
|
| 284 |
|
|
| 283 | 285 |
typedef typename Parent::Node Node; |
| 284 | 286 |
typedef typename Parent::Arc Arc; |
| 285 | 287 |
typedef typename Parent::Edge Edge; |
| 286 | 288 |
|
| 287 | 289 |
int maxId(Node) const {
|
| 288 | 290 |
return Parent::maxNodeId(); |
| 289 | 291 |
} |
| 290 | 292 |
|
| 291 | 293 |
int maxId(Arc) const {
|
| 292 | 294 |
return Parent::maxArcId(); |
| 293 | 295 |
} |
| 294 | 296 |
|
| 295 | 297 |
int maxId(Edge) const {
|
| 296 | 298 |
return Parent::maxEdgeId(); |
| 297 | 299 |
} |
| 298 | 300 |
|
| 299 | 301 |
Node fromId(int id, Node) const {
|
| 300 | 302 |
return Parent::nodeFromId(id); |
| 301 | 303 |
} |
| 302 | 304 |
|
| 303 | 305 |
Arc fromId(int id, Arc) const {
|
| 304 | 306 |
return Parent::arcFromId(id); |
| 305 | 307 |
} |
| 306 | 308 |
|
| 307 | 309 |
Edge fromId(int id, Edge) const {
|
| 308 | 310 |
return Parent::edgeFromId(id); |
| 309 | 311 |
} |
| 310 | 312 |
|
| 311 | 313 |
Node oppositeNode(const Node &n, const Edge &e) const {
|
| 312 | 314 |
if( n == Parent::u(e)) |
| 313 | 315 |
return Parent::v(e); |
| 314 | 316 |
else if( n == Parent::v(e)) |
| 315 | 317 |
return Parent::u(e); |
| 316 | 318 |
else |
| 317 | 319 |
return INVALID; |
| 318 | 320 |
} |
| 319 | 321 |
|
| 320 | 322 |
Arc oppositeArc(const Arc &e) const {
|
| 321 | 323 |
return Parent::direct(e, !Parent::direction(e)); |
| 322 | 324 |
} |
| 323 | 325 |
|
| 324 | 326 |
using Parent::direct; |
| 325 | 327 |
Arc direct(const Edge &e, const Node &s) const {
|
| 326 | 328 |
return Parent::direct(e, Parent::u(e) == s); |
| 327 | 329 |
} |
| 328 | 330 |
|
| 329 | 331 |
typedef AlterationNotifier<EdgeSetExtender, Arc> ArcNotifier; |
| 330 | 332 |
typedef AlterationNotifier<EdgeSetExtender, Edge> EdgeNotifier; |
| 331 | 333 |
|
| 332 | 334 |
|
| 333 | 335 |
protected: |
| 334 | 336 |
|
| 335 | 337 |
mutable ArcNotifier arc_notifier; |
| 336 | 338 |
mutable EdgeNotifier edge_notifier; |
| 337 | 339 |
|
| 338 | 340 |
public: |
| 339 | 341 |
|
| 340 | 342 |
using Parent::notifier; |
| 341 | 343 |
|
| 342 | 344 |
ArcNotifier& notifier(Arc) const {
|
| 343 | 345 |
return arc_notifier; |
| 344 | 346 |
} |
| 345 | 347 |
|
| 346 | 348 |
EdgeNotifier& notifier(Edge) const {
|
| 347 | 349 |
return edge_notifier; |
| 348 | 350 |
} |
| 349 | 351 |
|
| 350 | 352 |
|
| 351 | 353 |
class NodeIt : public Node {
|
| 352 | 354 |
const Graph* graph; |
| 353 | 355 |
public: |
| 354 | 356 |
|
| 355 | 357 |
NodeIt() {}
|
| 356 | 358 |
|
| 357 | 359 |
NodeIt(Invalid i) : Node(i) { }
|
| 358 | 360 |
|
| 359 | 361 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
| 360 | 362 |
_graph.first(static_cast<Node&>(*this)); |
| 361 | 363 |
} |
| 362 | 364 |
|
| 363 | 365 |
NodeIt(const Graph& _graph, const Node& node) |
| 364 | 366 |
: Node(node), graph(&_graph) {}
|
| 365 | 367 |
|
| 366 | 368 |
NodeIt& operator++() {
|
| 367 | 369 |
graph->next(*this); |
| 368 | 370 |
return *this; |
| 369 | 371 |
} |
| 370 | 372 |
|
| 371 | 373 |
}; |
| 372 | 374 |
|
| 373 | 375 |
|
| 374 | 376 |
class ArcIt : public Arc {
|
| 375 | 377 |
const Graph* graph; |
| 376 | 378 |
public: |
| 377 | 379 |
|
| 378 | 380 |
ArcIt() { }
|
| 379 | 381 |
|
| 380 | 382 |
ArcIt(Invalid i) : Arc(i) { }
|
| 381 | 383 |
|
| 382 | 384 |
explicit ArcIt(const Graph& _graph) : graph(&_graph) {
|
| 383 | 385 |
_graph.first(static_cast<Arc&>(*this)); |
| 384 | 386 |
} |
| 385 | 387 |
|
| 386 | 388 |
ArcIt(const Graph& _graph, const Arc& e) : |
| 387 | 389 |
Arc(e), graph(&_graph) { }
|
| 388 | 390 |
|
| 389 | 391 |
ArcIt& operator++() {
|
| 390 | 392 |
graph->next(*this); |
| 391 | 393 |
return *this; |
| 392 | 394 |
} |
| 393 | 395 |
|
| 394 | 396 |
}; |
| 395 | 397 |
|
| 396 | 398 |
|
| 397 | 399 |
class OutArcIt : public Arc {
|
| 398 | 400 |
const Graph* graph; |
| 399 | 401 |
public: |
| 400 | 402 |
|
| 401 | 403 |
OutArcIt() { }
|
| 402 | 404 |
|
| 403 | 405 |
OutArcIt(Invalid i) : Arc(i) { }
|
| 404 | 406 |
|
| 405 | 407 |
OutArcIt(const Graph& _graph, const Node& node) |
| 406 | 408 |
: graph(&_graph) {
|
| 407 | 409 |
_graph.firstOut(*this, node); |
| 408 | 410 |
} |
| 409 | 411 |
|
| 410 | 412 |
OutArcIt(const Graph& _graph, const Arc& arc) |
| 411 | 413 |
: Arc(arc), graph(&_graph) {}
|
| 412 | 414 |
|
| 413 | 415 |
OutArcIt& operator++() {
|
| 414 | 416 |
graph->nextOut(*this); |
| 415 | 417 |
return *this; |
| 416 | 418 |
} |
| 417 | 419 |
|
| 418 | 420 |
}; |
| 419 | 421 |
|
| 420 | 422 |
|
| 421 | 423 |
class InArcIt : public Arc {
|
| 422 | 424 |
const Graph* graph; |
| 423 | 425 |
public: |
| 424 | 426 |
|
| 425 | 427 |
InArcIt() { }
|
| 426 | 428 |
|
| 427 | 429 |
InArcIt(Invalid i) : Arc(i) { }
|
| 428 | 430 |
|
| 429 | 431 |
InArcIt(const Graph& _graph, const Node& node) |
| 430 | 432 |
: graph(&_graph) {
|
| 431 | 433 |
_graph.firstIn(*this, node); |
| 432 | 434 |
} |
| 433 | 435 |
|
| 434 | 436 |
InArcIt(const Graph& _graph, const Arc& arc) : |
| 435 | 437 |
Arc(arc), graph(&_graph) {}
|
| 436 | 438 |
|
| 437 | 439 |
InArcIt& operator++() {
|
| 438 | 440 |
graph->nextIn(*this); |
| 439 | 441 |
return *this; |
| 440 | 442 |
} |
| 441 | 443 |
|
| 442 | 444 |
}; |
| 443 | 445 |
|
| 444 | 446 |
|
| 445 | 447 |
class EdgeIt : public Parent::Edge {
|
| 446 | 448 |
const Graph* graph; |
| 447 | 449 |
public: |
| 448 | 450 |
|
| 449 | 451 |
EdgeIt() { }
|
| 450 | 452 |
|
| 451 | 453 |
EdgeIt(Invalid i) : Edge(i) { }
|
| 452 | 454 |
|
| 453 | 455 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
| 454 | 456 |
_graph.first(static_cast<Edge&>(*this)); |
| 455 | 457 |
} |
| 456 | 458 |
|
| 457 | 459 |
EdgeIt(const Graph& _graph, const Edge& e) : |
| 458 | 460 |
Edge(e), graph(&_graph) { }
|
| 459 | 461 |
|
| 460 | 462 |
EdgeIt& operator++() {
|
| 461 | 463 |
graph->next(*this); |
| 462 | 464 |
return *this; |
| 463 | 465 |
} |
| 464 | 466 |
|
| 465 | 467 |
}; |
| 466 | 468 |
|
| 467 | 469 |
class IncEdgeIt : public Parent::Edge {
|
| 468 | 470 |
friend class EdgeSetExtender; |
| 469 | 471 |
const Graph* graph; |
| 470 | 472 |
bool direction; |
| 471 | 473 |
public: |
| 472 | 474 |
|
| 473 | 475 |
IncEdgeIt() { }
|
| 474 | 476 |
| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2009 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#ifndef LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H |
| 20 | 20 |
#define LEMON_BITS_GRAPH_ADAPTOR_EXTENDER_H |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/core.h> |
| 23 | 23 |
#include <lemon/error.h> |
| 24 | 24 |
|
| 25 | 25 |
namespace lemon {
|
| 26 | 26 |
|
| 27 | 27 |
template <typename _Digraph> |
| 28 | 28 |
class DigraphAdaptorExtender : public _Digraph {
|
| 29 | 29 |
typedef _Digraph Parent; |
| 30 | 30 |
|
| 31 | 31 |
public: |
| 32 | 32 |
|
| 33 | 33 |
typedef _Digraph Digraph; |
| 34 | 34 |
typedef DigraphAdaptorExtender Adaptor; |
| 35 | 35 |
|
| 36 | 36 |
// Base extensions |
| 37 | 37 |
|
| 38 | 38 |
typedef typename Parent::Node Node; |
| 39 | 39 |
typedef typename Parent::Arc Arc; |
| 40 | 40 |
|
| 41 | 41 |
int maxId(Node) const {
|
| 42 | 42 |
return Parent::maxNodeId(); |
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 | 45 |
int maxId(Arc) const {
|
| 46 | 46 |
return Parent::maxArcId(); |
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 | 49 |
Node fromId(int id, Node) const {
|
| 50 | 50 |
return Parent::nodeFromId(id); |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 | 53 |
Arc fromId(int id, Arc) const {
|
| 54 | 54 |
return Parent::arcFromId(id); |
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 | 57 |
Node oppositeNode(const Node &n, const Arc &e) const {
|
| 58 | 58 |
if (n == Parent::source(e)) |
| 59 | 59 |
return Parent::target(e); |
| 60 | 60 |
else if(n==Parent::target(e)) |
| 61 | 61 |
return Parent::source(e); |
| 62 | 62 |
else |
| 63 | 63 |
return INVALID; |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 | 66 |
class NodeIt : public Node {
|
| 67 | 67 |
const Adaptor* _adaptor; |
| 68 | 68 |
public: |
| 69 | 69 |
|
| 70 | 70 |
NodeIt() {}
|
| 71 | 71 |
|
| 72 | 72 |
NodeIt(Invalid i) : Node(i) { }
|
| 73 | 73 |
|
| 74 | 74 |
explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
|
| 75 | 75 |
_adaptor->first(static_cast<Node&>(*this)); |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 | 78 |
NodeIt(const Adaptor& adaptor, const Node& node) |
| 79 | 79 |
: Node(node), _adaptor(&adaptor) {}
|
| 80 | 80 |
|
| 81 | 81 |
NodeIt& operator++() {
|
| 82 | 82 |
_adaptor->next(*this); |
| 83 | 83 |
return *this; |
| 84 | 84 |
} |
| 85 | 85 |
|
| 86 | 86 |
}; |
| 87 | 87 |
|
| 88 | 88 |
|
| 89 | 89 |
class ArcIt : public Arc {
|
| 90 | 90 |
const Adaptor* _adaptor; |
| 91 | 91 |
public: |
| 92 | 92 |
|
| 93 | 93 |
ArcIt() { }
|
| 94 | 94 |
|
| 95 | 95 |
ArcIt(Invalid i) : Arc(i) { }
|
| 96 | 96 |
|
| 97 | 97 |
explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
|
| 98 | 98 |
_adaptor->first(static_cast<Arc&>(*this)); |
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 | 101 |
ArcIt(const Adaptor& adaptor, const Arc& e) : |
| 102 | 102 |
Arc(e), _adaptor(&adaptor) { }
|
| 103 | 103 |
|
| 104 | 104 |
ArcIt& operator++() {
|
| 105 | 105 |
_adaptor->next(*this); |
| 106 | 106 |
return *this; |
| 107 | 107 |
} |
| 108 | 108 |
|
| 109 | 109 |
}; |
| 110 | 110 |
|
| 111 | 111 |
|
| 112 | 112 |
class OutArcIt : public Arc {
|
| 113 | 113 |
const Adaptor* _adaptor; |
| 114 | 114 |
public: |
| 115 | 115 |
|
| 116 | 116 |
OutArcIt() { }
|
| 117 | 117 |
|
| 118 | 118 |
OutArcIt(Invalid i) : Arc(i) { }
|
| 119 | 119 |
|
| 120 | 120 |
OutArcIt(const Adaptor& adaptor, const Node& node) |
| 121 | 121 |
: _adaptor(&adaptor) {
|
| 122 | 122 |
_adaptor->firstOut(*this, node); |
| 123 | 123 |
} |
| 124 | 124 |
|
| 125 | 125 |
OutArcIt(const Adaptor& adaptor, const Arc& arc) |
| 126 | 126 |
: Arc(arc), _adaptor(&adaptor) {}
|
| 127 | 127 |
|
| 128 | 128 |
OutArcIt& operator++() {
|
| 129 | 129 |
_adaptor->nextOut(*this); |
| 130 | 130 |
return *this; |
| 131 | 131 |
} |
| 132 | 132 |
|
| 133 | 133 |
}; |
| 134 | 134 |
|
| 135 | 135 |
|
| 136 | 136 |
class InArcIt : public Arc {
|
| 137 | 137 |
const Adaptor* _adaptor; |
| 138 | 138 |
public: |
| 139 | 139 |
|
| 140 | 140 |
InArcIt() { }
|
| 141 | 141 |
|
| 142 | 142 |
InArcIt(Invalid i) : Arc(i) { }
|
| 143 | 143 |
|
| 144 | 144 |
InArcIt(const Adaptor& adaptor, const Node& node) |
| 145 | 145 |
: _adaptor(&adaptor) {
|
| 146 | 146 |
_adaptor->firstIn(*this, node); |
| 147 | 147 |
} |
| 148 | 148 |
|
| 149 | 149 |
InArcIt(const Adaptor& adaptor, const Arc& arc) : |
| 150 | 150 |
Arc(arc), _adaptor(&adaptor) {}
|
| 151 | 151 |
|
| 152 | 152 |
InArcIt& operator++() {
|
| 153 | 153 |
_adaptor->nextIn(*this); |
| 154 | 154 |
return *this; |
| 155 | 155 |
} |
| 156 | 156 |
|
| 157 | 157 |
}; |
| 158 | 158 |
|
| 159 | 159 |
Node baseNode(const OutArcIt &e) const {
|
| 160 | 160 |
return Parent::source(e); |
| 161 | 161 |
} |
| 162 | 162 |
Node runningNode(const OutArcIt &e) const {
|
| 163 | 163 |
return Parent::target(e); |
| 164 | 164 |
} |
| 165 | 165 |
|
| 166 | 166 |
Node baseNode(const InArcIt &e) const {
|
| 167 | 167 |
return Parent::target(e); |
| 168 | 168 |
} |
| 169 | 169 |
Node runningNode(const InArcIt &e) const {
|
| 170 | 170 |
return Parent::source(e); |
| 171 | 171 |
} |
| 172 | 172 |
|
| 173 | 173 |
}; |
| 174 | 174 |
|
| 175 | 175 |
template <typename _Graph> |
| 176 | 176 |
class GraphAdaptorExtender : public _Graph {
|
| 177 | 177 |
typedef _Graph Parent; |
| 178 | 178 |
|
| 179 | 179 |
public: |
| 180 | 180 |
|
| 181 | 181 |
typedef _Graph Graph; |
| 182 | 182 |
typedef GraphAdaptorExtender Adaptor; |
| 183 | 183 |
|
| 184 |
typedef True UndirectedTag; |
|
| 185 |
|
|
| 184 | 186 |
typedef typename Parent::Node Node; |
| 185 | 187 |
typedef typename Parent::Arc Arc; |
| 186 | 188 |
typedef typename Parent::Edge Edge; |
| 187 | 189 |
|
| 188 | 190 |
// Graph extension |
| 189 | 191 |
|
| 190 | 192 |
int maxId(Node) const {
|
| 191 | 193 |
return Parent::maxNodeId(); |
| 192 | 194 |
} |
| 193 | 195 |
|
| 194 | 196 |
int maxId(Arc) const {
|
| 195 | 197 |
return Parent::maxArcId(); |
| 196 | 198 |
} |
| 197 | 199 |
|
| 198 | 200 |
int maxId(Edge) const {
|
| 199 | 201 |
return Parent::maxEdgeId(); |
| 200 | 202 |
} |
| 201 | 203 |
|
| 202 | 204 |
Node fromId(int id, Node) const {
|
| 203 | 205 |
return Parent::nodeFromId(id); |
| 204 | 206 |
} |
| 205 | 207 |
|
| 206 | 208 |
Arc fromId(int id, Arc) const {
|
| 207 | 209 |
return Parent::arcFromId(id); |
| 208 | 210 |
} |
| 209 | 211 |
|
| 210 | 212 |
Edge fromId(int id, Edge) const {
|
| 211 | 213 |
return Parent::edgeFromId(id); |
| 212 | 214 |
} |
| 213 | 215 |
|
| 214 | 216 |
Node oppositeNode(const Node &n, const Edge &e) const {
|
| 215 | 217 |
if( n == Parent::u(e)) |
| 216 | 218 |
return Parent::v(e); |
| 217 | 219 |
else if( n == Parent::v(e)) |
| 218 | 220 |
return Parent::u(e); |
| 219 | 221 |
else |
| 220 | 222 |
return INVALID; |
| 221 | 223 |
} |
| 222 | 224 |
|
| 223 | 225 |
Arc oppositeArc(const Arc &a) const {
|
| 224 | 226 |
return Parent::direct(a, !Parent::direction(a)); |
| 225 | 227 |
} |
| 226 | 228 |
|
| 227 | 229 |
using Parent::direct; |
| 228 | 230 |
Arc direct(const Edge &e, const Node &s) const {
|
| 229 | 231 |
return Parent::direct(e, Parent::u(e) == s); |
| 230 | 232 |
} |
| 231 | 233 |
|
| 232 | 234 |
|
| 233 | 235 |
class NodeIt : public Node {
|
| 234 | 236 |
const Adaptor* _adaptor; |
| 235 | 237 |
public: |
| 236 | 238 |
|
| 237 | 239 |
NodeIt() {}
|
| 238 | 240 |
|
| 239 | 241 |
NodeIt(Invalid i) : Node(i) { }
|
| 240 | 242 |
|
| 241 | 243 |
explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
|
| 242 | 244 |
_adaptor->first(static_cast<Node&>(*this)); |
| 243 | 245 |
} |
| 244 | 246 |
|
| 245 | 247 |
NodeIt(const Adaptor& adaptor, const Node& node) |
| 246 | 248 |
: Node(node), _adaptor(&adaptor) {}
|
| 247 | 249 |
|
| 248 | 250 |
NodeIt& operator++() {
|
| 249 | 251 |
_adaptor->next(*this); |
| 250 | 252 |
return *this; |
| 251 | 253 |
} |
| 252 | 254 |
|
| 253 | 255 |
}; |
| 254 | 256 |
|
| 255 | 257 |
|
| 256 | 258 |
class ArcIt : public Arc {
|
| 257 | 259 |
const Adaptor* _adaptor; |
| 258 | 260 |
public: |
| 259 | 261 |
|
| 260 | 262 |
ArcIt() { }
|
| 261 | 263 |
|
| 262 | 264 |
ArcIt(Invalid i) : Arc(i) { }
|
| 263 | 265 |
|
| 264 | 266 |
explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
|
| 265 | 267 |
_adaptor->first(static_cast<Arc&>(*this)); |
| 266 | 268 |
} |
| 267 | 269 |
|
| 268 | 270 |
ArcIt(const Adaptor& adaptor, const Arc& e) : |
| 269 | 271 |
Arc(e), _adaptor(&adaptor) { }
|
| 270 | 272 |
|
| 271 | 273 |
ArcIt& operator++() {
|
| 272 | 274 |
_adaptor->next(*this); |
| 273 | 275 |
return *this; |
| 274 | 276 |
} |
| 275 | 277 |
|
| 276 | 278 |
}; |
| 277 | 279 |
|
| 278 | 280 |
|
| 279 | 281 |
class OutArcIt : public Arc {
|
| 280 | 282 |
const Adaptor* _adaptor; |
| 281 | 283 |
public: |
| 282 | 284 |
|
| 283 | 285 |
OutArcIt() { }
|
| 284 | 286 |
|
| 285 | 287 |
OutArcIt(Invalid i) : Arc(i) { }
|
| 286 | 288 |
|
| 287 | 289 |
OutArcIt(const Adaptor& adaptor, const Node& node) |
| 288 | 290 |
: _adaptor(&adaptor) {
|
| 289 | 291 |
_adaptor->firstOut(*this, node); |
| 290 | 292 |
} |
| 291 | 293 |
|
| 292 | 294 |
OutArcIt(const Adaptor& adaptor, const Arc& arc) |
| 293 | 295 |
: Arc(arc), _adaptor(&adaptor) {}
|
| 294 | 296 |
|
| 295 | 297 |
OutArcIt& operator++() {
|
| 296 | 298 |
_adaptor->nextOut(*this); |
| 297 | 299 |
return *this; |
| 298 | 300 |
} |
| 299 | 301 |
|
| 300 | 302 |
}; |
| 301 | 303 |
|
| 302 | 304 |
|
| 303 | 305 |
class InArcIt : public Arc {
|
| 304 | 306 |
const Adaptor* _adaptor; |
| 305 | 307 |
public: |
| 306 | 308 |
|
| 307 | 309 |
InArcIt() { }
|
| 308 | 310 |
|
| 309 | 311 |
InArcIt(Invalid i) : Arc(i) { }
|
| 310 | 312 |
|
| 311 | 313 |
InArcIt(const Adaptor& adaptor, const Node& node) |
| 312 | 314 |
: _adaptor(&adaptor) {
|
| 313 | 315 |
_adaptor->firstIn(*this, node); |
| 314 | 316 |
} |
| 315 | 317 |
|
| 316 | 318 |
InArcIt(const Adaptor& adaptor, const Arc& arc) : |
| 317 | 319 |
Arc(arc), _adaptor(&adaptor) {}
|
| 318 | 320 |
|
| 319 | 321 |
InArcIt& operator++() {
|
| 320 | 322 |
_adaptor->nextIn(*this); |
| 321 | 323 |
return *this; |
| 322 | 324 |
} |
| 323 | 325 |
|
| 324 | 326 |
}; |
| 325 | 327 |
|
| 326 | 328 |
class EdgeIt : public Parent::Edge {
|
| 327 | 329 |
const Adaptor* _adaptor; |
| 328 | 330 |
public: |
| 329 | 331 |
|
| 330 | 332 |
EdgeIt() { }
|
| 331 | 333 |
|
| 332 | 334 |
EdgeIt(Invalid i) : Edge(i) { }
|
| 333 | 335 |
|
| 334 | 336 |
explicit EdgeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
|
| 335 | 337 |
_adaptor->first(static_cast<Edge&>(*this)); |
| 336 | 338 |
} |
| 337 | 339 |
|
| 338 | 340 |
EdgeIt(const Adaptor& adaptor, const Edge& e) : |
| 339 | 341 |
Edge(e), _adaptor(&adaptor) { }
|
| 340 | 342 |
|
| 341 | 343 |
EdgeIt& operator++() {
|
| 342 | 344 |
_adaptor->next(*this); |
| 343 | 345 |
return *this; |
| 344 | 346 |
} |
| 345 | 347 |
|
| 346 | 348 |
}; |
| 347 | 349 |
|
| 348 | 350 |
class IncEdgeIt : public Edge {
|
| 349 | 351 |
friend class GraphAdaptorExtender; |
| 350 | 352 |
const Adaptor* _adaptor; |
| 351 | 353 |
bool direction; |
| 352 | 354 |
public: |
| 353 | 355 |
|
| 354 | 356 |
IncEdgeIt() { }
|
| 355 | 357 |
|
| 356 | 358 |
IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
|
| 357 | 359 |
|
| 358 | 360 |
IncEdgeIt(const Adaptor& adaptor, const Node &n) : _adaptor(&adaptor) {
|
| 359 | 361 |
_adaptor->firstInc(static_cast<Edge&>(*this), direction, n); |
| 360 | 362 |
} |
| 361 | 363 |
|
| 362 | 364 |
IncEdgeIt(const Adaptor& adaptor, const Edge &e, const Node &n) |
| 363 | 365 |
: _adaptor(&adaptor), Edge(e) {
|
| 364 | 366 |
direction = (_adaptor->u(e) == n); |
| 365 | 367 |
} |
| 366 | 368 |
|
| 367 | 369 |
IncEdgeIt& operator++() {
|
| 368 | 370 |
_adaptor->nextInc(*this, direction); |
| 369 | 371 |
return *this; |
| 370 | 372 |
} |
| 371 | 373 |
}; |
| 372 | 374 |
|
| 373 | 375 |
Node baseNode(const OutArcIt &a) const {
|
| 374 | 376 |
return Parent::source(a); |
| 375 | 377 |
} |
0 comments (0 inline)