feat: add a new operator: eoAlgoReset
- Used in eoAlgoRestart, useful if one wants to reset some things before a restart. - Add operators to reset a pop (EO) and a distrib (EDO) and a wrapper to combine several reset operators.
This commit is contained in:
parent
412e054933
commit
d03f2abb46
3 changed files with 267 additions and 15 deletions
|
|
@ -5,8 +5,8 @@ own evolutionary algorithms.
|
|||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
License as published by the Free Software Foundation;
|
||||
version 2.1 of the License.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
|
@ -17,7 +17,7 @@ You should have received a copy of the GNU Lesser General Public
|
|||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Copyright (C) 2010 Thales group
|
||||
Copyright (C) 2020 Thales group
|
||||
*/
|
||||
/*
|
||||
Authors:
|
||||
|
|
@ -29,18 +29,23 @@ Authors:
|
|||
|
||||
#include "eoPop.h"
|
||||
#include "eoAlgo.h"
|
||||
#include "eoAlgoReset.h"
|
||||
|
||||
/** An algo that restart the given algorithm on a freshly init pop.
|
||||
/** An algo that restart the given algorithm on a freshly init setting.
|
||||
*
|
||||
* @note: The fresh population size is set to the size of the last population at previous run.
|
||||
* If no reseter is specified at construction,
|
||||
* a reset of the population is performed before each search.
|
||||
* @see eoAlgoPopReset
|
||||
*
|
||||
* @ingroup Algorithms
|
||||
* @ingroup Algorithms
|
||||
*/
|
||||
template<class EOT>
|
||||
class eoAlgoRestart : public eoAlgo<EOT>
|
||||
{
|
||||
public:
|
||||
/** Constructor with an eoPopEvalFunc
|
||||
*
|
||||
* Defaults to using eoAlgoPopReset.
|
||||
*
|
||||
* @param init the initialization operator
|
||||
* @param popeval an evaluator for populations
|
||||
|
|
@ -59,10 +64,14 @@ public:
|
|||
_loop_eval(_dummy_eval),
|
||||
_pop_eval(pop_eval),
|
||||
_algo(algo),
|
||||
_continue(continuator)
|
||||
_continue(continuator),
|
||||
_pop_reset(_init, _pop_eval),
|
||||
_reseter(_pop_reset)
|
||||
{}
|
||||
|
||||
/** Constructor with an eoEvalFunc
|
||||
*
|
||||
* Defaults to using eoAlgoPopReset.
|
||||
*
|
||||
* @param init the initialization operator
|
||||
* @param popeval an evaluator for populations
|
||||
|
|
@ -81,19 +90,65 @@ public:
|
|||
_loop_eval(_eval),
|
||||
_pop_eval(_loop_eval),
|
||||
_algo(algo),
|
||||
_continue(continuator)
|
||||
_continue(continuator),
|
||||
_pop_reset(_init, _pop_eval),
|
||||
_reseter(_pop_reset)
|
||||
{}
|
||||
|
||||
/** Constructor with an eoPopEvalFunc and an eoAlgoReset
|
||||
*
|
||||
* @param popeval an evaluator for populations
|
||||
* @param algo the algorithm to restart
|
||||
* @param continuator a stopping criterion to manage the number of restarts
|
||||
* @param reseter how to reset the search
|
||||
*/
|
||||
eoAlgoRestart(
|
||||
eoPopEvalFunc<EOT>& pop_eval,
|
||||
eoAlgo<EOT>& algo,
|
||||
eoContinue<EOT>& continuator,
|
||||
eoAlgoReset<EOT>& reseter
|
||||
) :
|
||||
eoAlgo<EOT>(),
|
||||
_init(_dummy_init),
|
||||
_eval(_dummy_eval),
|
||||
_loop_eval(_dummy_eval),
|
||||
_pop_eval(pop_eval),
|
||||
_algo(algo),
|
||||
_continue(continuator),
|
||||
_pop_reset(_dummy_init, _pop_eval),
|
||||
_reseter(reseter)
|
||||
{}
|
||||
|
||||
/** Constructor with an eoEvalFunc and an eoAlgoReset
|
||||
*
|
||||
* @param popeval an evaluator for populations
|
||||
* @param algo the algorithm to restart
|
||||
* @param continuator a stopping criterion to manage the number of restarts
|
||||
* @param reseter how to reset the search
|
||||
*/
|
||||
eoAlgoRestart(
|
||||
eoEvalFunc<EOT>& eval,
|
||||
eoAlgo<EOT>& algo,
|
||||
eoContinue<EOT>& continuator,
|
||||
eoAlgoReset<EOT>& reseter
|
||||
) :
|
||||
eoAlgo<EOT>(),
|
||||
_init(_dummy_init),
|
||||
_eval(eval),
|
||||
_loop_eval(_eval),
|
||||
_pop_eval(_loop_eval),
|
||||
_algo(algo),
|
||||
_continue(continuator),
|
||||
_pop_reset(_dummy_init, _pop_eval),
|
||||
_reseter(reseter)
|
||||
{}
|
||||
|
||||
|
||||
virtual void operator()(eoPop<EOT> & pop)
|
||||
{
|
||||
do {
|
||||
size_t pop_size = pop.size();
|
||||
pop.clear();
|
||||
pop.append(pop_size, _init);
|
||||
_pop_eval(pop,pop);
|
||||
|
||||
_reseter(pop);
|
||||
_algo(pop);
|
||||
|
||||
} while( _continue(pop) );
|
||||
}
|
||||
|
||||
|
|
@ -107,6 +162,9 @@ protected:
|
|||
eoAlgo<EOT>& _algo;
|
||||
eoContinue<EOT>& _continue;
|
||||
|
||||
eoAlgoPopReset<EOT> _pop_reset;
|
||||
eoAlgoReset<EOT>& _reseter;
|
||||
|
||||
class eoDummyEval : public eoEvalFunc<EOT>
|
||||
{
|
||||
public:
|
||||
|
|
@ -114,7 +172,16 @@ protected:
|
|||
{}
|
||||
};
|
||||
eoDummyEval _dummy_eval;
|
||||
|
||||
class eoDummyInit : public eoInit<EOT>
|
||||
{
|
||||
public:
|
||||
void operator()(EOT &)
|
||||
{}
|
||||
};
|
||||
eoDummyInit _dummy_init;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // _EOALGORESTART_H_
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue