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

View file

@ -39,12 +39,11 @@
#ifndef _MOEOEXHAUSTIVEUNVISITEDSELECT_H
#define _MOEOEXHAUSTIVEUNVISITEDSELECT_H
#include <eo>
#include <moeo>
#include <eoPop.h>
#include <moeoUnvisitedSelect.h>
/**
* TODO
* Selector which select all unvisited individuals of a population
*/
template < class MOEOT >
class moeoExhaustiveUnvisitedSelect : public moeoUnvisitedSelect < MOEOT >
@ -52,8 +51,16 @@ class moeoExhaustiveUnvisitedSelect : public moeoUnvisitedSelect < MOEOT >
public:
/**
* Default ctor
*/
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> res;

View file

@ -39,12 +39,11 @@
#ifndef _MOEONUMBERUNVISITEDSELECT_H
#define _MOEONUMBERUNVISITEDSELECT_H
#include <eo>
#include <moeo>
#include <eoPop.h>
#include <moeoUnvisitedSelect.h>
/**
* TODO
* Selector which select a part of unvisited individuals of a population
*/
template < class MOEOT >
class moeoNumberUnvisitedSelect : public moeoUnvisitedSelect < MOEOT >
@ -52,8 +51,17 @@ class moeoNumberUnvisitedSelect : public moeoUnvisitedSelect < MOEOT >
public:
/**
* Ctor
* @param _number the number of individuals to select
*/
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> res;
@ -72,6 +80,7 @@ public:
}
private:
/** number of individuals to select */
unsigned int number;
};

View file

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

View file

@ -39,16 +39,18 @@
#ifndef _MOEOPOPNEIGHBORHOODEXPLORER_H
#define _MOEOPOPNEIGHBORHOODEXPLORER_H
#include <eo>
#include <moeo>
#include <eoPop.h>
/**
* TODO
* Abstract class for multi-objective local search neighborhood exploration
*/
template < class Move >
class moeoPopNeighborhoodExplorer{
public:
/**
* abstract functor which realise exploration
*/
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
#define _MOEOSUBNEIGHBORHOODEXPLORER_H
#include <eo>
#include <moeo>
#include <eoPop.h>
#include <moMove.h>
#include <moMoveInit.h>
#include <moNextMove.h>
@ -48,16 +47,25 @@
#include <moeoPopNeighborhoodExplorer.h>
/**
* TODO
* Explorer which explore a part of the neighborhood
*/
template < class Move >
class moeoSubNeighborhoodExplorer : public moeoPopNeighborhoodExplorer < Move >
{
/** Alias for the type */
typedef typename Move::EOType MOEOT;
/** Alias for the objeciveVector */
typedef typename MOEOT::ObjectiveVector ObjectiveVector;
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(
moMoveInit < Move > & _moveInit,
moNextMove < Move > & _nextMove,
@ -65,45 +73,58 @@ public:
unsigned int _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)
{
if(number > 0){
for(unsigned int i=0; i<_select.size(); i++)
explore(_src, _select[i], _dest);
explore(_src[_select[i]], _dest);
}
}
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;
moveInit(move, _src[_i]);
moveInit(move, _src);
do
{
objVec = incrEval(move, _src[_i]);
_dest.push_back(_src[_i]);
objVec = incrEval(move, _src);
_dest.push_back(_src);
move(_dest.back());
_dest.back().objectiveVector(objVec);
_dest.back().flag(0);
tmp--;
}
while (nextMove(move, _src[_i]) && (tmp > 0));
if(!nextMove(move, _src[_i]))
_src[_i].flag(1);
while (nextMove(move, _src) && (tmp > 0));
if(!nextMove(move, _src))
_src.flag(1);
}
/** Move */
Move move;
/** ObjectiveVector */
ObjectiveVector objVec;
/** the move initializer */
moMoveInit < Move > & moveInit;
/** the neighborhood explorer */
/** the entity which allow to do a move */
moNextMove < Move > & nextMove;
/** the incremental evaluation */
moMoveIncrEval < Move, ObjectiveVector > & incrEval;
/** number of neighbor to explore for each solution*/
/** number of neighbor to explore for each selected individual*/
unsigned int number;
};
#endif /*_MOEOEXHAUSTIVENEIGHBORHOODEXPLORER_H_*/
#endif /*_MOEOSUBNEIGHBORHOODEXPLORER_H_*/

View file

@ -39,20 +39,34 @@
#ifndef _MOEOUNIFIEDDOMINANCEBASEDLS_H
#define _MOEOUNIFIEDDOMINANCEBASEDLS_H
#include <eo>
#include <moeo>
#include <eoPop.h>
#include <eoContinue.h>
#include <eoEvalFunc.h>
#include <eoPopEvalFunc.h>
#include <archive/moeoArchive.h>
#include <moeoPopLS.h>
#include <moeoPopNeighborhoodExplorer.h>
#include <moeoUnvisitedSelect.h>
/**
* A class to design dominance based local searches
*/
template < class Move >
class moeoUnifiedDominanceBasedLS : public moeoPopLS < Move >
{
public:
/** Alias for the type */
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(
eoContinue < MOEOT > & _continuator,
eoEvalFunc < MOEOT > & _eval,
@ -61,7 +75,6 @@ public:
moeoUnvisitedSelect < MOEOT > & _select) :
continuator(_continuator), loopEval(_eval), popEval(loopEval), archive(_archive), explorer(_explorer), select(_select) {}
/**
* Applies a few generation of evolution to the population _pop.
* @param _pop the population
@ -74,36 +87,48 @@ public:
archive(_pop);
do{
tmp_pop.resize(0);
//selection des individus non visités à explorer
//selection
selectionVector = select(archive);
//exploration
//explorer(archive, selectionVector, tmp_pop);
explorer(archive, selectionVector, tmp_pop);
//mise à jour de la pop ou archive
//archivage
archive(tmp_pop);
}
while (continuator(archive) && naturalContinuator(archive));
// std::cout << "Final archive\n";
// archive.sortedPrintOn(std::cout);
// std::cout << std::endl;
}
protected:
/** continuator */
eoContinue < MOEOT > & continuator;
/** loopEval */
eoPopLoopEval < MOEOT > loopEval;
/** popEval */
eoPopEvalFunc < MOEOT > & popEval;
/** archive */
moeoArchive < MOEOT > & archive;
/** explorer */
moeoPopNeighborhoodExplorer < Move > & explorer;
/** selector */
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:
/**
* Ctor
*/
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)
{
bool res = false;

View file

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