Essai du nouveau "modele"

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1655 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-01-20 09:43:06 +00:00
commit c3085595bf
13 changed files with 85 additions and 98 deletions

View file

@ -22,7 +22,7 @@ public:
* @return true if the neighbor1 is better than neighbor2
*/
virtual bool operator()(const Neighbor& _neighbor1, const Neighbor& _neighbor2) {
return (neighbor1.fitness() > neighbor2.fitness());
return (_neighbor1.fitness() > _neighbor2.fitness());
}
/**

View file

@ -4,11 +4,8 @@
#include <neighborhood/moBitNeighbor.h>
#include <ga.h>
/**
* contener of the neighbor information
*/
template< class Fitness >
class moFullEvalBitNeighbor : public moBitNeighbor<Fitness>
class moFullEvalBitNeighbor : public moFullEvalByModif<moBitNeighbor<Fitness> >
{
public:
typedef eoBit<Fitness> EOType ;

View file

@ -2,7 +2,7 @@
#define moFullEvalByModif_H
#include <eoEvalFunc.h>
#include <moEval.h>
#include <eval/moEval.h>
/**
* Full evaluation to use with a moBackableNeighbor
@ -11,14 +11,14 @@ template<class BackableNeighbor>
class moFullEvalByModif : public moEval<BackableNeighbor>
{
public:
using moEval<BackableNeighbor>::EOT EOT;
using moEval<BackableNeighbor>::Fitness Fitness;
typedef typename moEval<BackableNeighbor>::EOT EOT;
typedef typename moEval<BackableNeighbor>::Fitness Fitness;
/**
* Ctor
* @param _eval the full evaluation object
*/
moFullEvalByCopy(eoEvalFunc<EOT> & _eval) : eval(_eval) {}
moFullEvalByModif(eoEvalFunc<EOT>& _eval) : eval(_eval) {}
/**
* Full evaluation of the neighbor by copy
@ -44,6 +44,7 @@ public:
_neighbor.moveBack(_sol);
// set the fitness back
_sol.fitness(tmpFit);
}

View file

@ -5,6 +5,7 @@
#include <eoFunctor.h>
#include <neighborhood/moNeighborhood.h>
#include <eval/moEval.h>
/**
* Explore the neighborhood
@ -22,7 +23,7 @@ public:
* @param _neighborhood the neighborhood
* @param _eval the evaluation function
*/
moNeighborhoodExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval):neighborhood(_neighborhood), eval(_eval) {}
moNeighborhoodExplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _comparator):neighborhood(_neighborhood), eval(_eval), comparator(_comparator) {}
/**
* Init Search parameters
@ -73,7 +74,7 @@ public:
protected:
Neighborhood & neighborhood;
moEval<Neighbor>& eval;
moNeighborComparator<Neighbor>& comparator;
};
#endif

View file

@ -3,17 +3,22 @@
#include <explorer/moNeighborhoodExplorer.h>
template< class NH >
class moSimpleHCexplorer : public moNeighborhoodExplorer<NH>
template< class Neighborhood >
class moSimpleHCexplorer : public moNeighborhoodExplorer<Neighborhood>
{
public:
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
using moNeighborhoodExplorer<Neighborhood>::neighborhood;
using moNeighborhoodExplorer<Neighborhood>::eval;
using moNeighborhoodExplorer<Neighborhood>::comparator;
// empty constructor
moSimpleHCexplorer(Neighborhood & __neighborhood) : neighborhood(__neighborhood){
isAccept = false;
moSimpleHCexplorer(Neighborhood& _neighborhood, moEval<Neighbor>& _eval, moNeighborComparator<Neighbor>& _comparator) : moNeighborhoodExplorer<Neighborhood>(_neighborhood, _eval, _comparator){
isAccept = false;
current=new Neighbor();
best=new Neighbor();
}
virtual void initParam (EOT & solution) { } ;
@ -24,52 +29,51 @@ public:
virtual void operator() (EOT & solution) {
//est qu'on peut initializer
if(neighborhood.hasNeighbor(solution)){
neighborhood.init(solution, *current);
(*current).eval(solution);
best = &current;
//est qu'on peut initializer
while (neighborhood.cont(solution)) {
neighborhood.next(solution, *current);
if(neighborhood.hasNeighbor(solution)){
neighborhood.init(solution, (*current));
(*current).eval(solution);
if (current.betterThan(best)) {
best = &current;
eval(solution, (*current));
std::cout <<"sol et neighbor:"<< solution << ", "<< (*current) << std::endl;
(*best) = (*current);
while (neighborhood.cont(solution)) {
neighborhood.next(solution, (*current));
eval(solution, (*current));
std::cout <<"sol et neighbor:"<< solution << ", "<< (*current) << std::endl;
if (comparator((*current), (*best))) {
(*best) = (*current);
}
}
}
else{
isAccept=false;
}
}
}
else{
isAccept=false;
}
};
virtual bool isContinue(EOT & solution) {
return isAccept ;
return isAccept ;
};
virtual void move(EOT & solution) {
best.move(solution);
(*best).move(solution);
solution.fitness(best.fitness());
solution.fitness((*best).fitness());
};
virtual bool accept(EOT & solution) {
if(neighborhood.hasNeighbor(solution)){
isAccept = (solution.fitness() < best.fitness()) ;
}
return isAccept;
if(neighborhood.hasNeighbor(solution)){
isAccept = (solution.fitness() < (*best).fitness()) ;
}
return isAccept;
};
private:
Neighborhood & neighborhood;
// attention il faut que le constructeur vide existe
Neighbor* best;
@ -82,12 +86,3 @@ private:
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -5,7 +5,7 @@
* Neighbor with a move back function to use in a moFullEvalByModif
*/
template< class EOT , class Fitness >
class moBackableNeighbor : moNeighbor<EOT, Fitness>
class moBackableNeighbor : public moNeighbor<EOT, Fitness>
{
public:
@ -13,7 +13,7 @@ public:
* the move back function
* @param _solution the solution to moveBack
*/
virtual moveBack(EOT & _solution) = 0;
virtual void moveBack(EOT & _solution){}
};

View file

@ -2,24 +2,25 @@
#define _bitNeighbor_h
#include <ga/eoBit.h>
#include <neighborhood/moNeighbor.h>
#include <neighborhood/moBackableNeighbor.h>
/*
contener of the neighbor information
*/
template< class Fitness >
class moBitNeighbor : public moNeighbor< eoBit<Fitness> , Fitness>
class moBitNeighbor : public moBackableNeighbor<eoBit<Fitness>, Fitness>
{
public:
typedef eoBit<Fitness> EOType ;
using moNeighbor< eoBit<Fitness> , Fitness>::fitness;
using moNeighbor<eoBit<Fitness>, Fitness>::fitness;
// describe the neighbor
unsigned bit ;
// empty constructor needed
moBitNeighbor() : moNeighbor<eoBit<Fitness> , Fitness>() { } ;
moBitNeighbor() : moBackableNeighbor<eoBit<Fitness> , Fitness>() { } ;
// copy constructor
moBitNeighbor(const moBitNeighbor & n) : moNeighbor<eoBit<Fitness> , Fitness>(n) {
@ -43,7 +44,11 @@ public:
move the solution
*/
virtual void move(EOType & solution) {
solution[bit] = solution[bit]?false:true ;
solution[bit] = !solution[bit];
}
virtual void moveBack(EOType & solution) {
solution[bit] = !solution[bit];
}
// by default: if the fitness of the current solution is stricly higher than the other neighbor

View file

@ -22,18 +22,18 @@ public:
initialisation of the neighborhood
*/
virtual void init(EOT & solution, Neighbor & _neighbor) {
currentBit = 0 ;
currentBit = 0 ;
_neighbor.bit = currentBit ;
_neighbor.bit = currentBit ;
}
/*
Give the next neighbor
*/
virtual void next(EOT & solution, Neighbor & neighbor) {
currentBit++ ;
currentBit++ ;
neighbor.bit = currentBit ;
neighbor.bit = currentBit ;
}
/*
@ -50,11 +50,3 @@ private:
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -61,7 +61,7 @@ public:
* Copy Constructor
* @param _neighbor to copy
*/
moNeighbor(const moNeighbor<EOType, Fitness>& _neighbor) {
moNeighbor(const moNeighbor<EOT, Fitness>& _neighbor) {
repFitness = _neighbor.fitness();
}
@ -131,7 +131,7 @@ public:
_os << repFitness << ' ' ;
}
private:
protected:
// minimal information on the neighbor : fitness
Fitness repFitness ;