Changeset 209:765619b7cbb2 in lemon-1.2 for lemon/bits/base_extender.h
- Timestamp:
- 07/13/08 20:51:02 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/bits/base_extender.h
r107 r209 1 /* -*- C++-*-1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 2 * 3 * This file is a part of LEMON, a generic C++ optimization library 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 64 64 65 65 bool operator==(const Arc &that) const { 66 66 return forward==that.forward && Edge(*this)==Edge(that); 67 67 } 68 68 bool operator!=(const Arc &that) const { 69 69 return forward!=that.forward || Edge(*this)!=Edge(that); 70 70 } 71 71 bool operator<(const Arc &that) const { 72 73 72 return forward<that.forward || 73 (!(that.forward<forward) && Edge(*this)<Edge(that)); 74 74 } 75 75 }; … … 118 118 void next(Arc &e) const { 119 119 if( e.forward ) { 120 120 e.forward = false; 121 121 } 122 122 else { 123 124 123 Parent::next(e); 124 e.forward = true; 125 125 } 126 126 } … … 129 129 Parent::firstIn(e,n); 130 130 if( Edge(e) != INVALID ) { 131 131 e.forward = false; 132 132 } 133 133 else { 134 135 134 Parent::firstOut(e,n); 135 e.forward = true; 136 136 } 137 137 } 138 138 void nextOut(Arc &e) const { 139 139 if( ! e.forward ) { 140 141 142 143 144 145 140 Node n = Parent::target(e); 141 Parent::nextIn(e); 142 if( Edge(e) == INVALID ) { 143 Parent::firstOut(e, n); 144 e.forward = true; 145 } 146 146 } 147 147 else { 148 148 Parent::nextOut(e); 149 149 } 150 150 } … … 153 153 Parent::firstOut(e,n); 154 154 if( Edge(e) != INVALID ) { 155 155 e.forward = false; 156 156 } 157 157 else { 158 159 158 Parent::firstIn(e,n); 159 e.forward = true; 160 160 } 161 161 } 162 162 void nextIn(Arc &e) const { 163 163 if( ! e.forward ) { 164 165 166 167 168 169 164 Node n = Parent::source(e); 165 Parent::nextOut(e); 166 if( Edge(e) == INVALID ) { 167 Parent::firstIn(e, n); 168 e.forward = true; 169 } 170 170 } 171 171 else { 172 172 Parent::nextIn(e); 173 173 } 174 174 } … … 184 184 void nextInc(Edge &e, bool &d) const { 185 185 if (d) { 186 187 188 189 190 191 } else { 192 186 Node s = Parent::source(e); 187 Parent::nextOut(e); 188 if (e != INVALID) return; 189 d = false; 190 Parent::firstIn(e, s); 191 } else { 192 Parent::nextIn(e); 193 193 } 194 194 } … … 241 241 Arc findArc(Node s, Node t, Arc p = INVALID) const { 242 242 if (p == INVALID) { 243 244 245 246 243 Edge arc = Parent::findArc(s, t); 244 if (arc != INVALID) return direct(arc, true); 245 arc = Parent::findArc(t, s); 246 if (arc != INVALID) return direct(arc, false); 247 247 } else if (direction(p)) { 248 249 250 251 if (arc != INVALID) return direct(arc, false); 252 } else { 253 254 if (arc != INVALID) return direct(arc, false); 248 Edge arc = Parent::findArc(s, t, p); 249 if (arc != INVALID) return direct(arc, true); 250 arc = Parent::findArc(t, s); 251 if (arc != INVALID) return direct(arc, false); 252 } else { 253 Edge arc = Parent::findArc(t, s, p); 254 if (arc != INVALID) return direct(arc, false); 255 255 } 256 256 return INVALID; … … 268 268 if (arc != INVALID) return arc; 269 269 arc = Parent::findArc(t, s); 270 if (arc != INVALID) return arc; 270 if (arc != INVALID) return arc; 271 271 } else { 272 272 Edge arc = Parent::findArc(t, s, p); 273 if (arc != INVALID) return arc; 273 if (arc != INVALID) return arc; 274 274 } 275 275 } else { … … 300 300 Red() {} 301 301 Red(const Node& node) : Node(node) { 302 LEMON_ASSERT(Parent::red(node) || node == INVALID, 303 302 LEMON_ASSERT(Parent::red(node) || node == INVALID, 303 typename Parent::NodeSetError()); 304 304 } 305 305 Red& operator=(const Node& node) { 306 LEMON_ASSERT(Parent::red(node) || node == INVALID, 307 306 LEMON_ASSERT(Parent::red(node) || node == INVALID, 307 typename Parent::NodeSetError()); 308 308 Node::operator=(node); 309 309 return *this; … … 332 332 Blue() {} 333 333 Blue(const Node& node) : Node(node) { 334 335 334 LEMON_ASSERT(Parent::blue(node) || node == INVALID, 335 typename Parent::NodeSetError()); 336 336 } 337 337 Blue& operator=(const Node& node) { 338 LEMON_ASSERT(Parent::blue(node) || node == INVALID, 339 338 LEMON_ASSERT(Parent::blue(node) || node == INVALID, 339 typename Parent::NodeSetError()); 340 340 Node::operator=(node); 341 341 return *this; … … 354 354 Parent::nextBlue(static_cast<Node&>(node)); 355 355 } 356 356 357 357 int id(const Blue& node) const { 358 358 return Parent::redId(node); … … 368 368 void firstInc(Edge& arc, bool& dir, const Node& node) const { 369 369 if (Parent::red(node)) { 370 371 372 } else { 373 374 370 Parent::firstFromRed(arc, node); 371 dir = true; 372 } else { 373 Parent::firstFromBlue(arc, node); 374 dir = static_cast<Edge&>(arc) == INVALID; 375 375 } 376 376 } 377 377 void nextInc(Edge& arc, bool& dir) const { 378 378 if (dir) { 379 380 } else { 381 382 379 Parent::nextFromRed(arc); 380 } else { 381 Parent::nextFromBlue(arc); 382 if (arc == INVALID) dir = true; 383 383 } 384 384 } … … 390 390 391 391 Arc(const Edge& arc, bool _forward) 392 392 : Edge(arc), forward(_forward) {} 393 393 394 394 public: … … 396 396 Arc (Invalid) : Edge(INVALID), forward(true) {} 397 397 bool operator==(const Arc& i) const { 398 398 return Edge::operator==(i) && forward == i.forward; 399 399 } 400 400 bool operator!=(const Arc& i) const { 401 401 return Edge::operator!=(i) || forward != i.forward; 402 402 } 403 403 bool operator<(const Arc& i) const { 404 return Edge::operator<(i) || 405 404 return Edge::operator<(i) || 405 (!(i.forward<forward) && Edge(*this)<Edge(i)); 406 406 } 407 407 }; … … 414 414 void next(Arc& arc) const { 415 415 if (!arc.forward) { 416 416 Parent::next(static_cast<Edge&>(arc)); 417 417 } 418 418 arc.forward = !arc.forward; … … 421 421 void firstOut(Arc& arc, const Node& node) const { 422 422 if (Parent::red(node)) { 423 424 425 } else { 426 427 423 Parent::firstFromRed(arc, node); 424 arc.forward = true; 425 } else { 426 Parent::firstFromBlue(arc, node); 427 arc.forward = static_cast<Edge&>(arc) == INVALID; 428 428 } 429 429 } 430 430 void nextOut(Arc& arc) const { 431 431 if (arc.forward) { 432 433 } else { 434 432 Parent::nextFromRed(arc); 433 } else { 434 Parent::nextFromBlue(arc); 435 435 arc.forward = static_cast<Edge&>(arc) == INVALID; 436 436 } … … 439 439 void firstIn(Arc& arc, const Node& node) const { 440 440 if (Parent::blue(node)) { 441 442 arc.forward = true; 443 } else { 444 445 441 Parent::firstFromBlue(arc, node); 442 arc.forward = true; 443 } else { 444 Parent::firstFromRed(arc, node); 445 arc.forward = static_cast<Edge&>(arc) == INVALID; 446 446 } 447 447 } 448 448 void nextIn(Arc& arc) const { 449 449 if (arc.forward) { 450 451 } else { 452 453 450 Parent::nextFromBlue(arc); 451 } else { 452 Parent::nextFromRed(arc); 453 arc.forward = static_cast<Edge&>(arc) == INVALID; 454 454 } 455 455 } … … 463 463 464 464 int id(const Arc& arc) const { 465 return (Parent::id(static_cast<const Edge&>(arc)) << 1) + 465 return (Parent::id(static_cast<const Edge&>(arc)) << 1) + 466 466 (arc.forward ? 0 : 1); 467 467 }
Note: See TracChangeset
for help on using the changeset viewer.