Encore de la doc
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1660 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
278c0e70ab
commit
9cf5680823
7 changed files with 153 additions and 176 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <explorer/moNeighborhoodExplorer.h>
|
||||
#include <continuator/moContinuator.h>
|
||||
#include <eoEvalFunc.h>
|
||||
|
||||
/**
|
||||
* the main algorithm of the local search
|
||||
|
|
@ -19,41 +20,47 @@ public:
|
|||
/**
|
||||
* Constructor of a moLocalSearch needs a NeighborhooExplorer and a Continuator
|
||||
*/
|
||||
moLocalSearch(NeighborhoodExplorer& _searchExpl, Continuator & _continuator) : searchExplorer(_searchExpl), continuator(_continuator) { } ;
|
||||
moLocalSearch(NeighborhoodExplorer& _searchExpl, Continuator & _continuator, eoEvalFunc<EOT>& _fullEval) : searchExplorer(_searchExpl), continuator(_continuator), fullEval(_fullEval) { } ;
|
||||
|
||||
/**
|
||||
* Run the local search on a solution
|
||||
* @param _solution the related solution
|
||||
*/
|
||||
virtual bool operator() (EOT & _solution) {
|
||||
|
||||
if(_solution.invalid())
|
||||
fullEval(_solution);
|
||||
|
||||
// initialization of the external continuator (for example the time, or the number of generations)
|
||||
continuator.init(_solution);
|
||||
// initialization of the external continuator (for example the time, or the number of generations)
|
||||
continuator.init(_solution);
|
||||
|
||||
// initialization of the parameter of the search (for example fill empty the tabu list)
|
||||
searchExplorer.initParam(_solution);
|
||||
// initialization of the parameter of the search (for example fill empty the tabu list)
|
||||
searchExplorer.initParam(_solution);
|
||||
|
||||
unsigned num = 0;
|
||||
//A virer par la suite
|
||||
unsigned int num = 0;
|
||||
|
||||
do {
|
||||
// explore the neighborhood of the solution
|
||||
searchExplorer(_solution);
|
||||
do{
|
||||
// explore the neighborhood of the solution
|
||||
searchExplorer(_solution);
|
||||
|
||||
// if a solution in the neighborhood can be accepted
|
||||
if (searchExplorer.accept(_solution))
|
||||
searchExplorer.move(_solution);
|
||||
// if a solution in the neighborhood can be accepted
|
||||
if (searchExplorer.accept(_solution))
|
||||
searchExplorer.move(_solution);
|
||||
|
||||
// update the parameter of the search (for ex. Temperature of the SA)
|
||||
searchExplorer.updateParam(_solution);
|
||||
// update the parameter of the search (for ex. Temperature of the SA)
|
||||
searchExplorer.updateParam(_solution);
|
||||
|
||||
std::cout << num << " : " << _solution << std::endl ;
|
||||
num++;
|
||||
} while (continuator(_solution) && searchExplorer.isContinue(_solution));
|
||||
//A virer par la suite
|
||||
std::cout << num << " : " << _solution << std::endl ;
|
||||
num++;
|
||||
|
||||
searchExplorer.terminate(_solution);
|
||||
}while (continuator(_solution) && searchExplorer.isContinue(_solution));
|
||||
|
||||
//A CHANGER
|
||||
return true;
|
||||
searchExplorer.terminate(_solution);
|
||||
|
||||
//A CHANGER
|
||||
return true;
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -63,15 +70,10 @@ private:
|
|||
|
||||
// external continuator
|
||||
Continuator& continuator ;
|
||||
|
||||
//full evaluation function
|
||||
eoEvalFunc<EOT>& fullEval;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
|
|
|
|||
|
|
@ -4,30 +4,31 @@
|
|||
#include <continuator/moContinuator.h>
|
||||
|
||||
/**
|
||||
to make specific continuator from a solution
|
||||
*/
|
||||
* Continuator always return True
|
||||
*/
|
||||
template< class NH >
|
||||
class moTrueContinuator : public moContinuator<NH>
|
||||
{
|
||||
public:
|
||||
typedef NH Neighborhood ;
|
||||
typedef typename Neighborhood::EOT EOT ;
|
||||
typedef typename NH::EOT EOT ;
|
||||
|
||||
// empty constructor
|
||||
moTrueContinuator() { i=0;} ;
|
||||
moTrueContinuator() {} ;
|
||||
|
||||
/**
|
||||
always true
|
||||
*/
|
||||
virtual bool operator()(EOT & solution) {
|
||||
i++;
|
||||
return i<10;
|
||||
};
|
||||
|
||||
virtual void init(EOT & solution) {
|
||||
*@param _solution a solution
|
||||
*@return always true
|
||||
*/
|
||||
virtual bool operator()(EOT & _solution) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int i;
|
||||
/**
|
||||
* NOTHING TO DO
|
||||
* @param _solution a solution
|
||||
*/
|
||||
virtual void init(EOT & _solution) {}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@
|
|||
* Abstract class for the evaluation
|
||||
*/
|
||||
template<class Neighbor>
|
||||
class moEval : public eoBF<typename Neighbor::EOType &, Neighbor&, void>
|
||||
class moEval : public eoBF<typename Neighbor::EOT &, Neighbor&, void>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOType EOT;
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,108 +4,104 @@
|
|||
#include <ga/eoBit.h>
|
||||
#include <neighborhood/moBackableNeighbor.h>
|
||||
|
||||
/*
|
||||
contener of the neighbor information
|
||||
*/
|
||||
/**
|
||||
* Neighbor related to a vector of Bit
|
||||
*/
|
||||
template< class Fitness >
|
||||
class moBitNeighbor : public moBackableNeighbor<eoBit<Fitness>, Fitness>
|
||||
{
|
||||
public:
|
||||
typedef eoBit<Fitness> EOType ;
|
||||
typedef eoBit<Fitness> EOT ;
|
||||
|
||||
using moNeighbor<eoBit<Fitness>, Fitness>::fitness;
|
||||
|
||||
// describe the neighbor
|
||||
unsigned bit ;
|
||||
|
||||
// empty constructor needed
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
moBitNeighbor() : moBackableNeighbor<eoBit<Fitness> , Fitness>() { } ;
|
||||
|
||||
// copy constructor
|
||||
moBitNeighbor(const moBitNeighbor & n) : moNeighbor<eoBit<Fitness> , Fitness>(n) {
|
||||
this->bit = n.bit ;
|
||||
/**
|
||||
* Copy Constructor
|
||||
*/
|
||||
moBitNeighbor(const moBitNeighbor& _n) : moNeighbor<eoBit<Fitness> , Fitness>(_n) {
|
||||
this->bit = _n.bit ;
|
||||
} ;
|
||||
|
||||
moBitNeighbor(unsigned b) : moNeighbor<eoBit<Fitness> , Fitness>() , bit(b) { } ;
|
||||
/**
|
||||
* Constructor
|
||||
* @param _b index
|
||||
*/
|
||||
moBitNeighbor(unsigned int _b) : moNeighbor<eoBit<Fitness> , Fitness>() , bit(_b) { } ;
|
||||
|
||||
/*
|
||||
* operator of assignment
|
||||
*/
|
||||
virtual moBitNeighbor<Fitness> & operator=(const moBitNeighbor<Fitness> & source) {
|
||||
moNeighbor<EOType, Fitness>::operator=(source);
|
||||
|
||||
this->bit = source.bit ;
|
||||
|
||||
return *this ;
|
||||
/**
|
||||
* Assignment operator
|
||||
*/
|
||||
virtual moBitNeighbor<Fitness> & operator=(const moBitNeighbor<Fitness> & _source) {
|
||||
moNeighbor<EOT, Fitness>::operator=(_source);
|
||||
this->bit = _source.bit ;
|
||||
return *this ;
|
||||
}
|
||||
|
||||
/*
|
||||
move the solution
|
||||
*/
|
||||
virtual void move(EOType & solution) {
|
||||
solution[bit] = !solution[bit];
|
||||
/**
|
||||
* move the solution
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
_solution[bit] = !_solution[bit];
|
||||
}
|
||||
|
||||
virtual void moveBack(EOType & solution) {
|
||||
solution[bit] = !solution[bit];
|
||||
/**
|
||||
* move back the solution (useful for the evaluation by modif)
|
||||
* @param _solution the solution to move back
|
||||
*/
|
||||
virtual void moveBack(EOT & _solution) {
|
||||
_solution[bit] = !_solution[bit];
|
||||
}
|
||||
|
||||
// by default: if the fitness of the current solution is stricly higher than the other neighbor
|
||||
virtual bool betterThan(const moNeighbor<EOType, Fitness> & __neighbor) {
|
||||
return (this->fitness() > __neighbor.fitness()) ;
|
||||
};
|
||||
|
||||
/** Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const { return "moBitNeighbor"; }
|
||||
/**
|
||||
* Return the class id.
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moBitNeighbor";
|
||||
}
|
||||
|
||||
/**
|
||||
* Read object.\ \
|
||||
* Calls base class, just in case that one had something to do.
|
||||
* The read and print methods should be compatible and have the same format.
|
||||
* In principle, format is "plain": they just print a number
|
||||
* @param _is a std::istream.
|
||||
* @throw runtime_std::exception If a valid object can't be read.
|
||||
*/
|
||||
virtual void readFrom(std::istream& _is) {
|
||||
std::string fitness_str;
|
||||
int pos = _is.tellg();
|
||||
_is >> fitness_str;
|
||||
|
||||
if (fitness_str == "INVALID")
|
||||
{
|
||||
throw std::runtime_error("invalid fitness");
|
||||
/**
|
||||
* Read object.\ \
|
||||
* Calls base class, just in case that one had something to do.
|
||||
* The read and print methods should be compatible and have the same format.
|
||||
* In principle, format is "plain": they just print a number
|
||||
* @param _is a std::istream.
|
||||
* @throw runtime_std::exception If a valid object can't be read.
|
||||
*/
|
||||
virtual void readFrom(std::istream& _is) {
|
||||
std::string fitness_str;
|
||||
int pos = _is.tellg();
|
||||
_is >> fitness_str;
|
||||
if (fitness_str == "INVALID"){
|
||||
throw std::runtime_error("invalid fitness");
|
||||
}
|
||||
else{
|
||||
Fitness repFit ;
|
||||
_is.seekg(pos); // rewind
|
||||
_is >> repFit;
|
||||
_is >> bit;
|
||||
fitness(repFit);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Fitness repFit ;
|
||||
_is.seekg(pos); // rewind
|
||||
_is >> repFit;
|
||||
_is >> bit;
|
||||
|
||||
fitness(repFit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||
* @param _os A std::ostream.
|
||||
*/
|
||||
virtual void printOn(std::ostream& _os) const {
|
||||
_os << fitness() << ' ' << bit << ' ' ;
|
||||
_os << fitness() << ' ' << bit << std::endl;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
|
|
|
|||
|
|
@ -3,48 +3,62 @@
|
|||
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
|
||||
/**
|
||||
* Neighborhood related to a vector of Bit
|
||||
*/
|
||||
template< class N >
|
||||
class moBitNeighborhood : public moNeighborhood<N>
|
||||
{
|
||||
public:
|
||||
typedef N Neighbor ;
|
||||
typedef typename Neighbor::EOType EOT ;
|
||||
typedef typename Neighbor::EOT EOT ;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
moBitNeighborhood() : moNeighborhood<Neighbor>() { }
|
||||
|
||||
virtual bool hasNeighbor(EOT & solution) {
|
||||
|
||||
return true;
|
||||
|
||||
/**
|
||||
* Test if it exist a neighbor
|
||||
* @param _solution the solution to explore
|
||||
* @return always True
|
||||
*/
|
||||
virtual bool hasNeighbor(EOT& _solution) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
initialisation of the neighborhood
|
||||
*/
|
||||
virtual void init(EOT & solution, Neighbor & _neighbor) {
|
||||
/**
|
||||
* Initialization of the neighborhood
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the first neighbor
|
||||
*/
|
||||
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
||||
currentBit = 0 ;
|
||||
|
||||
_neighbor.bit = currentBit ;
|
||||
}
|
||||
|
||||
/*
|
||||
Give the next neighbor
|
||||
*/
|
||||
virtual void next(EOT & solution, Neighbor & neighbor) {
|
||||
/**
|
||||
* Give the next neighbor
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the next neighbor
|
||||
*/
|
||||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||
currentBit++ ;
|
||||
|
||||
neighbor.bit = currentBit ;
|
||||
_neighbor.bit = currentBit ;
|
||||
}
|
||||
|
||||
/*
|
||||
if false, there is no neighbor left to explore
|
||||
*/
|
||||
virtual bool cont(EOT & solution) {
|
||||
return (currentBit < solution.size()) ;
|
||||
/**
|
||||
* test if all neighbors are explore or not,if false, there is no neighbor left to explore
|
||||
* @param _solution the solution to explore
|
||||
* @return true if there is again a neighbor to explore
|
||||
*/
|
||||
virtual bool cont(EOT & _solution) {
|
||||
return (currentBit < _solution.size()) ;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned currentBit;
|
||||
//Position in the neighborhood
|
||||
unsigned int currentBit;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +1,3 @@
|
|||
/*
|
||||
<moNeighbor.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
|
||||
(C) OPAC Team, LIFL, 2002-2008
|
||||
|
||||
Sébastien Cahon, Jean-Charles Boisson (Jean-Charles.Boisson@lifl.fr)
|
||||
|
||||
This software is governed by the CeCILL license under French law and
|
||||
abiding by the rules of distribution of free software. You can use,
|
||||
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".
|
||||
|
||||
As a counterpart to the access to the source code and rights to copy,
|
||||
modify and redistribute granted by the license, users are provided only
|
||||
with a limited warranty and the software's author, the holder of the
|
||||
economic rights, and the successive licensors have only limited liability.
|
||||
|
||||
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 _moNeighbor_h
|
||||
#define _moNeighbor_h
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public:
|
|||
/**
|
||||
* Define type of a solution corresponding to Neighbor
|
||||
*/
|
||||
typedef typename Neighbor::EOType EOT;
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue