git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1560 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
jhumeau 2009-03-18 14:15:11 +00:00
commit 1d61b834d6
8 changed files with 132 additions and 51 deletions

View file

@ -39,8 +39,7 @@
#ifndef _MOEOEXHAUSTIVENEIGHBORHOODEXPLORER_H #ifndef _MOEOEXHAUSTIVENEIGHBORHOODEXPLORER_H
#define _MOEOEXHAUSTIVENEIGHBORHOODEXPLORER_H #define _MOEOEXHAUSTIVENEIGHBORHOODEXPLORER_H
#include <eo> #include <eoPop.h>
#include <moeo>
#include <moMove.h> #include <moMove.h>
#include <moMoveInit.h> #include <moMoveInit.h>
#include <moNextMove.h> #include <moNextMove.h>
@ -48,51 +47,71 @@
#include <moeoPopNeighborhoodExplorer.h> #include <moeoPopNeighborhoodExplorer.h>
/** /**
* TODO * Explorer which explore all the neighborhood
*/ */
template < class Move > template < class Move >
class moeoExhaustiveNeighborhoodExplorer : public moeoPopNeighborhoodExplorer < Move > class moeoExhaustiveNeighborhoodExplorer : public moeoPopNeighborhoodExplorer < Move >
{ {
/** Alias for the type */
typedef typename Move::EOType MOEOT; typedef typename Move::EOType MOEOT;
/** Alias for the objeciveVector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
public: public:
/**
* Ctor
* @param _moveInit the move initializer
* @param _nextMove allow to do or not a move
* @param _incrEval a (generally) efficient evaluation fonction
*/
moeoExhaustiveNeighborhoodExplorer( moeoExhaustiveNeighborhoodExplorer(
moMoveInit < Move > & _moveInit, moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove, moNextMove < Move > & _nextMove,
moMoveIncrEval < Move, ObjectiveVector > & _incrEval) moMoveIncrEval < Move, ObjectiveVector > & _incrEval)
: moveInit(_moveInit), nextMove(_nextMove), incrEval(_incrEval){} : moveInit(_moveInit), nextMove(_nextMove), incrEval(_incrEval){}
/**
* functor to explore the neighborhood
* @param _src the population to explore
* @param _select contains index of individuals from the population to explore
* @param _dest contains new generated individuals
*/
void operator()(eoPop < MOEOT > & _src, std::vector < unsigned int> _select, eoPop < MOEOT > & _dest) void operator()(eoPop < MOEOT > & _src, std::vector < unsigned int> _select, eoPop < MOEOT > & _dest)
{ {
for(unsigned int i=0; i<_select.size(); i++) for(unsigned int i=0; i<_select.size(); i++)
explore(_src, _select[i], _dest); explore(_src[_select[i]], _dest);
} }
private: private:
void explore(eoPop < MOEOT > & _src, unsigned int _i, eoPop < MOEOT > & _dest) /**
* explorer of one individual
* @param _src the individual to explore
* @param _dest contains new generated individuals
*/
void explore(MOEOT & _src , eoPop < MOEOT > & _dest)
{ {
moveInit(move, _src[_i]); moveInit(move, _src);
do do
{ {
objVec = incrEval(move, _src[_i]); objVec = incrEval(move, _src);
_dest.push_back(_src[_i]); _dest.push_back(_src);
move(_dest.back()); move(_dest.back());
_dest.back().objectiveVector(objVec); _dest.back().objectiveVector(objVec);
_dest.back().flag(0); _dest.back().flag(0);
} }
while (nextMove(move, _src[_i])); while (nextMove(move, _src));
_src[_i].flag(1); _src.flag(1);
} }
/** Move */ /** Move */
Move move; Move move;
/** ObjectiveVector */ /** ObjectiveVector */
ObjectiveVector objVec; ObjectiveVector objVec;
/** the move initializer */ /** the move initializer */
moMoveInit < Move > & moveInit; moMoveInit < Move > & moveInit;
/** the neighborhood explorer */ /** the entity which allow to do a move */
moNextMove < Move > & nextMove; moNextMove < Move > & nextMove;
/** the incremental evaluation */ /** the incremental evaluation */
moMoveIncrEval < Move, ObjectiveVector > & incrEval; moMoveIncrEval < Move, ObjectiveVector > & incrEval;

View file

@ -39,12 +39,11 @@
#ifndef _MOEOEXHAUSTIVEUNVISITEDSELECT_H #ifndef _MOEOEXHAUSTIVEUNVISITEDSELECT_H
#define _MOEOEXHAUSTIVEUNVISITEDSELECT_H #define _MOEOEXHAUSTIVEUNVISITEDSELECT_H
#include <eo> #include <eoPop.h>
#include <moeo>
#include <moeoUnvisitedSelect.h> #include <moeoUnvisitedSelect.h>
/** /**
* TODO * Selector which select all unvisited individuals of a population
*/ */
template < class MOEOT > template < class MOEOT >
class moeoExhaustiveUnvisitedSelect : public moeoUnvisitedSelect < MOEOT > class moeoExhaustiveUnvisitedSelect : public moeoUnvisitedSelect < MOEOT >
@ -52,8 +51,16 @@ class moeoExhaustiveUnvisitedSelect : public moeoUnvisitedSelect < MOEOT >
public: public:
/**
* Default ctor
*/
moeoExhaustiveUnvisitedSelect(){} moeoExhaustiveUnvisitedSelect(){}
/**
* functor which return index of selected individuals of a population
* @param _src the population
* @return the vector contains index of all unvisited individuals of the population
*/
std::vector <unsigned int> operator()(eoPop < MOEOT > & _src) std::vector <unsigned int> operator()(eoPop < MOEOT > & _src)
{ {
std::vector <unsigned int> res; std::vector <unsigned int> res;

View file

@ -39,12 +39,11 @@
#ifndef _MOEONUMBERUNVISITEDSELECT_H #ifndef _MOEONUMBERUNVISITEDSELECT_H
#define _MOEONUMBERUNVISITEDSELECT_H #define _MOEONUMBERUNVISITEDSELECT_H
#include <eo> #include <eoPop.h>
#include <moeo>
#include <moeoUnvisitedSelect.h> #include <moeoUnvisitedSelect.h>
/** /**
* TODO * Selector which select a part of unvisited individuals of a population
*/ */
template < class MOEOT > template < class MOEOT >
class moeoNumberUnvisitedSelect : public moeoUnvisitedSelect < MOEOT > class moeoNumberUnvisitedSelect : public moeoUnvisitedSelect < MOEOT >
@ -52,8 +51,17 @@ class moeoNumberUnvisitedSelect : public moeoUnvisitedSelect < MOEOT >
public: public:
/**
* Ctor
* @param _number the number of individuals to select
*/
moeoNumberUnvisitedSelect(unsigned int _number): number(_number){} moeoNumberUnvisitedSelect(unsigned int _number): number(_number){}
/**
* functor which return index of selected individuals of a population
* @param _src the population
* @return the vector contains index of the part of unvisited individuals of the population
*/
std::vector <unsigned int> operator()(eoPop < MOEOT > & _src) std::vector <unsigned int> operator()(eoPop < MOEOT > & _src)
{ {
std::vector <unsigned int> res; std::vector <unsigned int> res;
@ -72,6 +80,7 @@ public:
} }
private: private:
/** number of individuals to select */
unsigned int number; unsigned int number;
}; };

View file

@ -45,7 +45,6 @@
* Abstract class for Population based multi-objective local search. * Abstract class for Population based multi-objective local search.
*/ */
template < class Move > template < class Move >
class moeoPopLS : public moeoPopAlgo < typename Move::EOType > class moeoPopLS : public moeoPopAlgo < typename Move::EOType > {};
{};
#endif /*MOEOPOPLS_H_*/ #endif /*MOEOPOPLS_H_*/

View file

@ -39,16 +39,18 @@
#ifndef _MOEOPOPNEIGHBORHOODEXPLORER_H #ifndef _MOEOPOPNEIGHBORHOODEXPLORER_H
#define _MOEOPOPNEIGHBORHOODEXPLORER_H #define _MOEOPOPNEIGHBORHOODEXPLORER_H
#include <eo> #include <eoPop.h>
#include <moeo>
/** /**
* TODO * Abstract class for multi-objective local search neighborhood exploration
*/ */
template < class Move > template < class Move >
class moeoPopNeighborhoodExplorer{ class moeoPopNeighborhoodExplorer{
public: public:
/**
* abstract functor which realise exploration
*/
virtual void operator()(eoPop < typename Move::EOType > &, std::vector <unsigned int>, eoPop < typename Move::EOType > &) = 0; virtual void operator()(eoPop < typename Move::EOType > &, std::vector <unsigned int>, eoPop < typename Move::EOType > &) = 0;
}; };

View file

@ -39,8 +39,7 @@
#ifndef _MOEOSUBNEIGHBORHOODEXPLORER_H #ifndef _MOEOSUBNEIGHBORHOODEXPLORER_H
#define _MOEOSUBNEIGHBORHOODEXPLORER_H #define _MOEOSUBNEIGHBORHOODEXPLORER_H
#include <eo> #include <eoPop.h>
#include <moeo>
#include <moMove.h> #include <moMove.h>
#include <moMoveInit.h> #include <moMoveInit.h>
#include <moNextMove.h> #include <moNextMove.h>
@ -48,16 +47,25 @@
#include <moeoPopNeighborhoodExplorer.h> #include <moeoPopNeighborhoodExplorer.h>
/** /**
* TODO * Explorer which explore a part of the neighborhood
*/ */
template < class Move > template < class Move >
class moeoSubNeighborhoodExplorer : public moeoPopNeighborhoodExplorer < Move > class moeoSubNeighborhoodExplorer : public moeoPopNeighborhoodExplorer < Move >
{ {
/** Alias for the type */
typedef typename Move::EOType MOEOT; typedef typename Move::EOType MOEOT;
/** Alias for the objeciveVector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector; typedef typename MOEOT::ObjectiveVector ObjectiveVector;
public: public:
/**
* Ctor
* @param _moveInit the move initializer
* @param _nextMove allow to do or not a move
* @param _incrEval a (generally) efficient evaluation fonction
* @param _number the number of neighbor to explore
*/
moeoSubNeighborhoodExplorer( moeoSubNeighborhoodExplorer(
moMoveInit < Move > & _moveInit, moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove, moNextMove < Move > & _nextMove,
@ -65,45 +73,58 @@ public:
unsigned int _number) unsigned int _number)
: moveInit(_moveInit), nextMove(_nextMove), incrEval(_incrEval), number(_number){} : moveInit(_moveInit), nextMove(_nextMove), incrEval(_incrEval), number(_number){}
/**
* functor to explore the neighborhood
* @param _src the population to explore
* @param _select contains index of individuals from the population to explore
* @param _dest contains new generated individuals
*/
void operator()(eoPop < MOEOT > & _src, std::vector <unsigned int> _select, eoPop < MOEOT > & _dest) void operator()(eoPop < MOEOT > & _src, std::vector <unsigned int> _select, eoPop < MOEOT > & _dest)
{ {
if(number > 0){ if(number > 0){
for(unsigned int i=0; i<_select.size(); i++) for(unsigned int i=0; i<_select.size(); i++)
explore(_src, _select[i], _dest); explore(_src[_select[i]], _dest);
} }
} }
private: private:
void explore(eoPop < MOEOT > & _src, unsigned int _i, eoPop < MOEOT > & _dest) /**
* explorer of one individual
* @param _src the individual to explore
* @param _dest contains new generated individuals
*/
void explore(MOEOT & _src, eoPop < MOEOT > & _dest)
{ {
unsigned int tmp = number; unsigned int tmp = number;
moveInit(move, _src[_i]); moveInit(move, _src);
do do
{ {
objVec = incrEval(move, _src[_i]); objVec = incrEval(move, _src);
_dest.push_back(_src[_i]); _dest.push_back(_src);
move(_dest.back()); move(_dest.back());
_dest.back().objectiveVector(objVec); _dest.back().objectiveVector(objVec);
_dest.back().flag(0); _dest.back().flag(0);
tmp--; tmp--;
} }
while (nextMove(move, _src[_i]) && (tmp > 0)); while (nextMove(move, _src) && (tmp > 0));
if(!nextMove(move, _src[_i])) if(!nextMove(move, _src))
_src[_i].flag(1); _src.flag(1);
} }
/** Move */ /** Move */
Move move; Move move;
/** ObjectiveVector */ /** ObjectiveVector */
ObjectiveVector objVec; ObjectiveVector objVec;
/** the move initializer */ /** the move initializer */
moMoveInit < Move > & moveInit; moMoveInit < Move > & moveInit;
/** the neighborhood explorer */ /** the entity which allow to do a move */
moNextMove < Move > & nextMove; moNextMove < Move > & nextMove;
/** the incremental evaluation */ /** the incremental evaluation */
moMoveIncrEval < Move, ObjectiveVector > & incrEval; moMoveIncrEval < Move, ObjectiveVector > & incrEval;
/** number of neighbor to explore for each solution*/ /** number of neighbor to explore for each selected individual*/
unsigned int number; unsigned int number;
}; };
#endif /*_MOEOEXHAUSTIVENEIGHBORHOODEXPLORER_H_*/ #endif /*_MOEOSUBNEIGHBORHOODEXPLORER_H_*/

View file

@ -39,20 +39,34 @@
#ifndef _MOEOUNIFIEDDOMINANCEBASEDLS_H #ifndef _MOEOUNIFIEDDOMINANCEBASEDLS_H
#define _MOEOUNIFIEDDOMINANCEBASEDLS_H #define _MOEOUNIFIEDDOMINANCEBASEDLS_H
#include <eo> #include <eoPop.h>
#include <moeo> #include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoPopEvalFunc.h>
#include <archive/moeoArchive.h>
#include <moeoPopLS.h> #include <moeoPopLS.h>
#include <moeoPopNeighborhoodExplorer.h> #include <moeoPopNeighborhoodExplorer.h>
#include <moeoUnvisitedSelect.h> #include <moeoUnvisitedSelect.h>
/**
* A class to design dominance based local searches
*/
template < class Move > template < class Move >
class moeoUnifiedDominanceBasedLS : public moeoPopLS < Move > class moeoUnifiedDominanceBasedLS : public moeoPopLS < Move >
{ {
public: public:
/** Alias for the type */
typedef typename Move::EOType MOEOT; typedef typename Move::EOType MOEOT;
/**
* Ctor
* @param _continuator a stop creterion
* @param _eval a evaluation function
* @param _archive a archive to store no-dominated individuals
* @param _explorer a neighborhood explorer
* @param _select a selector of unvisited individuals of a population
*/
moeoUnifiedDominanceBasedLS( moeoUnifiedDominanceBasedLS(
eoContinue < MOEOT > & _continuator, eoContinue < MOEOT > & _continuator,
eoEvalFunc < MOEOT > & _eval, eoEvalFunc < MOEOT > & _eval,
@ -61,7 +75,6 @@ public:
moeoUnvisitedSelect < MOEOT > & _select) : moeoUnvisitedSelect < MOEOT > & _select) :
continuator(_continuator), loopEval(_eval), popEval(loopEval), archive(_archive), explorer(_explorer), select(_select) {} continuator(_continuator), loopEval(_eval), popEval(loopEval), archive(_archive), explorer(_explorer), select(_select) {}
/** /**
* Applies a few generation of evolution to the population _pop. * Applies a few generation of evolution to the population _pop.
* @param _pop the population * @param _pop the population
@ -74,36 +87,48 @@ public:
archive(_pop); archive(_pop);
do{ do{
tmp_pop.resize(0); tmp_pop.resize(0);
//selection des individus non visités à explorer //selection
selectionVector = select(archive); selectionVector = select(archive);
//exploration //exploration
//explorer(archive, selectionVector, tmp_pop);
explorer(archive, selectionVector, tmp_pop); explorer(archive, selectionVector, tmp_pop);
//mise à jour de la pop ou archive //archivage
archive(tmp_pop); archive(tmp_pop);
} }
while (continuator(archive) && naturalContinuator(archive)); while (continuator(archive) && naturalContinuator(archive));
// std::cout << "Final archive\n";
// archive.sortedPrintOn(std::cout);
// std::cout << std::endl;
} }
protected: protected:
/** continuator */
eoContinue < MOEOT > & continuator; eoContinue < MOEOT > & continuator;
/** loopEval */
eoPopLoopEval < MOEOT > loopEval; eoPopLoopEval < MOEOT > loopEval;
/** popEval */
eoPopEvalFunc < MOEOT > & popEval; eoPopEvalFunc < MOEOT > & popEval;
/** archive */
moeoArchive < MOEOT > & archive; moeoArchive < MOEOT > & archive;
/** explorer */
moeoPopNeighborhoodExplorer < Move > & explorer; moeoPopNeighborhoodExplorer < Move > & explorer;
/** selector */
moeoUnvisitedSelect < MOEOT > & select; moeoUnvisitedSelect < MOEOT > & select;
class moeoContinue : public eoUF < eoPop < MOEOT > &, bool > /**
* Natural Continuator (Stop when all individuals of the population are visited)
*/
class moeoContinue : public eoUF < eoPop < MOEOT > &, bool >
{ {
public: public:
/**
* Ctor
*/
moeoContinue(){} moeoContinue(){}
/**
* functor which evaluate if the algorithm continue or not
* @param _pop the population
* @return true if the algorithm continue, else return false
*/
virtual bool operator()(eoPop < MOEOT > & _pop) virtual bool operator()(eoPop < MOEOT > & _pop)
{ {
bool res = false; bool res = false;

View file

@ -39,11 +39,10 @@
#ifndef _MOEOUNVISITEDSELECT_H #ifndef _MOEOUNVISITEDSELECT_H
#define _MOEOUNVISITEDSELECT_H #define _MOEOUNVISITEDSELECT_H
#include <eo> #include <eoPop.h>
#include <moeo>
/** /**
* TODO * Abstract Selector
*/ */
template < class MOEOT > template < class MOEOT >
class moeoUnvisitedSelect: public eoUF < eoPop < MOEOT > &, std::vector< unsigned int > >{}; class moeoUnvisitedSelect: public eoUF < eoPop < MOEOT > &, std::vector< unsigned int > >{};