0
4
0
| ... | ... |
@@ -156,470 +156,470 @@ |
| 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 | 283 |
typedef typename Parent::Node Node; |
| 284 | 284 |
typedef typename Parent::Arc Arc; |
| 285 | 285 |
typedef typename Parent::Edge Edge; |
| 286 | 286 |
|
| 287 | 287 |
int maxId(Node) const {
|
| 288 | 288 |
return Parent::maxNodeId(); |
| 289 | 289 |
} |
| 290 | 290 |
|
| 291 | 291 |
int maxId(Arc) const {
|
| 292 | 292 |
return Parent::maxArcId(); |
| 293 | 293 |
} |
| 294 | 294 |
|
| 295 | 295 |
int maxId(Edge) const {
|
| 296 | 296 |
return Parent::maxEdgeId(); |
| 297 | 297 |
} |
| 298 | 298 |
|
| 299 | 299 |
Node fromId(int id, Node) const {
|
| 300 | 300 |
return Parent::nodeFromId(id); |
| 301 | 301 |
} |
| 302 | 302 |
|
| 303 | 303 |
Arc fromId(int id, Arc) const {
|
| 304 | 304 |
return Parent::arcFromId(id); |
| 305 | 305 |
} |
| 306 | 306 |
|
| 307 | 307 |
Edge fromId(int id, Edge) const {
|
| 308 | 308 |
return Parent::edgeFromId(id); |
| 309 | 309 |
} |
| 310 | 310 |
|
| 311 | 311 |
Node oppositeNode(const Node &n, const Edge &e) const {
|
| 312 | 312 |
if( n == Parent::u(e)) |
| 313 | 313 |
return Parent::v(e); |
| 314 | 314 |
else if( n == Parent::v(e)) |
| 315 | 315 |
return Parent::u(e); |
| 316 | 316 |
else |
| 317 | 317 |
return INVALID; |
| 318 | 318 |
} |
| 319 | 319 |
|
| 320 | 320 |
Arc oppositeArc(const Arc &e) const {
|
| 321 | 321 |
return Parent::direct(e, !Parent::direction(e)); |
| 322 | 322 |
} |
| 323 | 323 |
|
| 324 | 324 |
using Parent::direct; |
| 325 | 325 |
Arc direct(const Edge &e, const Node &s) const {
|
| 326 | 326 |
return Parent::direct(e, Parent::u(e) == s); |
| 327 | 327 |
} |
| 328 | 328 |
|
| 329 | 329 |
typedef AlterationNotifier<EdgeSetExtender, Arc> ArcNotifier; |
| 330 | 330 |
typedef AlterationNotifier<EdgeSetExtender, Edge> EdgeNotifier; |
| 331 | 331 |
|
| 332 | 332 |
|
| 333 | 333 |
protected: |
| 334 | 334 |
|
| 335 | 335 |
mutable ArcNotifier arc_notifier; |
| 336 | 336 |
mutable EdgeNotifier edge_notifier; |
| 337 | 337 |
|
| 338 | 338 |
public: |
| 339 | 339 |
|
| 340 | 340 |
using Parent::notifier; |
| 341 | 341 |
|
| 342 | 342 |
ArcNotifier& notifier(Arc) const {
|
| 343 | 343 |
return arc_notifier; |
| 344 | 344 |
} |
| 345 | 345 |
|
| 346 | 346 |
EdgeNotifier& notifier(Edge) const {
|
| 347 | 347 |
return edge_notifier; |
| 348 | 348 |
} |
| 349 | 349 |
|
| 350 | 350 |
|
| 351 | 351 |
class NodeIt : public Node {
|
| 352 | 352 |
const Graph* graph; |
| 353 | 353 |
public: |
| 354 | 354 |
|
| 355 | 355 |
NodeIt() {}
|
| 356 | 356 |
|
| 357 | 357 |
NodeIt(Invalid i) : Node(i) { }
|
| 358 | 358 |
|
| 359 | 359 |
explicit NodeIt(const Graph& _graph) : graph(&_graph) {
|
| 360 | 360 |
_graph.first(static_cast<Node&>(*this)); |
| 361 | 361 |
} |
| 362 | 362 |
|
| 363 | 363 |
NodeIt(const Graph& _graph, const Node& node) |
| 364 | 364 |
: Node(node), graph(&_graph) {}
|
| 365 | 365 |
|
| 366 | 366 |
NodeIt& operator++() {
|
| 367 | 367 |
graph->next(*this); |
| 368 | 368 |
return *this; |
| 369 | 369 |
} |
| 370 | 370 |
|
| 371 | 371 |
}; |
| 372 | 372 |
|
| 373 | 373 |
|
| 374 | 374 |
class ArcIt : public Arc {
|
| 375 | 375 |
const Graph* graph; |
| 376 | 376 |
public: |
| 377 | 377 |
|
| 378 | 378 |
ArcIt() { }
|
| 379 | 379 |
|
| 380 | 380 |
ArcIt(Invalid i) : Arc(i) { }
|
| 381 | 381 |
|
| 382 | 382 |
explicit ArcIt(const Graph& _graph) : graph(&_graph) {
|
| 383 | 383 |
_graph.first(static_cast<Arc&>(*this)); |
| 384 | 384 |
} |
| 385 | 385 |
|
| 386 | 386 |
ArcIt(const Graph& _graph, const Arc& e) : |
| 387 | 387 |
Arc(e), graph(&_graph) { }
|
| 388 | 388 |
|
| 389 | 389 |
ArcIt& operator++() {
|
| 390 | 390 |
graph->next(*this); |
| 391 | 391 |
return *this; |
| 392 | 392 |
} |
| 393 | 393 |
|
| 394 | 394 |
}; |
| 395 | 395 |
|
| 396 | 396 |
|
| 397 | 397 |
class OutArcIt : public Arc {
|
| 398 | 398 |
const Graph* graph; |
| 399 | 399 |
public: |
| 400 | 400 |
|
| 401 | 401 |
OutArcIt() { }
|
| 402 | 402 |
|
| 403 | 403 |
OutArcIt(Invalid i) : Arc(i) { }
|
| 404 | 404 |
|
| 405 | 405 |
OutArcIt(const Graph& _graph, const Node& node) |
| 406 | 406 |
: graph(&_graph) {
|
| 407 | 407 |
_graph.firstOut(*this, node); |
| 408 | 408 |
} |
| 409 | 409 |
|
| 410 | 410 |
OutArcIt(const Graph& _graph, const Arc& arc) |
| 411 | 411 |
: Arc(arc), graph(&_graph) {}
|
| 412 | 412 |
|
| 413 | 413 |
OutArcIt& operator++() {
|
| 414 | 414 |
graph->nextOut(*this); |
| 415 | 415 |
return *this; |
| 416 | 416 |
} |
| 417 | 417 |
|
| 418 | 418 |
}; |
| 419 | 419 |
|
| 420 | 420 |
|
| 421 | 421 |
class InArcIt : public Arc {
|
| 422 | 422 |
const Graph* graph; |
| 423 | 423 |
public: |
| 424 | 424 |
|
| 425 | 425 |
InArcIt() { }
|
| 426 | 426 |
|
| 427 | 427 |
InArcIt(Invalid i) : Arc(i) { }
|
| 428 | 428 |
|
| 429 | 429 |
InArcIt(const Graph& _graph, const Node& node) |
| 430 | 430 |
: graph(&_graph) {
|
| 431 | 431 |
_graph.firstIn(*this, node); |
| 432 | 432 |
} |
| 433 | 433 |
|
| 434 | 434 |
InArcIt(const Graph& _graph, const Arc& arc) : |
| 435 | 435 |
Arc(arc), graph(&_graph) {}
|
| 436 | 436 |
|
| 437 | 437 |
InArcIt& operator++() {
|
| 438 | 438 |
graph->nextIn(*this); |
| 439 | 439 |
return *this; |
| 440 | 440 |
} |
| 441 | 441 |
|
| 442 | 442 |
}; |
| 443 | 443 |
|
| 444 | 444 |
|
| 445 | 445 |
class EdgeIt : public Parent::Edge {
|
| 446 | 446 |
const Graph* graph; |
| 447 | 447 |
public: |
| 448 | 448 |
|
| 449 | 449 |
EdgeIt() { }
|
| 450 | 450 |
|
| 451 | 451 |
EdgeIt(Invalid i) : Edge(i) { }
|
| 452 | 452 |
|
| 453 | 453 |
explicit EdgeIt(const Graph& _graph) : graph(&_graph) {
|
| 454 | 454 |
_graph.first(static_cast<Edge&>(*this)); |
| 455 | 455 |
} |
| 456 | 456 |
|
| 457 | 457 |
EdgeIt(const Graph& _graph, const Edge& e) : |
| 458 | 458 |
Edge(e), graph(&_graph) { }
|
| 459 | 459 |
|
| 460 | 460 |
EdgeIt& operator++() {
|
| 461 | 461 |
graph->next(*this); |
| 462 | 462 |
return *this; |
| 463 | 463 |
} |
| 464 | 464 |
|
| 465 | 465 |
}; |
| 466 | 466 |
|
| 467 | 467 |
class IncEdgeIt : public Parent::Edge {
|
| 468 | 468 |
friend class EdgeSetExtender; |
| 469 | 469 |
const Graph* graph; |
| 470 | 470 |
bool direction; |
| 471 | 471 |
public: |
| 472 | 472 |
|
| 473 | 473 |
IncEdgeIt() { }
|
| 474 | 474 |
|
| 475 | 475 |
IncEdgeIt(Invalid i) : Edge(i), direction(false) { }
|
| 476 | 476 |
|
| 477 | 477 |
IncEdgeIt(const Graph& _graph, const Node &n) : graph(&_graph) {
|
| 478 | 478 |
_graph.firstInc(*this, direction, n); |
| 479 | 479 |
} |
| 480 | 480 |
|
| 481 | 481 |
IncEdgeIt(const Graph& _graph, const Edge &ue, const Node &n) |
| 482 | 482 |
: graph(&_graph), Edge(ue) {
|
| 483 | 483 |
direction = (_graph.source(ue) == n); |
| 484 | 484 |
} |
| 485 | 485 |
|
| 486 | 486 |
IncEdgeIt& operator++() {
|
| 487 | 487 |
graph->nextInc(*this, direction); |
| 488 | 488 |
return *this; |
| 489 | 489 |
} |
| 490 | 490 |
}; |
| 491 | 491 |
|
| 492 | 492 |
// \brief Base node of the iterator |
| 493 | 493 |
// |
| 494 | 494 |
// Returns the base node (ie. the source in this case) of the iterator |
| 495 | 495 |
Node baseNode(const OutArcIt &e) const {
|
| 496 | 496 |
return Parent::source(static_cast<const Arc&>(e)); |
| 497 | 497 |
} |
| 498 | 498 |
// \brief Running node of the iterator |
| 499 | 499 |
// |
| 500 | 500 |
// Returns the running node (ie. the target in this case) of the |
| 501 | 501 |
// iterator |
| 502 | 502 |
Node runningNode(const OutArcIt &e) const {
|
| 503 | 503 |
return Parent::target(static_cast<const Arc&>(e)); |
| 504 | 504 |
} |
| 505 | 505 |
|
| 506 | 506 |
// \brief Base node of the iterator |
| 507 | 507 |
// |
| 508 | 508 |
// Returns the base node (ie. the target in this case) of the iterator |
| 509 | 509 |
Node baseNode(const InArcIt &e) const {
|
| 510 | 510 |
return Parent::target(static_cast<const Arc&>(e)); |
| 511 | 511 |
} |
| 512 | 512 |
// \brief Running node of the iterator |
| 513 | 513 |
// |
| 514 | 514 |
// Returns the running node (ie. the source in this case) of the |
| 515 | 515 |
// iterator |
| 516 | 516 |
Node runningNode(const InArcIt &e) const {
|
| 517 | 517 |
return Parent::source(static_cast<const Arc&>(e)); |
| 518 | 518 |
} |
| 519 | 519 |
|
| 520 | 520 |
// Base node of the iterator |
| 521 | 521 |
// |
| 522 | 522 |
// Returns the base node of the iterator |
| 523 | 523 |
Node baseNode(const IncEdgeIt &e) const {
|
| 524 | 524 |
return e.direction ? u(e) : v(e); |
| 525 | 525 |
} |
| 526 | 526 |
// Running node of the iterator |
| 527 | 527 |
// |
| 528 | 528 |
// Returns the running node of the iterator |
| 529 | 529 |
Node runningNode(const IncEdgeIt &e) const {
|
| 530 | 530 |
return e.direction ? v(e) : u(e); |
| 531 | 531 |
} |
| 532 | 532 |
|
| 533 | 533 |
|
| 534 | 534 |
template <typename _Value> |
| 535 | 535 |
class ArcMap |
| 536 | 536 |
: public MapExtender<DefaultMap<Graph, Arc, _Value> > {
|
| 537 | 537 |
typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; |
| 538 | 538 |
|
| 539 | 539 |
public: |
| 540 |
ArcMap(const Graph& _g) |
|
| 540 |
explicit ArcMap(const Graph& _g) |
|
| 541 | 541 |
: Parent(_g) {}
|
| 542 | 542 |
ArcMap(const Graph& _g, const _Value& _v) |
| 543 | 543 |
: Parent(_g, _v) {}
|
| 544 | 544 |
|
| 545 | 545 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 546 | 546 |
return operator=<ArcMap>(cmap); |
| 547 | 547 |
} |
| 548 | 548 |
|
| 549 | 549 |
template <typename CMap> |
| 550 | 550 |
ArcMap& operator=(const CMap& cmap) {
|
| 551 | 551 |
Parent::operator=(cmap); |
| 552 | 552 |
return *this; |
| 553 | 553 |
} |
| 554 | 554 |
|
| 555 | 555 |
}; |
| 556 | 556 |
|
| 557 | 557 |
|
| 558 | 558 |
template <typename _Value> |
| 559 | 559 |
class EdgeMap |
| 560 | 560 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > {
|
| 561 | 561 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; |
| 562 | 562 |
|
| 563 | 563 |
public: |
| 564 |
EdgeMap(const Graph& _g) |
|
| 564 |
explicit EdgeMap(const Graph& _g) |
|
| 565 | 565 |
: Parent(_g) {}
|
| 566 | 566 |
|
| 567 | 567 |
EdgeMap(const Graph& _g, const _Value& _v) |
| 568 | 568 |
: Parent(_g, _v) {}
|
| 569 | 569 |
|
| 570 | 570 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 571 | 571 |
return operator=<EdgeMap>(cmap); |
| 572 | 572 |
} |
| 573 | 573 |
|
| 574 | 574 |
template <typename CMap> |
| 575 | 575 |
EdgeMap& operator=(const CMap& cmap) {
|
| 576 | 576 |
Parent::operator=(cmap); |
| 577 | 577 |
return *this; |
| 578 | 578 |
} |
| 579 | 579 |
|
| 580 | 580 |
}; |
| 581 | 581 |
|
| 582 | 582 |
|
| 583 | 583 |
// Alteration extension |
| 584 | 584 |
|
| 585 | 585 |
Edge addEdge(const Node& from, const Node& to) {
|
| 586 | 586 |
Edge edge = Parent::addEdge(from, to); |
| 587 | 587 |
notifier(Edge()).add(edge); |
| 588 | 588 |
std::vector<Arc> arcs; |
| 589 | 589 |
arcs.push_back(Parent::direct(edge, true)); |
| 590 | 590 |
arcs.push_back(Parent::direct(edge, false)); |
| 591 | 591 |
notifier(Arc()).add(arcs); |
| 592 | 592 |
return edge; |
| 593 | 593 |
} |
| 594 | 594 |
|
| 595 | 595 |
void clear() {
|
| 596 | 596 |
notifier(Arc()).clear(); |
| 597 | 597 |
notifier(Edge()).clear(); |
| 598 | 598 |
Parent::clear(); |
| 599 | 599 |
} |
| 600 | 600 |
|
| 601 | 601 |
void erase(const Edge& edge) {
|
| 602 | 602 |
std::vector<Arc> arcs; |
| 603 | 603 |
arcs.push_back(Parent::direct(edge, true)); |
| 604 | 604 |
arcs.push_back(Parent::direct(edge, false)); |
| 605 | 605 |
notifier(Arc()).erase(arcs); |
| 606 | 606 |
notifier(Edge()).erase(edge); |
| 607 | 607 |
Parent::erase(edge); |
| 608 | 608 |
} |
| 609 | 609 |
|
| 610 | 610 |
|
| 611 | 611 |
EdgeSetExtender() {
|
| 612 | 612 |
arc_notifier.setContainer(*this); |
| 613 | 613 |
edge_notifier.setContainer(*this); |
| 614 | 614 |
} |
| 615 | 615 |
|
| 616 | 616 |
~EdgeSetExtender() {
|
| 617 | 617 |
edge_notifier.clear(); |
| 618 | 618 |
arc_notifier.clear(); |
| 619 | 619 |
} |
| 620 | 620 |
|
| 621 | 621 |
}; |
| 622 | 622 |
|
| 623 | 623 |
} |
| 624 | 624 |
|
| 625 | 625 |
#endif |
| ... | ... |
@@ -223,529 +223,529 @@ |
| 223 | 223 |
|
| 224 | 224 |
public: |
| 225 | 225 |
explicit NodeMap(const Digraph& digraph) |
| 226 | 226 |
: Parent(digraph) {}
|
| 227 | 227 |
NodeMap(const Digraph& digraph, const _Value& value) |
| 228 | 228 |
: Parent(digraph, value) {}
|
| 229 | 229 |
|
| 230 | 230 |
private: |
| 231 | 231 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 232 | 232 |
return operator=<NodeMap>(cmap); |
| 233 | 233 |
} |
| 234 | 234 |
|
| 235 | 235 |
template <typename CMap> |
| 236 | 236 |
NodeMap& operator=(const CMap& cmap) {
|
| 237 | 237 |
Parent::operator=(cmap); |
| 238 | 238 |
return *this; |
| 239 | 239 |
} |
| 240 | 240 |
|
| 241 | 241 |
}; |
| 242 | 242 |
|
| 243 | 243 |
template <typename _Value> |
| 244 | 244 |
class ArcMap |
| 245 | 245 |
: public MapExtender<DefaultMap<Digraph, Arc, _Value> > {
|
| 246 | 246 |
typedef MapExtender<DefaultMap<Digraph, Arc, _Value> > Parent; |
| 247 | 247 |
|
| 248 | 248 |
public: |
| 249 | 249 |
explicit ArcMap(const Digraph& digraph) |
| 250 | 250 |
: Parent(digraph) {}
|
| 251 | 251 |
ArcMap(const Digraph& digraph, const _Value& value) |
| 252 | 252 |
: Parent(digraph, value) {}
|
| 253 | 253 |
|
| 254 | 254 |
private: |
| 255 | 255 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 256 | 256 |
return operator=<ArcMap>(cmap); |
| 257 | 257 |
} |
| 258 | 258 |
|
| 259 | 259 |
template <typename CMap> |
| 260 | 260 |
ArcMap& operator=(const CMap& cmap) {
|
| 261 | 261 |
Parent::operator=(cmap); |
| 262 | 262 |
return *this; |
| 263 | 263 |
} |
| 264 | 264 |
}; |
| 265 | 265 |
|
| 266 | 266 |
|
| 267 | 267 |
Node addNode() {
|
| 268 | 268 |
Node node = Parent::addNode(); |
| 269 | 269 |
notifier(Node()).add(node); |
| 270 | 270 |
return node; |
| 271 | 271 |
} |
| 272 | 272 |
|
| 273 | 273 |
Arc addArc(const Node& from, const Node& to) {
|
| 274 | 274 |
Arc arc = Parent::addArc(from, to); |
| 275 | 275 |
notifier(Arc()).add(arc); |
| 276 | 276 |
return arc; |
| 277 | 277 |
} |
| 278 | 278 |
|
| 279 | 279 |
void clear() {
|
| 280 | 280 |
notifier(Arc()).clear(); |
| 281 | 281 |
notifier(Node()).clear(); |
| 282 | 282 |
Parent::clear(); |
| 283 | 283 |
} |
| 284 | 284 |
|
| 285 | 285 |
template <typename Digraph, typename NodeRefMap, typename ArcRefMap> |
| 286 | 286 |
void build(const Digraph& digraph, NodeRefMap& nodeRef, ArcRefMap& arcRef) {
|
| 287 | 287 |
Parent::build(digraph, nodeRef, arcRef); |
| 288 | 288 |
notifier(Node()).build(); |
| 289 | 289 |
notifier(Arc()).build(); |
| 290 | 290 |
} |
| 291 | 291 |
|
| 292 | 292 |
void erase(const Node& node) {
|
| 293 | 293 |
Arc arc; |
| 294 | 294 |
Parent::firstOut(arc, node); |
| 295 | 295 |
while (arc != INVALID ) {
|
| 296 | 296 |
erase(arc); |
| 297 | 297 |
Parent::firstOut(arc, node); |
| 298 | 298 |
} |
| 299 | 299 |
|
| 300 | 300 |
Parent::firstIn(arc, node); |
| 301 | 301 |
while (arc != INVALID ) {
|
| 302 | 302 |
erase(arc); |
| 303 | 303 |
Parent::firstIn(arc, node); |
| 304 | 304 |
} |
| 305 | 305 |
|
| 306 | 306 |
notifier(Node()).erase(node); |
| 307 | 307 |
Parent::erase(node); |
| 308 | 308 |
} |
| 309 | 309 |
|
| 310 | 310 |
void erase(const Arc& arc) {
|
| 311 | 311 |
notifier(Arc()).erase(arc); |
| 312 | 312 |
Parent::erase(arc); |
| 313 | 313 |
} |
| 314 | 314 |
|
| 315 | 315 |
DigraphExtender() {
|
| 316 | 316 |
node_notifier.setContainer(*this); |
| 317 | 317 |
arc_notifier.setContainer(*this); |
| 318 | 318 |
} |
| 319 | 319 |
|
| 320 | 320 |
|
| 321 | 321 |
~DigraphExtender() {
|
| 322 | 322 |
arc_notifier.clear(); |
| 323 | 323 |
node_notifier.clear(); |
| 324 | 324 |
} |
| 325 | 325 |
}; |
| 326 | 326 |
|
| 327 | 327 |
// \ingroup _graphbits |
| 328 | 328 |
// |
| 329 | 329 |
// \brief Extender for the Graphs |
| 330 | 330 |
template <typename Base> |
| 331 | 331 |
class GraphExtender : public Base {
|
| 332 | 332 |
typedef Base Parent; |
| 333 | 333 |
|
| 334 | 334 |
public: |
| 335 | 335 |
|
| 336 | 336 |
typedef GraphExtender Graph; |
| 337 | 337 |
|
| 338 | 338 |
typedef True UndirectedTag; |
| 339 | 339 |
|
| 340 | 340 |
typedef typename Parent::Node Node; |
| 341 | 341 |
typedef typename Parent::Arc Arc; |
| 342 | 342 |
typedef typename Parent::Edge Edge; |
| 343 | 343 |
|
| 344 | 344 |
// Graph extension |
| 345 | 345 |
|
| 346 | 346 |
int maxId(Node) const {
|
| 347 | 347 |
return Parent::maxNodeId(); |
| 348 | 348 |
} |
| 349 | 349 |
|
| 350 | 350 |
int maxId(Arc) const {
|
| 351 | 351 |
return Parent::maxArcId(); |
| 352 | 352 |
} |
| 353 | 353 |
|
| 354 | 354 |
int maxId(Edge) const {
|
| 355 | 355 |
return Parent::maxEdgeId(); |
| 356 | 356 |
} |
| 357 | 357 |
|
| 358 | 358 |
Node fromId(int id, Node) const {
|
| 359 | 359 |
return Parent::nodeFromId(id); |
| 360 | 360 |
} |
| 361 | 361 |
|
| 362 | 362 |
Arc fromId(int id, Arc) const {
|
| 363 | 363 |
return Parent::arcFromId(id); |
| 364 | 364 |
} |
| 365 | 365 |
|
| 366 | 366 |
Edge fromId(int id, Edge) const {
|
| 367 | 367 |
return Parent::edgeFromId(id); |
| 368 | 368 |
} |
| 369 | 369 |
|
| 370 | 370 |
Node oppositeNode(const Node &n, const Edge &e) const {
|
| 371 | 371 |
if( n == Parent::u(e)) |
| 372 | 372 |
return Parent::v(e); |
| 373 | 373 |
else if( n == Parent::v(e)) |
| 374 | 374 |
return Parent::u(e); |
| 375 | 375 |
else |
| 376 | 376 |
return INVALID; |
| 377 | 377 |
} |
| 378 | 378 |
|
| 379 | 379 |
Arc oppositeArc(const Arc &arc) const {
|
| 380 | 380 |
return Parent::direct(arc, !Parent::direction(arc)); |
| 381 | 381 |
} |
| 382 | 382 |
|
| 383 | 383 |
using Parent::direct; |
| 384 | 384 |
Arc direct(const Edge &edge, const Node &node) const {
|
| 385 | 385 |
return Parent::direct(edge, Parent::u(edge) == node); |
| 386 | 386 |
} |
| 387 | 387 |
|
| 388 | 388 |
// Alterable extension |
| 389 | 389 |
|
| 390 | 390 |
typedef AlterationNotifier<GraphExtender, Node> NodeNotifier; |
| 391 | 391 |
typedef AlterationNotifier<GraphExtender, Arc> ArcNotifier; |
| 392 | 392 |
typedef AlterationNotifier<GraphExtender, Edge> EdgeNotifier; |
| 393 | 393 |
|
| 394 | 394 |
|
| 395 | 395 |
protected: |
| 396 | 396 |
|
| 397 | 397 |
mutable NodeNotifier node_notifier; |
| 398 | 398 |
mutable ArcNotifier arc_notifier; |
| 399 | 399 |
mutable EdgeNotifier edge_notifier; |
| 400 | 400 |
|
| 401 | 401 |
public: |
| 402 | 402 |
|
| 403 | 403 |
NodeNotifier& notifier(Node) const {
|
| 404 | 404 |
return node_notifier; |
| 405 | 405 |
} |
| 406 | 406 |
|
| 407 | 407 |
ArcNotifier& notifier(Arc) const {
|
| 408 | 408 |
return arc_notifier; |
| 409 | 409 |
} |
| 410 | 410 |
|
| 411 | 411 |
EdgeNotifier& notifier(Edge) const {
|
| 412 | 412 |
return edge_notifier; |
| 413 | 413 |
} |
| 414 | 414 |
|
| 415 | 415 |
|
| 416 | 416 |
|
| 417 | 417 |
class NodeIt : public Node {
|
| 418 | 418 |
const Graph* _graph; |
| 419 | 419 |
public: |
| 420 | 420 |
|
| 421 | 421 |
NodeIt() {}
|
| 422 | 422 |
|
| 423 | 423 |
NodeIt(Invalid i) : Node(i) { }
|
| 424 | 424 |
|
| 425 | 425 |
explicit NodeIt(const Graph& graph) : _graph(&graph) {
|
| 426 | 426 |
_graph->first(static_cast<Node&>(*this)); |
| 427 | 427 |
} |
| 428 | 428 |
|
| 429 | 429 |
NodeIt(const Graph& graph, const Node& node) |
| 430 | 430 |
: Node(node), _graph(&graph) {}
|
| 431 | 431 |
|
| 432 | 432 |
NodeIt& operator++() {
|
| 433 | 433 |
_graph->next(*this); |
| 434 | 434 |
return *this; |
| 435 | 435 |
} |
| 436 | 436 |
|
| 437 | 437 |
}; |
| 438 | 438 |
|
| 439 | 439 |
|
| 440 | 440 |
class ArcIt : public Arc {
|
| 441 | 441 |
const Graph* _graph; |
| 442 | 442 |
public: |
| 443 | 443 |
|
| 444 | 444 |
ArcIt() { }
|
| 445 | 445 |
|
| 446 | 446 |
ArcIt(Invalid i) : Arc(i) { }
|
| 447 | 447 |
|
| 448 | 448 |
explicit ArcIt(const Graph& graph) : _graph(&graph) {
|
| 449 | 449 |
_graph->first(static_cast<Arc&>(*this)); |
| 450 | 450 |
} |
| 451 | 451 |
|
| 452 | 452 |
ArcIt(const Graph& graph, const Arc& arc) : |
| 453 | 453 |
Arc(arc), _graph(&graph) { }
|
| 454 | 454 |
|
| 455 | 455 |
ArcIt& operator++() {
|
| 456 | 456 |
_graph->next(*this); |
| 457 | 457 |
return *this; |
| 458 | 458 |
} |
| 459 | 459 |
|
| 460 | 460 |
}; |
| 461 | 461 |
|
| 462 | 462 |
|
| 463 | 463 |
class OutArcIt : public Arc {
|
| 464 | 464 |
const Graph* _graph; |
| 465 | 465 |
public: |
| 466 | 466 |
|
| 467 | 467 |
OutArcIt() { }
|
| 468 | 468 |
|
| 469 | 469 |
OutArcIt(Invalid i) : Arc(i) { }
|
| 470 | 470 |
|
| 471 | 471 |
OutArcIt(const Graph& graph, const Node& node) |
| 472 | 472 |
: _graph(&graph) {
|
| 473 | 473 |
_graph->firstOut(*this, node); |
| 474 | 474 |
} |
| 475 | 475 |
|
| 476 | 476 |
OutArcIt(const Graph& graph, const Arc& arc) |
| 477 | 477 |
: Arc(arc), _graph(&graph) {}
|
| 478 | 478 |
|
| 479 | 479 |
OutArcIt& operator++() {
|
| 480 | 480 |
_graph->nextOut(*this); |
| 481 | 481 |
return *this; |
| 482 | 482 |
} |
| 483 | 483 |
|
| 484 | 484 |
}; |
| 485 | 485 |
|
| 486 | 486 |
|
| 487 | 487 |
class InArcIt : public Arc {
|
| 488 | 488 |
const Graph* _graph; |
| 489 | 489 |
public: |
| 490 | 490 |
|
| 491 | 491 |
InArcIt() { }
|
| 492 | 492 |
|
| 493 | 493 |
InArcIt(Invalid i) : Arc(i) { }
|
| 494 | 494 |
|
| 495 | 495 |
InArcIt(const Graph& graph, const Node& node) |
| 496 | 496 |
: _graph(&graph) {
|
| 497 | 497 |
_graph->firstIn(*this, node); |
| 498 | 498 |
} |
| 499 | 499 |
|
| 500 | 500 |
InArcIt(const Graph& graph, const Arc& arc) : |
| 501 | 501 |
Arc(arc), _graph(&graph) {}
|
| 502 | 502 |
|
| 503 | 503 |
InArcIt& operator++() {
|
| 504 | 504 |
_graph->nextIn(*this); |
| 505 | 505 |
return *this; |
| 506 | 506 |
} |
| 507 | 507 |
|
| 508 | 508 |
}; |
| 509 | 509 |
|
| 510 | 510 |
|
| 511 | 511 |
class EdgeIt : public Parent::Edge {
|
| 512 | 512 |
const Graph* _graph; |
| 513 | 513 |
public: |
| 514 | 514 |
|
| 515 | 515 |
EdgeIt() { }
|
| 516 | 516 |
|
| 517 | 517 |
EdgeIt(Invalid i) : Edge(i) { }
|
| 518 | 518 |
|
| 519 | 519 |
explicit EdgeIt(const Graph& graph) : _graph(&graph) {
|
| 520 | 520 |
_graph->first(static_cast<Edge&>(*this)); |
| 521 | 521 |
} |
| 522 | 522 |
|
| 523 | 523 |
EdgeIt(const Graph& graph, const Edge& edge) : |
| 524 | 524 |
Edge(edge), _graph(&graph) { }
|
| 525 | 525 |
|
| 526 | 526 |
EdgeIt& operator++() {
|
| 527 | 527 |
_graph->next(*this); |
| 528 | 528 |
return *this; |
| 529 | 529 |
} |
| 530 | 530 |
|
| 531 | 531 |
}; |
| 532 | 532 |
|
| 533 | 533 |
class IncEdgeIt : public Parent::Edge {
|
| 534 | 534 |
friend class GraphExtender; |
| 535 | 535 |
const Graph* _graph; |
| 536 | 536 |
bool _direction; |
| 537 | 537 |
public: |
| 538 | 538 |
|
| 539 | 539 |
IncEdgeIt() { }
|
| 540 | 540 |
|
| 541 | 541 |
IncEdgeIt(Invalid i) : Edge(i), _direction(false) { }
|
| 542 | 542 |
|
| 543 | 543 |
IncEdgeIt(const Graph& graph, const Node &node) : _graph(&graph) {
|
| 544 | 544 |
_graph->firstInc(*this, _direction, node); |
| 545 | 545 |
} |
| 546 | 546 |
|
| 547 | 547 |
IncEdgeIt(const Graph& graph, const Edge &edge, const Node &node) |
| 548 | 548 |
: _graph(&graph), Edge(edge) {
|
| 549 | 549 |
_direction = (_graph->source(edge) == node); |
| 550 | 550 |
} |
| 551 | 551 |
|
| 552 | 552 |
IncEdgeIt& operator++() {
|
| 553 | 553 |
_graph->nextInc(*this, _direction); |
| 554 | 554 |
return *this; |
| 555 | 555 |
} |
| 556 | 556 |
}; |
| 557 | 557 |
|
| 558 | 558 |
// \brief Base node of the iterator |
| 559 | 559 |
// |
| 560 | 560 |
// Returns the base node (ie. the source in this case) of the iterator |
| 561 | 561 |
Node baseNode(const OutArcIt &arc) const {
|
| 562 | 562 |
return Parent::source(static_cast<const Arc&>(arc)); |
| 563 | 563 |
} |
| 564 | 564 |
// \brief Running node of the iterator |
| 565 | 565 |
// |
| 566 | 566 |
// Returns the running node (ie. the target in this case) of the |
| 567 | 567 |
// iterator |
| 568 | 568 |
Node runningNode(const OutArcIt &arc) const {
|
| 569 | 569 |
return Parent::target(static_cast<const Arc&>(arc)); |
| 570 | 570 |
} |
| 571 | 571 |
|
| 572 | 572 |
// \brief Base node of the iterator |
| 573 | 573 |
// |
| 574 | 574 |
// Returns the base node (ie. the target in this case) of the iterator |
| 575 | 575 |
Node baseNode(const InArcIt &arc) const {
|
| 576 | 576 |
return Parent::target(static_cast<const Arc&>(arc)); |
| 577 | 577 |
} |
| 578 | 578 |
// \brief Running node of the iterator |
| 579 | 579 |
// |
| 580 | 580 |
// Returns the running node (ie. the source in this case) of the |
| 581 | 581 |
// iterator |
| 582 | 582 |
Node runningNode(const InArcIt &arc) const {
|
| 583 | 583 |
return Parent::source(static_cast<const Arc&>(arc)); |
| 584 | 584 |
} |
| 585 | 585 |
|
| 586 | 586 |
// Base node of the iterator |
| 587 | 587 |
// |
| 588 | 588 |
// Returns the base node of the iterator |
| 589 | 589 |
Node baseNode(const IncEdgeIt &edge) const {
|
| 590 | 590 |
return edge._direction ? u(edge) : v(edge); |
| 591 | 591 |
} |
| 592 | 592 |
// Running node of the iterator |
| 593 | 593 |
// |
| 594 | 594 |
// Returns the running node of the iterator |
| 595 | 595 |
Node runningNode(const IncEdgeIt &edge) const {
|
| 596 | 596 |
return edge._direction ? v(edge) : u(edge); |
| 597 | 597 |
} |
| 598 | 598 |
|
| 599 | 599 |
// Mappable extension |
| 600 | 600 |
|
| 601 | 601 |
template <typename _Value> |
| 602 | 602 |
class NodeMap |
| 603 | 603 |
: public MapExtender<DefaultMap<Graph, Node, _Value> > {
|
| 604 | 604 |
typedef MapExtender<DefaultMap<Graph, Node, _Value> > Parent; |
| 605 | 605 |
|
| 606 | 606 |
public: |
| 607 |
NodeMap(const Graph& graph) |
|
| 607 |
explicit NodeMap(const Graph& graph) |
|
| 608 | 608 |
: Parent(graph) {}
|
| 609 | 609 |
NodeMap(const Graph& graph, const _Value& value) |
| 610 | 610 |
: Parent(graph, value) {}
|
| 611 | 611 |
|
| 612 | 612 |
private: |
| 613 | 613 |
NodeMap& operator=(const NodeMap& cmap) {
|
| 614 | 614 |
return operator=<NodeMap>(cmap); |
| 615 | 615 |
} |
| 616 | 616 |
|
| 617 | 617 |
template <typename CMap> |
| 618 | 618 |
NodeMap& operator=(const CMap& cmap) {
|
| 619 | 619 |
Parent::operator=(cmap); |
| 620 | 620 |
return *this; |
| 621 | 621 |
} |
| 622 | 622 |
|
| 623 | 623 |
}; |
| 624 | 624 |
|
| 625 | 625 |
template <typename _Value> |
| 626 | 626 |
class ArcMap |
| 627 | 627 |
: public MapExtender<DefaultMap<Graph, Arc, _Value> > {
|
| 628 | 628 |
typedef MapExtender<DefaultMap<Graph, Arc, _Value> > Parent; |
| 629 | 629 |
|
| 630 | 630 |
public: |
| 631 |
ArcMap(const Graph& graph) |
|
| 631 |
explicit ArcMap(const Graph& graph) |
|
| 632 | 632 |
: Parent(graph) {}
|
| 633 | 633 |
ArcMap(const Graph& graph, const _Value& value) |
| 634 | 634 |
: Parent(graph, value) {}
|
| 635 | 635 |
|
| 636 | 636 |
private: |
| 637 | 637 |
ArcMap& operator=(const ArcMap& cmap) {
|
| 638 | 638 |
return operator=<ArcMap>(cmap); |
| 639 | 639 |
} |
| 640 | 640 |
|
| 641 | 641 |
template <typename CMap> |
| 642 | 642 |
ArcMap& operator=(const CMap& cmap) {
|
| 643 | 643 |
Parent::operator=(cmap); |
| 644 | 644 |
return *this; |
| 645 | 645 |
} |
| 646 | 646 |
}; |
| 647 | 647 |
|
| 648 | 648 |
|
| 649 | 649 |
template <typename _Value> |
| 650 | 650 |
class EdgeMap |
| 651 | 651 |
: public MapExtender<DefaultMap<Graph, Edge, _Value> > {
|
| 652 | 652 |
typedef MapExtender<DefaultMap<Graph, Edge, _Value> > Parent; |
| 653 | 653 |
|
| 654 | 654 |
public: |
| 655 |
EdgeMap(const Graph& graph) |
|
| 655 |
explicit EdgeMap(const Graph& graph) |
|
| 656 | 656 |
: Parent(graph) {}
|
| 657 | 657 |
|
| 658 | 658 |
EdgeMap(const Graph& graph, const _Value& value) |
| 659 | 659 |
: Parent(graph, value) {}
|
| 660 | 660 |
|
| 661 | 661 |
private: |
| 662 | 662 |
EdgeMap& operator=(const EdgeMap& cmap) {
|
| 663 | 663 |
return operator=<EdgeMap>(cmap); |
| 664 | 664 |
} |
| 665 | 665 |
|
| 666 | 666 |
template <typename CMap> |
| 667 | 667 |
EdgeMap& operator=(const CMap& cmap) {
|
| 668 | 668 |
Parent::operator=(cmap); |
| 669 | 669 |
return *this; |
| 670 | 670 |
} |
| 671 | 671 |
|
| 672 | 672 |
}; |
| 673 | 673 |
|
| 674 | 674 |
// Alteration extension |
| 675 | 675 |
|
| 676 | 676 |
Node addNode() {
|
| 677 | 677 |
Node node = Parent::addNode(); |
| 678 | 678 |
notifier(Node()).add(node); |
| 679 | 679 |
return node; |
| 680 | 680 |
} |
| 681 | 681 |
|
| 682 | 682 |
Edge addEdge(const Node& from, const Node& to) {
|
| 683 | 683 |
Edge edge = Parent::addEdge(from, to); |
| 684 | 684 |
notifier(Edge()).add(edge); |
| 685 | 685 |
std::vector<Arc> ev; |
| 686 | 686 |
ev.push_back(Parent::direct(edge, true)); |
| 687 | 687 |
ev.push_back(Parent::direct(edge, false)); |
| 688 | 688 |
notifier(Arc()).add(ev); |
| 689 | 689 |
return edge; |
| 690 | 690 |
} |
| 691 | 691 |
|
| 692 | 692 |
void clear() {
|
| 693 | 693 |
notifier(Arc()).clear(); |
| 694 | 694 |
notifier(Edge()).clear(); |
| 695 | 695 |
notifier(Node()).clear(); |
| 696 | 696 |
Parent::clear(); |
| 697 | 697 |
} |
| 698 | 698 |
|
| 699 | 699 |
template <typename Graph, typename NodeRefMap, typename EdgeRefMap> |
| 700 | 700 |
void build(const Graph& graph, NodeRefMap& nodeRef, |
| 701 | 701 |
EdgeRefMap& edgeRef) {
|
| 702 | 702 |
Parent::build(graph, nodeRef, edgeRef); |
| 703 | 703 |
notifier(Node()).build(); |
| 704 | 704 |
notifier(Edge()).build(); |
| 705 | 705 |
notifier(Arc()).build(); |
| 706 | 706 |
} |
| 707 | 707 |
|
| 708 | 708 |
void erase(const Node& node) {
|
| 709 | 709 |
Arc arc; |
| 710 | 710 |
Parent::firstOut(arc, node); |
| 711 | 711 |
while (arc != INVALID ) {
|
| 712 | 712 |
erase(arc); |
| 713 | 713 |
Parent::firstOut(arc, node); |
| 714 | 714 |
} |
| 715 | 715 |
|
| 716 | 716 |
Parent::firstIn(arc, node); |
| 717 | 717 |
while (arc != INVALID ) {
|
| 718 | 718 |
erase(arc); |
| 719 | 719 |
Parent::firstIn(arc, node); |
| 720 | 720 |
} |
| 721 | 721 |
|
| 722 | 722 |
notifier(Node()).erase(node); |
| 723 | 723 |
Parent::erase(node); |
| 724 | 724 |
} |
| 725 | 725 |
|
| 726 | 726 |
void erase(const Edge& edge) {
|
| 727 | 727 |
std::vector<Arc> av; |
| 728 | 728 |
av.push_back(Parent::direct(edge, true)); |
| 729 | 729 |
av.push_back(Parent::direct(edge, false)); |
| 730 | 730 |
notifier(Arc()).erase(av); |
| 731 | 731 |
notifier(Edge()).erase(edge); |
| 732 | 732 |
Parent::erase(edge); |
| 733 | 733 |
} |
| 734 | 734 |
|
| 735 | 735 |
GraphExtender() {
|
| 736 | 736 |
node_notifier.setContainer(*this); |
| 737 | 737 |
arc_notifier.setContainer(*this); |
| 738 | 738 |
edge_notifier.setContainer(*this); |
| 739 | 739 |
} |
| 740 | 740 |
|
| 741 | 741 |
~GraphExtender() {
|
| 742 | 742 |
edge_notifier.clear(); |
| 743 | 743 |
arc_notifier.clear(); |
| 744 | 744 |
node_notifier.clear(); |
| 745 | 745 |
} |
| 746 | 746 |
|
| 747 | 747 |
}; |
| 748 | 748 |
|
| 749 | 749 |
} |
| 750 | 750 |
|
| 751 | 751 |
#endif |
| ... | ... |
@@ -1521,952 +1521,971 @@ |
| 1521 | 1521 |
/// negation of the values of the given map. |
| 1522 | 1522 |
/// Its \c Key is inherited from \c M and its \c Value is \c bool. |
| 1523 | 1523 |
/// |
| 1524 | 1524 |
/// The simplest way of using this map is through the notMap() |
| 1525 | 1525 |
/// function. |
| 1526 | 1526 |
/// |
| 1527 | 1527 |
/// \sa NotWriteMap |
| 1528 | 1528 |
template <typename M> |
| 1529 | 1529 |
class NotMap : public MapBase<typename M::Key, bool> {
|
| 1530 | 1530 |
const M &_m; |
| 1531 | 1531 |
public: |
| 1532 | 1532 |
///\e |
| 1533 | 1533 |
typedef typename M::Key Key; |
| 1534 | 1534 |
///\e |
| 1535 | 1535 |
typedef bool Value; |
| 1536 | 1536 |
|
| 1537 | 1537 |
/// Constructor |
| 1538 | 1538 |
NotMap(const M &m) : _m(m) {}
|
| 1539 | 1539 |
///\e |
| 1540 | 1540 |
Value operator[](const Key &k) const { return !_m[k]; }
|
| 1541 | 1541 |
}; |
| 1542 | 1542 |
|
| 1543 | 1543 |
/// Logical 'not' of a map (read-write version) |
| 1544 | 1544 |
|
| 1545 | 1545 |
/// This \ref concepts::ReadWriteMap "read-write map" returns the |
| 1546 | 1546 |
/// logical negation of the values of the given map. |
| 1547 | 1547 |
/// Its \c Key is inherited from \c M and its \c Value is \c bool. |
| 1548 | 1548 |
/// It makes also possible to write the map. When a value is set, |
| 1549 | 1549 |
/// the opposite value is set to the original map. |
| 1550 | 1550 |
/// |
| 1551 | 1551 |
/// The simplest way of using this map is through the notWriteMap() |
| 1552 | 1552 |
/// function. |
| 1553 | 1553 |
/// |
| 1554 | 1554 |
/// \sa NotMap |
| 1555 | 1555 |
template <typename M> |
| 1556 | 1556 |
class NotWriteMap : public MapBase<typename M::Key, bool> {
|
| 1557 | 1557 |
M &_m; |
| 1558 | 1558 |
public: |
| 1559 | 1559 |
///\e |
| 1560 | 1560 |
typedef typename M::Key Key; |
| 1561 | 1561 |
///\e |
| 1562 | 1562 |
typedef bool Value; |
| 1563 | 1563 |
|
| 1564 | 1564 |
/// Constructor |
| 1565 | 1565 |
NotWriteMap(M &m) : _m(m) {}
|
| 1566 | 1566 |
///\e |
| 1567 | 1567 |
Value operator[](const Key &k) const { return !_m[k]; }
|
| 1568 | 1568 |
///\e |
| 1569 | 1569 |
void set(const Key &k, bool v) { _m.set(k, !v); }
|
| 1570 | 1570 |
}; |
| 1571 | 1571 |
|
| 1572 | 1572 |
/// Returns a \c NotMap class |
| 1573 | 1573 |
|
| 1574 | 1574 |
/// This function just returns a \c NotMap class. |
| 1575 | 1575 |
/// |
| 1576 | 1576 |
/// For example, if \c m is a map with \c bool values, then |
| 1577 | 1577 |
/// <tt>notMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>. |
| 1578 | 1578 |
/// |
| 1579 | 1579 |
/// \relates NotMap |
| 1580 | 1580 |
template <typename M> |
| 1581 | 1581 |
inline NotMap<M> notMap(const M &m) {
|
| 1582 | 1582 |
return NotMap<M>(m); |
| 1583 | 1583 |
} |
| 1584 | 1584 |
|
| 1585 | 1585 |
/// Returns a \c NotWriteMap class |
| 1586 | 1586 |
|
| 1587 | 1587 |
/// This function just returns a \c NotWriteMap class. |
| 1588 | 1588 |
/// |
| 1589 | 1589 |
/// For example, if \c m is a map with \c bool values, then |
| 1590 | 1590 |
/// <tt>notWriteMap(m)[x]</tt> will be equal to <tt>!m[x]</tt>. |
| 1591 | 1591 |
/// Moreover it makes also possible to write the map. |
| 1592 | 1592 |
/// |
| 1593 | 1593 |
/// \relates NotWriteMap |
| 1594 | 1594 |
template <typename M> |
| 1595 | 1595 |
inline NotWriteMap<M> notWriteMap(M &m) {
|
| 1596 | 1596 |
return NotWriteMap<M>(m); |
| 1597 | 1597 |
} |
| 1598 | 1598 |
|
| 1599 | 1599 |
|
| 1600 | 1600 |
/// Combination of two maps using the \c == operator |
| 1601 | 1601 |
|
| 1602 | 1602 |
/// This \ref concepts::ReadMap "read-only map" assigns \c true to |
| 1603 | 1603 |
/// the keys for which the corresponding values of the two maps are |
| 1604 | 1604 |
/// equal. |
| 1605 | 1605 |
/// Its \c Key type is inherited from \c M1 and its \c Value type is |
| 1606 | 1606 |
/// \c bool. \c M2::Key must be convertible to \c M1::Key. |
| 1607 | 1607 |
/// |
| 1608 | 1608 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 1609 | 1609 |
/// \code |
| 1610 | 1610 |
/// EqualMap<M1,M2> em(m1,m2); |
| 1611 | 1611 |
/// \endcode |
| 1612 | 1612 |
/// <tt>em[x]</tt> will be equal to <tt>m1[x]==m2[x]</tt>. |
| 1613 | 1613 |
/// |
| 1614 | 1614 |
/// The simplest way of using this map is through the equalMap() |
| 1615 | 1615 |
/// function. |
| 1616 | 1616 |
/// |
| 1617 | 1617 |
/// \sa LessMap |
| 1618 | 1618 |
template<typename M1, typename M2> |
| 1619 | 1619 |
class EqualMap : public MapBase<typename M1::Key, bool> {
|
| 1620 | 1620 |
const M1 &_m1; |
| 1621 | 1621 |
const M2 &_m2; |
| 1622 | 1622 |
public: |
| 1623 | 1623 |
///\e |
| 1624 | 1624 |
typedef typename M1::Key Key; |
| 1625 | 1625 |
///\e |
| 1626 | 1626 |
typedef bool Value; |
| 1627 | 1627 |
|
| 1628 | 1628 |
/// Constructor |
| 1629 | 1629 |
EqualMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 1630 | 1630 |
///\e |
| 1631 | 1631 |
Value operator[](const Key &k) const { return _m1[k]==_m2[k]; }
|
| 1632 | 1632 |
}; |
| 1633 | 1633 |
|
| 1634 | 1634 |
/// Returns an \c EqualMap class |
| 1635 | 1635 |
|
| 1636 | 1636 |
/// This function just returns an \c EqualMap class. |
| 1637 | 1637 |
/// |
| 1638 | 1638 |
/// For example, if \c m1 and \c m2 are maps with keys and values of |
| 1639 | 1639 |
/// the same type, then <tt>equalMap(m1,m2)[x]</tt> will be equal to |
| 1640 | 1640 |
/// <tt>m1[x]==m2[x]</tt>. |
| 1641 | 1641 |
/// |
| 1642 | 1642 |
/// \relates EqualMap |
| 1643 | 1643 |
template<typename M1, typename M2> |
| 1644 | 1644 |
inline EqualMap<M1, M2> equalMap(const M1 &m1, const M2 &m2) {
|
| 1645 | 1645 |
return EqualMap<M1, M2>(m1,m2); |
| 1646 | 1646 |
} |
| 1647 | 1647 |
|
| 1648 | 1648 |
|
| 1649 | 1649 |
/// Combination of two maps using the \c < operator |
| 1650 | 1650 |
|
| 1651 | 1651 |
/// This \ref concepts::ReadMap "read-only map" assigns \c true to |
| 1652 | 1652 |
/// the keys for which the corresponding value of the first map is |
| 1653 | 1653 |
/// less then the value of the second map. |
| 1654 | 1654 |
/// Its \c Key type is inherited from \c M1 and its \c Value type is |
| 1655 | 1655 |
/// \c bool. \c M2::Key must be convertible to \c M1::Key. |
| 1656 | 1656 |
/// |
| 1657 | 1657 |
/// If \c m1 is of type \c M1 and \c m2 is of \c M2, then for |
| 1658 | 1658 |
/// \code |
| 1659 | 1659 |
/// LessMap<M1,M2> lm(m1,m2); |
| 1660 | 1660 |
/// \endcode |
| 1661 | 1661 |
/// <tt>lm[x]</tt> will be equal to <tt>m1[x]<m2[x]</tt>. |
| 1662 | 1662 |
/// |
| 1663 | 1663 |
/// The simplest way of using this map is through the lessMap() |
| 1664 | 1664 |
/// function. |
| 1665 | 1665 |
/// |
| 1666 | 1666 |
/// \sa EqualMap |
| 1667 | 1667 |
template<typename M1, typename M2> |
| 1668 | 1668 |
class LessMap : public MapBase<typename M1::Key, bool> {
|
| 1669 | 1669 |
const M1 &_m1; |
| 1670 | 1670 |
const M2 &_m2; |
| 1671 | 1671 |
public: |
| 1672 | 1672 |
///\e |
| 1673 | 1673 |
typedef typename M1::Key Key; |
| 1674 | 1674 |
///\e |
| 1675 | 1675 |
typedef bool Value; |
| 1676 | 1676 |
|
| 1677 | 1677 |
/// Constructor |
| 1678 | 1678 |
LessMap(const M1 &m1, const M2 &m2) : _m1(m1), _m2(m2) {}
|
| 1679 | 1679 |
///\e |
| 1680 | 1680 |
Value operator[](const Key &k) const { return _m1[k]<_m2[k]; }
|
| 1681 | 1681 |
}; |
| 1682 | 1682 |
|
| 1683 | 1683 |
/// Returns an \c LessMap class |
| 1684 | 1684 |
|
| 1685 | 1685 |
/// This function just returns an \c LessMap class. |
| 1686 | 1686 |
/// |
| 1687 | 1687 |
/// For example, if \c m1 and \c m2 are maps with keys and values of |
| 1688 | 1688 |
/// the same type, then <tt>lessMap(m1,m2)[x]</tt> will be equal to |
| 1689 | 1689 |
/// <tt>m1[x]<m2[x]</tt>. |
| 1690 | 1690 |
/// |
| 1691 | 1691 |
/// \relates LessMap |
| 1692 | 1692 |
template<typename M1, typename M2> |
| 1693 | 1693 |
inline LessMap<M1, M2> lessMap(const M1 &m1, const M2 &m2) {
|
| 1694 | 1694 |
return LessMap<M1, M2>(m1,m2); |
| 1695 | 1695 |
} |
| 1696 | 1696 |
|
| 1697 | 1697 |
namespace _maps_bits {
|
| 1698 | 1698 |
|
| 1699 | 1699 |
template <typename _Iterator, typename Enable = void> |
| 1700 | 1700 |
struct IteratorTraits {
|
| 1701 | 1701 |
typedef typename std::iterator_traits<_Iterator>::value_type Value; |
| 1702 | 1702 |
}; |
| 1703 | 1703 |
|
| 1704 | 1704 |
template <typename _Iterator> |
| 1705 | 1705 |
struct IteratorTraits<_Iterator, |
| 1706 | 1706 |
typename exists<typename _Iterator::container_type>::type> |
| 1707 | 1707 |
{
|
| 1708 | 1708 |
typedef typename _Iterator::container_type::value_type Value; |
| 1709 | 1709 |
}; |
| 1710 | 1710 |
|
| 1711 | 1711 |
} |
| 1712 | 1712 |
|
| 1713 | 1713 |
/// @} |
| 1714 | 1714 |
|
| 1715 | 1715 |
/// \addtogroup maps |
| 1716 | 1716 |
/// @{
|
| 1717 | 1717 |
|
| 1718 | 1718 |
/// \brief Writable bool map for logging each \c true assigned element |
| 1719 | 1719 |
/// |
| 1720 | 1720 |
/// A \ref concepts::WriteMap "writable" bool map for logging |
| 1721 | 1721 |
/// each \c true assigned element, i.e it copies subsequently each |
| 1722 | 1722 |
/// keys set to \c true to the given iterator. |
| 1723 | 1723 |
/// The most important usage of it is storing certain nodes or arcs |
| 1724 | 1724 |
/// that were marked \c true by an algorithm. |
| 1725 | 1725 |
/// |
| 1726 | 1726 |
/// There are several algorithms that provide solutions through bool |
| 1727 | 1727 |
/// maps and most of them assign \c true at most once for each key. |
| 1728 | 1728 |
/// In these cases it is a natural request to store each \c true |
| 1729 | 1729 |
/// assigned elements (in order of the assignment), which can be |
| 1730 | 1730 |
/// easily done with LoggerBoolMap. |
| 1731 | 1731 |
/// |
| 1732 | 1732 |
/// The simplest way of using this map is through the loggerBoolMap() |
| 1733 | 1733 |
/// function. |
| 1734 | 1734 |
/// |
| 1735 | 1735 |
/// \tparam IT The type of the iterator. |
| 1736 | 1736 |
/// \tparam KEY The key type of the map. The default value set |
| 1737 | 1737 |
/// according to the iterator type should work in most cases. |
| 1738 | 1738 |
/// |
| 1739 | 1739 |
/// \note The container of the iterator must contain enough space |
| 1740 | 1740 |
/// for the elements or the iterator should be an inserter iterator. |
| 1741 | 1741 |
#ifdef DOXYGEN |
| 1742 | 1742 |
template <typename IT, typename KEY> |
| 1743 | 1743 |
#else |
| 1744 | 1744 |
template <typename IT, |
| 1745 | 1745 |
typename KEY = typename _maps_bits::IteratorTraits<IT>::Value> |
| 1746 | 1746 |
#endif |
| 1747 | 1747 |
class LoggerBoolMap : public MapBase<KEY, bool> {
|
| 1748 | 1748 |
public: |
| 1749 | 1749 |
|
| 1750 | 1750 |
///\e |
| 1751 | 1751 |
typedef KEY Key; |
| 1752 | 1752 |
///\e |
| 1753 | 1753 |
typedef bool Value; |
| 1754 | 1754 |
///\e |
| 1755 | 1755 |
typedef IT Iterator; |
| 1756 | 1756 |
|
| 1757 | 1757 |
/// Constructor |
| 1758 | 1758 |
LoggerBoolMap(Iterator it) |
| 1759 | 1759 |
: _begin(it), _end(it) {}
|
| 1760 | 1760 |
|
| 1761 | 1761 |
/// Gives back the given iterator set for the first key |
| 1762 | 1762 |
Iterator begin() const {
|
| 1763 | 1763 |
return _begin; |
| 1764 | 1764 |
} |
| 1765 | 1765 |
|
| 1766 | 1766 |
/// Gives back the the 'after the last' iterator |
| 1767 | 1767 |
Iterator end() const {
|
| 1768 | 1768 |
return _end; |
| 1769 | 1769 |
} |
| 1770 | 1770 |
|
| 1771 | 1771 |
/// The set function of the map |
| 1772 | 1772 |
void set(const Key& key, Value value) {
|
| 1773 | 1773 |
if (value) {
|
| 1774 | 1774 |
*_end++ = key; |
| 1775 | 1775 |
} |
| 1776 | 1776 |
} |
| 1777 | 1777 |
|
| 1778 | 1778 |
private: |
| 1779 | 1779 |
Iterator _begin; |
| 1780 | 1780 |
Iterator _end; |
| 1781 | 1781 |
}; |
| 1782 | 1782 |
|
| 1783 | 1783 |
/// Returns a \c LoggerBoolMap class |
| 1784 | 1784 |
|
| 1785 | 1785 |
/// This function just returns a \c LoggerBoolMap class. |
| 1786 | 1786 |
/// |
| 1787 | 1787 |
/// The most important usage of it is storing certain nodes or arcs |
| 1788 | 1788 |
/// that were marked \c true by an algorithm. |
| 1789 | 1789 |
/// For example it makes easier to store the nodes in the processing |
| 1790 | 1790 |
/// order of Dfs algorithm, as the following examples show. |
| 1791 | 1791 |
/// \code |
| 1792 | 1792 |
/// std::vector<Node> v; |
| 1793 | 1793 |
/// dfs(g,s).processedMap(loggerBoolMap(std::back_inserter(v))).run(); |
| 1794 | 1794 |
/// \endcode |
| 1795 | 1795 |
/// \code |
| 1796 | 1796 |
/// std::vector<Node> v(countNodes(g)); |
| 1797 | 1797 |
/// dfs(g,s).processedMap(loggerBoolMap(v.begin())).run(); |
| 1798 | 1798 |
/// \endcode |
| 1799 | 1799 |
/// |
| 1800 | 1800 |
/// \note The container of the iterator must contain enough space |
| 1801 | 1801 |
/// for the elements or the iterator should be an inserter iterator. |
| 1802 | 1802 |
/// |
| 1803 | 1803 |
/// \note LoggerBoolMap is just \ref concepts::WriteMap "writable", so |
| 1804 | 1804 |
/// it cannot be used when a readable map is needed, for example as |
| 1805 | 1805 |
/// \c ReachedMap for \c Bfs, \c Dfs and \c Dijkstra algorithms. |
| 1806 | 1806 |
/// |
| 1807 | 1807 |
/// \relates LoggerBoolMap |
| 1808 | 1808 |
template<typename Iterator> |
| 1809 | 1809 |
inline LoggerBoolMap<Iterator> loggerBoolMap(Iterator it) {
|
| 1810 | 1810 |
return LoggerBoolMap<Iterator>(it); |
| 1811 | 1811 |
} |
| 1812 | 1812 |
|
| 1813 | 1813 |
/// @} |
| 1814 | 1814 |
|
| 1815 | 1815 |
/// \addtogroup graph_maps |
| 1816 | 1816 |
/// @{
|
| 1817 | 1817 |
|
| 1818 | 1818 |
/// \brief Provides an immutable and unique id for each item in a graph. |
| 1819 | 1819 |
/// |
| 1820 | 1820 |
/// IdMap provides a unique and immutable id for each item of the |
| 1821 | 1821 |
/// same type (\c Node, \c Arc or \c Edge) in a graph. This id is |
| 1822 | 1822 |
/// - \b unique: different items get different ids, |
| 1823 | 1823 |
/// - \b immutable: the id of an item does not change (even if you |
| 1824 | 1824 |
/// delete other nodes). |
| 1825 | 1825 |
/// |
| 1826 | 1826 |
/// Using this map you get access (i.e. can read) the inner id values of |
| 1827 | 1827 |
/// the items stored in the graph, which is returned by the \c id() |
| 1828 | 1828 |
/// function of the graph. This map can be inverted with its member |
| 1829 | 1829 |
/// class \c InverseMap or with the \c operator() member. |
| 1830 | 1830 |
/// |
| 1831 | 1831 |
/// \tparam GR The graph type. |
| 1832 | 1832 |
/// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
| 1833 | 1833 |
/// \c GR::Edge). |
| 1834 | 1834 |
/// |
| 1835 | 1835 |
/// \see RangeIdMap |
| 1836 | 1836 |
template <typename GR, typename K> |
| 1837 | 1837 |
class IdMap : public MapBase<K, int> {
|
| 1838 | 1838 |
public: |
| 1839 | 1839 |
/// The graph type of IdMap. |
| 1840 | 1840 |
typedef GR Graph; |
| 1841 | 1841 |
typedef GR Digraph; |
| 1842 | 1842 |
/// The key type of IdMap (\c Node, \c Arc or \c Edge). |
| 1843 | 1843 |
typedef K Item; |
| 1844 | 1844 |
/// The key type of IdMap (\c Node, \c Arc or \c Edge). |
| 1845 | 1845 |
typedef K Key; |
| 1846 | 1846 |
/// The value type of IdMap. |
| 1847 | 1847 |
typedef int Value; |
| 1848 | 1848 |
|
| 1849 | 1849 |
/// \brief Constructor. |
| 1850 | 1850 |
/// |
| 1851 | 1851 |
/// Constructor of the map. |
| 1852 | 1852 |
explicit IdMap(const Graph& graph) : _graph(&graph) {}
|
| 1853 | 1853 |
|
| 1854 | 1854 |
/// \brief Gives back the \e id of the item. |
| 1855 | 1855 |
/// |
| 1856 | 1856 |
/// Gives back the immutable and unique \e id of the item. |
| 1857 | 1857 |
int operator[](const Item& item) const { return _graph->id(item);}
|
| 1858 | 1858 |
|
| 1859 | 1859 |
/// \brief Gives back the \e item by its id. |
| 1860 | 1860 |
/// |
| 1861 | 1861 |
/// Gives back the \e item by its id. |
| 1862 | 1862 |
Item operator()(int id) { return _graph->fromId(id, Item()); }
|
| 1863 | 1863 |
|
| 1864 | 1864 |
private: |
| 1865 | 1865 |
const Graph* _graph; |
| 1866 | 1866 |
|
| 1867 | 1867 |
public: |
| 1868 | 1868 |
|
| 1869 | 1869 |
/// \brief This class represents the inverse of its owner (IdMap). |
| 1870 | 1870 |
/// |
| 1871 | 1871 |
/// This class represents the inverse of its owner (IdMap). |
| 1872 | 1872 |
/// \see inverse() |
| 1873 | 1873 |
class InverseMap {
|
| 1874 | 1874 |
public: |
| 1875 | 1875 |
|
| 1876 | 1876 |
/// \brief Constructor. |
| 1877 | 1877 |
/// |
| 1878 | 1878 |
/// Constructor for creating an id-to-item map. |
| 1879 | 1879 |
explicit InverseMap(const Graph& graph) : _graph(&graph) {}
|
| 1880 | 1880 |
|
| 1881 | 1881 |
/// \brief Constructor. |
| 1882 | 1882 |
/// |
| 1883 | 1883 |
/// Constructor for creating an id-to-item map. |
| 1884 | 1884 |
explicit InverseMap(const IdMap& map) : _graph(map._graph) {}
|
| 1885 | 1885 |
|
| 1886 | 1886 |
/// \brief Gives back the given item from its id. |
| 1887 | 1887 |
/// |
| 1888 | 1888 |
/// Gives back the given item from its id. |
| 1889 | 1889 |
Item operator[](int id) const { return _graph->fromId(id, Item());}
|
| 1890 | 1890 |
|
| 1891 | 1891 |
private: |
| 1892 | 1892 |
const Graph* _graph; |
| 1893 | 1893 |
}; |
| 1894 | 1894 |
|
| 1895 | 1895 |
/// \brief Gives back the inverse of the map. |
| 1896 | 1896 |
/// |
| 1897 | 1897 |
/// Gives back the inverse of the IdMap. |
| 1898 | 1898 |
InverseMap inverse() const { return InverseMap(*_graph);}
|
| 1899 | 1899 |
}; |
| 1900 | 1900 |
|
| 1901 | 1901 |
|
| 1902 | 1902 |
/// \brief General cross reference graph map type. |
| 1903 | 1903 |
|
| 1904 | 1904 |
/// This class provides simple invertable graph maps. |
| 1905 |
/// It wraps an arbitrary \ref concepts::ReadWriteMap "ReadWriteMap" |
|
| 1906 |
/// and if a key is set to a new value then store it |
|
| 1907 |
/// in the inverse map. |
|
| 1908 |
/// |
|
| 1905 |
/// It wraps a standard graph map (\c NodeMap, \c ArcMap or \c EdgeMap) |
|
| 1906 |
/// and if a key is set to a new value, then stores it in the inverse map. |
|
| 1909 | 1907 |
/// The values of the map can be accessed |
| 1910 | 1908 |
/// with stl compatible forward iterator. |
| 1911 | 1909 |
/// |
| 1910 |
/// This type is not reference map, so it cannot be modified with |
|
| 1911 |
/// the subscript operator. |
|
| 1912 |
/// |
|
| 1912 | 1913 |
/// \tparam GR The graph type. |
| 1913 | 1914 |
/// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
| 1914 | 1915 |
/// \c GR::Edge). |
| 1915 | 1916 |
/// \tparam V The value type of the map. |
| 1916 | 1917 |
/// |
| 1917 | 1918 |
/// \see IterableValueMap |
| 1918 | 1919 |
template <typename GR, typename K, typename V> |
| 1919 | 1920 |
class CrossRefMap |
| 1920 | 1921 |
: protected ItemSetTraits<GR, K>::template Map<V>::Type {
|
| 1921 | 1922 |
private: |
| 1922 | 1923 |
|
| 1923 | 1924 |
typedef typename ItemSetTraits<GR, K>:: |
| 1924 | 1925 |
template Map<V>::Type Map; |
| 1925 | 1926 |
|
| 1926 |
typedef std:: |
|
| 1927 |
typedef std::multimap<V, K> Container; |
|
| 1927 | 1928 |
Container _inv_map; |
| 1928 | 1929 |
|
| 1929 | 1930 |
public: |
| 1930 | 1931 |
|
| 1931 | 1932 |
/// The graph type of CrossRefMap. |
| 1932 | 1933 |
typedef GR Graph; |
| 1933 | 1934 |
typedef GR Digraph; |
| 1934 | 1935 |
/// The key type of CrossRefMap (\c Node, \c Arc or \c Edge). |
| 1935 | 1936 |
typedef K Item; |
| 1936 | 1937 |
/// The key type of CrossRefMap (\c Node, \c Arc or \c Edge). |
| 1937 | 1938 |
typedef K Key; |
| 1938 | 1939 |
/// The value type of CrossRefMap. |
| 1939 | 1940 |
typedef V Value; |
| 1940 | 1941 |
|
| 1941 | 1942 |
/// \brief Constructor. |
| 1942 | 1943 |
/// |
| 1943 | 1944 |
/// Construct a new CrossRefMap for the given graph. |
| 1944 | 1945 |
explicit CrossRefMap(const Graph& graph) : Map(graph) {}
|
| 1945 | 1946 |
|
| 1946 | 1947 |
/// \brief Forward iterator for values. |
| 1947 | 1948 |
/// |
| 1948 | 1949 |
/// This iterator is an stl compatible forward |
| 1949 | 1950 |
/// iterator on the values of the map. The values can |
| 1950 | 1951 |
/// be accessed in the <tt>[beginValue, endValue)</tt> range. |
| 1952 |
/// They are considered with multiplicity, so each value is |
|
| 1953 |
/// traversed for each item it is assigned to. |
|
| 1951 | 1954 |
class ValueIterator |
| 1952 | 1955 |
: public std::iterator<std::forward_iterator_tag, Value> {
|
| 1953 | 1956 |
friend class CrossRefMap; |
| 1954 | 1957 |
private: |
| 1955 | 1958 |
ValueIterator(typename Container::const_iterator _it) |
| 1956 | 1959 |
: it(_it) {}
|
| 1957 | 1960 |
public: |
| 1958 | 1961 |
|
| 1959 | 1962 |
ValueIterator() {}
|
| 1960 | 1963 |
|
| 1961 | 1964 |
ValueIterator& operator++() { ++it; return *this; }
|
| 1962 | 1965 |
ValueIterator operator++(int) {
|
| 1963 | 1966 |
ValueIterator tmp(*this); |
| 1964 | 1967 |
operator++(); |
| 1965 | 1968 |
return tmp; |
| 1966 | 1969 |
} |
| 1967 | 1970 |
|
| 1968 | 1971 |
const Value& operator*() const { return it->first; }
|
| 1969 | 1972 |
const Value* operator->() const { return &(it->first); }
|
| 1970 | 1973 |
|
| 1971 | 1974 |
bool operator==(ValueIterator jt) const { return it == jt.it; }
|
| 1972 | 1975 |
bool operator!=(ValueIterator jt) const { return it != jt.it; }
|
| 1973 | 1976 |
|
| 1974 | 1977 |
private: |
| 1975 | 1978 |
typename Container::const_iterator it; |
| 1976 | 1979 |
}; |
| 1977 | 1980 |
|
| 1978 | 1981 |
/// \brief Returns an iterator to the first value. |
| 1979 | 1982 |
/// |
| 1980 | 1983 |
/// Returns an stl compatible iterator to the |
| 1981 | 1984 |
/// first value of the map. The values of the |
| 1982 | 1985 |
/// map can be accessed in the <tt>[beginValue, endValue)</tt> |
| 1983 | 1986 |
/// range. |
| 1984 | 1987 |
ValueIterator beginValue() const {
|
| 1985 | 1988 |
return ValueIterator(_inv_map.begin()); |
| 1986 | 1989 |
} |
| 1987 | 1990 |
|
| 1988 | 1991 |
/// \brief Returns an iterator after the last value. |
| 1989 | 1992 |
/// |
| 1990 | 1993 |
/// Returns an stl compatible iterator after the |
| 1991 | 1994 |
/// last value of the map. The values of the |
| 1992 | 1995 |
/// map can be accessed in the <tt>[beginValue, endValue)</tt> |
| 1993 | 1996 |
/// range. |
| 1994 | 1997 |
ValueIterator endValue() const {
|
| 1995 | 1998 |
return ValueIterator(_inv_map.end()); |
| 1996 | 1999 |
} |
| 1997 | 2000 |
|
| 1998 | 2001 |
/// \brief Sets the value associated with the given key. |
| 1999 | 2002 |
/// |
| 2000 | 2003 |
/// Sets the value associated with the given key. |
| 2001 | 2004 |
void set(const Key& key, const Value& val) {
|
| 2002 | 2005 |
Value oldval = Map::operator[](key); |
| 2003 |
typename Container::iterator it = _inv_map.find(oldval); |
|
| 2004 |
if (it != _inv_map.end() && it->second == key) {
|
|
| 2005 |
|
|
| 2006 |
typename Container::iterator it; |
|
| 2007 |
for (it = _inv_map.equal_range(oldval).first; |
|
| 2008 |
it != _inv_map.equal_range(oldval).second; ++it) {
|
|
| 2009 |
if (it->second == key) {
|
|
| 2010 |
_inv_map.erase(it); |
|
| 2011 |
break; |
|
| 2012 |
} |
|
| 2006 | 2013 |
} |
| 2007 |
_inv_map.insert(make_pair(val, key)); |
|
| 2014 |
_inv_map.insert(std::make_pair(val, key)); |
|
| 2008 | 2015 |
Map::set(key, val); |
| 2009 | 2016 |
} |
| 2010 | 2017 |
|
| 2011 | 2018 |
/// \brief Returns the value associated with the given key. |
| 2012 | 2019 |
/// |
| 2013 | 2020 |
/// Returns the value associated with the given key. |
| 2014 | 2021 |
typename MapTraits<Map>::ConstReturnValue |
| 2015 | 2022 |
operator[](const Key& key) const {
|
| 2016 | 2023 |
return Map::operator[](key); |
| 2017 | 2024 |
} |
| 2018 | 2025 |
|
| 2019 |
/// \brief Gives back |
|
| 2026 |
/// \brief Gives back an item by its value. |
|
| 2020 | 2027 |
/// |
| 2021 |
/// Gives back the item by its value. |
|
| 2022 |
Key operator()(const Value& key) const {
|
|
| 2023 |
|
|
| 2028 |
/// This function gives back an item that is assigned to |
|
| 2029 |
/// the given value or \c INVALID if no such item exists. |
|
| 2030 |
/// If there are more items with the same associated value, |
|
| 2031 |
/// only one of them is returned. |
|
| 2032 |
Key operator()(const Value& val) const {
|
|
| 2033 |
typename Container::const_iterator it = _inv_map.find(val); |
|
| 2024 | 2034 |
return it != _inv_map.end() ? it->second : INVALID; |
| 2025 | 2035 |
} |
| 2026 | 2036 |
|
| 2027 | 2037 |
protected: |
| 2028 | 2038 |
|
| 2029 | 2039 |
/// \brief Erase the key from the map and the inverse map. |
| 2030 | 2040 |
/// |
| 2031 | 2041 |
/// Erase the key from the map and the inverse map. It is called by the |
| 2032 | 2042 |
/// \c AlterationNotifier. |
| 2033 | 2043 |
virtual void erase(const Key& key) {
|
| 2034 | 2044 |
Value val = Map::operator[](key); |
| 2035 |
typename Container::iterator it = _inv_map.find(val); |
|
| 2036 |
if (it != _inv_map.end() && it->second == key) {
|
|
| 2037 |
|
|
| 2045 |
typename Container::iterator it; |
|
| 2046 |
for (it = _inv_map.equal_range(val).first; |
|
| 2047 |
it != _inv_map.equal_range(val).second; ++it) {
|
|
| 2048 |
if (it->second == key) {
|
|
| 2049 |
_inv_map.erase(it); |
|
| 2050 |
break; |
|
| 2051 |
} |
|
| 2038 | 2052 |
} |
| 2039 | 2053 |
Map::erase(key); |
| 2040 | 2054 |
} |
| 2041 | 2055 |
|
| 2042 | 2056 |
/// \brief Erase more keys from the map and the inverse map. |
| 2043 | 2057 |
/// |
| 2044 | 2058 |
/// Erase more keys from the map and the inverse map. It is called by the |
| 2045 | 2059 |
/// \c AlterationNotifier. |
| 2046 | 2060 |
virtual void erase(const std::vector<Key>& keys) {
|
| 2047 | 2061 |
for (int i = 0; i < int(keys.size()); ++i) {
|
| 2048 | 2062 |
Value val = Map::operator[](keys[i]); |
| 2049 |
typename Container::iterator it = _inv_map.find(val); |
|
| 2050 |
if (it != _inv_map.end() && it->second == keys[i]) {
|
|
| 2051 |
|
|
| 2063 |
typename Container::iterator it; |
|
| 2064 |
for (it = _inv_map.equal_range(val).first; |
|
| 2065 |
it != _inv_map.equal_range(val).second; ++it) {
|
|
| 2066 |
if (it->second == keys[i]) {
|
|
| 2067 |
_inv_map.erase(it); |
|
| 2068 |
break; |
|
| 2069 |
} |
|
| 2052 | 2070 |
} |
| 2053 | 2071 |
} |
| 2054 | 2072 |
Map::erase(keys); |
| 2055 | 2073 |
} |
| 2056 | 2074 |
|
| 2057 | 2075 |
/// \brief Clear the keys from the map and the inverse map. |
| 2058 | 2076 |
/// |
| 2059 | 2077 |
/// Clear the keys from the map and the inverse map. It is called by the |
| 2060 | 2078 |
/// \c AlterationNotifier. |
| 2061 | 2079 |
virtual void clear() {
|
| 2062 | 2080 |
_inv_map.clear(); |
| 2063 | 2081 |
Map::clear(); |
| 2064 | 2082 |
} |
| 2065 | 2083 |
|
| 2066 | 2084 |
public: |
| 2067 | 2085 |
|
| 2068 | 2086 |
/// \brief The inverse map type. |
| 2069 | 2087 |
/// |
| 2070 | 2088 |
/// The inverse of this map. The subscript operator of the map |
| 2071 | 2089 |
/// gives back the item that was last assigned to the value. |
| 2072 | 2090 |
class InverseMap {
|
| 2073 | 2091 |
public: |
| 2074 | 2092 |
/// \brief Constructor |
| 2075 | 2093 |
/// |
| 2076 | 2094 |
/// Constructor of the InverseMap. |
| 2077 | 2095 |
explicit InverseMap(const CrossRefMap& inverted) |
| 2078 | 2096 |
: _inverted(inverted) {}
|
| 2079 | 2097 |
|
| 2080 | 2098 |
/// The value type of the InverseMap. |
| 2081 | 2099 |
typedef typename CrossRefMap::Key Value; |
| 2082 | 2100 |
/// The key type of the InverseMap. |
| 2083 | 2101 |
typedef typename CrossRefMap::Value Key; |
| 2084 | 2102 |
|
| 2085 | 2103 |
/// \brief Subscript operator. |
| 2086 | 2104 |
/// |
| 2087 |
/// Subscript operator. It gives back the item |
|
| 2088 |
/// that was last assigned to the given value. |
|
| 2105 |
/// Subscript operator. It gives back an item |
|
| 2106 |
/// that is assigned to the given value or \c INVALID |
|
| 2107 |
/// if no such item exists. |
|
| 2089 | 2108 |
Value operator[](const Key& key) const {
|
| 2090 | 2109 |
return _inverted(key); |
| 2091 | 2110 |
} |
| 2092 | 2111 |
|
| 2093 | 2112 |
private: |
| 2094 | 2113 |
const CrossRefMap& _inverted; |
| 2095 | 2114 |
}; |
| 2096 | 2115 |
|
| 2097 | 2116 |
/// \brief It gives back the read-only inverse map. |
| 2098 | 2117 |
/// |
| 2099 | 2118 |
/// It gives back the read-only inverse map. |
| 2100 | 2119 |
InverseMap inverse() const {
|
| 2101 | 2120 |
return InverseMap(*this); |
| 2102 | 2121 |
} |
| 2103 | 2122 |
|
| 2104 | 2123 |
}; |
| 2105 | 2124 |
|
| 2106 | 2125 |
/// \brief Provides continuous and unique ID for the |
| 2107 | 2126 |
/// items of a graph. |
| 2108 | 2127 |
/// |
| 2109 | 2128 |
/// RangeIdMap provides a unique and continuous |
| 2110 | 2129 |
/// ID for each item of a given type (\c Node, \c Arc or |
| 2111 | 2130 |
/// \c Edge) in a graph. This id is |
| 2112 | 2131 |
/// - \b unique: different items get different ids, |
| 2113 | 2132 |
/// - \b continuous: the range of the ids is the set of integers |
| 2114 | 2133 |
/// between 0 and \c n-1, where \c n is the number of the items of |
| 2115 | 2134 |
/// this type (\c Node, \c Arc or \c Edge). |
| 2116 | 2135 |
/// - So, the ids can change when deleting an item of the same type. |
| 2117 | 2136 |
/// |
| 2118 | 2137 |
/// Thus this id is not (necessarily) the same as what can get using |
| 2119 | 2138 |
/// the \c id() function of the graph or \ref IdMap. |
| 2120 | 2139 |
/// This map can be inverted with its member class \c InverseMap, |
| 2121 | 2140 |
/// or with the \c operator() member. |
| 2122 | 2141 |
/// |
| 2123 | 2142 |
/// \tparam GR The graph type. |
| 2124 | 2143 |
/// \tparam K The key type of the map (\c GR::Node, \c GR::Arc or |
| 2125 | 2144 |
/// \c GR::Edge). |
| 2126 | 2145 |
/// |
| 2127 | 2146 |
/// \see IdMap |
| 2128 | 2147 |
template <typename GR, typename K> |
| 2129 | 2148 |
class RangeIdMap |
| 2130 | 2149 |
: protected ItemSetTraits<GR, K>::template Map<int>::Type {
|
| 2131 | 2150 |
|
| 2132 | 2151 |
typedef typename ItemSetTraits<GR, K>::template Map<int>::Type Map; |
| 2133 | 2152 |
|
| 2134 | 2153 |
public: |
| 2135 | 2154 |
/// The graph type of RangeIdMap. |
| 2136 | 2155 |
typedef GR Graph; |
| 2137 | 2156 |
typedef GR Digraph; |
| 2138 | 2157 |
/// The key type of RangeIdMap (\c Node, \c Arc or \c Edge). |
| 2139 | 2158 |
typedef K Item; |
| 2140 | 2159 |
/// The key type of RangeIdMap (\c Node, \c Arc or \c Edge). |
| 2141 | 2160 |
typedef K Key; |
| 2142 | 2161 |
/// The value type of RangeIdMap. |
| 2143 | 2162 |
typedef int Value; |
| 2144 | 2163 |
|
| 2145 | 2164 |
/// \brief Constructor. |
| 2146 | 2165 |
/// |
| 2147 | 2166 |
/// Constructor. |
| 2148 | 2167 |
explicit RangeIdMap(const Graph& gr) : Map(gr) {
|
| 2149 | 2168 |
Item it; |
| 2150 | 2169 |
const typename Map::Notifier* nf = Map::notifier(); |
| 2151 | 2170 |
for (nf->first(it); it != INVALID; nf->next(it)) {
|
| 2152 | 2171 |
Map::set(it, _inv_map.size()); |
| 2153 | 2172 |
_inv_map.push_back(it); |
| 2154 | 2173 |
} |
| 2155 | 2174 |
} |
| 2156 | 2175 |
|
| 2157 | 2176 |
protected: |
| 2158 | 2177 |
|
| 2159 | 2178 |
/// \brief Adds a new key to the map. |
| 2160 | 2179 |
/// |
| 2161 | 2180 |
/// Add a new key to the map. It is called by the |
| 2162 | 2181 |
/// \c AlterationNotifier. |
| 2163 | 2182 |
virtual void add(const Item& item) {
|
| 2164 | 2183 |
Map::add(item); |
| 2165 | 2184 |
Map::set(item, _inv_map.size()); |
| 2166 | 2185 |
_inv_map.push_back(item); |
| 2167 | 2186 |
} |
| 2168 | 2187 |
|
| 2169 | 2188 |
/// \brief Add more new keys to the map. |
| 2170 | 2189 |
/// |
| 2171 | 2190 |
/// Add more new keys to the map. It is called by the |
| 2172 | 2191 |
/// \c AlterationNotifier. |
| 2173 | 2192 |
virtual void add(const std::vector<Item>& items) {
|
| 2174 | 2193 |
Map::add(items); |
| 2175 | 2194 |
for (int i = 0; i < int(items.size()); ++i) {
|
| 2176 | 2195 |
Map::set(items[i], _inv_map.size()); |
| 2177 | 2196 |
_inv_map.push_back(items[i]); |
| 2178 | 2197 |
} |
| 2179 | 2198 |
} |
| 2180 | 2199 |
|
| 2181 | 2200 |
/// \brief Erase the key from the map. |
| 2182 | 2201 |
/// |
| 2183 | 2202 |
/// Erase the key from the map. It is called by the |
| 2184 | 2203 |
/// \c AlterationNotifier. |
| 2185 | 2204 |
virtual void erase(const Item& item) {
|
| 2186 | 2205 |
Map::set(_inv_map.back(), Map::operator[](item)); |
| 2187 | 2206 |
_inv_map[Map::operator[](item)] = _inv_map.back(); |
| 2188 | 2207 |
_inv_map.pop_back(); |
| 2189 | 2208 |
Map::erase(item); |
| 2190 | 2209 |
} |
| 2191 | 2210 |
|
| 2192 | 2211 |
/// \brief Erase more keys from the map. |
| 2193 | 2212 |
/// |
| 2194 | 2213 |
/// Erase more keys from the map. It is called by the |
| 2195 | 2214 |
/// \c AlterationNotifier. |
| 2196 | 2215 |
virtual void erase(const std::vector<Item>& items) {
|
| 2197 | 2216 |
for (int i = 0; i < int(items.size()); ++i) {
|
| 2198 | 2217 |
Map::set(_inv_map.back(), Map::operator[](items[i])); |
| 2199 | 2218 |
_inv_map[Map::operator[](items[i])] = _inv_map.back(); |
| 2200 | 2219 |
_inv_map.pop_back(); |
| 2201 | 2220 |
} |
| 2202 | 2221 |
Map::erase(items); |
| 2203 | 2222 |
} |
| 2204 | 2223 |
|
| 2205 | 2224 |
/// \brief Build the unique map. |
| 2206 | 2225 |
/// |
| 2207 | 2226 |
/// Build the unique map. It is called by the |
| 2208 | 2227 |
/// \c AlterationNotifier. |
| 2209 | 2228 |
virtual void build() {
|
| 2210 | 2229 |
Map::build(); |
| 2211 | 2230 |
Item it; |
| 2212 | 2231 |
const typename Map::Notifier* nf = Map::notifier(); |
| 2213 | 2232 |
for (nf->first(it); it != INVALID; nf->next(it)) {
|
| 2214 | 2233 |
Map::set(it, _inv_map.size()); |
| 2215 | 2234 |
_inv_map.push_back(it); |
| 2216 | 2235 |
} |
| 2217 | 2236 |
} |
| 2218 | 2237 |
|
| 2219 | 2238 |
/// \brief Clear the keys from the map. |
| 2220 | 2239 |
/// |
| 2221 | 2240 |
/// Clear the keys from the map. It is called by the |
| 2222 | 2241 |
/// \c AlterationNotifier. |
| 2223 | 2242 |
virtual void clear() {
|
| 2224 | 2243 |
_inv_map.clear(); |
| 2225 | 2244 |
Map::clear(); |
| 2226 | 2245 |
} |
| 2227 | 2246 |
|
| 2228 | 2247 |
public: |
| 2229 | 2248 |
|
| 2230 | 2249 |
/// \brief Returns the maximal value plus one. |
| 2231 | 2250 |
/// |
| 2232 | 2251 |
/// Returns the maximal value plus one in the map. |
| 2233 | 2252 |
unsigned int size() const {
|
| 2234 | 2253 |
return _inv_map.size(); |
| 2235 | 2254 |
} |
| 2236 | 2255 |
|
| 2237 | 2256 |
/// \brief Swaps the position of the two items in the map. |
| 2238 | 2257 |
/// |
| 2239 | 2258 |
/// Swaps the position of the two items in the map. |
| 2240 | 2259 |
void swap(const Item& p, const Item& q) {
|
| 2241 | 2260 |
int pi = Map::operator[](p); |
| 2242 | 2261 |
int qi = Map::operator[](q); |
| 2243 | 2262 |
Map::set(p, qi); |
| 2244 | 2263 |
_inv_map[qi] = p; |
| 2245 | 2264 |
Map::set(q, pi); |
| 2246 | 2265 |
_inv_map[pi] = q; |
| 2247 | 2266 |
} |
| 2248 | 2267 |
|
| 2249 | 2268 |
/// \brief Gives back the \e RangeId of the item |
| 2250 | 2269 |
/// |
| 2251 | 2270 |
/// Gives back the \e RangeId of the item. |
| 2252 | 2271 |
int operator[](const Item& item) const {
|
| 2253 | 2272 |
return Map::operator[](item); |
| 2254 | 2273 |
} |
| 2255 | 2274 |
|
| 2256 | 2275 |
/// \brief Gives back the item belonging to a \e RangeId |
| 2257 | 2276 |
/// |
| 2258 | 2277 |
/// Gives back the item belonging to a \e RangeId. |
| 2259 | 2278 |
Item operator()(int id) const {
|
| 2260 | 2279 |
return _inv_map[id]; |
| 2261 | 2280 |
} |
| 2262 | 2281 |
|
| 2263 | 2282 |
private: |
| 2264 | 2283 |
|
| 2265 | 2284 |
typedef std::vector<Item> Container; |
| 2266 | 2285 |
Container _inv_map; |
| 2267 | 2286 |
|
| 2268 | 2287 |
public: |
| 2269 | 2288 |
|
| 2270 | 2289 |
/// \brief The inverse map type of RangeIdMap. |
| 2271 | 2290 |
/// |
| 2272 | 2291 |
/// The inverse map type of RangeIdMap. |
| 2273 | 2292 |
class InverseMap {
|
| 2274 | 2293 |
public: |
| 2275 | 2294 |
/// \brief Constructor |
| 2276 | 2295 |
/// |
| 2277 | 2296 |
/// Constructor of the InverseMap. |
| 2278 | 2297 |
explicit InverseMap(const RangeIdMap& inverted) |
| 2279 | 2298 |
: _inverted(inverted) {}
|
| 2280 | 2299 |
|
| 2281 | 2300 |
|
| 2282 | 2301 |
/// The value type of the InverseMap. |
| 2283 | 2302 |
typedef typename RangeIdMap::Key Value; |
| 2284 | 2303 |
/// The key type of the InverseMap. |
| 2285 | 2304 |
typedef typename RangeIdMap::Value Key; |
| 2286 | 2305 |
|
| 2287 | 2306 |
/// \brief Subscript operator. |
| 2288 | 2307 |
/// |
| 2289 | 2308 |
/// Subscript operator. It gives back the item |
| 2290 | 2309 |
/// that the descriptor currently belongs to. |
| 2291 | 2310 |
Value operator[](const Key& key) const {
|
| 2292 | 2311 |
return _inverted(key); |
| 2293 | 2312 |
} |
| 2294 | 2313 |
|
| 2295 | 2314 |
/// \brief Size of the map. |
| 2296 | 2315 |
/// |
| 2297 | 2316 |
/// Returns the size of the map. |
| 2298 | 2317 |
unsigned int size() const {
|
| 2299 | 2318 |
return _inverted.size(); |
| 2300 | 2319 |
} |
| 2301 | 2320 |
|
| 2302 | 2321 |
private: |
| 2303 | 2322 |
const RangeIdMap& _inverted; |
| 2304 | 2323 |
}; |
| 2305 | 2324 |
|
| 2306 | 2325 |
/// \brief Gives back the inverse of the map. |
| 2307 | 2326 |
/// |
| 2308 | 2327 |
/// Gives back the inverse of the map. |
| 2309 | 2328 |
const InverseMap inverse() const {
|
| 2310 | 2329 |
return InverseMap(*this); |
| 2311 | 2330 |
} |
| 2312 | 2331 |
}; |
| 2313 | 2332 |
|
| 2314 | 2333 |
/// \brief Map of the source nodes of arcs in a digraph. |
| 2315 | 2334 |
/// |
| 2316 | 2335 |
/// SourceMap provides access for the source node of each arc in a digraph, |
| 2317 | 2336 |
/// which is returned by the \c source() function of the digraph. |
| 2318 | 2337 |
/// \tparam GR The digraph type. |
| 2319 | 2338 |
/// \see TargetMap |
| 2320 | 2339 |
template <typename GR> |
| 2321 | 2340 |
class SourceMap {
|
| 2322 | 2341 |
public: |
| 2323 | 2342 |
|
| 2324 | 2343 |
///\e |
| 2325 | 2344 |
typedef typename GR::Arc Key; |
| 2326 | 2345 |
///\e |
| 2327 | 2346 |
typedef typename GR::Node Value; |
| 2328 | 2347 |
|
| 2329 | 2348 |
/// \brief Constructor |
| 2330 | 2349 |
/// |
| 2331 | 2350 |
/// Constructor. |
| 2332 | 2351 |
/// \param digraph The digraph that the map belongs to. |
| 2333 | 2352 |
explicit SourceMap(const GR& digraph) : _graph(digraph) {}
|
| 2334 | 2353 |
|
| 2335 | 2354 |
/// \brief Returns the source node of the given arc. |
| 2336 | 2355 |
/// |
| 2337 | 2356 |
/// Returns the source node of the given arc. |
| 2338 | 2357 |
Value operator[](const Key& arc) const {
|
| 2339 | 2358 |
return _graph.source(arc); |
| 2340 | 2359 |
} |
| 2341 | 2360 |
|
| 2342 | 2361 |
private: |
| 2343 | 2362 |
const GR& _graph; |
| 2344 | 2363 |
}; |
| 2345 | 2364 |
|
| 2346 | 2365 |
/// \brief Returns a \c SourceMap class. |
| 2347 | 2366 |
/// |
| 2348 | 2367 |
/// This function just returns an \c SourceMap class. |
| 2349 | 2368 |
/// \relates SourceMap |
| 2350 | 2369 |
template <typename GR> |
| 2351 | 2370 |
inline SourceMap<GR> sourceMap(const GR& graph) {
|
| 2352 | 2371 |
return SourceMap<GR>(graph); |
| 2353 | 2372 |
} |
| 2354 | 2373 |
|
| 2355 | 2374 |
/// \brief Map of the target nodes of arcs in a digraph. |
| 2356 | 2375 |
/// |
| 2357 | 2376 |
/// TargetMap provides access for the target node of each arc in a digraph, |
| 2358 | 2377 |
/// which is returned by the \c target() function of the digraph. |
| 2359 | 2378 |
/// \tparam GR The digraph type. |
| 2360 | 2379 |
/// \see SourceMap |
| 2361 | 2380 |
template <typename GR> |
| 2362 | 2381 |
class TargetMap {
|
| 2363 | 2382 |
public: |
| 2364 | 2383 |
|
| 2365 | 2384 |
///\e |
| 2366 | 2385 |
typedef typename GR::Arc Key; |
| 2367 | 2386 |
///\e |
| 2368 | 2387 |
typedef typename GR::Node Value; |
| 2369 | 2388 |
|
| 2370 | 2389 |
/// \brief Constructor |
| 2371 | 2390 |
/// |
| 2372 | 2391 |
/// Constructor. |
| 2373 | 2392 |
/// \param digraph The digraph that the map belongs to. |
| 2374 | 2393 |
explicit TargetMap(const GR& digraph) : _graph(digraph) {}
|
| 2375 | 2394 |
|
| 2376 | 2395 |
/// \brief Returns the target node of the given arc. |
| 2377 | 2396 |
/// |
| 2378 | 2397 |
/// Returns the target node of the given arc. |
| 2379 | 2398 |
Value operator[](const Key& e) const {
|
| 2380 | 2399 |
return _graph.target(e); |
| 2381 | 2400 |
} |
| 2382 | 2401 |
|
| 2383 | 2402 |
private: |
| 2384 | 2403 |
const GR& _graph; |
| 2385 | 2404 |
}; |
| 2386 | 2405 |
|
| 2387 | 2406 |
/// \brief Returns a \c TargetMap class. |
| 2388 | 2407 |
/// |
| 2389 | 2408 |
/// This function just returns a \c TargetMap class. |
| 2390 | 2409 |
/// \relates TargetMap |
| 2391 | 2410 |
template <typename GR> |
| 2392 | 2411 |
inline TargetMap<GR> targetMap(const GR& graph) {
|
| 2393 | 2412 |
return TargetMap<GR>(graph); |
| 2394 | 2413 |
} |
| 2395 | 2414 |
|
| 2396 | 2415 |
/// \brief Map of the "forward" directed arc view of edges in a graph. |
| 2397 | 2416 |
/// |
| 2398 | 2417 |
/// ForwardMap provides access for the "forward" directed arc view of |
| 2399 | 2418 |
/// each edge in a graph, which is returned by the \c direct() function |
| 2400 | 2419 |
/// of the graph with \c true parameter. |
| 2401 | 2420 |
/// \tparam GR The graph type. |
| 2402 | 2421 |
/// \see BackwardMap |
| 2403 | 2422 |
template <typename GR> |
| 2404 | 2423 |
class ForwardMap {
|
| 2405 | 2424 |
public: |
| 2406 | 2425 |
|
| 2407 | 2426 |
typedef typename GR::Arc Value; |
| 2408 | 2427 |
typedef typename GR::Edge Key; |
| 2409 | 2428 |
|
| 2410 | 2429 |
/// \brief Constructor |
| 2411 | 2430 |
/// |
| 2412 | 2431 |
/// Constructor. |
| 2413 | 2432 |
/// \param graph The graph that the map belongs to. |
| 2414 | 2433 |
explicit ForwardMap(const GR& graph) : _graph(graph) {}
|
| 2415 | 2434 |
|
| 2416 | 2435 |
/// \brief Returns the "forward" directed arc view of the given edge. |
| 2417 | 2436 |
/// |
| 2418 | 2437 |
/// Returns the "forward" directed arc view of the given edge. |
| 2419 | 2438 |
Value operator[](const Key& key) const {
|
| 2420 | 2439 |
return _graph.direct(key, true); |
| 2421 | 2440 |
} |
| 2422 | 2441 |
|
| 2423 | 2442 |
private: |
| 2424 | 2443 |
const GR& _graph; |
| 2425 | 2444 |
}; |
| 2426 | 2445 |
|
| 2427 | 2446 |
/// \brief Returns a \c ForwardMap class. |
| 2428 | 2447 |
/// |
| 2429 | 2448 |
/// This function just returns an \c ForwardMap class. |
| 2430 | 2449 |
/// \relates ForwardMap |
| 2431 | 2450 |
template <typename GR> |
| 2432 | 2451 |
inline ForwardMap<GR> forwardMap(const GR& graph) {
|
| 2433 | 2452 |
return ForwardMap<GR>(graph); |
| 2434 | 2453 |
} |
| 2435 | 2454 |
|
| 2436 | 2455 |
/// \brief Map of the "backward" directed arc view of edges in a graph. |
| 2437 | 2456 |
/// |
| 2438 | 2457 |
/// BackwardMap provides access for the "backward" directed arc view of |
| 2439 | 2458 |
/// each edge in a graph, which is returned by the \c direct() function |
| 2440 | 2459 |
/// of the graph with \c false parameter. |
| 2441 | 2460 |
/// \tparam GR The graph type. |
| 2442 | 2461 |
/// \see ForwardMap |
| 2443 | 2462 |
template <typename GR> |
| 2444 | 2463 |
class BackwardMap {
|
| 2445 | 2464 |
public: |
| 2446 | 2465 |
|
| 2447 | 2466 |
typedef typename GR::Arc Value; |
| 2448 | 2467 |
typedef typename GR::Edge Key; |
| 2449 | 2468 |
|
| 2450 | 2469 |
/// \brief Constructor |
| 2451 | 2470 |
/// |
| 2452 | 2471 |
/// Constructor. |
| 2453 | 2472 |
/// \param graph The graph that the map belongs to. |
| 2454 | 2473 |
explicit BackwardMap(const GR& graph) : _graph(graph) {}
|
| 2455 | 2474 |
|
| 2456 | 2475 |
/// \brief Returns the "backward" directed arc view of the given edge. |
| 2457 | 2476 |
/// |
| 2458 | 2477 |
/// Returns the "backward" directed arc view of the given edge. |
| 2459 | 2478 |
Value operator[](const Key& key) const {
|
| 2460 | 2479 |
return _graph.direct(key, false); |
| 2461 | 2480 |
} |
| 2462 | 2481 |
|
| 2463 | 2482 |
private: |
| 2464 | 2483 |
const GR& _graph; |
| 2465 | 2484 |
}; |
| 2466 | 2485 |
|
| 2467 | 2486 |
/// \brief Returns a \c BackwardMap class |
| 2468 | 2487 |
|
| 2469 | 2488 |
/// This function just returns a \c BackwardMap class. |
| 2470 | 2489 |
/// \relates BackwardMap |
| 2471 | 2490 |
template <typename GR> |
| 2472 | 2491 |
inline BackwardMap<GR> backwardMap(const GR& graph) {
|
| 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 |
#include <deque> |
| 20 | 20 |
#include <set> |
| 21 | 21 |
|
| 22 | 22 |
#include <lemon/concept_check.h> |
| 23 | 23 |
#include <lemon/concepts/maps.h> |
| 24 | 24 |
#include <lemon/maps.h> |
| 25 |
#include <lemon/list_graph.h> |
|
| 25 | 26 |
|
| 26 | 27 |
#include "test_tools.h" |
| 27 | 28 |
|
| 28 | 29 |
using namespace lemon; |
| 29 | 30 |
using namespace lemon::concepts; |
| 30 | 31 |
|
| 31 | 32 |
struct A {};
|
| 32 | 33 |
inline bool operator<(A, A) { return true; }
|
| 33 | 34 |
struct B {};
|
| 34 | 35 |
|
| 35 | 36 |
class C {
|
| 36 | 37 |
int x; |
| 37 | 38 |
public: |
| 38 | 39 |
C(int _x) : x(_x) {}
|
| 39 | 40 |
}; |
| 40 | 41 |
|
| 41 | 42 |
class F {
|
| 42 | 43 |
public: |
| 43 | 44 |
typedef A argument_type; |
| 44 | 45 |
typedef B result_type; |
| 45 | 46 |
|
| 46 | 47 |
B operator()(const A&) const { return B(); }
|
| 47 | 48 |
private: |
| 48 | 49 |
F& operator=(const F&); |
| 49 | 50 |
}; |
| 50 | 51 |
|
| 51 | 52 |
int func(A) { return 3; }
|
| 52 | 53 |
|
| 53 | 54 |
int binc(int a, B) { return a+1; }
|
| 54 | 55 |
|
| 55 | 56 |
typedef ReadMap<A, double> DoubleMap; |
| 56 | 57 |
typedef ReadWriteMap<A, double> DoubleWriteMap; |
| 57 | 58 |
typedef ReferenceMap<A, double, double&, const double&> DoubleRefMap; |
| 58 | 59 |
|
| 59 | 60 |
typedef ReadMap<A, bool> BoolMap; |
| 60 | 61 |
typedef ReadWriteMap<A, bool> BoolWriteMap; |
| 61 | 62 |
typedef ReferenceMap<A, bool, bool&, const bool&> BoolRefMap; |
| 62 | 63 |
|
| 63 | 64 |
int main() |
| 64 | 65 |
{
|
| 65 | 66 |
// Map concepts |
| 66 | 67 |
checkConcept<ReadMap<A,B>, ReadMap<A,B> >(); |
| 67 | 68 |
checkConcept<ReadMap<A,C>, ReadMap<A,C> >(); |
| 68 | 69 |
checkConcept<WriteMap<A,B>, WriteMap<A,B> >(); |
| 69 | 70 |
checkConcept<WriteMap<A,C>, WriteMap<A,C> >(); |
| 70 | 71 |
checkConcept<ReadWriteMap<A,B>, ReadWriteMap<A,B> >(); |
| 71 | 72 |
checkConcept<ReadWriteMap<A,C>, ReadWriteMap<A,C> >(); |
| 72 | 73 |
checkConcept<ReferenceMap<A,B,B&,const B&>, ReferenceMap<A,B,B&,const B&> >(); |
| 73 | 74 |
checkConcept<ReferenceMap<A,C,C&,const C&>, ReferenceMap<A,C,C&,const C&> >(); |
| 74 | 75 |
|
| 75 | 76 |
// NullMap |
| 76 | 77 |
{
|
| 77 | 78 |
checkConcept<ReadWriteMap<A,B>, NullMap<A,B> >(); |
| 78 | 79 |
NullMap<A,B> map1; |
| 79 | 80 |
NullMap<A,B> map2 = map1; |
| 80 | 81 |
map1 = nullMap<A,B>(); |
| 81 | 82 |
} |
| 82 | 83 |
|
| 83 | 84 |
// ConstMap |
| 84 | 85 |
{
|
| 85 | 86 |
checkConcept<ReadWriteMap<A,B>, ConstMap<A,B> >(); |
| 86 | 87 |
checkConcept<ReadWriteMap<A,C>, ConstMap<A,C> >(); |
| 87 | 88 |
ConstMap<A,B> map1; |
| 88 | 89 |
ConstMap<A,B> map2 = B(); |
| 89 | 90 |
ConstMap<A,B> map3 = map1; |
| 90 | 91 |
map1 = constMap<A>(B()); |
| 91 | 92 |
map1 = constMap<A,B>(); |
| 92 | 93 |
map1.setAll(B()); |
| 93 | 94 |
ConstMap<A,C> map4(C(1)); |
| 94 | 95 |
ConstMap<A,C> map5 = map4; |
| 95 | 96 |
map4 = constMap<A>(C(2)); |
| 96 | 97 |
map4.setAll(C(3)); |
| 97 | 98 |
|
| 98 | 99 |
checkConcept<ReadWriteMap<A,int>, ConstMap<A,int> >(); |
| 99 | 100 |
check(constMap<A>(10)[A()] == 10, "Something is wrong with ConstMap"); |
| 100 | 101 |
|
| 101 | 102 |
checkConcept<ReadWriteMap<A,int>, ConstMap<A,Const<int,10> > >(); |
| 102 | 103 |
ConstMap<A,Const<int,10> > map6; |
| 103 | 104 |
ConstMap<A,Const<int,10> > map7 = map6; |
| 104 | 105 |
map6 = constMap<A,int,10>(); |
| 105 | 106 |
map7 = constMap<A,Const<int,10> >(); |
| 106 | 107 |
check(map6[A()] == 10 && map7[A()] == 10, |
| 107 | 108 |
"Something is wrong with ConstMap"); |
| 108 | 109 |
} |
| 109 | 110 |
|
| 110 | 111 |
// IdentityMap |
| 111 | 112 |
{
|
| 112 | 113 |
checkConcept<ReadMap<A,A>, IdentityMap<A> >(); |
| 113 | 114 |
IdentityMap<A> map1; |
| 114 | 115 |
IdentityMap<A> map2 = map1; |
| 115 | 116 |
map1 = identityMap<A>(); |
| 116 | 117 |
|
| 117 | 118 |
checkConcept<ReadMap<double,double>, IdentityMap<double> >(); |
| 118 | 119 |
check(identityMap<double>()[1.0] == 1.0 && |
| 119 | 120 |
identityMap<double>()[3.14] == 3.14, |
| 120 | 121 |
"Something is wrong with IdentityMap"); |
| 121 | 122 |
} |
| 122 | 123 |
|
| 123 | 124 |
// RangeMap |
| 124 | 125 |
{
|
| 125 | 126 |
checkConcept<ReferenceMap<int,B,B&,const B&>, RangeMap<B> >(); |
| 126 | 127 |
RangeMap<B> map1; |
| 127 | 128 |
RangeMap<B> map2(10); |
| 128 | 129 |
RangeMap<B> map3(10,B()); |
| 129 | 130 |
RangeMap<B> map4 = map1; |
| 130 | 131 |
RangeMap<B> map5 = rangeMap<B>(); |
| 131 | 132 |
RangeMap<B> map6 = rangeMap<B>(10); |
| 132 | 133 |
RangeMap<B> map7 = rangeMap(10,B()); |
| 133 | 134 |
|
| 134 | 135 |
checkConcept< ReferenceMap<int, double, double&, const double&>, |
| 135 | 136 |
RangeMap<double> >(); |
| 136 | 137 |
std::vector<double> v(10, 0); |
| 137 | 138 |
v[5] = 100; |
| 138 | 139 |
RangeMap<double> map8(v); |
| 139 | 140 |
RangeMap<double> map9 = rangeMap(v); |
| 140 | 141 |
check(map9.size() == 10 && map9[2] == 0 && map9[5] == 100, |
| 141 | 142 |
"Something is wrong with RangeMap"); |
| 142 | 143 |
} |
| 143 | 144 |
|
| 144 | 145 |
// SparseMap |
| 145 | 146 |
{
|
| 146 | 147 |
checkConcept<ReferenceMap<A,B,B&,const B&>, SparseMap<A,B> >(); |
| 147 | 148 |
SparseMap<A,B> map1; |
| 148 | 149 |
SparseMap<A,B> map2 = B(); |
| 149 | 150 |
SparseMap<A,B> map3 = sparseMap<A,B>(); |
| 150 | 151 |
SparseMap<A,B> map4 = sparseMap<A>(B()); |
| 151 | 152 |
|
| 152 | 153 |
checkConcept< ReferenceMap<double, int, int&, const int&>, |
| 153 | 154 |
SparseMap<double, int> >(); |
| 154 | 155 |
std::map<double, int> m; |
| 155 | 156 |
SparseMap<double, int> map5(m); |
| 156 | 157 |
SparseMap<double, int> map6(m,10); |
| 157 | 158 |
SparseMap<double, int> map7 = sparseMap(m); |
| 158 | 159 |
SparseMap<double, int> map8 = sparseMap(m,10); |
| 159 | 160 |
|
| 160 | 161 |
check(map5[1.0] == 0 && map5[3.14] == 0 && |
| 161 | 162 |
map6[1.0] == 10 && map6[3.14] == 10, |
| 162 | 163 |
"Something is wrong with SparseMap"); |
| 163 | 164 |
map5[1.0] = map6[3.14] = 100; |
| 164 | 165 |
check(map5[1.0] == 100 && map5[3.14] == 0 && |
| 165 | 166 |
map6[1.0] == 10 && map6[3.14] == 100, |
| 166 | 167 |
"Something is wrong with SparseMap"); |
| 167 | 168 |
} |
| 168 | 169 |
|
| 169 | 170 |
// ComposeMap |
| 170 | 171 |
{
|
| 171 | 172 |
typedef ComposeMap<DoubleMap, ReadMap<B,A> > CompMap; |
| 172 | 173 |
checkConcept<ReadMap<B,double>, CompMap>(); |
| 173 | 174 |
CompMap map1 = CompMap(DoubleMap(),ReadMap<B,A>()); |
| 174 | 175 |
CompMap map2 = composeMap(DoubleMap(), ReadMap<B,A>()); |
| 175 | 176 |
|
| 176 | 177 |
SparseMap<double, bool> m1(false); m1[3.14] = true; |
| 177 | 178 |
RangeMap<double> m2(2); m2[0] = 3.0; m2[1] = 3.14; |
| 178 | 179 |
check(!composeMap(m1,m2)[0] && composeMap(m1,m2)[1], |
| 179 | 180 |
"Something is wrong with ComposeMap") |
| 180 | 181 |
} |
| 181 | 182 |
|
| 182 | 183 |
// CombineMap |
| 183 | 184 |
{
|
| 184 | 185 |
typedef CombineMap<DoubleMap, DoubleMap, std::plus<double> > CombMap; |
| 185 | 186 |
checkConcept<ReadMap<A,double>, CombMap>(); |
| 186 | 187 |
CombMap map1 = CombMap(DoubleMap(), DoubleMap()); |
| 187 | 188 |
CombMap map2 = combineMap(DoubleMap(), DoubleMap(), std::plus<double>()); |
| 188 | 189 |
|
| 189 | 190 |
check(combineMap(constMap<B,int,2>(), identityMap<B>(), &binc)[B()] == 3, |
| 190 | 191 |
"Something is wrong with CombineMap"); |
| 191 | 192 |
} |
| 192 | 193 |
|
| 193 | 194 |
// FunctorToMap, MapToFunctor |
| 194 | 195 |
{
|
| 195 | 196 |
checkConcept<ReadMap<A,B>, FunctorToMap<F,A,B> >(); |
| 196 | 197 |
checkConcept<ReadMap<A,B>, FunctorToMap<F> >(); |
| 197 | 198 |
FunctorToMap<F> map1; |
| 198 | 199 |
FunctorToMap<F> map2 = FunctorToMap<F>(F()); |
| 199 | 200 |
B b = functorToMap(F())[A()]; |
| 200 | 201 |
|
| 201 | 202 |
checkConcept<ReadMap<A,B>, MapToFunctor<ReadMap<A,B> > >(); |
| 202 | 203 |
MapToFunctor<ReadMap<A,B> > map = MapToFunctor<ReadMap<A,B> >(ReadMap<A,B>()); |
| 203 | 204 |
|
| 204 | 205 |
check(functorToMap(&func)[A()] == 3, |
| 205 | 206 |
"Something is wrong with FunctorToMap"); |
| 206 | 207 |
check(mapToFunctor(constMap<A,int>(2))(A()) == 2, |
| 207 | 208 |
"Something is wrong with MapToFunctor"); |
| 208 | 209 |
check(mapToFunctor(functorToMap(&func))(A()) == 3 && |
| 209 | 210 |
mapToFunctor(functorToMap(&func))[A()] == 3, |
| 210 | 211 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
| 211 | 212 |
check(functorToMap(mapToFunctor(constMap<A,int>(2)))[A()] == 2, |
| 212 | 213 |
"Something is wrong with FunctorToMap or MapToFunctor"); |
| 213 | 214 |
} |
| 214 | 215 |
|
| 215 | 216 |
// ConvertMap |
| 216 | 217 |
{
|
| 217 | 218 |
checkConcept<ReadMap<double,double>, |
| 218 | 219 |
ConvertMap<ReadMap<double, int>, double> >(); |
| 219 | 220 |
ConvertMap<RangeMap<bool>, int> map1(rangeMap(1, true)); |
| 220 | 221 |
ConvertMap<RangeMap<bool>, int> map2 = convertMap<int>(rangeMap(2, false)); |
| 221 | 222 |
} |
| 222 | 223 |
|
| 223 | 224 |
// ForkMap |
| 224 | 225 |
{
|
| 225 | 226 |
checkConcept<DoubleWriteMap, ForkMap<DoubleWriteMap, DoubleWriteMap> >(); |
| 226 | 227 |
|
| 227 | 228 |
typedef RangeMap<double> RM; |
| 228 | 229 |
typedef SparseMap<int, double> SM; |
| 229 | 230 |
RM m1(10, -1); |
| 230 | 231 |
SM m2(-1); |
| 231 | 232 |
checkConcept<ReadWriteMap<int, double>, ForkMap<RM, SM> >(); |
| 232 | 233 |
checkConcept<ReadWriteMap<int, double>, ForkMap<SM, RM> >(); |
| 233 | 234 |
ForkMap<RM, SM> map1(m1,m2); |
| 234 | 235 |
ForkMap<SM, RM> map2 = forkMap(m2,m1); |
| 235 | 236 |
map2.set(5, 10); |
| 236 | 237 |
check(m1[1] == -1 && m1[5] == 10 && m2[1] == -1 && |
| 237 | 238 |
m2[5] == 10 && map2[1] == -1 && map2[5] == 10, |
| 238 | 239 |
"Something is wrong with ForkMap"); |
| 239 | 240 |
} |
| 240 | 241 |
|
| 241 | 242 |
// Arithmetic maps: |
| 242 | 243 |
// - AddMap, SubMap, MulMap, DivMap |
| 243 | 244 |
// - ShiftMap, ShiftWriteMap, ScaleMap, ScaleWriteMap |
| 244 | 245 |
// - NegMap, NegWriteMap, AbsMap |
| 245 | 246 |
{
|
| 246 | 247 |
checkConcept<DoubleMap, AddMap<DoubleMap,DoubleMap> >(); |
| 247 | 248 |
checkConcept<DoubleMap, SubMap<DoubleMap,DoubleMap> >(); |
| 248 | 249 |
checkConcept<DoubleMap, MulMap<DoubleMap,DoubleMap> >(); |
| 249 | 250 |
checkConcept<DoubleMap, DivMap<DoubleMap,DoubleMap> >(); |
| 250 | 251 |
|
| 251 | 252 |
ConstMap<int, double> c1(1.0), c2(3.14); |
| 252 | 253 |
IdentityMap<int> im; |
| 253 | 254 |
ConvertMap<IdentityMap<int>, double> id(im); |
| 254 | 255 |
check(addMap(c1,id)[0] == 1.0 && addMap(c1,id)[10] == 11.0, |
| 255 | 256 |
"Something is wrong with AddMap"); |
| 256 | 257 |
check(subMap(id,c1)[0] == -1.0 && subMap(id,c1)[10] == 9.0, |
| 257 | 258 |
"Something is wrong with SubMap"); |
| 258 | 259 |
check(mulMap(id,c2)[0] == 0 && mulMap(id,c2)[2] == 6.28, |
| 259 | 260 |
"Something is wrong with MulMap"); |
| 260 | 261 |
check(divMap(c2,id)[1] == 3.14 && divMap(c2,id)[2] == 1.57, |
| 261 | 262 |
"Something is wrong with DivMap"); |
| 262 | 263 |
|
| 263 | 264 |
checkConcept<DoubleMap, ShiftMap<DoubleMap> >(); |
| 264 | 265 |
checkConcept<DoubleWriteMap, ShiftWriteMap<DoubleWriteMap> >(); |
| 265 | 266 |
checkConcept<DoubleMap, ScaleMap<DoubleMap> >(); |
| 266 | 267 |
checkConcept<DoubleWriteMap, ScaleWriteMap<DoubleWriteMap> >(); |
| 267 | 268 |
checkConcept<DoubleMap, NegMap<DoubleMap> >(); |
| 268 | 269 |
checkConcept<DoubleWriteMap, NegWriteMap<DoubleWriteMap> >(); |
| 269 | 270 |
checkConcept<DoubleMap, AbsMap<DoubleMap> >(); |
| 270 | 271 |
|
| 271 | 272 |
check(shiftMap(id, 2.0)[1] == 3.0 && shiftMap(id, 2.0)[10] == 12.0, |
| 272 | 273 |
"Something is wrong with ShiftMap"); |
| 273 | 274 |
check(shiftWriteMap(id, 2.0)[1] == 3.0 && |
| 274 | 275 |
shiftWriteMap(id, 2.0)[10] == 12.0, |
| 275 | 276 |
"Something is wrong with ShiftWriteMap"); |
| 276 | 277 |
check(scaleMap(id, 2.0)[1] == 2.0 && scaleMap(id, 2.0)[10] == 20.0, |
| 277 | 278 |
"Something is wrong with ScaleMap"); |
| 278 | 279 |
check(scaleWriteMap(id, 2.0)[1] == 2.0 && |
| 279 | 280 |
scaleWriteMap(id, 2.0)[10] == 20.0, |
| 280 | 281 |
"Something is wrong with ScaleWriteMap"); |
| 281 | 282 |
check(negMap(id)[1] == -1.0 && negMap(id)[-10] == 10.0, |
| 282 | 283 |
"Something is wrong with NegMap"); |
| 283 | 284 |
check(negWriteMap(id)[1] == -1.0 && negWriteMap(id)[-10] == 10.0, |
| 284 | 285 |
"Something is wrong with NegWriteMap"); |
| 285 | 286 |
check(absMap(id)[1] == 1.0 && absMap(id)[-10] == 10.0, |
| 286 | 287 |
"Something is wrong with AbsMap"); |
| 287 | 288 |
} |
| 288 | 289 |
|
| 289 | 290 |
// Logical maps: |
| 290 | 291 |
// - TrueMap, FalseMap |
| 291 | 292 |
// - AndMap, OrMap |
| 292 | 293 |
// - NotMap, NotWriteMap |
| 293 | 294 |
// - EqualMap, LessMap |
| 294 | 295 |
{
|
| 295 | 296 |
checkConcept<BoolMap, TrueMap<A> >(); |
| 296 | 297 |
checkConcept<BoolMap, FalseMap<A> >(); |
| 297 | 298 |
checkConcept<BoolMap, AndMap<BoolMap,BoolMap> >(); |
| 298 | 299 |
checkConcept<BoolMap, OrMap<BoolMap,BoolMap> >(); |
| 299 | 300 |
checkConcept<BoolMap, NotMap<BoolMap> >(); |
| 300 | 301 |
checkConcept<BoolWriteMap, NotWriteMap<BoolWriteMap> >(); |
| 301 | 302 |
checkConcept<BoolMap, EqualMap<DoubleMap,DoubleMap> >(); |
| 302 | 303 |
checkConcept<BoolMap, LessMap<DoubleMap,DoubleMap> >(); |
| 303 | 304 |
|
| 304 | 305 |
TrueMap<int> tm; |
| 305 | 306 |
FalseMap<int> fm; |
| 306 | 307 |
RangeMap<bool> rm(2); |
| 307 | 308 |
rm[0] = true; rm[1] = false; |
| 308 | 309 |
check(andMap(tm,rm)[0] && !andMap(tm,rm)[1] && |
| 309 | 310 |
!andMap(fm,rm)[0] && !andMap(fm,rm)[1], |
| 310 | 311 |
"Something is wrong with AndMap"); |
| 311 | 312 |
check(orMap(tm,rm)[0] && orMap(tm,rm)[1] && |
| 312 | 313 |
orMap(fm,rm)[0] && !orMap(fm,rm)[1], |
| 313 | 314 |
"Something is wrong with OrMap"); |
| 314 | 315 |
check(!notMap(rm)[0] && notMap(rm)[1], |
| 315 | 316 |
"Something is wrong with NotMap"); |
| 316 | 317 |
check(!notWriteMap(rm)[0] && notWriteMap(rm)[1], |
| 317 | 318 |
"Something is wrong with NotWriteMap"); |
| 318 | 319 |
|
| 319 | 320 |
ConstMap<int, double> cm(2.0); |
| 320 | 321 |
IdentityMap<int> im; |
| 321 | 322 |
ConvertMap<IdentityMap<int>, double> id(im); |
| 322 | 323 |
check(lessMap(id,cm)[1] && !lessMap(id,cm)[2] && !lessMap(id,cm)[3], |
| 323 | 324 |
"Something is wrong with LessMap"); |
| 324 | 325 |
check(!equalMap(id,cm)[1] && equalMap(id,cm)[2] && !equalMap(id,cm)[3], |
| 325 | 326 |
"Something is wrong with EqualMap"); |
| 326 | 327 |
} |
| 327 | 328 |
|
| 328 | 329 |
// LoggerBoolMap |
| 329 | 330 |
{
|
| 330 | 331 |
typedef std::vector<int> vec; |
| 331 | 332 |
vec v1; |
| 332 | 333 |
vec v2(10); |
| 333 | 334 |
LoggerBoolMap<std::back_insert_iterator<vec> > |
| 334 | 335 |
map1(std::back_inserter(v1)); |
| 335 | 336 |
LoggerBoolMap<vec::iterator> map2(v2.begin()); |
| 336 | 337 |
map1.set(10, false); |
| 337 | 338 |
map1.set(20, true); map2.set(20, true); |
| 338 | 339 |
map1.set(30, false); map2.set(40, false); |
| 339 | 340 |
map1.set(50, true); map2.set(50, true); |
| 340 | 341 |
map1.set(60, true); map2.set(60, true); |
| 341 | 342 |
check(v1.size() == 3 && v2.size() == 10 && |
| 342 | 343 |
v1[0]==20 && v1[1]==50 && v1[2]==60 && |
| 343 | 344 |
v2[0]==20 && v2[1]==50 && v2[2]==60, |
| 344 | 345 |
"Something is wrong with LoggerBoolMap"); |
| 345 | 346 |
|
| 346 | 347 |
int i = 0; |
| 347 | 348 |
for ( LoggerBoolMap<vec::iterator>::Iterator it = map2.begin(); |
| 348 | 349 |
it != map2.end(); ++it ) |
| 349 | 350 |
check(v1[i++] == *it, "Something is wrong with LoggerBoolMap"); |
| 350 | 351 |
} |
| 352 |
|
|
| 353 |
// CrossRefMap |
|
| 354 |
{
|
|
| 355 |
typedef ListDigraph Graph; |
|
| 356 |
DIGRAPH_TYPEDEFS(Graph); |
|
| 357 |
|
|
| 358 |
checkConcept<ReadWriteMap<Node, int>, |
|
| 359 |
CrossRefMap<Graph, Node, int> >(); |
|
| 360 |
|
|
| 361 |
Graph gr; |
|
| 362 |
typedef CrossRefMap<Graph, Node, char> CRMap; |
|
| 363 |
typedef CRMap::ValueIterator ValueIt; |
|
| 364 |
CRMap map(gr); |
|
| 365 |
|
|
| 366 |
Node n0 = gr.addNode(); |
|
| 367 |
Node n1 = gr.addNode(); |
|
| 368 |
Node n2 = gr.addNode(); |
|
| 369 |
|
|
| 370 |
map.set(n0, 'A'); |
|
| 371 |
map.set(n1, 'B'); |
|
| 372 |
map.set(n2, 'C'); |
|
| 373 |
map.set(n2, 'A'); |
|
| 374 |
map.set(n0, 'C'); |
|
| 375 |
|
|
| 376 |
check(map[n0] == 'C' && map[n1] == 'B' && map[n2] == 'A', |
|
| 377 |
"Wrong CrossRefMap"); |
|
| 378 |
check(map('A') == n2 && map.inverse()['A'] == n2, "Wrong CrossRefMap");
|
|
| 379 |
check(map('B') == n1 && map.inverse()['B'] == n1, "Wrong CrossRefMap");
|
|
| 380 |
check(map('C') == n0 && map.inverse()['C'] == n0, "Wrong CrossRefMap");
|
|
| 381 |
|
|
| 382 |
ValueIt it = map.beginValue(); |
|
| 383 |
check(*it++ == 'A' && *it++ == 'B' && *it++ == 'C' && |
|
| 384 |
it == map.endValue(), "Wrong value iterator"); |
|
| 385 |
} |
|
| 351 | 386 |
|
| 352 | 387 |
return 0; |
| 353 | 388 |
} |
0 comments (0 inline)