| ... | ... |
@@ -309,209 +309,216 @@ |
| 309 | 309 |
template <class T> |
| 310 | 310 |
struct SetCardinalityMap |
| 311 | 311 |
: public MaxCardinalitySearch<Digraph, CapacityMap, |
| 312 | 312 |
DefCardinalityMapTraits<T> > {
|
| 313 | 313 |
typedef MaxCardinalitySearch<Digraph, CapacityMap, |
| 314 | 314 |
DefCardinalityMapTraits<T> > Create; |
| 315 | 315 |
}; |
| 316 | 316 |
|
| 317 | 317 |
template <class T> |
| 318 | 318 |
struct DefProcessedMapTraits : public Traits {
|
| 319 | 319 |
typedef T ProcessedMap; |
| 320 | 320 |
static ProcessedMap *createProcessedMap(const Digraph &) {
|
| 321 | 321 |
LEMON_ASSERT(false,"Uninitialized parameter."); |
| 322 | 322 |
return 0; |
| 323 | 323 |
} |
| 324 | 324 |
}; |
| 325 | 325 |
/// \brief \ref named-templ-param "Named parameter" for setting |
| 326 | 326 |
/// ProcessedMap type |
| 327 | 327 |
/// |
| 328 | 328 |
/// \ref named-templ-param "Named parameter" for setting ProcessedMap type |
| 329 | 329 |
/// for the algorithm. |
| 330 | 330 |
template <class T> |
| 331 | 331 |
struct SetProcessedMap |
| 332 | 332 |
: public MaxCardinalitySearch<Digraph, CapacityMap, |
| 333 | 333 |
DefProcessedMapTraits<T> > {
|
| 334 | 334 |
typedef MaxCardinalitySearch<Digraph, CapacityMap, |
| 335 | 335 |
DefProcessedMapTraits<T> > Create; |
| 336 | 336 |
}; |
| 337 | 337 |
|
| 338 | 338 |
template <class H, class CR> |
| 339 | 339 |
struct DefHeapTraits : public Traits {
|
| 340 | 340 |
typedef CR HeapCrossRef; |
| 341 | 341 |
typedef H Heap; |
| 342 | 342 |
static HeapCrossRef *createHeapCrossRef(const Digraph &) {
|
| 343 | 343 |
LEMON_ASSERT(false,"Uninitialized parameter."); |
| 344 | 344 |
return 0; |
| 345 | 345 |
} |
| 346 | 346 |
static Heap *createHeap(HeapCrossRef &) {
|
| 347 | 347 |
LEMON_ASSERT(false,"Uninitialized parameter."); |
| 348 | 348 |
return 0; |
| 349 | 349 |
} |
| 350 | 350 |
}; |
| 351 | 351 |
/// \brief \ref named-templ-param "Named parameter" for setting heap |
| 352 | 352 |
/// and cross reference type |
| 353 | 353 |
/// |
| 354 | 354 |
/// \ref named-templ-param "Named parameter" for setting heap and cross |
| 355 | 355 |
/// reference type for the algorithm. |
| 356 | 356 |
template <class H, class CR = typename Digraph::template NodeMap<int> > |
| 357 | 357 |
struct SetHeap |
| 358 | 358 |
: public MaxCardinalitySearch<Digraph, CapacityMap, |
| 359 | 359 |
DefHeapTraits<H, CR> > {
|
| 360 | 360 |
typedef MaxCardinalitySearch< Digraph, CapacityMap, |
| 361 | 361 |
DefHeapTraits<H, CR> > Create; |
| 362 | 362 |
}; |
| 363 | 363 |
|
| 364 | 364 |
template <class H, class CR> |
| 365 | 365 |
struct DefStandardHeapTraits : public Traits {
|
| 366 | 366 |
typedef CR HeapCrossRef; |
| 367 | 367 |
typedef H Heap; |
| 368 | 368 |
static HeapCrossRef *createHeapCrossRef(const Digraph &digraph) {
|
| 369 | 369 |
return new HeapCrossRef(digraph); |
| 370 | 370 |
} |
| 371 | 371 |
static Heap *createHeap(HeapCrossRef &crossref) {
|
| 372 | 372 |
return new Heap(crossref); |
| 373 | 373 |
} |
| 374 | 374 |
}; |
| 375 | 375 |
|
| 376 | 376 |
/// \brief \ref named-templ-param "Named parameter" for setting heap and |
| 377 | 377 |
/// cross reference type with automatic allocation |
| 378 | 378 |
/// |
| 379 | 379 |
/// \ref named-templ-param "Named parameter" for setting heap and cross |
| 380 | 380 |
/// reference type. It can allocate the heap and the cross reference |
| 381 | 381 |
/// object if the cross reference's constructor waits for the digraph as |
| 382 | 382 |
/// parameter and the heap's constructor waits for the cross reference. |
| 383 | 383 |
template <class H, class CR = typename Digraph::template NodeMap<int> > |
| 384 | 384 |
struct SetStandardHeap |
| 385 | 385 |
: public MaxCardinalitySearch<Digraph, CapacityMap, |
| 386 | 386 |
DefStandardHeapTraits<H, CR> > {
|
| 387 | 387 |
typedef MaxCardinalitySearch<Digraph, CapacityMap, |
| 388 | 388 |
DefStandardHeapTraits<H, CR> > |
| 389 | 389 |
Create; |
| 390 | 390 |
}; |
| 391 | 391 |
|
| 392 | 392 |
///@} |
| 393 | 393 |
|
| 394 | 394 |
|
| 395 | 395 |
protected: |
| 396 | 396 |
|
| 397 | 397 |
MaxCardinalitySearch() {}
|
| 398 | 398 |
|
| 399 | 399 |
public: |
| 400 | 400 |
|
| 401 | 401 |
/// \brief Constructor. |
| 402 | 402 |
/// |
| 403 | 403 |
///\param digraph the digraph the algorithm will run on. |
| 404 | 404 |
///\param capacity the capacity map used by the algorithm. |
| 405 |
///When no capacity map given, a constant 1 capacity map will |
|
| 406 |
///be allocated. |
|
| 407 |
#ifdef DOXYGEN |
|
| 408 | 405 |
MaxCardinalitySearch(const Digraph& digraph, |
| 409 |
const CapacityMap& capacity=0 ) : |
|
| 410 |
#else |
|
| 411 |
MaxCardinalitySearch(const Digraph& digraph, |
|
| 412 |
const CapacityMap& capacity=*static_cast<const CapacityMap*>(0) ) : |
|
| 413 |
|
|
| 406 |
const CapacityMap& capacity) : |
|
| 414 | 407 |
_graph(&digraph), |
| 415 | 408 |
_capacity(&capacity), local_capacity(false), |
| 416 | 409 |
_cardinality(0), local_cardinality(false), |
| 417 | 410 |
_processed(0), local_processed(false), |
| 418 | 411 |
_heap_cross_ref(0), local_heap_cross_ref(false), |
| 419 | 412 |
_heap(0), local_heap(false) |
| 420 | 413 |
{ }
|
| 421 | 414 |
|
| 415 |
/// \brief Constructor. |
|
| 416 |
/// |
|
| 417 |
///\param digraph the digraph the algorithm will run on. |
|
| 418 |
/// |
|
| 419 |
///A constant 1 capacity map will be allocated. |
|
| 420 |
MaxCardinalitySearch(const Digraph& digraph) : |
|
| 421 |
_graph(&digraph), |
|
| 422 |
_capacity(0), local_capacity(false), |
|
| 423 |
_cardinality(0), local_cardinality(false), |
|
| 424 |
_processed(0), local_processed(false), |
|
| 425 |
_heap_cross_ref(0), local_heap_cross_ref(false), |
|
| 426 |
_heap(0), local_heap(false) |
|
| 427 |
{ }
|
|
| 428 |
|
|
| 422 | 429 |
/// \brief Destructor. |
| 423 | 430 |
~MaxCardinalitySearch() {
|
| 424 | 431 |
if(local_capacity) delete _capacity; |
| 425 | 432 |
if(local_cardinality) delete _cardinality; |
| 426 | 433 |
if(local_processed) delete _processed; |
| 427 | 434 |
if(local_heap_cross_ref) delete _heap_cross_ref; |
| 428 | 435 |
if(local_heap) delete _heap; |
| 429 | 436 |
} |
| 430 | 437 |
|
| 431 | 438 |
/// \brief Sets the capacity map. |
| 432 | 439 |
/// |
| 433 | 440 |
/// Sets the capacity map. |
| 434 | 441 |
/// \return <tt> (*this) </tt> |
| 435 | 442 |
MaxCardinalitySearch &capacityMap(const CapacityMap &m) {
|
| 436 | 443 |
if (local_capacity) {
|
| 437 | 444 |
delete _capacity; |
| 438 | 445 |
local_capacity=false; |
| 439 | 446 |
} |
| 440 | 447 |
_capacity=&m; |
| 441 | 448 |
return *this; |
| 442 | 449 |
} |
| 443 | 450 |
|
| 444 | 451 |
/// \brief Returns a const reference to the capacity map. |
| 445 | 452 |
/// |
| 446 | 453 |
/// Returns a const reference to the capacity map used by |
| 447 | 454 |
/// the algorithm. |
| 448 | 455 |
const CapacityMap &capacityMap() const {
|
| 449 | 456 |
return *_capacity; |
| 450 | 457 |
} |
| 451 | 458 |
|
| 452 | 459 |
/// \brief Sets the map storing the cardinalities calculated by the |
| 453 | 460 |
/// algorithm. |
| 454 | 461 |
/// |
| 455 | 462 |
/// Sets the map storing the cardinalities calculated by the algorithm. |
| 456 | 463 |
/// If you don't use this function before calling \ref run(), |
| 457 | 464 |
/// it will allocate one. The destuctor deallocates this |
| 458 | 465 |
/// automatically allocated map, of course. |
| 459 | 466 |
/// \return <tt> (*this) </tt> |
| 460 | 467 |
MaxCardinalitySearch &cardinalityMap(CardinalityMap &m) {
|
| 461 | 468 |
if(local_cardinality) {
|
| 462 | 469 |
delete _cardinality; |
| 463 | 470 |
local_cardinality=false; |
| 464 | 471 |
} |
| 465 | 472 |
_cardinality = &m; |
| 466 | 473 |
return *this; |
| 467 | 474 |
} |
| 468 | 475 |
|
| 469 | 476 |
/// \brief Sets the map storing the processed nodes. |
| 470 | 477 |
/// |
| 471 | 478 |
/// Sets the map storing the processed nodes. |
| 472 | 479 |
/// If you don't use this function before calling \ref run(), |
| 473 | 480 |
/// it will allocate one. The destuctor deallocates this |
| 474 | 481 |
/// automatically allocated map, of course. |
| 475 | 482 |
/// \return <tt> (*this) </tt> |
| 476 | 483 |
MaxCardinalitySearch &processedMap(ProcessedMap &m) |
| 477 | 484 |
{
|
| 478 | 485 |
if(local_processed) {
|
| 479 | 486 |
delete _processed; |
| 480 | 487 |
local_processed=false; |
| 481 | 488 |
} |
| 482 | 489 |
_processed = &m; |
| 483 | 490 |
return *this; |
| 484 | 491 |
} |
| 485 | 492 |
|
| 486 | 493 |
/// \brief Returns a const reference to the cardinality map. |
| 487 | 494 |
/// |
| 488 | 495 |
/// Returns a const reference to the cardinality map used by |
| 489 | 496 |
/// the algorithm. |
| 490 | 497 |
const ProcessedMap &processedMap() const {
|
| 491 | 498 |
return *_processed; |
| 492 | 499 |
} |
| 493 | 500 |
|
| 494 | 501 |
/// \brief Sets the heap and the cross reference used by algorithm. |
| 495 | 502 |
/// |
| 496 | 503 |
/// Sets the heap and the cross reference used by algorithm. |
| 497 | 504 |
/// If you don't use this function before calling \ref run(), |
| 498 | 505 |
/// it will allocate one. The destuctor deallocates this |
| 499 | 506 |
/// automatically allocated map, of course. |
| 500 | 507 |
/// \return <tt> (*this) </tt> |
| 501 | 508 |
MaxCardinalitySearch &heap(Heap& hp, HeapCrossRef &cr) {
|
| 502 | 509 |
if(local_heap_cross_ref) {
|
| 503 | 510 |
delete _heap_cross_ref; |
| 504 | 511 |
local_heap_cross_ref = false; |
| 505 | 512 |
} |
| 506 | 513 |
_heap_cross_ref = &cr; |
| 507 | 514 |
if(local_heap) {
|
| 508 | 515 |
delete _heap; |
| 509 | 516 |
local_heap = false; |
| 510 | 517 |
} |
| 511 | 518 |
_heap = &hp; |
| 512 | 519 |
return *this; |
| 513 | 520 |
} |
| 514 | 521 |
|
| 515 | 522 |
/// \brief Returns a const reference to the heap. |
| 516 | 523 |
/// |
| 517 | 524 |
/// Returns a const reference to the heap used by |
0 comments (0 inline)