Début du dev de newMo

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1639 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-01-15 10:45:55 +00:00
commit e13fd250d1
34 changed files with 1946 additions and 48 deletions

View file

@ -0,0 +1,64 @@
#ifndef _moLocalSearch_h
#define _moLocalSearch_h
#include <explorer/moNeighborhoodExplorer.h>
#include <continuator/moContinuator.h>
/*
the main algorithm of the local search
*/
template< class NHE , class C >
class moLocalSearch: public eoMonOp<typename NHE::EOT>
{
public:
typedef NHE NeighborhoodExplorer ;
typedef C Continuator ;
typedef typename NeighborhoodExplorer::EOT EOT ;
moLocalSearch(NeighborhoodExplorer & __searchExpl, Continuator & __continuator) : searchExplorer(__searchExpl), continuator(__continuator) { } ;
virtual bool operator() (EOT & 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);
unsigned num = 0;
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);
// 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));
};
private:
// make the exploration of the neighborhood according to a local search heuristic
NeighborhoodExplorer & searchExplorer ;
// external continuator
Continuator & continuator ;
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,34 @@
#ifndef _moNeighborComparator_h
#define _moNeighborComparator_h
#include <neighborhood/moNeighbor.h>
template< class Neigh >
class moNeighborComparator : public eoBF<const Neigh & , const Neigh & , bool>
{
public:
/*
* true if the neighbor1 is better than neighbor2
*/
virtual bool operator()(const Neigh & neighbor1, const Neigh & neighbor2) {
return (neighbor1.fitness() > neighbor2.fitness());
}
/** Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const { return "moNeighborComparator"; }
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,29 @@
#ifndef _moContinuator_h
#define _moContinuator_h
/*
to make specific continuator from a solution
*/
template< class NH >
class moContinuator : public eoUF<typename NH::EOT &, bool>
{
public:
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
// empty constructor
moContinuator() { } ;
virtual void init(EOT & solution) = 0 ;
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,42 @@
#ifndef _moTrueContinuator_h
#define _moTrueContinuator_h
#include <continuator/moContinuator.h>
/*
to make specific continuator from a solution
*/
template< class NH >
class moTrueContinuator : public moContinuator<NH>
{
public:
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
// empty constructor
moTrueContinuator() { i=0;} ;
/*
always true
*/
virtual bool operator()(EOT & solution) {
i++;
return i<10;
};
virtual void init(EOT & solution) {
}
int i;
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,43 @@
#ifndef _neighborhoodExplorer_h
#define _neighborhoodExplorer_h
#include <neighborhood/moNeighborhood.h>
/*
explore the neighborhood
*/
template< class NH >
class moNeighborhoodExplorer : public eoUF<typename NH::EOT & , void>
{
public:
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
// empty constructor
moNeighborhoodExplorer() { } ;
virtual void initParam (EOT & solution) = 0 ;
virtual void updateParam (EOT & solution) = 0 ;
virtual bool isContinue(EOT & solution) = 0 ;
virtual void move(EOT & solution) = 0 ;
virtual bool accept(EOT & solution) = 0 ;
/** Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const { return "moNeighborhoodExplorer"; }
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,91 @@
#ifndef _moSimpleHCexplorer_h
#define _moSimpleHCexplorer_h
#include <explorer/moNeighborhoodExplorer.h>
template< class NH >
class moSimpleHCexplorer : public moNeighborhoodExplorer<NH>
{
public:
typedef NH Neighborhood ;
typedef typename Neighborhood::EOT EOT ;
typedef typename Neighborhood::Neighbor Neighbor ;
// empty constructor
moSimpleHCexplorer(Neighborhood & __neighborhood) : neighborhood(__neighborhood) {
isAccept = false;
}
virtual void initParam (EOT & solution) { } ;
virtual void updateParam (EOT & solution) { } ;
virtual void operator() (EOT & solution) {
//est qu'on peut initializer
if(neighborhood.hasNeighbor(solution)){
neighborhood.init(solution, current);
current.eval(solution);
best = current;
while (neighborhood.cont(solution)) {
neighborhood.next(solution, current);
current.eval(solution);
if (current.betterThan(best)) {
best = current;
}
}
}
else{
isAccept=false;
}
};
virtual bool isContinue(EOT & solution) {
return isAccept ;
};
virtual void move(EOT & solution) {
best.move(solution);
solution.fitness(best.fitness());
};
virtual bool accept(EOT & solution) {
if(neighborhood.hasNeighbor(solution)){
isAccept = (solution.fitness() < best.fitness()) ;
}
return isAccept;
};
private:
Neighborhood & neighborhood;
// attention il faut que le constructeur vide existe
Neighbor best ;
Neighbor current ;
// true if the move is accepted
bool isAccept ;
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,57 @@
/*
<moMove.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 _moMove_h
#define _moMove_h
#include <eoFunctor.h>
//! Definition of a move.
/*!
A move transforms a solution to another close solution.
It describes how a solution can be modified to another one.
*/
template < class EOT >
class moMove:public eoUF < EOT &, void >
{
public:
//! Alias for the type
typedef EOT EOType;
};
#endif

View file

@ -0,0 +1,52 @@
/*
<moMoveIncrEval.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 _moMoveIncrEval_h
#define _moMoveIncrEval_h
#include <eoFunctor.h>
//! (generally) Efficient evaluation function based a move and a solution.
/*!
From a move and a solution, it computes
a new fitness that could be associated to
the solution if this one is updated.
*/
template < class M, class Objective = typename M::EOType::Fitness>
class moMoveIncrEval:public eoBF < const M &, const typename M::EOType &, Objective >
{};
#endif

View file

@ -1,21 +1,21 @@
/*
<mo.h>
Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
(C) OPAC Team, LIFL, 2002-2007
<moMoveInit.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,
@ -28,14 +28,23 @@
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 _mo_h
#define _mo_h
#ifndef _moMoveInit_h
#define _moMoveInit_h
#include <algo/moAlgo.h>
#include <eoFunctor.h>
//! Move (moMove) initializer
/*!
Class which allows to initiase a move.
Only a description... An object that herits from this class needs to be designed to be used.
*/
template < class M >
class moMoveInit:public eoBF < M &, const typename M::EOType &, void >
{};
#endif

View file

@ -0,0 +1,50 @@
/*
<moNextMove.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 _moNextMove_h
#define _moNextMove_h
#include <eoFunctor.h>
//! Class which allows to generate a new move (moMove).
/*!
Useful for the explorer (for moTS or moHC).
Does nothing... An object that herits from this class needs to be designed for being used.
*/
template < class M >
class moNextMove:public eoBF < M &, const typename M::EOType &, bool >
{};
#endif

View file

@ -0,0 +1,107 @@
#ifndef _bitNeighbor_h
#define _bitNeighbor_h
#include <ga/eoBit.h>
#include <neighborhood/moNeighbor.h>
/*
contener of the neighbor information
*/
template< class Fitness >
class moBitNeighbor : public moNeighbor< eoBit<Fitness> , Fitness>
{
public:
typedef eoBit<Fitness> EOType ;
using moNeighbor< eoBit<Fitness> , Fitness>::fitness;
// describe the neighbor
unsigned bit ;
// empty constructor needed
moBitNeighbor() : moNeighbor<eoBit<Fitness> , Fitness>() { } ;
// copy constructor
moBitNeighbor(const moBitNeighbor & n) : moNeighbor<eoBit<Fitness> , Fitness>(n) {
this->bit = n.bit ;
} ;
moBitNeighbor(unsigned 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 ;
}
/*
move the solution
*/
virtual void move(EOType & solution) {
solution[bit] = solution[bit]?false:true ;
}
// 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"; }
/**
* 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);
}
}
/**
* 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 << ' ' ;
}
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,60 @@
#ifndef _bitNeighborhood_h
#define _bitNeighborhood_h
#include <neighborhood/moNeighborhood.h>
template< class N >
class moBitNeighborhood : public moNeighborhood<N>
{
public:
typedef N Neighbor ;
typedef typename Neighbor::EOType EOT ;
moBitNeighborhood() : moNeighborhood<Neighbor>() { }
virtual bool hasNeighbor(EOT & solution) {
return true;
}
/*
initialisation of the neighborhood
*/
virtual void init(EOT & solution, Neighbor & _neighbor) {
currentBit = 0 ;
_neighbor.bit = currentBit ;
}
/*
Give the next neighbor
*/
virtual void next(EOT & solution, Neighbor & neighbor) {
currentBit++ ;
neighbor.bit = currentBit ;
}
/*
if false, there is no neighbor left to explore
*/
virtual bool cont(EOT & solution) {
return (currentBit < solution.size()) ;
}
private:
unsigned currentBit;
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,41 @@
#ifndef _emptyNeighbor_h
#define _emptyNeighbor_h
#include <neighborhood/moNeighbor.h>
/*
contener of the neighbor information
*/
template< class EOT , class Fitness >
class moEmptyNeighbor : public moNeighbor<EOT,Fitness>
{
public:
typedef EOT EOType ;
// empty constructor
moEmptyNeighbor() : moNeighbor<EOType, Fitness>() { } ;
/*
make the evaluation of the current neighbor and update the information on this neighbor
*/
virtual void eval(EOT & solution) { }
/*
move the solution
*/
virtual void move(EOT & solution) { }
// true if the this is better than the neighbor __neighbor
virtual bool betterThan(moNeighbor<EOT,Fitness> & __neighbor) { return true; }
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,64 @@
#ifndef _fullEvalBitNeighbor_h
#define _fullEvalBitNeighbor_h
#include <neighborhood/moBitNeighbor.h>
#include <ga.h>
/*
contener of the neighbor information
*/
template< class Fitness >
class moFullEvalBitNeighbor : public moBitNeighbor<Fitness>
{
public:
typedef eoBit<Fitness> EOType ;
using moBitNeighbor<Fitness>::bit ;
// empty constructor needed
moFullEvalBitNeighbor() : moBitNeighbor<Fitness>() { } ;
moFullEvalBitNeighbor(unsigned b) : moBitNeighbor<Fitness>(bit) { } ;
/*
make the evaluation of the current neighbor and update the information on this neighbor
*/
virtual void eval(EOType & solution) {
Fitness fit = solution.fitness();
solution[bit] = solution[bit]?false:true ;
(*fullEval)(solution);
fitness(solution.fitness());
solution[bit] = solution[bit]?false:true ;
solution.fitness(fit);
};
static void setFullEvalFunc(eoEvalFunc<EOType> & eval) {
fullEval = & eval ;
}
static eoEvalFunc<EOType> * fullEval ;
/** Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const { return "moFullEvalBitNeighbor"; }
};
template<class Fitness>
eoEvalFunc< eoBit<Fitness> > * moFullEvalBitNeighbor<Fitness>::fullEval = NULL ;
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,46 @@
#ifndef _fullEvalNeighbor_h
#define _fullEvalNeighbor_h
/*
neighbor with full evaluation
*/
template< class EOT , class Fitness >
class moFullEvalNeighbor : moNeighbor<EOT, Fitness>
{
public:
// empty constructor
moFullEvalNeighbor(eoEvalFunc<EOT> & _eval) : fulleval(_eval) { } ;
/*
make the evaluation of the current neighbor and update the information on this neighbor
*/
virtual void eval(EOT & solution) {
Fitness fit = solution.fitness();
move(solution);
fulleval(solution);
moveBack(solution);
fitness = solution.fitness();
solution.fitness(fit);
};
virtual moveBack(EOT & solution) ;
private:
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:

View file

@ -0,0 +1,108 @@
#ifndef _moMoveNeighbor_h
#define _moMoveNeighbor_h
#include <eo>
#include <neighborhood/moNeighbor.h>
#include <move/moMoveIncrEval.h>
#include <move/moMove.h>
/*
contener of the neighbor informations
*/
template< class M , class Fitness >
class moMoveNeighbor : public moNeighbor <typename M::EOType, Fitness>
{
public:
typedef typename M::EOType EOT;
// empty constructor
moMoveNeighbor() {_move=new M();};
~moMoveNeighbor() {delete _move;};
// copy constructeur
moMoveNeighbor(const moMoveNeighbor<M, Fitness> & _n) {
moNeighbor<EOT, Fitness>::operator=(_n);
(*_move) = *(_n._move);
}
// assignment operator
virtual moMoveNeighbor<M, Fitness> & operator=(const moMoveNeighbor<M, Fitness> & _n) {
moNeighbor <EOT, Fitness>::operator=(_n);
(*_move) = *(_n._move);
std::cout << moNeighbor<EOT, Fitness>::fitness() << " , " << _n.fitness() << std::endl;
return *this ;
}
/*
* make the evaluation of the current neighbor and update the information on this neighbor
* the evaluation could be increamental
*/
virtual void eval(EOT & solution){
fitness((*_incrEval)(*_move, solution));
}
/*
* move the solution
*/
virtual void move(EOT & solution){
(*_move)(solution);
}
/** Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const { return "moMoveNeighbor"; }
static void setIncrEval(moMoveIncrEval<M, Fitness>& increm) {
_incrEval = & increm ;
}
/**
* 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
{
_is.seekg(pos); // rewind
_is >> repFitness;
}
}
*/
/**
* 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 << repFitness << ' ' ;
}*/
M* _move;
private:
static moMoveIncrEval<M, Fitness>* _incrEval;
};
template< class M , class Fitness >
moMoveIncrEval<M, Fitness> * moMoveNeighbor<M, Fitness>::_incrEval = NULL;
#endif

View file

@ -0,0 +1,59 @@
#ifndef _moMoveNeighborhood_h
#define _moMoveNeighborhood_h
#include <neighborhood/moMoveNeighbor.h>
#include <neighborhood/moNeighborhood.h>
#include <move/moMoveInit.h>
#include <move/moNextMove.h>
template< class M, class Fitness >
class moMoveNeighborhood : public moNeighborhood <moMoveNeighbor<M, Fitness> >
{
public:
typedef moMoveNeighbor<M, Fitness> Neighbor;
typedef typename M::EOType EOT;
moMoveNeighborhood(moMoveInit<M>& i, moNextMove<M>& n):_init(i), _next(n), isContinue(true) {}
virtual bool hasNeighbor(EOT & solution){
return true;
}
/*
initialisation of the neighborhood
*/
virtual void init(EOT & solution, Neighbor & current){
_init(*(current._move), solution);
isContinue=true;
}
/*
Give the next neighbor
*/
virtual void next(EOT & solution, Neighbor & current){
isContinue=_next(*(current._move), solution);
}
/*
if false, there is no neighbor left to explore
*/
virtual bool cont(EOT & solution){
return isContinue;
}
/** Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const { return "moMoveNeighborhood"; }
private:
moMoveInit<M>& _init;
moNextMove<M>& _next;
bool isContinue;
};
#endif

View file

@ -0,0 +1,135 @@
#ifndef _moNeighbor_h
#define _moNeighbor_h
#include <eo>
#include <comparator/moNeighborComparator.h>
/*
contener of the neighbor informations
*/
template< class EOT , class Fitness >
class moNeighbor : public eoObject, public eoPersistent
{
public:
typedef EOT EOType ;
// empty constructor
moNeighbor() { } ;
// copy constructeur
moNeighbor(const moNeighbor<EOType, Fitness> & _n) {
repFitness = _n.fitness();
}
// assignment operator
virtual moNeighbor<EOType, Fitness> & operator=(const moNeighbor<EOType, Fitness> & _n) {
repFitness = _n.fitness();
return *this ;
}
/*
* make the evaluation of the current neighbor and update the information on this neighbor
* the evaluation could be increamental
*/
virtual void eval(EOT & solution) = 0 ;
/*
* move the solution
*/
virtual void move(EOT & solution) = 0 ;
// true if the this is better than the neighbor __neighbor
// virtual bool betterThan(const moNeighbor<EOT,Fitness> & __neighbor) = 0 ;
virtual bool betterThan(const moNeighbor<EOT,Fitness> & __neighbor) {
return (*neighborComparator)(*this, __neighbor) ;
} ;
/// Return fitness value.
const Fitness& fitness() const {
return repFitness;
}
/// Get fitness as reference, useful when fitness is set in a multi-stage way, e.g., MOFitness gets performance information, is subsequently ranked
Fitness& fitnessReference() {
return repFitness;
}
/** Set fitness. At the same time, validates it.
* @param _fitness New fitness value.
*/
void fitness(const Fitness& _fitness)
{
repFitness = _fitness;
}
/** Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const { return "moNeighbor"; }
/**
* 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
{
_is.seekg(pos); // rewind
_is >> repFitness;
}
}
/**
* 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 << repFitness << ' ' ;
}
static void setNeighborComparator(const moNeighborComparator< moNeighbor<EOType, Fitness> > & comparator) {
neighborComparator = & comparator ;
}
static const moNeighborComparator< moNeighbor<EOType, Fitness> > & getNeighborComparator() {
return *neighborComparator ;
}
private:
// minimal information on the neighbor : fitness
Fitness repFitness ;
// the comparator of neighbors
static moNeighborComparator<moNeighbor<EOType, Fitness> > * neighborComparator ;
};
// static default comparor
template<class EOT, class Fitness>
moNeighborComparator<moNeighbor<EOT, Fitness> > * moNeighbor<EOT, Fitness>::neighborComparator = new moNeighborComparator<moNeighbor<EOT, Fitness> >();
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -0,0 +1,46 @@
#ifndef _moNeighborhood_h
#define _moNeighborhood_h
template< class Neigh >
class moNeighborhood : public eoObject
{
public:
typedef Neigh Neighbor;
typedef typename Neighbor::EOType EOT;
moNeighborhood() { }
virtual bool hasNeighbor(EOT & solution) = 0 ;
/*
initialisation of the neighborhood
*/
virtual void init(EOT & solution, Neighbor & current) = 0 ;
/*
Give the next neighbor
*/
virtual void next(EOT & solution, Neighbor & current) = 0 ;
/*
if false, there is no neighbor left to explore
*/
virtual bool cont(EOT & solution) = 0 ;
/** Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const { return "moNeighborhood"; }
};
#endif
// Local Variables:
// coding: iso-8859-1
// mode: C++
// c-file-offsets: ((c . 0))
// c-file-style: "Stroustrup"
// fill-column: 80
// End:

View file

@ -1,10 +1,7 @@
/*
/*
<mo>
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)
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
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
@ -33,9 +30,10 @@
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef __mo
#define __mo
#include "mo.h"
#ifndef __newmo
#define __newmo
#include "newmo.h"
#endif

61
branches/newMo/src/newmo.h Executable file
View file

@ -0,0 +1,61 @@
/*
<mo.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
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 _newmo_h
#define _newmo_h
#include <algo/moLocalSearch.h>
#include <comparator/moNeighborComparator.h>
#include <continuator/moContinuator.h>
#include <continuator/moTrueContinuator.h>
#include <explorer/moNeighborhoodExplorer.h>
#include <explorer/moSimpleHCexplorer.h>
#include <neighborhood/moBitNeighbor.h>
#include <neighborhood/moBitNeighborhood.h>
#include <neighborhood/moEmptyNeighbor.h>
#include <neighborhood/moFullEvalBitNeighbor.h>
#include <neighborhood/moFullEvalNeighbor.h>
#include <neighborhood/moMoveNeighbor.h>
#include <neighborhood/moMoveNeighborhood.h>
#include <neighborhood/moNeighbor.h>
#include <neighborhood/moNeighborhood.h>
#include <move/moMove.h>
#include <move/moMoveIncrEval.h>
#include <move/moMoveInit.h>
#include <move/moNextMove.h>
#endif