lemon/grosso_locatelli_pullan_mc.h
changeset 1184 3c00344f49c9
parent 1053 1c978b5bcc65
equal deleted inserted replaced
2:571f99a50202 3:7fb203c59459
     1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
     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  * Copyright (C) 2003-2010
     5  * Copyright (C) 2003-2013
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     8  *
     9  * Permission to use, modify and distribute this software is granted
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    10  * provided that this copyright notice appears in all copies. For
   118     IntNodeMap _id;
   118     IntNodeMap _id;
   119 
   119 
   120     // Internal matrix representation of the graph
   120     // Internal matrix representation of the graph
   121     BoolMatrix _gr;
   121     BoolMatrix _gr;
   122     int _n;
   122     int _n;
   123     
   123 
   124     // Search options
   124     // Search options
   125     bool _delta_based_restart;
   125     bool _delta_based_restart;
   126     int _restart_delta_limit;
   126     int _restart_delta_limit;
   127  
   127 
   128     // Search limits
   128     // Search limits
   129     int _iteration_limit;
   129     int _iteration_limit;
   130     int _step_limit;
   130     int _step_limit;
   131     int _size_limit;
   131     int _size_limit;
   132 
   132 
   440       initOptions();
   440       initOptions();
   441     }
   441     }
   442 
   442 
   443     /// \name Execution Control
   443     /// \name Execution Control
   444     /// The \ref run() function can be used to execute the algorithm.\n
   444     /// The \ref run() function can be used to execute the algorithm.\n
   445     /// The functions \ref iterationLimit(int), \ref stepLimit(int), and 
   445     /// The functions \ref iterationLimit(int), \ref stepLimit(int), and
   446     /// \ref sizeLimit(int) can be used to specify various limits for the
   446     /// \ref sizeLimit(int) can be used to specify various limits for the
   447     /// search process.
   447     /// search process.
   448     
   448 
   449     /// @{
   449     /// @{
   450     
   450 
   451     /// \brief Sets the maximum number of iterations.
   451     /// \brief Sets the maximum number of iterations.
   452     ///
   452     ///
   453     /// This function sets the maximum number of iterations.
   453     /// This function sets the maximum number of iterations.
   454     /// Each iteration of the algorithm finds a maximal clique (but not
   454     /// Each iteration of the algorithm finds a maximal clique (but not
   455     /// necessarily the largest one) by performing several search steps
   455     /// necessarily the largest one) by performing several search steps
   457     ///
   457     ///
   458     /// This limit controls the running time and the success of the
   458     /// This limit controls the running time and the success of the
   459     /// algorithm. For larger values, the algorithm runs slower, but it more
   459     /// algorithm. For larger values, the algorithm runs slower, but it more
   460     /// likely finds larger cliques. For smaller values, the algorithm is
   460     /// likely finds larger cliques. For smaller values, the algorithm is
   461     /// faster but probably gives worse results.
   461     /// faster but probably gives worse results.
   462     /// 
   462     ///
   463     /// The default value is \c 1000.
   463     /// The default value is \c 1000.
   464     /// \c -1 means that number of iterations is not limited.
   464     /// \c -1 means that number of iterations is not limited.
   465     ///
   465     ///
   466     /// \warning You should specify a reasonable limit for the number of
   466     /// \warning You should specify a reasonable limit for the number of
   467     /// iterations and/or the number of search steps.
   467     /// iterations and/or the number of search steps.
   472     /// \sa sizeLimit(int)
   472     /// \sa sizeLimit(int)
   473     GrossoLocatelliPullanMc& iterationLimit(int limit) {
   473     GrossoLocatelliPullanMc& iterationLimit(int limit) {
   474       _iteration_limit = limit;
   474       _iteration_limit = limit;
   475       return *this;
   475       return *this;
   476     }
   476     }
   477     
   477 
   478     /// \brief Sets the maximum number of search steps.
   478     /// \brief Sets the maximum number of search steps.
   479     ///
   479     ///
   480     /// This function sets the maximum number of elementary search steps.
   480     /// This function sets the maximum number of elementary search steps.
   481     /// Each iteration of the algorithm finds a maximal clique (but not
   481     /// Each iteration of the algorithm finds a maximal clique (but not
   482     /// necessarily the largest one) by performing several search steps
   482     /// necessarily the largest one) by performing several search steps
   484     ///
   484     ///
   485     /// This limit controls the running time and the success of the
   485     /// This limit controls the running time and the success of the
   486     /// algorithm. For larger values, the algorithm runs slower, but it more
   486     /// algorithm. For larger values, the algorithm runs slower, but it more
   487     /// likely finds larger cliques. For smaller values, the algorithm is
   487     /// likely finds larger cliques. For smaller values, the algorithm is
   488     /// faster but probably gives worse results.
   488     /// faster but probably gives worse results.
   489     /// 
   489     ///
   490     /// The default value is \c -1, which means that number of steps
   490     /// The default value is \c -1, which means that number of steps
   491     /// is not limited explicitly. However, the number of iterations is
   491     /// is not limited explicitly. However, the number of iterations is
   492     /// limited and each iteration performs a finite number of search steps.
   492     /// limited and each iteration performs a finite number of search steps.
   493     ///
   493     ///
   494     /// \warning You should specify a reasonable limit for the number of
   494     /// \warning You should specify a reasonable limit for the number of
   500     /// \sa sizeLimit(int)
   500     /// \sa sizeLimit(int)
   501     GrossoLocatelliPullanMc& stepLimit(int limit) {
   501     GrossoLocatelliPullanMc& stepLimit(int limit) {
   502       _step_limit = limit;
   502       _step_limit = limit;
   503       return *this;
   503       return *this;
   504     }
   504     }
   505     
   505 
   506     /// \brief Sets the desired clique size.
   506     /// \brief Sets the desired clique size.
   507     ///
   507     ///
   508     /// This function sets the desired clique size that serves as a search
   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
   509     /// limit. If a clique of this size (or a larger one) is found, then the
   510     /// algorithm terminates.
   510     /// algorithm terminates.
   511     /// 
   511     ///
   512     /// This function is especially useful if you know an exact upper bound
   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 
   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.
   514     /// a certain size limit is sufficient for your application.
   515     /// 
   515     ///
   516     /// The default value is \c -1, which means that the size limit is set to
   516     /// The default value is \c -1, which means that the size limit is set to
   517     /// the number of nodes in the graph.
   517     /// the number of nodes in the graph.
   518     ///
   518     ///
   519     /// \return <tt>(*this)</tt>
   519     /// \return <tt>(*this)</tt>
   520     ///
   520     ///
   522     /// \sa stepLimit(int)
   522     /// \sa stepLimit(int)
   523     GrossoLocatelliPullanMc& sizeLimit(int limit) {
   523     GrossoLocatelliPullanMc& sizeLimit(int limit) {
   524       _size_limit = limit;
   524       _size_limit = limit;
   525       return *this;
   525       return *this;
   526     }
   526     }
   527     
   527 
   528     /// \brief The maximum number of iterations.
   528     /// \brief The maximum number of iterations.
   529     ///
   529     ///
   530     /// This function gives back the maximum number of iterations.
   530     /// This function gives back the maximum number of iterations.
   531     /// \c -1 means that no limit is specified.
   531     /// \c -1 means that no limit is specified.
   532     ///
   532     ///
   533     /// \sa iterationLimit(int)
   533     /// \sa iterationLimit(int)
   534     int iterationLimit() const {
   534     int iterationLimit() const {
   535       return _iteration_limit;
   535       return _iteration_limit;
   536     }
   536     }
   537     
   537 
   538     /// \brief The maximum number of search steps.
   538     /// \brief The maximum number of search steps.
   539     ///
   539     ///
   540     /// This function gives back the maximum number of search steps.
   540     /// This function gives back the maximum number of search steps.
   541     /// \c -1 means that no limit is specified.
   541     /// \c -1 means that no limit is specified.
   542     ///
   542     ///
   543     /// \sa stepLimit(int)
   543     /// \sa stepLimit(int)
   544     int stepLimit() const {
   544     int stepLimit() const {
   545       return _step_limit;
   545       return _step_limit;
   546     }
   546     }
   547     
   547 
   548     /// \brief The desired clique size.
   548     /// \brief The desired clique size.
   549     ///
   549     ///
   550     /// This function gives back the desired clique size that serves as a
   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
   551     /// search limit. \c -1 means that this limit is set to the number of
   552     /// nodes in the graph.
   552     /// nodes in the graph.
   581 
   581 
   582     /// @}
   582     /// @}
   583 
   583 
   584     /// \name Query Functions
   584     /// \name Query Functions
   585     /// The results of the algorithm can be obtained using these functions.\n
   585     /// The results of the algorithm can be obtained using these functions.\n
   586     /// The run() function must be called before using them. 
   586     /// The run() function must be called before using them.
   587 
   587 
   588     /// @{
   588     /// @{
   589 
   589 
   590     /// \brief The size of the found clique
   590     /// \brief The size of the found clique
   591     ///
   591     ///
   674     };
   674     };
   675 
   675 
   676     /// @}
   676     /// @}
   677 
   677 
   678   private:
   678   private:
   679   
   679 
   680     // Initialize search options and limits
   680     // Initialize search options and limits
   681     void initOptions() {
   681     void initOptions() {
   682       // Search options
   682       // Search options
   683       _delta_based_restart = true;
   683       _delta_based_restart = true;
   684       _restart_delta_limit = 4;
   684       _restart_delta_limit = 4;
   685      
   685 
   686       // Search limits
   686       // Search limits
   687       _iteration_limit = 1000;
   687       _iteration_limit = 1000;
   688       _step_limit = -1;             // this is disabled by default
   688       _step_limit = -1;             // this is disabled by default
   689       _size_limit = -1;             // this is disabled by default
   689       _size_limit = -1;             // this is disabled by default
   690     }
   690     }