Merge branch 'master' of ssh://localhost:8479/gitroot/eodev/eodev
This commit is contained in:
commit
12e003b12d
23 changed files with 576 additions and 279 deletions
|
|
@ -42,7 +42,6 @@ INCLUDE_DIRECTORIES(
|
||||||
|
|
||||||
LINK_DIRECTORIES(
|
LINK_DIRECTORIES(
|
||||||
${EO_LIBRARY_DIRS}
|
${EO_LIBRARY_DIRS}
|
||||||
${MO_LIBRARY_DIRS}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,4 @@ FILE(GLOB SOURCES *.cpp)
|
||||||
SET(EXECUTABLE_OUTPUT_PATH ${EDO_BINARY_DIR})
|
SET(EXECUTABLE_OUTPUT_PATH ${EDO_BINARY_DIR})
|
||||||
|
|
||||||
ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES})
|
ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES})
|
||||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} edo edoutils ${EO_LIBRARIES} ${MO_LIBRARIES} ${Boost_LIBRARIES})
|
TARGET_LINK_LIBRARIES(${PROJECT_NAME} edo edoutils ${EO_LIBRARIES} ${Boost_LIBRARIES})
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,14 @@ Authors:
|
||||||
|
|
||||||
#include "edoVectorBounds.h"
|
#include "edoVectorBounds.h"
|
||||||
|
|
||||||
|
#include "edoRepairer.h"
|
||||||
|
#include "edoRepairerDispatcher.h"
|
||||||
|
#include "edoRepairerRound.h"
|
||||||
#include "edoBounder.h"
|
#include "edoBounder.h"
|
||||||
#include "edoBounderNo.h"
|
#include "edoBounderNo.h"
|
||||||
#include "edoBounderBound.h"
|
#include "edoBounderBound.h"
|
||||||
#include "edoBounderRng.h"
|
#include "edoBounderRng.h"
|
||||||
|
#include "edoBounderUniform.h"
|
||||||
|
|
||||||
#include "edoContinue.h"
|
#include "edoContinue.h"
|
||||||
#include "utils/edoCheckPoint.h"
|
#include "utils/edoCheckPoint.h"
|
||||||
|
|
|
||||||
|
|
@ -28,18 +28,22 @@ Authors:
|
||||||
#ifndef _edoBounder_h
|
#ifndef _edoBounder_h
|
||||||
#define _edoBounder_h
|
#define _edoBounder_h
|
||||||
|
|
||||||
#include <eoFunctor.h>
|
#include <edoRepairer.h>
|
||||||
|
|
||||||
/** The interface of a set of classes that modifies a solution so as to respect
|
/** The interface of a set of classes that modifies a solution so as to respect
|
||||||
* a given set of bounds (typically an hypercube).
|
* a given set of bounds (typically an hypercube).
|
||||||
*
|
*
|
||||||
* @ingroup Bounders
|
* @ingroup Repairers
|
||||||
*/
|
*/
|
||||||
template < typename EOT >
|
template < typename EOT >
|
||||||
class edoBounder : public eoUF< EOT&, void >
|
class edoBounder : public edoRepairer< EOT >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
edoBounder( EOT min = EOT(1, 0), EOT max = EOT(1, 0) )
|
edoBounder()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
edoBounder( EOT min/* = EOT(1, 0)*/, EOT max/* = EOT(1, 1)*/ )
|
||||||
: _min(min), _max(max)
|
: _min(min), _max(max)
|
||||||
{
|
{
|
||||||
assert(_min.size() > 0);
|
assert(_min.size() > 0);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ Authors:
|
||||||
|
|
||||||
/** A bounder that correct an incorrect variable by setting it to the min/max
|
/** A bounder that correct an incorrect variable by setting it to the min/max
|
||||||
*
|
*
|
||||||
* @ingroup Bounders
|
* @ingroup Repairers
|
||||||
*/
|
*/
|
||||||
template < typename EOT >
|
template < typename EOT >
|
||||||
class edoBounderBound : public edoBounder< EOT >
|
class edoBounderBound : public edoBounder< EOT >
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ Authors:
|
||||||
|
|
||||||
/** A bounder that does nothing.
|
/** A bounder that does nothing.
|
||||||
*
|
*
|
||||||
* @ingroup Bounders
|
* @ingroup Repairers
|
||||||
*/
|
*/
|
||||||
template < typename EOT >
|
template < typename EOT >
|
||||||
class edoBounderNo : public edoBounder< EOT >
|
class edoBounderNo : public edoBounder< EOT >
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ Authors:
|
||||||
/** A bounder that randomly draw new values for variables going out bounds,
|
/** A bounder that randomly draw new values for variables going out bounds,
|
||||||
* using an eoRng to do so.
|
* using an eoRng to do so.
|
||||||
*
|
*
|
||||||
* @ingroup Bounders
|
* @ingroup Repairers
|
||||||
*/
|
*/
|
||||||
template < typename EOT >
|
template < typename EOT >
|
||||||
class edoBounderRng : public edoBounder< EOT >
|
class edoBounderRng : public edoBounder< EOT >
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ Authors:
|
||||||
/** A bounder that randomly draw new values for variables going out bounds,
|
/** A bounder that randomly draw new values for variables going out bounds,
|
||||||
* in a given uniform distribution.
|
* in a given uniform distribution.
|
||||||
*
|
*
|
||||||
* @ingroup Bounders
|
* @ingroup Repairers
|
||||||
*/
|
*/
|
||||||
template < typename EOT >
|
template < typename EOT >
|
||||||
class edoBounderUniform : public edoBounder< EOT >
|
class edoBounderUniform : public edoBounder< EOT >
|
||||||
|
|
@ -40,13 +40,17 @@ class edoBounderUniform : public edoBounder< EOT >
|
||||||
public:
|
public:
|
||||||
edoBounderUniform( EOT min, EOT max )
|
edoBounderUniform( EOT min, EOT max )
|
||||||
: edoBounder< EOT >( min, max )
|
: edoBounder< EOT >( min, max )
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void operator()( EOT& sol )
|
void operator()( EOT& sol )
|
||||||
{
|
{
|
||||||
unsigned int size = sol.size();
|
assert( this->min().size() > 0 );
|
||||||
assert(size > 0);
|
assert( this->max().size() > 0 );
|
||||||
|
|
||||||
|
assert( sol.size() > 0);
|
||||||
|
|
||||||
|
unsigned int size = sol.size();
|
||||||
for (unsigned int d = 0; d < size; ++d) {
|
for (unsigned int d = 0; d < size; ++d) {
|
||||||
|
|
||||||
if ( sol[d] < this->min()[d] || sol[d] > this->max()[d]) {
|
if ( sol[d] < this->min()[d] || sol[d] > this->max()[d]) {
|
||||||
|
|
|
||||||
|
|
@ -60,32 +60,63 @@ public:
|
||||||
/*!
|
/*!
|
||||||
Takes algo operators, all are mandatory
|
Takes algo operators, all are mandatory
|
||||||
|
|
||||||
|
\param evaluation Evaluate a population
|
||||||
\param selector Selection of the best candidate solutions in the population
|
\param selector Selection of the best candidate solutions in the population
|
||||||
\param estimator Estimation of the distribution parameters
|
\param estimator Estimation of the distribution parameters
|
||||||
\param sampler Generate feasible solutions using the distribution
|
\param sampler Generate feasible solutions using the distribution
|
||||||
|
\param replacor Replace old solutions by new ones
|
||||||
\param pop_continuator Stopping criterion based on the population features
|
\param pop_continuator Stopping criterion based on the population features
|
||||||
\param distribution_continuator Stopping criterion based on the distribution features
|
\param distribution_continuator Stopping criterion based on the distribution features
|
||||||
\param evaluation Evaluate a population
|
|
||||||
\param replacor Replace old solutions by new ones
|
|
||||||
*/
|
*/
|
||||||
edoEDA (
|
edoEDA (
|
||||||
|
eoPopEvalFunc < EOT > & evaluator,
|
||||||
eoSelect< EOT > & selector,
|
eoSelect< EOT > & selector,
|
||||||
edoEstimator< D > & estimator,
|
edoEstimator< D > & estimator,
|
||||||
edoSampler< D > & sampler,
|
edoSampler< D > & sampler,
|
||||||
|
eoReplacement< EOT > & replacor,
|
||||||
eoContinue< EOT > & pop_continuator,
|
eoContinue< EOT > & pop_continuator,
|
||||||
edoContinue< D > & distribution_continuator,
|
edoContinue< D > & distribution_continuator
|
||||||
eoPopEvalFunc < EOT > & evaluator,
|
) :
|
||||||
eoReplacement< EOT > & replacor
|
_evaluator(evaluator),
|
||||||
)
|
_selector(selector),
|
||||||
: _selector(selector),
|
|
||||||
_estimator(estimator),
|
_estimator(estimator),
|
||||||
_sampler(sampler),
|
_sampler(sampler),
|
||||||
|
_replacor(replacor),
|
||||||
_pop_continuator(pop_continuator),
|
_pop_continuator(pop_continuator),
|
||||||
_distribution_continuator(distribution_continuator),
|
_dummy_continue(),
|
||||||
_evaluator(evaluator),
|
_distribution_continuator(distribution_continuator)
|
||||||
_replacor(replacor)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
//! edoEDA constructor without an edoContinue
|
||||||
|
/*!
|
||||||
|
Takes algo operators, all are mandatory
|
||||||
|
|
||||||
|
\param evaluation Evaluate a population
|
||||||
|
\param selector Selection of the best candidate solutions in the population
|
||||||
|
\param estimator Estimation of the distribution parameters
|
||||||
|
\param sampler Generate feasible solutions using the distribution
|
||||||
|
\param replacor Replace old solutions by new ones
|
||||||
|
\param pop_continuator Stopping criterion based on the population features
|
||||||
|
*/
|
||||||
|
edoEDA (
|
||||||
|
eoPopEvalFunc < EOT > & evaluator,
|
||||||
|
eoSelect< EOT > & selector,
|
||||||
|
edoEstimator< D > & estimator,
|
||||||
|
edoSampler< D > & sampler,
|
||||||
|
eoReplacement< EOT > & replacor,
|
||||||
|
eoContinue< EOT > & pop_continuator
|
||||||
|
) :
|
||||||
|
_evaluator(evaluator),
|
||||||
|
_selector(selector),
|
||||||
|
_estimator(estimator),
|
||||||
|
_sampler(sampler),
|
||||||
|
_replacor(replacor),
|
||||||
|
_pop_continuator(pop_continuator),
|
||||||
|
_dummy_continue(),
|
||||||
|
_distribution_continuator( _dummy_continue )
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
/** A basic EDA algorithm that iterates over:
|
/** A basic EDA algorithm that iterates over:
|
||||||
* selection, estimation, sampling, bounding, evaluation, replacement
|
* selection, estimation, sampling, bounding, evaluation, replacement
|
||||||
*
|
*
|
||||||
|
|
@ -135,6 +166,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
//! A full evaluation function.
|
||||||
|
eoPopEvalFunc < EOT > & _evaluator;
|
||||||
|
|
||||||
//! A EOT selector
|
//! A EOT selector
|
||||||
eoSelect < EOT > & _selector;
|
eoSelect < EOT > & _selector;
|
||||||
|
|
||||||
|
|
@ -144,17 +178,18 @@ private:
|
||||||
//! A D sampler
|
//! A D sampler
|
||||||
edoSampler< D > & _sampler;
|
edoSampler< D > & _sampler;
|
||||||
|
|
||||||
|
//! A EOT replacor
|
||||||
|
eoReplacement < EOT > & _replacor;
|
||||||
|
|
||||||
//! A EOT population continuator
|
//! A EOT population continuator
|
||||||
eoContinue < EOT > & _pop_continuator;
|
eoContinue < EOT > & _pop_continuator;
|
||||||
|
|
||||||
|
//! A D continuator that always return true
|
||||||
|
edoDummyContinue<D> _dummy_continue;
|
||||||
|
|
||||||
//! A D continuator
|
//! A D continuator
|
||||||
edoContinue < D > & _distribution_continuator;
|
edoContinue < D > & _distribution_continuator;
|
||||||
|
|
||||||
//! A full evaluation function.
|
|
||||||
eoPopEvalFunc < EOT > & _evaluator;
|
|
||||||
|
|
||||||
//! A EOT replacor
|
|
||||||
eoReplacement < EOT > & _replacor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !_edoEDA_h
|
#endif // !_edoEDA_h
|
||||||
|
|
|
||||||
47
edo/src/edoRepairer.h
Normal file
47
edo/src/edoRepairer.h
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||||
|
ANSI-C++ evolutionary computation library which helps you to write your
|
||||||
|
own estimation of distribution 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.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
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) 2011 Thales group
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Authors:
|
||||||
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
|
Pierre Savéant <pierre.saveant@thalesgroup.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _edoRepairer_h
|
||||||
|
#define _edoRepairer_h
|
||||||
|
|
||||||
|
#include <eoFunctor.h>
|
||||||
|
|
||||||
|
/** The interface of a set of classes that modifies an unfeasible candidate
|
||||||
|
* solution so as to respect a given set of constraints and thus make a feasible
|
||||||
|
* solution.
|
||||||
|
*
|
||||||
|
* @ingroup Repairers
|
||||||
|
*/
|
||||||
|
template < typename EOT >
|
||||||
|
class edoRepairer : public eoUF< EOT&, void >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// virtual void operator()( EOT& ) = 0 (provided by eoUF< A1, R >)
|
||||||
|
virtual void operator()( EOT& ) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // !_edoRepairer_h
|
||||||
115
edo/src/edoRepairerDispatcher.h
Normal file
115
edo/src/edoRepairerDispatcher.h
Normal file
|
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||||
|
ANSI-C++ evolutionary computation library which helps you to write your
|
||||||
|
own estimation of distribution 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.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
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) 2011 Thales group
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Authors:
|
||||||
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
|
Pierre Savéant <pierre.saveant@thalesgroup.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _edoRepairerDispatcher_h
|
||||||
|
#define _edoRepairerDispatcher_h
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "edoRepairer.h"
|
||||||
|
|
||||||
|
/** Repair a candidate solution by sequentially applying several repairers on
|
||||||
|
* subparts of the solution (subparts being defined by the corresponding set
|
||||||
|
* of indexes).
|
||||||
|
*
|
||||||
|
* Only work on EOT that implements the "push_back( EOT::AtomType )" and
|
||||||
|
* "operator[](uint)" and "at(uint)" methods.
|
||||||
|
*
|
||||||
|
* Expects _addresses_ of the repairer operators.
|
||||||
|
*
|
||||||
|
* @example t-dispatcher-round.cpp
|
||||||
|
*
|
||||||
|
* @ingroup Repairers
|
||||||
|
*/
|
||||||
|
|
||||||
|
template < typename EOT >
|
||||||
|
class edoRepairerDispatcher
|
||||||
|
: public edoRepairer<EOT>,
|
||||||
|
std::vector<
|
||||||
|
std::pair< std::set< unsigned int >, edoRepairer< EOT >* >
|
||||||
|
>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Empty constructor
|
||||||
|
edoRepairerDispatcher() :
|
||||||
|
std::vector<
|
||||||
|
std::pair< std::set< unsigned int >, edoRepairer< EOT >* >
|
||||||
|
>()
|
||||||
|
{}
|
||||||
|
|
||||||
|
//! Constructor with a single index set and repairer operator
|
||||||
|
edoRepairerDispatcher( std::set<unsigned int> idx, edoRepairer<EOT>* op ) :
|
||||||
|
std::vector<
|
||||||
|
std::pair< std::set< unsigned int >, edoRepairer< EOT >* >
|
||||||
|
>()
|
||||||
|
{
|
||||||
|
this->add( idx, op );
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Add more indexes set and their corresponding repairer operator address to the list
|
||||||
|
void add( std::set<unsigned int> idx, edoRepairer<EOT>* op )
|
||||||
|
{
|
||||||
|
assert( idx.size() > 0 );
|
||||||
|
assert( op != NULL );
|
||||||
|
|
||||||
|
this->push_back( std::make_pair(idx, op) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Repair a solution by calling several repair operator on subset of indexes
|
||||||
|
virtual void operator()( EOT& sol )
|
||||||
|
{
|
||||||
|
// ipair is an iterator that points on a pair
|
||||||
|
for( typename edoRepairerDispatcher<EOT>::iterator ipair = this->begin(); ipair != this->end(); ++ipair ) {
|
||||||
|
// a partial copy of the sol
|
||||||
|
EOT partsol;
|
||||||
|
|
||||||
|
// j is an iterator that points on an uint
|
||||||
|
for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) {
|
||||||
|
partsol.push_back( sol.at(*j) );
|
||||||
|
} // for j
|
||||||
|
|
||||||
|
assert( partsol.size() > 0 );
|
||||||
|
|
||||||
|
// apply the repairer on the partial copy
|
||||||
|
// the repairer is a functor, thus second is callable
|
||||||
|
(*(ipair->second))( partsol );
|
||||||
|
|
||||||
|
{ // copy back the repaired partial solution to sol
|
||||||
|
// browse partsol with uint k, and the idx set with an iterator (std::set is an associative tab)
|
||||||
|
unsigned int k=0;
|
||||||
|
for( std::set< unsigned int >::iterator j = ipair->first.begin(); j != ipair->first.end(); ++j ) {
|
||||||
|
sol[ *j ] = partsol[ k ];
|
||||||
|
k++;
|
||||||
|
} // for j
|
||||||
|
} // context for k
|
||||||
|
} // for ipair
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // !_edoRepairerDispatcher_h
|
||||||
68
edo/src/edoRepairerRound.h
Normal file
68
edo/src/edoRepairerRound.h
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||||
|
ANSI-C++ evolutionary computation library which helps you to write your
|
||||||
|
own estimation of distribution 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.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
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) 2011 Thales group
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Authors:
|
||||||
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
|
Pierre Savéant <pierre.saveant@thalesgroup.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _edoRepairerRound_h
|
||||||
|
#define _edoRepairerRound_h
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "edoRepairer.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @ingroup Repairers
|
||||||
|
*/
|
||||||
|
template < typename EOT >
|
||||||
|
class edoRepairerFloor : public edoRepairer<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void operator()( EOT& sol )
|
||||||
|
{
|
||||||
|
for( unsigned int i=0; i < sol.size(); ++i ) {
|
||||||
|
sol[i] = floor( sol[i] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @ingroup Repairers
|
||||||
|
*/
|
||||||
|
template < typename EOT >
|
||||||
|
class edoRepairerCeil : public edoRepairer<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void operator()( EOT& sol )
|
||||||
|
{
|
||||||
|
for( unsigned int i=0; i < sol.size(); ++i ) {
|
||||||
|
sol[i] = ceil( sol[i] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // !_edoRepairerRound_h
|
||||||
|
|
@ -30,7 +30,7 @@ Authors:
|
||||||
|
|
||||||
#include <eoFunctor.h>
|
#include <eoFunctor.h>
|
||||||
|
|
||||||
#include "edoBounder.h"
|
#include "edoRepairer.h"
|
||||||
#include "edoBounderNo.h"
|
#include "edoBounderNo.h"
|
||||||
|
|
||||||
//! edoSampler< D >
|
//! edoSampler< D >
|
||||||
|
|
@ -41,15 +41,15 @@ class edoSampler : public eoUF< D&, typename D::EOType >
|
||||||
public:
|
public:
|
||||||
typedef typename D::EOType EOType;
|
typedef typename D::EOType EOType;
|
||||||
|
|
||||||
edoSampler(edoBounder< EOType > & bounder)
|
edoSampler(edoRepairer< EOType > & repairer)
|
||||||
: /*_dummy_bounder(),*/ _bounder(bounder)
|
: _dummy_repairer(), _repairer(repairer)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/*
|
|
||||||
edoSampler()
|
edoSampler()
|
||||||
: _dummy_bounder(), _bounder( _dummy_bounder )
|
: _dummy_repairer(), _repairer( _dummy_repairer )
|
||||||
{}
|
{}
|
||||||
*/
|
|
||||||
|
|
||||||
// virtual EOType operator()( D& ) = 0 (provided by eoUF< A1, R >)
|
// virtual EOType operator()( D& ) = 0 (provided by eoUF< A1, R >)
|
||||||
|
|
||||||
|
|
@ -58,28 +58,15 @@ public:
|
||||||
unsigned int size = distrib.size();
|
unsigned int size = distrib.size();
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
// Point we want to sample to get higher a set of points
|
// Point we want to sample to get higher a set of points
|
||||||
// (coordinates in n dimension)
|
// (coordinates in n dimension)
|
||||||
// x = {x1, x2, ..., xn}
|
// x = {x1, x2, ..., xn}
|
||||||
// the sample method is implemented in the derivated class
|
// the sample method is implemented in the derivated class
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
EOType solution(sample(distrib));
|
EOType solution(sample(distrib));
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
// Now we are bounding the distribution thanks to min and max
|
// Now we are bounding the distribution thanks to min and max
|
||||||
// parameters.
|
// parameters.
|
||||||
//-------------------------------------------------------------
|
_repairer(solution);
|
||||||
|
|
||||||
_bounder(solution);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
return solution;
|
return solution;
|
||||||
}
|
}
|
||||||
|
|
@ -89,10 +76,10 @@ protected:
|
||||||
virtual EOType sample( D& ) = 0;
|
virtual EOType sample( D& ) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//edoBounderNo<EOType> _dummy_bounder;
|
edoBounderNo<EOType> _dummy_repairer;
|
||||||
|
|
||||||
//! Bounder functor
|
//! repairer functor
|
||||||
edoBounder< EOType > & _bounder;
|
edoRepairer< EOType > & _repairer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,37 +39,25 @@ Authors:
|
||||||
* This class uses the NormalMono distribution parameters (bounds) to return
|
* This class uses the NormalMono distribution parameters (bounds) to return
|
||||||
* a random position used for population sampling.
|
* a random position used for population sampling.
|
||||||
*/
|
*/
|
||||||
template < typename EOT >
|
template < typename EOT, typename D = edoNormalMono< EOT > >
|
||||||
class edoSamplerNormalMono : public edoSampler< edoNormalMono< EOT > >
|
class edoSamplerNormalMono : public edoSampler< D >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename EOT::AtomType AtomType;
|
typedef typename EOT::AtomType AtomType;
|
||||||
|
|
||||||
edoSamplerNormalMono( edoBounder< EOT > & bounder )
|
edoSamplerNormalMono( edoRepairer<EOT> & repairer ) : edoSampler< D >( repairer) {}
|
||||||
: edoSampler< edoNormalMono< EOT > >( bounder )
|
|
||||||
{}
|
|
||||||
|
|
||||||
EOT sample( edoNormalMono< EOT >& distrib )
|
EOT sample( edoNormalMono< EOT >& distrib )
|
||||||
{
|
{
|
||||||
unsigned int size = distrib.size();
|
unsigned int size = distrib.size();
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
// Point we want to sample to get higher a set of points
|
// Point we want to sample to get higher a set of points
|
||||||
// (coordinates in n dimension)
|
// (coordinates in n dimension)
|
||||||
// x = {x1, x2, ..., xn}
|
// x = {x1, x2, ..., xn}
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
EOT solution;
|
EOT solution;
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
// Sampling all dimensions
|
// Sampling all dimensions
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < size; ++i)
|
for (unsigned int i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
AtomType mean = distrib.mean()[i];
|
AtomType mean = distrib.mean()[i];
|
||||||
|
|
@ -81,9 +69,6 @@ public:
|
||||||
solution.push_back(random);
|
solution.push_back(random);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
return solution;
|
return solution;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,14 @@ Authors:
|
||||||
|
|
||||||
//! edoSamplerNormalMulti< EOT >
|
//! edoSamplerNormalMulti< EOT >
|
||||||
|
|
||||||
template< class EOT >
|
template< class EOT, typename D = edoNormalMulti< EOT > >
|
||||||
class edoSamplerNormalMulti : public edoSampler< edoNormalMulti< EOT > >
|
class edoSamplerNormalMulti : public edoSampler< D >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename EOT::AtomType AtomType;
|
typedef typename EOT::AtomType AtomType;
|
||||||
|
|
||||||
|
edoSamplerNormalMulti( edoRepairer<EOT> & repairer ) : edoSampler< D >( repairer) {}
|
||||||
|
|
||||||
class Cholesky
|
class Cholesky
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -38,57 +38,33 @@ Authors:
|
||||||
* This class uses the Uniform distribution parameters (bounds) to return
|
* This class uses the Uniform distribution parameters (bounds) to return
|
||||||
* a random position used for population sampling.
|
* a random position used for population sampling.
|
||||||
*/
|
*/
|
||||||
template < typename EOT, class D=edoUniform<EOT> > // FIXME: D template name is there really used ?!?
|
template < typename EOT, class D = edoUniform<EOT> >
|
||||||
class edoSamplerUniform : public edoSampler< edoUniform< EOT > >
|
class edoSamplerUniform : public edoSampler< D >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef D Distrib;
|
typedef D Distrib;
|
||||||
|
|
||||||
edoSamplerUniform(edoBounder< EOT > & bounder)
|
edoSamplerUniform( edoRepairer<EOT> & repairer ) : edoSampler< D >( repairer) {}
|
||||||
: edoSampler< edoUniform<EOT> >(bounder) // FIXME: Why D is not used here ?
|
|
||||||
{}
|
|
||||||
|
|
||||||
/*
|
|
||||||
edoSamplerUniform()
|
|
||||||
: edoSampler< edoUniform<EOT> >()
|
|
||||||
{}
|
|
||||||
*/
|
|
||||||
|
|
||||||
EOT sample( edoUniform< EOT >& distrib )
|
EOT sample( edoUniform< EOT >& distrib )
|
||||||
{
|
{
|
||||||
unsigned int size = distrib.size();
|
unsigned int size = distrib.size();
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
// Point we want to sample to get higher a set of points
|
// Point we want to sample to get higher a set of points
|
||||||
// (coordinates in n dimension)
|
// (coordinates in n dimension)
|
||||||
// x = {x1, x2, ..., xn}
|
// x = {x1, x2, ..., xn}
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
EOT solution;
|
EOT solution;
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
// Sampling all dimensions
|
// Sampling all dimensions
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < size; ++i)
|
for (unsigned int i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
double min = distrib.min()[i];
|
double min = distrib.min()[i];
|
||||||
double max = distrib.max()[i];
|
double max = distrib.max()[i];
|
||||||
double random = rng.uniform(min, max);
|
double random = rng.uniform(min, max);
|
||||||
|
|
||||||
assert(min <= random && random <= max);
|
|
||||||
|
|
||||||
solution.push_back(random);
|
solution.push_back(random);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
return solution;
|
return solution;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ SET(SOURCES
|
||||||
t-bounderno
|
t-bounderno
|
||||||
t-uniform
|
t-uniform
|
||||||
t-continue
|
t-continue
|
||||||
|
t-dispatcher-round
|
||||||
)
|
)
|
||||||
|
|
||||||
FOREACH(current ${SOURCES})
|
FOREACH(current ${SOURCES})
|
||||||
|
|
|
||||||
62
edo/test/t-dispatcher-round.cpp
Normal file
62
edo/test/t-dispatcher-round.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
The Evolving Distribution Objects framework (EDO) is a template-based,
|
||||||
|
ANSI-C++ evolutionary computation library which helps you to write your
|
||||||
|
own estimation of distribution 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.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Authors:
|
||||||
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
|
Pierre Savéant <pierre.saveant@thalesgroup.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
|
#include <edo>
|
||||||
|
#include <es.h>
|
||||||
|
|
||||||
|
typedef eoReal< eoMinimizingFitness > EOT;
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
EOT sol;
|
||||||
|
sol.push_back(1.1);
|
||||||
|
sol.push_back(1.1);
|
||||||
|
sol.push_back(3.9);
|
||||||
|
sol.push_back(3.9);
|
||||||
|
// we expect {1,2,3,4}
|
||||||
|
|
||||||
|
edoRepairer<EOT>* rep1 = new edoRepairerFloor<EOT>();
|
||||||
|
edoRepairer<EOT>* rep2 = new edoRepairerCeil<EOT>();
|
||||||
|
|
||||||
|
std::set<unsigned int> indexes1;
|
||||||
|
indexes1.insert(0);
|
||||||
|
indexes1.insert(2);
|
||||||
|
|
||||||
|
std::set<unsigned int> indexes2;
|
||||||
|
indexes2.insert(1);
|
||||||
|
indexes2.insert(3);
|
||||||
|
|
||||||
|
edoRepairerDispatcher<EOT> repare( indexes1, rep1 );
|
||||||
|
repare.add( indexes2, rep2 );
|
||||||
|
|
||||||
|
repare(sol);
|
||||||
|
|
||||||
|
std::cout << sol << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -35,16 +35,11 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
#include <utils/compatibility.h>
|
#include <utils/compatibility.h>
|
||||||
|
|
||||||
#include <utils/eoParser.h>
|
#include <utils/eoParser.h>
|
||||||
|
#include <utils/eoLogger.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void eoWarning(std::string str)
|
|
||||||
{
|
|
||||||
cout << str << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream& printSectionHeader(std::ostream& os, std::string section)
|
std::ostream& printSectionHeader(std::ostream& os, std::string section)
|
||||||
{
|
{
|
||||||
if (section == "")
|
if (section == "")
|
||||||
|
|
@ -117,6 +112,11 @@ eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string eoParser::get( const std::string & name) const
|
||||||
|
{
|
||||||
|
return getParamWithLongName( name )->getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
eoParam * eoParser::getParamWithLongName(const std::string& _name) const
|
eoParam * eoParser::getParamWithLongName(const std::string& _name) const
|
||||||
{
|
{
|
||||||
|
|
@ -130,7 +130,6 @@ eoParam * eoParser::getParamWithLongName(const std::string& _name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void eoParser::processParam(eoParam& param, std::string section)
|
void eoParser::processParam(eoParam& param, std::string section)
|
||||||
{
|
{
|
||||||
// this param enters the parser: add the prefix to the long name
|
// this param enters the parser: add the prefix to the long name
|
||||||
|
|
@ -214,7 +213,7 @@ void eoParser::readFrom(istream& is)
|
||||||
{
|
{
|
||||||
if (str.size() < 2)
|
if (str.size() < 2)
|
||||||
{
|
{
|
||||||
eoWarning("Missing parameter");
|
eo::log << eo::warnings << "Missing parameter" << std::endl;
|
||||||
needHelp.value() = true;
|
needHelp.value() = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,11 @@ private :
|
||||||
This class is persistent, so it can be stored and reloaded to restore
|
This class is persistent, so it can be stored and reloaded to restore
|
||||||
parameter settings.
|
parameter settings.
|
||||||
|
|
||||||
|
Parameters can be read from argv, strings or streams, and must be specified
|
||||||
|
using the following convention: --name=value or -n=value
|
||||||
|
|
||||||
|
You should not use space as a separator between the parameter and its value.
|
||||||
|
|
||||||
@ingroup Parameters
|
@ingroup Parameters
|
||||||
*/
|
*/
|
||||||
class eoParser : public eoParameterLoader, public eoObject, public eoPersistent
|
class eoParser : public eoParameterLoader, public eoObject, public eoPersistent
|
||||||
|
|
@ -156,6 +161,10 @@ public:
|
||||||
virtual bool isItThere(eoParam& _param) const
|
virtual bool isItThere(eoParam& _param) const
|
||||||
{ return getValue(_param).first; }
|
{ return getValue(_param).first; }
|
||||||
|
|
||||||
|
|
||||||
|
std::string get( const std::string & name) const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a handle on a param from its longName
|
* get a handle on a param from its longName
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Reference in a new issue