0
11
0
... | ... |
@@ -95,16 +95,16 @@ |
95 | 95 |
\code |
96 | 96 |
all_lower_case_with_underscores |
97 | 97 |
\endcode |
98 | 98 |
|
99 | 99 |
\subsection pri-loc-var Private member variables |
100 | 100 |
|
101 |
Private member variables should start with underscore |
|
101 |
Private member variables should start with underscore. |
|
102 | 102 |
|
103 | 103 |
\code |
104 |
|
|
104 |
_start_with_underscore |
|
105 | 105 |
\endcode |
106 | 106 |
|
107 | 107 |
\subsection cs-excep Exceptions |
108 | 108 |
|
109 | 109 |
When writing exceptions please comply the following naming conventions. |
110 | 110 |
... | ... |
@@ -403,16 +403,16 @@ |
403 | 403 |
\ref bunnagel98efficient. |
404 | 404 |
- \ref CapacityScaling Capacity Scaling algorithm based on the successive |
405 | 405 |
shortest path method \ref edmondskarp72theoretical. |
406 | 406 |
- \ref CycleCanceling Cycle-Canceling algorithms, two of which are |
407 | 407 |
strongly polynomial \ref klein67primal, \ref goldberg89cyclecanceling. |
408 | 408 |
|
409 |
In general NetworkSimplex is the most efficient implementation, |
|
410 |
but in special cases other algorithms could be faster. |
|
409 |
In general, \ref NetworkSimplex and \ref CostScaling are the most efficient |
|
410 |
implementations, but the other two algorithms could be faster in special cases. |
|
411 | 411 |
For example, if the total supply and/or capacities are rather small, |
412 |
CapacityScaling is usually the fastest algorithm (without effective scaling). |
|
412 |
\ref CapacityScaling is usually the fastest algorithm (without effective scaling). |
|
413 | 413 |
*/ |
414 | 414 |
|
415 | 415 |
/** |
416 | 416 |
@defgroup min_cut Minimum Cut Algorithms |
417 | 417 |
@ingroup algs |
418 | 418 |
|
... | ... |
@@ -468,13 +468,13 @@ |
468 | 468 |
\ref dasdan98minmeancycle. |
469 | 469 |
- \ref HartmannOrlinMmc Hartmann-Orlin's algorithm, which is an improved |
470 | 470 |
version of Karp's algorithm \ref dasdan98minmeancycle. |
471 | 471 |
- \ref HowardMmc Howard's policy iteration algorithm |
472 | 472 |
\ref dasdan98minmeancycle. |
473 | 473 |
|
474 |
In practice, the \ref HowardMmc "Howard" algorithm |
|
474 |
In practice, the \ref HowardMmc "Howard" algorithm turned out to be by far the |
|
475 | 475 |
most efficient one, though the best known theoretical bound on its running |
476 | 476 |
time is exponential. |
477 | 477 |
Both \ref KarpMmc "Karp" and \ref HartmannOrlinMmc "Hartmann-Orlin" algorithms |
478 | 478 |
run in time O(ne) and use space O(n<sup>2</sup>+e), but the latter one is |
479 | 479 |
typically faster due to the applied early termination scheme. |
480 | 480 |
*/ |
... | ... |
@@ -536,13 +536,13 @@ |
536 | 536 |
|
537 | 537 |
\image html connected_components.png |
538 | 538 |
\image latex connected_components.eps "Connected components" width=\textwidth |
539 | 539 |
*/ |
540 | 540 |
|
541 | 541 |
/** |
542 |
@defgroup planar |
|
542 |
@defgroup planar Planar Embedding and Drawing |
|
543 | 543 |
@ingroup algs |
544 | 544 |
\brief Algorithms for planarity checking, embedding and drawing |
545 | 545 |
|
546 | 546 |
This group contains the algorithms for planarity checking, |
547 | 547 |
embedding and drawing. |
548 | 548 |
... | ... |
@@ -86,14 +86,14 @@ |
86 | 86 |
/// In most cases, this parameter should not be set directly, |
87 | 87 |
/// consider to use the named template parameters instead. |
88 | 88 |
/// |
89 | 89 |
/// \warning Both \c V and \c C must be signed number types. |
90 | 90 |
/// \warning All input data (capacities, supply values, and costs) must |
91 | 91 |
/// be integer. |
92 |
/// \warning This algorithm does not support negative costs for such |
|
93 |
/// arcs that have infinite upper bound. |
|
92 |
/// \warning This algorithm does not support negative costs for |
|
93 |
/// arcs having infinite upper bound. |
|
94 | 94 |
#ifdef DOXYGEN |
95 | 95 |
template <typename GR, typename V, typename C, typename TR> |
96 | 96 |
#else |
97 | 97 |
template < typename GR, typename V = int, typename C = V, |
98 | 98 |
typename TR = CapacityScalingDefaultTraits<GR, V, C> > |
99 | 99 |
#endif |
... | ... |
@@ -420,13 +420,13 @@ |
420 | 420 |
/// This function sets a single source node and a single target node |
421 | 421 |
/// and the required flow value. |
422 | 422 |
/// If neither this function nor \ref supplyMap() is used before |
423 | 423 |
/// calling \ref run(), the supply of each node will be set to zero. |
424 | 424 |
/// |
425 | 425 |
/// Using this function has the same effect as using \ref supplyMap() |
426 |
/// with |
|
426 |
/// with a map in which \c k is assigned to \c s, \c -k is |
|
427 | 427 |
/// assigned to \c t and all other nodes have zero supply value. |
428 | 428 |
/// |
429 | 429 |
/// \param s The source node. |
430 | 430 |
/// \param t The target node. |
431 | 431 |
/// \param k The required amount of flow from node \c s to node \c t |
432 | 432 |
/// (i.e. the supply of \c s and the demand of \c t). |
... | ... |
@@ -444,13 +444,13 @@ |
444 | 444 |
to.build(from, nodeRefMap, edgeRefMap); |
445 | 445 |
} |
446 | 446 |
}; |
447 | 447 |
|
448 | 448 |
} |
449 | 449 |
|
450 |
/// Check whether a graph is undirected. |
|
450 |
/// \brief Check whether a graph is undirected. |
|
451 | 451 |
/// |
452 | 452 |
/// This function returns \c true if the given graph is undirected. |
453 | 453 |
#ifdef DOXYGEN |
454 | 454 |
template <typename GR> |
455 | 455 |
bool undirected(const GR& g) { return false; } |
456 | 456 |
#else |
... | ... |
@@ -94,12 +94,15 @@ |
94 | 94 |
/// "minimum cost flow" \ref amo93networkflows, \ref goldberg90approximation, |
95 | 95 |
/// \ref goldberg97efficient, \ref bunnagel98efficient. |
96 | 96 |
/// It is a highly efficient primal-dual solution method, which |
97 | 97 |
/// can be viewed as the generalization of the \ref Preflow |
98 | 98 |
/// "preflow push-relabel" algorithm for the maximum flow problem. |
99 | 99 |
/// |
100 |
/// In general, \ref NetworkSimplex and \ref CostScaling are the fastest |
|
101 |
/// implementations available in LEMON for this problem. |
|
102 |
/// |
|
100 | 103 |
/// Most of the parameters of the problem (except for the digraph) |
101 | 104 |
/// can be given using separate functions, and the algorithm can be |
102 | 105 |
/// executed using the \ref run() function. If some parameters are not |
103 | 106 |
/// specified, then default values will be used. |
104 | 107 |
/// |
105 | 108 |
/// \tparam GR The digraph type the algorithm runs on. |
... | ... |
@@ -113,14 +116,14 @@ |
113 | 116 |
/// In most cases, this parameter should not be set directly, |
114 | 117 |
/// consider to use the named template parameters instead. |
115 | 118 |
/// |
116 | 119 |
/// \warning Both \c V and \c C must be signed number types. |
117 | 120 |
/// \warning All input data (capacities, supply values, and costs) must |
118 | 121 |
/// be integer. |
119 |
/// \warning This algorithm does not support negative costs for such |
|
120 |
/// arcs that have infinite upper bound. |
|
122 |
/// \warning This algorithm does not support negative costs for |
|
123 |
/// arcs having infinite upper bound. |
|
121 | 124 |
/// |
122 | 125 |
/// \note %CostScaling provides three different internal methods, |
123 | 126 |
/// from which the most efficient one is used by default. |
124 | 127 |
/// For more information, see \ref Method. |
125 | 128 |
#ifdef DOXYGEN |
126 | 129 |
template <typename GR, typename V, typename C, typename TR> |
... | ... |
@@ -176,13 +179,13 @@ |
176 | 179 |
/// for the \ref run() function. |
177 | 180 |
/// |
178 | 181 |
/// \ref CostScaling provides three internal methods that differ mainly |
179 | 182 |
/// in their base operations, which are used in conjunction with the |
180 | 183 |
/// relabel operation. |
181 | 184 |
/// By default, the so called \ref PARTIAL_AUGMENT |
182 |
/// "Partial Augment-Relabel" method is used, which |
|
185 |
/// "Partial Augment-Relabel" method is used, which turned out to be |
|
183 | 186 |
/// the most efficient and the most robust on various test inputs. |
184 | 187 |
/// However, the other methods can be selected using the \ref run() |
185 | 188 |
/// function with the proper parameter. |
186 | 189 |
enum Method { |
187 | 190 |
/// Local push operations are used, i.e. flow is moved only on one |
188 | 191 |
/// admissible arc at once. |
... | ... |
@@ -445,13 +448,13 @@ |
445 | 448 |
/// This function sets a single source node and a single target node |
446 | 449 |
/// and the required flow value. |
447 | 450 |
/// If neither this function nor \ref supplyMap() is used before |
448 | 451 |
/// calling \ref run(), the supply of each node will be set to zero. |
449 | 452 |
/// |
450 | 453 |
/// Using this function has the same effect as using \ref supplyMap() |
451 |
/// with |
|
454 |
/// with a map in which \c k is assigned to \c s, \c -k is |
|
452 | 455 |
/// assigned to \c t and all other nodes have zero supply value. |
453 | 456 |
/// |
454 | 457 |
/// \param s The source node. |
455 | 458 |
/// \param t The target node. |
456 | 459 |
/// \param k The required amount of flow from node \c s to node \c t |
457 | 460 |
/// (i.e. the supply of \c s and the demand of \c t). |
... | ... |
@@ -65,14 +65,14 @@ |
65 | 65 |
/// \tparam C The number type used for costs and potentials in the |
66 | 66 |
/// algorithm. By default, it is the same as \c V. |
67 | 67 |
/// |
68 | 68 |
/// \warning Both \c V and \c C must be signed number types. |
69 | 69 |
/// \warning All input data (capacities, supply values, and costs) must |
70 | 70 |
/// be integer. |
71 |
/// \warning This algorithm does not support negative costs for such |
|
72 |
/// arcs that have infinite upper bound. |
|
71 |
/// \warning This algorithm does not support negative costs for |
|
72 |
/// arcs having infinite upper bound. |
|
73 | 73 |
/// |
74 | 74 |
/// \note For more information about the three available methods, |
75 | 75 |
/// see \ref Method. |
76 | 76 |
#ifdef DOXYGEN |
77 | 77 |
template <typename GR, typename V, typename C> |
78 | 78 |
#else |
... | ... |
@@ -114,14 +114,13 @@ |
114 | 114 |
/// |
115 | 115 |
/// Enum type containing constants for selecting the used method |
116 | 116 |
/// for the \ref run() function. |
117 | 117 |
/// |
118 | 118 |
/// \ref CycleCanceling provides three different cycle-canceling |
119 | 119 |
/// methods. By default, \ref CANCEL_AND_TIGHTEN "Cancel and Tighten" |
120 |
/// is used, which proved to be the most efficient and the most robust |
|
121 |
/// on various test inputs. |
|
120 |
/// is used, which is by far the most efficient and the most robust. |
|
122 | 121 |
/// However, the other methods can be selected using the \ref run() |
123 | 122 |
/// function with the proper parameter. |
124 | 123 |
enum Method { |
125 | 124 |
/// A simple cycle-canceling method, which uses the |
126 | 125 |
/// \ref BellmanFord "Bellman-Ford" algorithm with limited iteration |
127 | 126 |
/// number for detecting negative cycles in the residual network. |
... | ... |
@@ -347,13 +346,13 @@ |
347 | 346 |
/// This function sets a single source node and a single target node |
348 | 347 |
/// and the required flow value. |
349 | 348 |
/// If neither this function nor \ref supplyMap() is used before |
350 | 349 |
/// calling \ref run(), the supply of each node will be set to zero. |
351 | 350 |
/// |
352 | 351 |
/// Using this function has the same effect as using \ref supplyMap() |
353 |
/// with |
|
352 |
/// with a map in which \c k is assigned to \c s, \c -k is |
|
354 | 353 |
/// assigned to \c t and all other nodes have zero supply value. |
355 | 354 |
/// |
356 | 355 |
/// \param s The source node. |
357 | 356 |
/// \param t The target node. |
358 | 357 |
/// \param k The required amount of flow from node \c s to node \c t |
359 | 358 |
/// (i.e. the supply of \c s and the demand of \c t). |
... | ... |
@@ -33,13 +33,13 @@ |
33 | 33 |
///if a (di)graph is \e Eulerian. |
34 | 34 |
|
35 | 35 |
namespace lemon { |
36 | 36 |
|
37 | 37 |
///Euler tour iterator for digraphs. |
38 | 38 |
|
39 |
/// \ingroup |
|
39 |
/// \ingroup graph_properties |
|
40 | 40 |
///This iterator provides an Euler tour (Eulerian circuit) of a \e directed |
41 | 41 |
///graph (if there exists) and it converts to the \c Arc type of the digraph. |
42 | 42 |
/// |
43 | 43 |
///For example, if the given digraph has an Euler tour (i.e it has only one |
44 | 44 |
///non-trivial component and the in-degree is equal to the out-degree |
45 | 45 |
///for all nodes), then the following code will put the arcs of \c g |
... | ... |
@@ -43,14 +43,18 @@ |
43 | 43 |
/// \e clique \e problem \ref grosso08maxclique. |
44 | 44 |
/// It is to find the largest complete subgraph (\e clique) in an |
45 | 45 |
/// undirected graph, i.e., the largest set of nodes where each |
46 | 46 |
/// pair of nodes is connected. |
47 | 47 |
/// |
48 | 48 |
/// This class provides a simple but highly efficient and robust heuristic |
49 |
/// method that quickly finds a large clique, but not necessarily the |
|
49 |
/// method that quickly finds a quite large clique, but not necessarily the |
|
50 | 50 |
/// largest one. |
51 |
/// The algorithm performs a certain number of iterations to find several |
|
52 |
/// cliques and selects the largest one among them. Various limits can be |
|
53 |
/// specified to control the running time and the effectiveness of the |
|
54 |
/// search process. |
|
51 | 55 |
/// |
52 | 56 |
/// \tparam GR The undirected graph type the algorithm runs on. |
53 | 57 |
/// |
54 | 58 |
/// \note %GrossoLocatelliPullanMc provides three different node selection |
55 | 59 |
/// rules, from which the most powerful one is used by default. |
56 | 60 |
/// For more information, see \ref SelectionRule. |
... | ... |
@@ -81,27 +85,53 @@ |
81 | 85 |
/// A node of minimum penalty is selected randomly at each step. |
82 | 86 |
/// The node penalties are updated adaptively after each stage of the |
83 | 87 |
/// search process. |
84 | 88 |
PENALTY_BASED |
85 | 89 |
}; |
86 | 90 |
|
91 |
/// \brief Constants for the causes of search termination. |
|
92 |
/// |
|
93 |
/// Enum type containing constants for the different causes of search |
|
94 |
/// termination. The \ref run() function returns one of these values. |
|
95 |
enum TerminationCause { |
|
96 |
|
|
97 |
/// The iteration count limit is reached. |
|
98 |
ITERATION_LIMIT, |
|
99 |
|
|
100 |
/// The step count limit is reached. |
|
101 |
STEP_LIMIT, |
|
102 |
|
|
103 |
/// The clique size limit is reached. |
|
104 |
SIZE_LIMIT |
|
105 |
}; |
|
106 |
|
|
87 | 107 |
private: |
88 | 108 |
|
89 | 109 |
TEMPLATE_GRAPH_TYPEDEFS(GR); |
90 | 110 |
|
91 | 111 |
typedef std::vector<int> IntVector; |
92 | 112 |
typedef std::vector<char> BoolVector; |
93 | 113 |
typedef std::vector<BoolVector> BoolMatrix; |
94 | 114 |
// Note: vector<char> is used instead of vector<bool> for efficiency reasons |
95 | 115 |
|
116 |
// The underlying graph |
|
96 | 117 |
const GR &_graph; |
97 | 118 |
IntNodeMap _id; |
98 | 119 |
|
99 | 120 |
// Internal matrix representation of the graph |
100 | 121 |
BoolMatrix _gr; |
101 | 122 |
int _n; |
123 |
|
|
124 |
// Search options |
|
125 |
bool _delta_based_restart; |
|
126 |
int _restart_delta_limit; |
|
127 |
|
|
128 |
// Search limits |
|
129 |
int _iteration_limit; |
|
130 |
int _step_limit; |
|
131 |
int _size_limit; |
|
102 | 132 |
|
103 | 133 |
// The current clique |
104 | 134 |
BoolVector _clique; |
105 | 135 |
int _size; |
106 | 136 |
|
107 | 137 |
// The best clique found so far |
... | ... |
@@ -377,71 +407,187 @@ |
377 | 407 |
/// The global \ref rnd "random number generator instance" is used |
378 | 408 |
/// during the algorithm. |
379 | 409 |
/// |
380 | 410 |
/// \param graph The undirected graph the algorithm runs on. |
381 | 411 |
GrossoLocatelliPullanMc(const GR& graph) : |
382 | 412 |
_graph(graph), _id(_graph), _rnd(rnd) |
383 |
{ |
|
413 |
{ |
|
414 |
initOptions(); |
|
415 |
} |
|
384 | 416 |
|
385 | 417 |
/// \brief Constructor with random seed. |
386 | 418 |
/// |
387 | 419 |
/// Constructor with random seed. |
388 | 420 |
/// |
389 | 421 |
/// \param graph The undirected graph the algorithm runs on. |
390 | 422 |
/// \param seed Seed value for the internal random number generator |
391 | 423 |
/// that is used during the algorithm. |
392 | 424 |
GrossoLocatelliPullanMc(const GR& graph, int seed) : |
393 | 425 |
_graph(graph), _id(_graph), _rnd(seed) |
394 |
{ |
|
426 |
{ |
|
427 |
initOptions(); |
|
428 |
} |
|
395 | 429 |
|
396 | 430 |
/// \brief Constructor with random number generator. |
397 | 431 |
/// |
398 | 432 |
/// Constructor with random number generator. |
399 | 433 |
/// |
400 | 434 |
/// \param graph The undirected graph the algorithm runs on. |
401 | 435 |
/// \param random A random number generator that is used during the |
402 | 436 |
/// algorithm. |
403 | 437 |
GrossoLocatelliPullanMc(const GR& graph, const Random& random) : |
404 | 438 |
_graph(graph), _id(_graph), _rnd(random) |
405 |
{ |
|
439 |
{ |
|
440 |
initOptions(); |
|
441 |
} |
|
406 | 442 |
|
407 | 443 |
/// \name Execution Control |
444 |
/// The \ref run() function can be used to execute the algorithm.\n |
|
445 |
/// The functions \ref iterationLimit(int), \ref stepLimit(int), and |
|
446 |
/// \ref sizeLimit(int) can be used to specify various limits for the |
|
447 |
/// search process. |
|
448 |
|
|
408 | 449 |
/// @{ |
450 |
|
|
451 |
/// \brief Sets the maximum number of iterations. |
|
452 |
/// |
|
453 |
/// This function sets the maximum number of iterations. |
|
454 |
/// Each iteration of the algorithm finds a maximal clique (but not |
|
455 |
/// necessarily the largest one) by performing several search steps |
|
456 |
/// (node selections). |
|
457 |
/// |
|
458 |
/// This limit controls the running time and the success of the |
|
459 |
/// algorithm. For larger values, the algorithm runs slower, but it more |
|
460 |
/// likely finds larger cliques. For smaller values, the algorithm is |
|
461 |
/// faster but probably gives worse results. |
|
462 |
/// |
|
463 |
/// The default value is \c 1000. |
|
464 |
/// \c -1 means that number of iterations is not limited. |
|
465 |
/// |
|
466 |
/// \warning You should specify a reasonable limit for the number of |
|
467 |
/// iterations and/or the number of search steps. |
|
468 |
/// |
|
469 |
/// \return <tt>(*this)</tt> |
|
470 |
/// |
|
471 |
/// \sa stepLimit(int) |
|
472 |
/// \sa sizeLimit(int) |
|
473 |
GrossoLocatelliPullanMc& iterationLimit(int limit) { |
|
474 |
_iteration_limit = limit; |
|
475 |
return *this; |
|
476 |
} |
|
477 |
|
|
478 |
/// \brief Sets the maximum number of search steps. |
|
479 |
/// |
|
480 |
/// This function sets the maximum number of elementary search steps. |
|
481 |
/// Each iteration of the algorithm finds a maximal clique (but not |
|
482 |
/// necessarily the largest one) by performing several search steps |
|
483 |
/// (node selections). |
|
484 |
/// |
|
485 |
/// This limit controls the running time and the success of the |
|
486 |
/// algorithm. For larger values, the algorithm runs slower, but it more |
|
487 |
/// likely finds larger cliques. For smaller values, the algorithm is |
|
488 |
/// faster but probably gives worse results. |
|
489 |
/// |
|
490 |
/// The default value is \c -1, which means that number of steps |
|
491 |
/// is not limited explicitly. However, the number of iterations is |
|
492 |
/// limited and each iteration performs a finite number of search steps. |
|
493 |
/// |
|
494 |
/// \warning You should specify a reasonable limit for the number of |
|
495 |
/// iterations and/or the number of search steps. |
|
496 |
/// |
|
497 |
/// \return <tt>(*this)</tt> |
|
498 |
/// |
|
499 |
/// \sa iterationLimit(int) |
|
500 |
/// \sa sizeLimit(int) |
|
501 |
GrossoLocatelliPullanMc& stepLimit(int limit) { |
|
502 |
_step_limit = limit; |
|
503 |
return *this; |
|
504 |
} |
|
505 |
|
|
506 |
/// \brief Sets the desired clique size. |
|
507 |
/// |
|
508 |
/// This function sets the desired clique size that serves as a search |
|
509 |
/// limit. If a clique of this size (or a larger one) is found, then the |
|
510 |
/// algorithm terminates. |
|
511 |
/// |
|
512 |
/// This function is especially useful if you know an exact upper bound |
|
513 |
/// for the size of the cliques in the graph or if any clique above |
|
514 |
/// a certain size limit is sufficient for your application. |
|
515 |
/// |
|
516 |
/// The default value is \c -1, which means that the size limit is set to |
|
517 |
/// the number of nodes in the graph. |
|
518 |
/// |
|
519 |
/// \return <tt>(*this)</tt> |
|
520 |
/// |
|
521 |
/// \sa iterationLimit(int) |
|
522 |
/// \sa stepLimit(int) |
|
523 |
GrossoLocatelliPullanMc& sizeLimit(int limit) { |
|
524 |
_size_limit = limit; |
|
525 |
return *this; |
|
526 |
} |
|
527 |
|
|
528 |
/// \brief The maximum number of iterations. |
|
529 |
/// |
|
530 |
/// This function gives back the maximum number of iterations. |
|
531 |
/// \c -1 means that no limit is specified. |
|
532 |
/// |
|
533 |
/// \sa iterationLimit(int) |
|
534 |
int iterationLimit() const { |
|
535 |
return _iteration_limit; |
|
536 |
} |
|
537 |
|
|
538 |
/// \brief The maximum number of search steps. |
|
539 |
/// |
|
540 |
/// This function gives back the maximum number of search steps. |
|
541 |
/// \c -1 means that no limit is specified. |
|
542 |
/// |
|
543 |
/// \sa stepLimit(int) |
|
544 |
int stepLimit() const { |
|
545 |
return _step_limit; |
|
546 |
} |
|
547 |
|
|
548 |
/// \brief The desired clique size. |
|
549 |
/// |
|
550 |
/// This function gives back the desired clique size that serves as a |
|
551 |
/// search limit. \c -1 means that this limit is set to the number of |
|
552 |
/// nodes in the graph. |
|
553 |
/// |
|
554 |
/// \sa sizeLimit(int) |
|
555 |
int sizeLimit() const { |
|
556 |
return _size_limit; |
|
557 |
} |
|
409 | 558 |
|
410 | 559 |
/// \brief Runs the algorithm. |
411 | 560 |
/// |
412 |
/// This function runs the algorithm. |
|
561 |
/// This function runs the algorithm. If one of the specified limits |
|
562 |
/// is reached, the search process terminates. |
|
413 | 563 |
/// |
414 |
/// \param step_num The maximum number of node selections (steps) |
|
415 |
/// during the search process. |
|
416 |
/// This parameter controls the running time and the success of the |
|
417 |
/// algorithm. For larger values, the algorithm runs slower but it more |
|
418 |
/// likely finds larger cliques. For smaller values, the algorithm is |
|
419 |
/// faster but probably gives worse results. |
|
420 | 564 |
/// \param rule The node selection rule. For more information, see |
421 | 565 |
/// \ref SelectionRule. |
422 | 566 |
/// |
423 |
/// \return The size of the found clique. |
|
424 |
int run(int step_num = 100000, |
|
425 |
|
|
567 |
/// \return The termination cause of the search. For more information, |
|
568 |
/// see \ref TerminationCause. |
|
569 |
TerminationCause run(SelectionRule rule = PENALTY_BASED) |
|
426 | 570 |
{ |
427 | 571 |
init(); |
428 | 572 |
switch (rule) { |
429 | 573 |
case RANDOM: |
430 |
return start<RandomSelectionRule>( |
|
574 |
return start<RandomSelectionRule>(); |
|
431 | 575 |
case DEGREE_BASED: |
432 |
return start<DegreeBasedSelectionRule>(step_num); |
|
433 |
case PENALTY_BASED: |
|
434 |
return start< |
|
576 |
return start<DegreeBasedSelectionRule>(); |
|
577 |
default: |
|
578 |
return start<PenaltyBasedSelectionRule>(); |
|
435 | 579 |
} |
436 |
return 0; // avoid warning |
|
437 | 580 |
} |
438 | 581 |
|
439 | 582 |
/// @} |
440 | 583 |
|
441 | 584 |
/// \name Query Functions |
585 |
/// The results of the algorithm can be obtained using these functions.\n |
|
586 |
/// The run() function must be called before using them. |
|
587 |
|
|
442 | 588 |
/// @{ |
443 | 589 |
|
444 | 590 |
/// \brief The size of the found clique |
445 | 591 |
/// |
446 | 592 |
/// This function returns the size of the found clique. |
447 | 593 |
/// |
... | ... |
@@ -527,12 +673,24 @@ |
527 | 673 |
|
528 | 674 |
}; |
529 | 675 |
|
530 | 676 |
/// @} |
531 | 677 |
|
532 | 678 |
private: |
679 |
|
|
680 |
// Initialize search options and limits |
|
681 |
void initOptions() { |
|
682 |
// Search options |
|
683 |
_delta_based_restart = true; |
|
684 |
_restart_delta_limit = 4; |
|
685 |
|
|
686 |
// Search limits |
|
687 |
_iteration_limit = 1000; |
|
688 |
_step_limit = -1; // this is disabled by default |
|
689 |
_size_limit = -1; // this is disabled by default |
|
690 |
} |
|
533 | 691 |
|
534 | 692 |
// Adds a node to the current clique |
535 | 693 |
void addCliqueNode(int u) { |
536 | 694 |
if (_clique[u]) return; |
537 | 695 |
_clique[u] = true; |
538 | 696 |
_size++; |
... | ... |
@@ -583,36 +741,38 @@ |
583 | 741 |
_tabu.clear(); |
584 | 742 |
_tabu.resize(_n, false); |
585 | 743 |
} |
586 | 744 |
|
587 | 745 |
// Executes the algorithm |
588 | 746 |
template <typename SelectionRuleImpl> |
589 |
int start(int max_select) { |
|
590 |
// Options for the restart rule |
|
591 |
const bool delta_based_restart = true; |
|
592 |
const int restart_delta_limit = 4; |
|
593 |
|
|
594 |
if (_n == 0) return 0; |
|
747 |
TerminationCause start() { |
|
748 |
if (_n == 0) return SIZE_LIMIT; |
|
595 | 749 |
if (_n == 1) { |
596 | 750 |
_best_clique[0] = true; |
597 | 751 |
_best_size = 1; |
598 |
return |
|
752 |
return SIZE_LIMIT; |
|
599 | 753 |
} |
600 | 754 |
|
601 |
// Iterated local search |
|
755 |
// Iterated local search algorithm |
|
756 |
const int max_size = _size_limit >= 0 ? _size_limit : _n; |
|
757 |
const int max_restart = _iteration_limit >= 0 ? |
|
758 |
_iteration_limit : std::numeric_limits<int>::max(); |
|
759 |
const int max_select = _step_limit >= 0 ? |
|
760 |
_step_limit : std::numeric_limits<int>::max(); |
|
761 |
|
|
602 | 762 |
SelectionRuleImpl sel_method(*this); |
603 |
int select = 0; |
|
763 |
int select = 0, restart = 0; |
|
604 | 764 |
IntVector restart_nodes; |
605 |
|
|
606 |
while (select < max_select) { |
|
765 |
while (select < max_select && restart < max_restart) { |
|
607 | 766 |
|
608 | 767 |
// Perturbation/restart |
609 |
|
|
768 |
restart++; |
|
769 |
if (_delta_based_restart) { |
|
610 | 770 |
restart_nodes.clear(); |
611 | 771 |
for (int i = 0; i != _n; i++) { |
612 |
if (_delta[i] >= |
|
772 |
if (_delta[i] >= _restart_delta_limit) |
|
613 | 773 |
restart_nodes.push_back(i); |
614 | 774 |
} |
615 | 775 |
} |
616 | 776 |
int rs_node = -1; |
617 | 777 |
if (restart_nodes.size() > 0) { |
618 | 778 |
rs_node = restart_nodes[_rnd[restart_nodes.size()]]; |
... | ... |
@@ -660,18 +820,18 @@ |
660 | 820 |
} |
661 | 821 |
else break; |
662 | 822 |
} |
663 | 823 |
if (_size > _best_size) { |
664 | 824 |
_best_clique = _clique; |
665 | 825 |
_best_size = _size; |
666 |
if (_best_size |
|
826 |
if (_best_size >= max_size) return SIZE_LIMIT; |
|
667 | 827 |
} |
668 | 828 |
sel_method.update(); |
669 | 829 |
} |
670 | 830 |
|
671 |
return |
|
831 |
return (restart >= max_restart ? ITERATION_LIMIT : STEP_LIMIT); |
|
672 | 832 |
} |
673 | 833 |
|
674 | 834 |
}; //class GrossoLocatelliPullanMc |
675 | 835 |
|
676 | 836 |
///@} |
677 | 837 |
... | ... |
@@ -44,16 +44,16 @@ |
44 | 44 |
/// \ref amo93networkflows, \ref dantzig63linearprog, |
45 | 45 |
/// \ref kellyoneill91netsimplex. |
46 | 46 |
/// This algorithm is a highly efficient specialized version of the |
47 | 47 |
/// linear programming simplex method directly for the minimum cost |
48 | 48 |
/// flow problem. |
49 | 49 |
/// |
50 |
/// In general, %NetworkSimplex is the fastest implementation available |
|
51 |
/// in LEMON for this problem. |
|
52 |
/// Moreover, it supports both directions of the supply/demand inequality |
|
53 |
/// constraints. For more information, see \ref SupplyType. |
|
50 |
/// In general, \ref NetworkSimplex and \ref CostScaling are the fastest |
|
51 |
/// implementations available in LEMON for this problem. |
|
52 |
/// Furthermore, this class supports both directions of the supply/demand |
|
53 |
/// inequality constraints. For more information, see \ref SupplyType. |
|
54 | 54 |
/// |
55 | 55 |
/// Most of the parameters of the problem (except for the digraph) |
56 | 56 |
/// can be given using separate functions, and the algorithm can be |
57 | 57 |
/// executed using the \ref run() function. If some parameters are not |
58 | 58 |
/// specified, then default values will be used. |
59 | 59 |
/// |
... | ... |
@@ -123,13 +123,13 @@ |
123 | 123 |
/// the \ref run() function. |
124 | 124 |
/// |
125 | 125 |
/// \ref NetworkSimplex provides five different pivot rule |
126 | 126 |
/// implementations that significantly affect the running time |
127 | 127 |
/// of the algorithm. |
128 | 128 |
/// By default, \ref BLOCK_SEARCH "Block Search" is used, which |
129 |
/// |
|
129 |
/// turend out to be the most efficient and the most robust on various |
|
130 | 130 |
/// test inputs. |
131 | 131 |
/// However, another pivot rule can be selected using the \ref run() |
132 | 132 |
/// function with the proper parameter. |
133 | 133 |
enum PivotRule { |
134 | 134 |
|
135 | 135 |
/// The \e First \e Eligible pivot rule. |
... | ... |
@@ -165,13 +165,13 @@ |
165 | 165 |
TEMPLATE_DIGRAPH_TYPEDEFS(GR); |
166 | 166 |
|
167 | 167 |
typedef std::vector<int> IntVector; |
168 | 168 |
typedef std::vector<Value> ValueVector; |
169 | 169 |
typedef std::vector<Cost> CostVector; |
170 | 170 |
typedef std::vector<signed char> CharVector; |
171 |
// Note: vector<signed char> is used instead of vector<ArcState> and |
|
171 |
// Note: vector<signed char> is used instead of vector<ArcState> and |
|
172 | 172 |
// vector<ArcDirection> for efficiency reasons |
173 | 173 |
|
174 | 174 |
// State constants for arcs |
175 | 175 |
enum ArcState { |
176 | 176 |
STATE_UPPER = -1, |
177 | 177 |
STATE_TREE = 0, |
... | ... |
@@ -732,12 +732,14 @@ |
732 | 732 |
/// |
733 | 733 |
/// \param map A node map storing the supply values. |
734 | 734 |
/// Its \c Value type must be convertible to the \c Value type |
735 | 735 |
/// of the algorithm. |
736 | 736 |
/// |
737 | 737 |
/// \return <tt>(*this)</tt> |
738 |
/// |
|
739 |
/// \sa supplyType() |
|
738 | 740 |
template<typename SupplyMap> |
739 | 741 |
NetworkSimplex& supplyMap(const SupplyMap& map) { |
740 | 742 |
for (NodeIt n(_graph); n != INVALID; ++n) { |
741 | 743 |
_supply[_node_id[n]] = map[n]; |
742 | 744 |
} |
743 | 745 |
return *this; |
... | ... |
@@ -748,13 +750,13 @@ |
748 | 750 |
/// This function sets a single source node and a single target node |
749 | 751 |
/// and the required flow value. |
750 | 752 |
/// If neither this function nor \ref supplyMap() is used before |
751 | 753 |
/// calling \ref run(), the supply of each node will be set to zero. |
752 | 754 |
/// |
753 | 755 |
/// Using this function has the same effect as using \ref supplyMap() |
754 |
/// with |
|
756 |
/// with a map in which \c k is assigned to \c s, \c -k is |
|
755 | 757 |
/// assigned to \c t and all other nodes have zero supply value. |
756 | 758 |
/// |
757 | 759 |
/// \param s The source node. |
758 | 760 |
/// \param t The target node. |
759 | 761 |
/// \param k The required amount of flow from node \c s to node \c t |
760 | 762 |
/// (i.e. the supply of \c s and the demand of \c t). |
... | ... |
@@ -40,13 +40,13 @@ |
40 | 40 |
/// \brief A structure for representing directed paths in a digraph. |
41 | 41 |
/// |
42 | 42 |
/// A structure for representing directed path in a digraph. |
43 | 43 |
/// \tparam GR The digraph type in which the path is. |
44 | 44 |
/// |
45 | 45 |
/// In a sense, the path can be treated as a list of arcs. The |
46 |
/// |
|
46 |
/// LEMON path type stores just this list. As a consequence, it |
|
47 | 47 |
/// cannot enumerate the nodes of the path and the source node of |
48 | 48 |
/// a zero length path is undefined. |
49 | 49 |
/// |
50 | 50 |
/// This implementation is a back and front insertable and erasable |
51 | 51 |
/// path type. It can be indexed in O(1) time. The front and back |
52 | 52 |
/// insertion and erase is done in O(1) (amortized) time. The |
... | ... |
@@ -132,21 +132,21 @@ |
132 | 132 |
/// \brief Return whether the path is empty. |
133 | 133 |
bool empty() const { return head.empty() && tail.empty(); } |
134 | 134 |
|
135 | 135 |
/// \brief Reset the path to an empty one. |
136 | 136 |
void clear() { head.clear(); tail.clear(); } |
137 | 137 |
|
138 |
/// \brief The |
|
138 |
/// \brief The n-th arc. |
|
139 | 139 |
/// |
140 | 140 |
/// \pre \c n is in the <tt>[0..length() - 1]</tt> range. |
141 | 141 |
const Arc& nth(int n) const { |
142 | 142 |
return n < int(head.size()) ? *(head.rbegin() + n) : |
143 | 143 |
*(tail.begin() + (n - head.size())); |
144 | 144 |
} |
145 | 145 |
|
146 |
/// \brief Initialize arc iterator to point to the |
|
146 |
/// \brief Initialize arc iterator to point to the n-th arc |
|
147 | 147 |
/// |
148 | 148 |
/// \pre \c n is in the <tt>[0..length() - 1]</tt> range. |
149 | 149 |
ArcIt nthIt(int n) const { |
150 | 150 |
return ArcIt(*this, n); |
151 | 151 |
} |
152 | 152 |
|
... | ... |
@@ -228,13 +228,13 @@ |
228 | 228 |
/// \brief A structure for representing directed paths in a digraph. |
229 | 229 |
/// |
230 | 230 |
/// A structure for representing directed path in a digraph. |
231 | 231 |
/// \tparam GR The digraph type in which the path is. |
232 | 232 |
/// |
233 | 233 |
/// In a sense, the path can be treated as a list of arcs. The |
234 |
/// |
|
234 |
/// LEMON path type stores just this list. As a consequence it |
|
235 | 235 |
/// cannot enumerate the nodes in the path and the zero length paths |
236 | 236 |
/// cannot store the source. |
237 | 237 |
/// |
238 | 238 |
/// This implementation is a just back insertable and erasable path |
239 | 239 |
/// type. It can be indexed in O(1) time. The back insertion and |
240 | 240 |
/// erasure is amortized O(1) time. This implementation is faster |
... | ... |
@@ -324,20 +324,20 @@ |
324 | 324 |
/// \brief Return true if the path is empty. |
325 | 325 |
bool empty() const { return data.empty(); } |
326 | 326 |
|
327 | 327 |
/// \brief Reset the path to an empty one. |
328 | 328 |
void clear() { data.clear(); } |
329 | 329 |
|
330 |
/// \brief The |
|
330 |
/// \brief The n-th arc. |
|
331 | 331 |
/// |
332 | 332 |
/// \pre \c n is in the <tt>[0..length() - 1]</tt> range. |
333 | 333 |
const Arc& nth(int n) const { |
334 | 334 |
return data[n]; |
335 | 335 |
} |
336 | 336 |
|
337 |
/// \brief Initializes arc iterator to point to the |
|
337 |
/// \brief Initializes arc iterator to point to the n-th arc. |
|
338 | 338 |
ArcIt nthIt(int n) const { |
339 | 339 |
return ArcIt(*this, n); |
340 | 340 |
} |
341 | 341 |
|
342 | 342 |
/// \brief The first arc of the path. |
343 | 343 |
const Arc& front() const { |
... | ... |
@@ -392,13 +392,13 @@ |
392 | 392 |
/// \brief A structure for representing directed paths in a digraph. |
393 | 393 |
/// |
394 | 394 |
/// A structure for representing directed path in a digraph. |
395 | 395 |
/// \tparam GR The digraph type in which the path is. |
396 | 396 |
/// |
397 | 397 |
/// In a sense, the path can be treated as a list of arcs. The |
398 |
/// |
|
398 |
/// LEMON path type stores just this list. As a consequence it |
|
399 | 399 |
/// cannot enumerate the nodes in the path and the zero length paths |
400 | 400 |
/// cannot store the source. |
401 | 401 |
/// |
402 | 402 |
/// This implementation is a back and front insertable and erasable |
403 | 403 |
/// path type. It can be indexed in O(k) time, where k is the rank |
404 | 404 |
/// of the arc in the path. The length can be computed in O(n) |
... | ... |
@@ -501,25 +501,25 @@ |
501 | 501 |
|
502 | 502 |
private: |
503 | 503 |
const ListPath *path; |
504 | 504 |
Node *node; |
505 | 505 |
}; |
506 | 506 |
|
507 |
/// \brief The |
|
507 |
/// \brief The n-th arc. |
|
508 | 508 |
/// |
509 |
/// This function looks for the |
|
509 |
/// This function looks for the n-th arc in O(n) time. |
|
510 | 510 |
/// \pre \c n is in the <tt>[0..length() - 1]</tt> range. |
511 | 511 |
const Arc& nth(int n) const { |
512 | 512 |
Node *node = first; |
513 | 513 |
for (int i = 0; i < n; ++i) { |
514 | 514 |
node = node->next; |
515 | 515 |
} |
516 | 516 |
return node->arc; |
517 | 517 |
} |
518 | 518 |
|
519 |
/// \brief Initializes arc iterator to point to the |
|
519 |
/// \brief Initializes arc iterator to point to the n-th arc. |
|
520 | 520 |
ArcIt nthIt(int n) const { |
521 | 521 |
Node *node = first; |
522 | 522 |
for (int i = 0; i < n; ++i) { |
523 | 523 |
node = node->next; |
524 | 524 |
} |
525 | 525 |
return ArcIt(*this, node); |
... | ... |
@@ -732,13 +732,13 @@ |
732 | 732 |
/// \brief A structure for representing directed paths in a digraph. |
733 | 733 |
/// |
734 | 734 |
/// A structure for representing directed path in a digraph. |
735 | 735 |
/// \tparam GR The digraph type in which the path is. |
736 | 736 |
/// |
737 | 737 |
/// In a sense, the path can be treated as a list of arcs. The |
738 |
/// |
|
738 |
/// LEMON path type stores just this list. As a consequence it |
|
739 | 739 |
/// cannot enumerate the nodes in the path and the source node of |
740 | 740 |
/// a zero length path is undefined. |
741 | 741 |
/// |
742 | 742 |
/// This implementation is completly static, i.e. it can be copy constucted |
743 | 743 |
/// or copy assigned from another path, but otherwise it cannot be |
744 | 744 |
/// modified. |
... | ... |
@@ -828,20 +828,20 @@ |
828 | 828 |
|
829 | 829 |
private: |
830 | 830 |
const StaticPath *path; |
831 | 831 |
int idx; |
832 | 832 |
}; |
833 | 833 |
|
834 |
/// \brief The |
|
834 |
/// \brief The n-th arc. |
|
835 | 835 |
/// |
836 | 836 |
/// \pre \c n is in the <tt>[0..length() - 1]</tt> range. |
837 | 837 |
const Arc& nth(int n) const { |
838 | 838 |
return arcs[n]; |
839 | 839 |
} |
840 | 840 |
|
841 |
/// \brief The arc iterator pointing to the |
|
841 |
/// \brief The arc iterator pointing to the n-th arc. |
|
842 | 842 |
ArcIt nthIt(int n) const { |
843 | 843 |
return ArcIt(*this, n); |
844 | 844 |
} |
845 | 845 |
|
846 | 846 |
/// \brief The length of the path. |
847 | 847 |
int length() const { return len; } |
... | ... |
@@ -1039,13 +1039,13 @@ |
1039 | 1039 |
return path.empty() ? INVALID : digraph.target(path.back()); |
1040 | 1040 |
} |
1041 | 1041 |
|
1042 | 1042 |
/// \brief Class which helps to iterate through the nodes of a path |
1043 | 1043 |
/// |
1044 | 1044 |
/// In a sense, the path can be treated as a list of arcs. The |
1045 |
/// |
|
1045 |
/// LEMON path type stores only this list. As a consequence, it |
|
1046 | 1046 |
/// cannot enumerate the nodes in the path and the zero length paths |
1047 | 1047 |
/// cannot have a source node. |
1048 | 1048 |
/// |
1049 | 1049 |
/// This class implements the node iterator of a path structure. To |
1050 | 1050 |
/// provide this feature, the underlying digraph should be passed to |
1051 | 1051 |
/// the constructor of the iterator. |
... | ... |
@@ -55,45 +55,46 @@ |
55 | 55 |
"5 7 14\n" |
56 | 56 |
"6 7 15\n"; |
57 | 57 |
|
58 | 58 |
|
59 | 59 |
// Check with general graphs |
60 | 60 |
template <typename Param> |
61 |
void checkMaxCliqueGeneral( |
|
61 |
void checkMaxCliqueGeneral(Param rule) { |
|
62 | 62 |
typedef ListGraph GR; |
63 | 63 |
typedef GrossoLocatelliPullanMc<GR> McAlg; |
64 | 64 |
typedef McAlg::CliqueNodeIt CliqueIt; |
65 | 65 |
|
66 | 66 |
// Basic tests |
67 | 67 |
{ |
68 | 68 |
GR g; |
69 | 69 |
GR::NodeMap<bool> map(g); |
70 | 70 |
McAlg mc(g); |
71 |
|
|
71 |
mc.iterationLimit(50); |
|
72 |
check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause"); |
|
72 | 73 |
check(mc.cliqueSize() == 0, "Wrong clique size"); |
73 | 74 |
check(CliqueIt(mc) == INVALID, "Wrong CliqueNodeIt"); |
74 | 75 |
|
75 | 76 |
GR::Node u = g.addNode(); |
76 |
check(mc.run( |
|
77 |
check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause"); |
|
77 | 78 |
check(mc.cliqueSize() == 1, "Wrong clique size"); |
78 | 79 |
mc.cliqueMap(map); |
79 | 80 |
check(map[u], "Wrong clique map"); |
80 | 81 |
CliqueIt it1(mc); |
81 | 82 |
check(static_cast<GR::Node>(it1) == u && ++it1 == INVALID, |
82 | 83 |
"Wrong CliqueNodeIt"); |
83 | 84 |
|
84 | 85 |
GR::Node v = g.addNode(); |
85 |
check(mc.run( |
|
86 |
check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause"); |
|
86 | 87 |
check(mc.cliqueSize() == 1, "Wrong clique size"); |
87 | 88 |
mc.cliqueMap(map); |
88 | 89 |
check((map[u] && !map[v]) || (map[v] && !map[u]), "Wrong clique map"); |
89 | 90 |
CliqueIt it2(mc); |
90 | 91 |
check(it2 != INVALID && ++it2 == INVALID, "Wrong CliqueNodeIt"); |
91 | 92 |
|
92 | 93 |
g.addEdge(u, v); |
93 |
check(mc.run( |
|
94 |
check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause"); |
|
94 | 95 |
check(mc.cliqueSize() == 2, "Wrong clique size"); |
95 | 96 |
mc.cliqueMap(map); |
96 | 97 |
check(map[u] && map[v], "Wrong clique map"); |
97 | 98 |
CliqueIt it3(mc); |
98 | 99 |
check(it3 != INVALID && ++it3 != INVALID && ++it3 == INVALID, |
99 | 100 |
"Wrong CliqueNodeIt"); |
... | ... |
@@ -107,13 +108,14 @@ |
107 | 108 |
std::istringstream input(test_lgf); |
108 | 109 |
graphReader(g, input) |
109 | 110 |
.nodeMap("max_clique", max_clique) |
110 | 111 |
.run(); |
111 | 112 |
|
112 | 113 |
McAlg mc(g); |
113 |
|
|
114 |
mc.iterationLimit(50); |
|
115 |
check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause"); |
|
114 | 116 |
check(mc.cliqueSize() == 4, "Wrong clique size"); |
115 | 117 |
mc.cliqueMap(map); |
116 | 118 |
for (GR::NodeIt n(g); n != INVALID; ++n) { |
117 | 119 |
check(map[n] == max_clique[n], "Wrong clique map"); |
118 | 120 |
} |
119 | 121 |
int cnt = 0; |
... | ... |
@@ -124,22 +126,22 @@ |
124 | 126 |
check(cnt == 4, "Wrong CliqueNodeIt"); |
125 | 127 |
} |
126 | 128 |
} |
127 | 129 |
|
128 | 130 |
// Check with full graphs |
129 | 131 |
template <typename Param> |
130 |
void checkMaxCliqueFullGraph( |
|
132 |
void checkMaxCliqueFullGraph(Param rule) { |
|
131 | 133 |
typedef FullGraph GR; |
132 | 134 |
typedef GrossoLocatelliPullanMc<FullGraph> McAlg; |
133 | 135 |
typedef McAlg::CliqueNodeIt CliqueIt; |
134 | 136 |
|
135 | 137 |
for (int size = 0; size <= 40; size = size * 3 + 1) { |
136 | 138 |
GR g(size); |
137 | 139 |
GR::NodeMap<bool> map(g); |
138 | 140 |
McAlg mc(g); |
139 |
check(mc.run( |
|
141 |
check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause"); |
|
140 | 142 |
check(mc.cliqueSize() == size, "Wrong clique size"); |
141 | 143 |
mc.cliqueMap(map); |
142 | 144 |
for (GR::NodeIt n(g); n != INVALID; ++n) { |
143 | 145 |
check(map[n], "Wrong clique map"); |
144 | 146 |
} |
145 | 147 |
int cnt = 0; |
... | ... |
@@ -147,30 +149,40 @@ |
147 | 149 |
check(cnt == size, "Wrong CliqueNodeIt"); |
148 | 150 |
} |
149 | 151 |
} |
150 | 152 |
|
151 | 153 |
// Check with grid graphs |
152 | 154 |
template <typename Param> |
153 |
void checkMaxCliqueGridGraph( |
|
155 |
void checkMaxCliqueGridGraph(Param rule) { |
|
154 | 156 |
GridGraph g(5, 7); |
155 | 157 |
GridGraph::NodeMap<char> map(g); |
156 | 158 |
GrossoLocatelliPullanMc<GridGraph> mc(g); |
157 |
|
|
159 |
|
|
160 |
mc.iterationLimit(100); |
|
161 |
check(mc.run(rule) == mc.ITERATION_LIMIT, "Wrong termination cause"); |
|
162 |
check(mc.cliqueSize() == 2, "Wrong clique size"); |
|
163 |
|
|
164 |
mc.stepLimit(100); |
|
165 |
check(mc.run(rule) == mc.STEP_LIMIT, "Wrong termination cause"); |
|
166 |
check(mc.cliqueSize() == 2, "Wrong clique size"); |
|
167 |
|
|
168 |
mc.sizeLimit(2); |
|
169 |
check(mc.run(rule) == mc.SIZE_LIMIT, "Wrong termination cause"); |
|
158 | 170 |
check(mc.cliqueSize() == 2, "Wrong clique size"); |
159 | 171 |
} |
160 | 172 |
|
161 | 173 |
|
162 | 174 |
int main() { |
163 |
checkMaxCliqueGeneral(50, GrossoLocatelliPullanMc<ListGraph>::RANDOM); |
|
164 |
checkMaxCliqueGeneral(50, GrossoLocatelliPullanMc<ListGraph>::DEGREE_BASED); |
|
165 |
checkMaxCliqueGeneral( |
|
175 |
checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::RANDOM); |
|
176 |
checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::DEGREE_BASED); |
|
177 |
checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::PENALTY_BASED); |
|
166 | 178 |
|
167 |
checkMaxCliqueFullGraph(50, GrossoLocatelliPullanMc<FullGraph>::RANDOM); |
|
168 |
checkMaxCliqueFullGraph(50, GrossoLocatelliPullanMc<FullGraph>::DEGREE_BASED); |
|
169 |
checkMaxCliqueFullGraph( |
|
179 |
checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::RANDOM); |
|
180 |
checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::DEGREE_BASED); |
|
181 |
checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::PENALTY_BASED); |
|
170 | 182 |
|
171 |
checkMaxCliqueGridGraph(50, GrossoLocatelliPullanMc<GridGraph>::RANDOM); |
|
172 |
checkMaxCliqueGridGraph(50, GrossoLocatelliPullanMc<GridGraph>::DEGREE_BASED); |
|
173 |
checkMaxCliqueGridGraph( |
|
183 |
checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::RANDOM); |
|
184 |
checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::DEGREE_BASED); |
|
185 |
checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::PENALTY_BASED); |
|
174 | 186 |
|
175 | 187 |
return 0; |
176 | 188 |
} |
0 comments (0 inline)