Perturb and acceptCrit added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1728 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
6bb2a4a822
commit
c2771d8a3a
10 changed files with 690 additions and 8 deletions
|
|
@ -30,5 +30,34 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#ifndef _moBetterAcceptCrit_h
|
||||
#define _moBetterAcceptCrit_h
|
||||
|
||||
#include <acceptCrit/moAcceptanceCriterion.h>
|
||||
#include <memory/moDummyMemory.h>
|
||||
#include <comparator/moSolComparator.h>
|
||||
|
||||
/**
|
||||
* Acceptance Criterion for extreme intensification : accept if the new solution is better than previous one
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moBetterAcceptCrit : public moAcceptanceCriterion<Neighbor>, public moDummyMemory<Neighbor>{
|
||||
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
moBetterAcceptCrit(moSolComparator<EOT>& _comparator):comparator(_comparator){}
|
||||
|
||||
/**
|
||||
* Accept if the new solution is better than previous one
|
||||
* @param _sol1 the previous solution
|
||||
* @param _sol2 the new solution after local search
|
||||
* @return true if the new solution is better than previous one
|
||||
*/
|
||||
bool operator()(EOT& _sol1, EOT& _sol2){
|
||||
return comparator(_sol1, _sol2);
|
||||
}
|
||||
|
||||
private:
|
||||
moSolComparator<EOT>& comparator;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -35,13 +35,9 @@
|
|||
#ifndef _moNeighborComparator_h
|
||||
#define _moNeighborComparator_h
|
||||
|
||||
#include <EO.h>
|
||||
#include <eoFunctor.h>
|
||||
|
||||
#include <neighborhood/moNeighbor.h>
|
||||
#include <comparator/moComparator.h>
|
||||
|
||||
|
||||
/**
|
||||
* Comparator of two neighbors
|
||||
*/
|
||||
|
|
|
|||
72
trunk/paradiseo-mo/src/comparator/moSolComparator.h
Normal file
72
trunk/paradiseo-mo/src/comparator/moSolComparator.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
<moSolComparator.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can ue,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef _moSolComparator_h
|
||||
#define _moSolComparator_h
|
||||
|
||||
#include <comparator/moComparator.h>
|
||||
|
||||
/**
|
||||
* Comparator of two solutions
|
||||
*/
|
||||
template< class EOT >
|
||||
class moSolComparator : public moComparator<EOT, EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Compare two solutions
|
||||
* @param _sol1 the first solution
|
||||
* @param _sol2 the second solution
|
||||
* @return true if the solution2 is better than solution1
|
||||
*/
|
||||
virtual bool operator()(const EOT& _sol1, const EOT& _sol2) {
|
||||
return (_sol1.fitness() < _sol2.fitness());
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two solutions
|
||||
* @param _sol1 the first solution
|
||||
* @param _sol2 the second solution
|
||||
* @return true if the solution2 is equal to solution1
|
||||
*/
|
||||
virtual bool equals(const EOT& _sol1, const EOT& _sol2) {
|
||||
return (_sol1.fitness() == _sol2.fitness());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moSolComparator";
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
119
trunk/paradiseo-mo/src/memory/moCountMoveMemory.h
Normal file
119
trunk/paradiseo-mo/src/memory/moCountMoveMemory.h
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
<moCountMoveMemory.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can ue,
|
||||
modify and/ or redistribute the software under the terms of the CeCILL
|
||||
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
"http://www.cecill.info".
|
||||
|
||||
In this respect, the user's attention is drawn to the risks associated
|
||||
with loading, using, modifying and/or developing or reproducing the
|
||||
software by the user in light of its specific status of free software,
|
||||
that may mean that it is complicated to manipulate, and that also
|
||||
therefore means that it is reserved for developers and experienced
|
||||
professionals having in-depth computer knowledge. Users are therefore
|
||||
encouraged to load and test the software's suitability as regards their
|
||||
requirements in conditions enabling the security of their systems and/or
|
||||
data to be ensured and, more generally, to use and operate it in the
|
||||
same conditions as regards security.
|
||||
The fact that you are presently reading this means that you have had
|
||||
knowledge of the CeCILL license and that you accept its terms.
|
||||
|
||||
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||
*/
|
||||
|
||||
#ifndef _moCountMoveMemory_h
|
||||
#define _moCountMoveMemory_h
|
||||
|
||||
#include <memory/moMemory.h>
|
||||
|
||||
/**
|
||||
* Count the number of move, noMove and the number of successive stagnation since the last Move
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moCountMoveMemory : virtual public moMemory<Neighbor>{
|
||||
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Init all the counters
|
||||
* @param _sol unused solution
|
||||
*/
|
||||
void init(EOT & _sol) {
|
||||
nbMove=0;
|
||||
nbNoMove=0;
|
||||
counter=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _sol unused solution
|
||||
* @param _neighbor unused neighbor
|
||||
*/
|
||||
void add(EOT & _sol, Neighbor & _neighbor) {
|
||||
nbMove++;
|
||||
counter=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _sol unused solution
|
||||
* @param _neighbor unused neighbor
|
||||
*/
|
||||
void update(EOT & _sol, Neighbor & _neighbor) {
|
||||
nbNoMove++;
|
||||
counter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* ClearMemory : Reinit all the counters
|
||||
*/
|
||||
void clearMemory() {
|
||||
nbMove=0;
|
||||
nbNoMove=0;
|
||||
counter=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter of the number of move
|
||||
* @return the counter
|
||||
*/
|
||||
unsigned int getNbMove(){
|
||||
return nbMove;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter of the number of no move
|
||||
* @return the counter
|
||||
*/
|
||||
unsigned int getNbNoMove(){
|
||||
return nbNoMove;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter of the number of successive stagnation since the last Move
|
||||
* @return the counter
|
||||
*/
|
||||
unsigned int getCounter(){
|
||||
return counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init counter
|
||||
*/
|
||||
void initCounter(){
|
||||
counter=0;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int nbMove;
|
||||
unsigned int nbNoMove;
|
||||
unsigned int counter;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -40,6 +40,7 @@
|
|||
#include <comparator/moComparator.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
#include <comparator/moSolComparator.h>
|
||||
|
||||
#include <continuator/moCheckpoint.h>
|
||||
#include <continuator/moContinuator.h>
|
||||
|
|
@ -86,6 +87,7 @@
|
|||
#include <memory/moMemory.h>
|
||||
#include <memory/moSolVectorTabuList.h>
|
||||
#include <memory/moTabuList.h>
|
||||
#include <memory/moCountMoveMemory.h>
|
||||
|
||||
#include <neighborhood/moBackableNeighbor.h>
|
||||
#include <neighborhood/moBitNeighbor.h>
|
||||
|
|
@ -100,9 +102,12 @@
|
|||
|
||||
#include <perturb/moPerturbation.h>
|
||||
#include <perturb/moMonOpPerturb.h>
|
||||
#include <perturb/moRestartPerturb.h>
|
||||
#include <perturb/moNeighborhoodPerturb.h>
|
||||
|
||||
#include <acceptCrit/moAcceptanceCriterion.h>
|
||||
#include <acceptCrit/moAlwaysAcceptCrit.h>
|
||||
#include <acceptCrit/moBetterAcceptCrit.h>
|
||||
|
||||
#include <coolingSchedule/moCoolingSchedule.h>
|
||||
#include <coolingSchedule/moSimpleCoolingSchedule.h>
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ public:
|
|||
/**
|
||||
* Default Constructor
|
||||
* @param _monOp an eoMonOp (pertubation operator)
|
||||
* @param _fullEval a full evaluation function
|
||||
*/
|
||||
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval):monOp(_monOp), fullEval(_fullEval){}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,5 +30,79 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#ifndef _moNeighborhoodPerturb_h
|
||||
#define _moNeighborhoodPerturb_h
|
||||
|
||||
#include <eval/moEval.h>
|
||||
#include <perturb/moPerturbation.h>
|
||||
|
||||
/**
|
||||
* Neighborhood Perturbation: explore the neighborhood to perturb the solution (the neighborhood could be different as the one used in the Local Search)
|
||||
*/
|
||||
template< class Neighbor, class OtherNH >
|
||||
class moNeighborhoodPerturb : public moPerturbation<Neighbor>{
|
||||
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
typedef typename OtherNH::Neighbor OtherN;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _otherNeighborhood a neighborhood
|
||||
* @param _eval an Evaluation Function
|
||||
*/
|
||||
moNeighborhoodPerturb(OtherNH& _otherNeighborhood, moEval<OtherN>& _eval): otherNeighborhood(_otherNeighborhood), eval(_eval){}
|
||||
|
||||
/**
|
||||
* Apply move on the solution
|
||||
* @param _solution the current solution
|
||||
* @return true
|
||||
*/
|
||||
virtual bool operator()(EOT& _solution){
|
||||
if(otherNeighborhood.hasNeighbor(_solution)){
|
||||
eval(_solution, current);
|
||||
current.move(_solution);
|
||||
_solution.fitness(current.fitness());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the neighborhood
|
||||
* @param _sol the current solution
|
||||
*/
|
||||
virtual void init(EOT & _sol){
|
||||
if(otherNeighborhood.hasNeighbor(_sol))
|
||||
otherNeighborhood.init(_sol, current);
|
||||
}
|
||||
|
||||
/**
|
||||
* ReInit the neighborhood because a move was done
|
||||
* @param _sol the current solution
|
||||
* @param _neighbor unused neighbor (always empty)
|
||||
*/
|
||||
virtual void add(EOT & _sol, Neighbor & _neighbor){
|
||||
(*this).init(_sol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Explore another neighbor because no move was done
|
||||
* @param _sol the current solution
|
||||
* @param _neighbor unused neighbor (always empty)
|
||||
*/
|
||||
virtual void update(EOT & _sol, Neighbor & _neighbor){
|
||||
if(otherNeighborhood.cont(_sol))
|
||||
otherNeighborhood.next(_sol, current);
|
||||
else
|
||||
(*this).init(_sol);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTHING TO DO
|
||||
*/
|
||||
virtual void clearMemory(){}
|
||||
|
||||
private:
|
||||
OtherNH& otherNeighborhood;
|
||||
moEval<OtherN>& eval;
|
||||
OtherN current;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -31,4 +31,47 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
|||
#define _moRestartPerturb_h
|
||||
|
||||
|
||||
#include <eoEvalFunc.h>
|
||||
#include <eoInit.h>
|
||||
#include <perturb/moPerturbation.h>
|
||||
#include <memory/moCountMoveMemory.h>
|
||||
|
||||
/**
|
||||
* Restart Perturbation : restart when maximum number of iteration with no improvement is reached
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moRestartPerturb : public moPerturbation<Neighbor>, public moCountMoveMemory<Neighbor> {
|
||||
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
* @param _init an initializer of solution
|
||||
* @param _fullEval a full evaluation function
|
||||
* @param _threshold maximum number of iteration with no improvement
|
||||
*/
|
||||
moRestartPerturb(eoInit<EOT>& _init, eoEvalFunc<EOT>& _fullEval, unsigned int _threshold):init(_init), fullEval(_fullEval), threshold(_threshold) {}
|
||||
|
||||
/**
|
||||
* Apply restart when necessary
|
||||
* @param _solution to restart
|
||||
* @return true
|
||||
*/
|
||||
bool operator()(EOT& _solution){
|
||||
if((*this).getCounter()>= threshold){
|
||||
init(_solution);
|
||||
fullEval(_solution);
|
||||
(*this).initCounter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
eoInit<EOT>& init;
|
||||
eoEvalFunc<EOT>& fullEval;
|
||||
unsigned int threshold;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue