| ... | ... |
@@ -36,49 +36,49 @@ |
| 36 | 36 |
/// |
| 37 | 37 |
///\ingroup auxdat |
| 38 | 38 |
///Using this class you can assign "labels" (nonnegative integer numbers) |
| 39 | 39 |
///to the edges or nodes of a graph, manipulate and query them through |
| 40 | 40 |
///operations typically arising in "push-relabel" type algorithms. |
| 41 | 41 |
/// |
| 42 | 42 |
///Each item is either \em active or not, and you can also choose a |
| 43 | 43 |
///highest level active item. |
| 44 | 44 |
/// |
| 45 | 45 |
///\sa LinkedElevator |
| 46 | 46 |
/// |
| 47 | 47 |
///\param Graph the underlying graph type |
| 48 | 48 |
///\param Item Type of the items the data is assigned to (Graph::Node, |
| 49 | 49 |
///Graph::Edge, Graph::UEdge) |
| 50 | 50 |
template<class Graph, class Item> |
| 51 | 51 |
class Elevator |
| 52 | 52 |
{
|
| 53 | 53 |
public: |
| 54 | 54 |
|
| 55 | 55 |
typedef Item Key; |
| 56 | 56 |
typedef int Value; |
| 57 | 57 |
|
| 58 | 58 |
private: |
| 59 | 59 |
|
| 60 |
typedef |
|
| 60 |
typedef Item *Vit; |
|
| 61 | 61 |
typedef typename ItemSetTraits<Graph,Item>::template Map<Vit>::Type VitMap; |
| 62 | 62 |
typedef typename ItemSetTraits<Graph,Item>::template Map<int>::Type IntMap; |
| 63 | 63 |
|
| 64 | 64 |
const Graph &_g; |
| 65 | 65 |
int _max_level; |
| 66 | 66 |
int _item_num; |
| 67 | 67 |
VitMap _where; |
| 68 | 68 |
IntMap _level; |
| 69 | 69 |
std::vector<Item> _items; |
| 70 | 70 |
std::vector<Vit> _first; |
| 71 | 71 |
std::vector<Vit> _last_active; |
| 72 | 72 |
|
| 73 | 73 |
int _highest_active; |
| 74 | 74 |
|
| 75 | 75 |
void copy(Item i, Vit p) |
| 76 | 76 |
{
|
| 77 | 77 |
_where[*p=i]=p; |
| 78 | 78 |
} |
| 79 | 79 |
void copy(Vit s, Vit p) |
| 80 | 80 |
{
|
| 81 | 81 |
if(s!=p) |
| 82 | 82 |
{
|
| 83 | 83 |
Item i=*s; |
| 84 | 84 |
*p=i; |
| ... | ... |
@@ -412,92 +412,92 @@ |
| 412 | 412 |
} |
| 413 | 413 |
|
| 414 | 414 |
private: |
| 415 | 415 |
int _init_lev; |
| 416 | 416 |
Vit _init_num; |
| 417 | 417 |
|
| 418 | 418 |
public: |
| 419 | 419 |
|
| 420 | 420 |
///\name Initialization |
| 421 | 421 |
///Using this function you can initialize the levels of the item. |
| 422 | 422 |
///\n |
| 423 | 423 |
///This initializatios is started with calling \c initStart(). |
| 424 | 424 |
///Then the |
| 425 | 425 |
///items should be listed levels by levels statring with the lowest one |
| 426 | 426 |
///(with level 0). This is done by using \c initAddItem() |
| 427 | 427 |
///and \c initNewLevel(). Finally \c initFinish() must be called. |
| 428 | 428 |
///The items not listed will be put on the highest level. |
| 429 | 429 |
///@{
|
| 430 | 430 |
|
| 431 | 431 |
///Start the initialization process. |
| 432 | 432 |
|
| 433 | 433 |
void initStart() |
| 434 | 434 |
{
|
| 435 | 435 |
_init_lev=0; |
| 436 |
_init_num=_items.begin(); |
|
| 437 |
_first[0]=_items.begin(); |
|
| 438 |
_last_active[0]=_items.begin()-1; |
|
| 439 |
Vit n=_items.begin(); |
|
| 436 |
_init_num=&_items[0]; |
|
| 437 |
_first[0]=&_items[0]; |
|
| 438 |
_last_active[0]=&_items[0]-1; |
|
| 439 |
Vit n=&_items[0]; |
|
| 440 | 440 |
for(typename ItemSetTraits<Graph,Item>::ItemIt i(_g);i!=INVALID;++i) |
| 441 | 441 |
{
|
| 442 | 442 |
*n=i; |
| 443 | 443 |
_where[i]=n; |
| 444 | 444 |
_level[i]=_max_level; |
| 445 | 445 |
++n; |
| 446 | 446 |
} |
| 447 | 447 |
} |
| 448 | 448 |
|
| 449 | 449 |
///Add an item to the current level. |
| 450 | 450 |
|
| 451 | 451 |
void initAddItem(Item i) |
| 452 | 452 |
{
|
| 453 | 453 |
swap(_where[i],_init_num); |
| 454 | 454 |
_level[i]=_init_lev; |
| 455 | 455 |
++_init_num; |
| 456 | 456 |
} |
| 457 | 457 |
|
| 458 | 458 |
///Start a new level. |
| 459 | 459 |
|
| 460 | 460 |
///Start a new level. |
| 461 | 461 |
///It shouldn't be used before the items on level 0 are listed. |
| 462 | 462 |
void initNewLevel() |
| 463 | 463 |
{
|
| 464 | 464 |
_init_lev++; |
| 465 | 465 |
_first[_init_lev]=_init_num; |
| 466 | 466 |
_last_active[_init_lev]=_init_num-1; |
| 467 | 467 |
} |
| 468 | 468 |
|
| 469 | 469 |
///Finalize the initialization process. |
| 470 | 470 |
|
| 471 | 471 |
void initFinish() |
| 472 | 472 |
{
|
| 473 | 473 |
for(_init_lev++;_init_lev<=_max_level;_init_lev++) |
| 474 | 474 |
{
|
| 475 | 475 |
_first[_init_lev]=_init_num; |
| 476 | 476 |
_last_active[_init_lev]=_init_num-1; |
| 477 | 477 |
} |
| 478 |
_first[_max_level+1]=_items.begin()+_item_num; |
|
| 479 |
_last_active[_max_level+1]=_items.begin()+_item_num-1; |
|
| 478 |
_first[_max_level+1]=&_items[0]+_item_num; |
|
| 479 |
_last_active[_max_level+1]=&_items[0]+_item_num-1; |
|
| 480 | 480 |
_highest_active = -1; |
| 481 | 481 |
} |
| 482 | 482 |
|
| 483 | 483 |
///@} |
| 484 | 484 |
|
| 485 | 485 |
}; |
| 486 | 486 |
|
| 487 | 487 |
///Class for handling "labels" in push-relabel type algorithms. |
| 488 | 488 |
|
| 489 | 489 |
///A class for handling "labels" in push-relabel type algorithms. |
| 490 | 490 |
/// |
| 491 | 491 |
///\ingroup auxdat |
| 492 | 492 |
///Using this class you can assign "labels" (nonnegative integer numbers) |
| 493 | 493 |
///to the edges or nodes of a graph, manipulate and query them through |
| 494 | 494 |
///operations typically arising in "push-relabel" type algorithms. |
| 495 | 495 |
/// |
| 496 | 496 |
///Each item is either \em active or not, and you can also choose a |
| 497 | 497 |
///highest level active item. |
| 498 | 498 |
/// |
| 499 | 499 |
///\sa Elevator |
| 500 | 500 |
/// |
| 501 | 501 |
///\param Graph the underlying graph type |
| 502 | 502 |
///\param Item Type of the items the data is assigned to (Graph::Node, |
| 503 | 503 |
///Graph::Edge, Graph::UEdge) |
0 comments (0 inline)