paradiseo new mo added

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1712 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jhumeau 2010-03-24 10:07:28 +00:00
commit d7496cafff
116 changed files with 12034 additions and 0 deletions

View file

@ -0,0 +1,56 @@
/*
<moBackableNeighbor.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 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 _BackableNeighbor_h
#define _BackableNeighbor_h
#include <neighborhood/moNeighbor.h>
/**
* Neighbor with a move back function to use in a moFullEvalByModif
*/
template< class EOT , class Fitness >
class moBackableNeighbor : virtual public moNeighbor<EOT, Fitness>
{
public:
/**
* the move back function
* @param _solution the solution to moveBack
*/
virtual void moveBack(EOT & _solution)=0;
};
#endif

View file

@ -0,0 +1,111 @@
/*
<moBitNeighbor.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 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 _bitNeighbor_h
#define _bitNeighbor_h
#include <ga/eoBit.h>
#include <neighborhood/moBackableNeighbor.h>
#include <neighborhood/moIndexNeighbor.h>
/**
* Neighbor related to a vector of Bit
*/
template< class Fitness >
class moBitNeighbor : public moBackableNeighbor<eoBit<Fitness>, Fitness>, public moIndexNeighbor<eoBit<Fitness>, Fitness>
{
public:
typedef eoBit<Fitness> EOT ;
using moBackableNeighbor<eoBit<Fitness>, Fitness>::fitness;
using moIndexNeighbor<eoBit<Fitness>, Fitness>::key;
/**
* move the solution
* @param _solution the solution to move
*/
virtual void move(EOT & _solution) {
_solution[key] = !_solution[key];
}
/**
* move back the solution (useful for the evaluation by modif)
* @param _solution the solution to move back
*/
virtual void moveBack(EOT & _solution) {
_solution[key] = !_solution[key];
}
/**
* 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 >> key;
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() << ' ' << key << std::endl;
}
};
#endif

View file

@ -0,0 +1,101 @@
/*
<moIndexNeighbor.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 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 _IndexNeighbor_h
#define _IndexNeighbor_h
#include <neighborhood/moNeighbor.h>
/**
* Index Neighbor
*/
template< class EOT , class Fitness >
class moIndexNeighbor : virtual public moNeighbor<EOT, Fitness>
{
public:
using moNeighbor<EOT, Fitness>::fitness;
/**
* Default Constructor
*/
moIndexNeighbor() : moNeighbor<EOT, Fitness>(), key(0){}
/**
* Copy Constructor
*/
moIndexNeighbor(const moIndexNeighbor& _n) : moNeighbor<EOT, Fitness>(_n) {
this->key = _n.key ;
}
/**
* Assignment operator
*/
virtual moIndexNeighbor<EOT, Fitness> & operator=(const moIndexNeighbor<EOT, Fitness> & _source) {
moNeighbor<EOT, Fitness>::operator=(_source);
this->key = _source.key ;
return *this ;
}
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moIndexNeighbor";
}
/**
* Getter
* @return index of the IndexNeighbor
*/
unsigned int index(){
return key;
}
/**
* Setter
* @param _key index of the IndexNeighbor
*/
void index(unsigned int _key){
key=_key;
}
protected:
// key allowing to describe the neighbor
unsigned int key;
};
#endif

View file

@ -0,0 +1,70 @@
/*
<moIndexNeighborhood.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 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 _moIndexNeighborhood_h
#define _moIndexNeighborhood_h
#include <neighborhood/moNeighborhood.h>
/**
* A Indexed Neighborhood
*/
template< class Neighbor >
class moIndexNeighborhood : virtual public moNeighborhood<Neighbor>
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
typedef typename Neighbor::EOT EOT;
/**
* Constructor
* @param _neighborhoodSize the size of the neighborhood
*/
moIndexNeighborhood(unsigned int _neighborhoodSize):neighborhoodSize(_neighborhoodSize){}
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moIndexNeighborhood";
}
protected:
unsigned int neighborhoodSize;
};
#endif

View file

@ -0,0 +1,136 @@
/*
<moNeighbor.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 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
//EO inclusion
#include <EO.h>
#include <eoObject.h>
#include <eoPersistent.h>
/**
* Container of the neighbor informations
*/
template< class EOType , class Fitness >
class moNeighbor : public eoObject, public eoPersistent
{
public:
typedef EOType EOT;
/**
* Default Constructor
*/
moNeighbor(){}
/**
* Copy Constructor
* @param _neighbor to copy
*/
moNeighbor(const moNeighbor<EOT, Fitness>& _neighbor) {
repFitness = _neighbor.fitness();
}
/**
* Assignment operator
* @param _neighbor the neighbor to assign
* @return a neighbor equal to the other
*/
virtual moNeighbor<EOT, Fitness>& operator=(const moNeighbor<EOT, Fitness>& _neighbor) {
repFitness = _neighbor.fitness();
return (*this);
}
/**
* Move a solution
* @param _solution the related solution
*/
virtual void move(EOT & _solution) = 0 ;
/**
* Get the fitness of the neighbor
* @return fitness of the neighbor
*/
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
* @return fitness as reference of the neighbor
*/
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.
*/
virtual void readFrom(std::istream& _is) {
_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 << std::endl;
}
protected:
// minimal information on the neighbor : fitness
Fitness repFitness ;
};
#endif

View file

@ -0,0 +1,101 @@
/*
<moNeighborhood.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 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 _moNeighborhood_h
#define _moNeighborhood_h
#include <eoObject.h>
/**
* A Neighborhood
*/
template< class Neighbor >
class moNeighborhood : public eoObject
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
typedef typename Neighbor::EOT EOT;
/**
* Default Constructor
*/
moNeighborhood(){}
/**
* @return if the neighborhood is random
*/
virtual bool isRandom(){
return false;
}
/**
* Test if a solution has (again) a Neighbor
* @param _solution the related solution
* @return if _solution has a Neighbor
*/
virtual bool hasNeighbor(EOT & _solution) = 0 ;
/**
* Initialization of the neighborhood
* @param _solution the solution to explore
* @param _current the first neighbor
*/
virtual void init(EOT & _solution, Neighbor & _current) = 0 ;
/**
* Give the next neighbor
* @param _solution the solution to explore
* @param _current the next neighbor
*/
virtual void next(EOT & _solution, Neighbor & _current) = 0 ;
/**
* Test if there is again a neighbor
* @param _solution the solution to explore
* @return if there is again a neighbor not explored
*/
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

View file

@ -0,0 +1,125 @@
/*
<moOrderNeighborhood.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 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 _moOrderNeighborhood_h
#define _moOrderNeighborhood_h
#include <neighborhood/moIndexNeighborhood.h>
/**
* A Ordered Neighborhood
*/
template< class N >
class moOrderNeighborhood : public moIndexNeighborhood<N>
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
typedef N Neighbor;
typedef typename Neighbor::EOT EOT;
using moIndexNeighborhood<Neighbor>::neighborhoodSize;
/**
* Constructor
* @param _neighborhoodSize the size of the neighborhood
*/
moOrderNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize), currentIndex(0){}
/**
* Test if it exist a neighbor
* @param _solution the solution to explore
* @return true if the neighborhood was not empty
*/
virtual bool hasNeighbor(EOT& _solution) {
return neighborhoodSize > 0;
}
/**
* Initialization of the neighborhood
* @param _solution the solution to explore
* @param _neighbor the first neighbor
*/
virtual void init(EOT & _solution, Neighbor & _neighbor) {
currentIndex = 0 ;
_neighbor.index(currentIndex) ;
}
/**
* Give the next neighbor
* @param _solution the solution to explore
* @param _neighbor the next neighbor
*/
virtual void next(EOT & _solution, Neighbor & _neighbor) {
currentIndex++ ;
_neighbor.index(currentIndex);
}
/**
* test if all neighbors are explore or not,if false, there is no neighbor left to explore
* currentIndex is the index which have been used before, it is not the next neighbor which can be possibly evaluated
*
* @param _solution the solution to explore
* @return true if there is again a neighbor to explore
*/
virtual bool cont(EOT & _solution) {
return (currentIndex < neighborhoodSize - 1) ;
}
/**
* Getter
* @return the position in the Neighborhood
*/
unsigned int position(){
return currentIndex;
}
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moOrderNeighborhood";
}
private:
unsigned int currentIndex;
};
#endif

View file

@ -0,0 +1,45 @@
/*
<moRndNeighborhood.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 _moRndNeighborhood_h
#define _moRndNeighborhood_h
#include <neighborhood/moNeighborhood.h>
template< class Neighbor >
class moRndNeighborhood : virtual public moNeighborhood<Neighbor>{
public:
bool isRandom(){
return true;
}
};
#endif

View file

@ -0,0 +1,111 @@
/*
<moRndWithReplNeighborhood.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 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 _moRndWithReplNeighborhood_h
#define _moRndWithReplNeighborhood_h
#include <neighborhood/moIndexNeighborhood.h>
#include <neighborhood/moRndNeighborhood.h>
#include <utils/eoRNG.h>
/**
* A Random With replacement Neighborhood
*/
template< class N >
class moRndWithReplNeighborhood : public moIndexNeighborhood<N>, public moRndNeighborhood<N>
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
typedef N Neighbor;
typedef typename Neighbor::EOT EOT;
using moIndexNeighborhood<Neighbor>::neighborhoodSize;
/**
* Constructor
* @param _neighborhoodSize the size of the neighborhood
*/
moRndWithReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize){}
/**
* Test if it exist a neighbor
* @param _solution the solution to explore
* @return true if the neighborhood was not empty
*/
virtual bool hasNeighbor(EOT& _solution) {
return neighborhoodSize > 0;
}
/**
* Initialization of the neighborhood
* @param _solution the solution to explore
* @param _neighbor the first neighbor
*/
virtual void init(EOT & _solution, Neighbor & _neighbor) {
_neighbor.index(rng.random(neighborhoodSize));
}
/**
* Give the next neighbor
* @param _solution the solution to explore
* @param _neighbor the next neighbor
*/
virtual void next(EOT & _solution, Neighbor & _neighbor) {
_neighbor.index(rng.random(neighborhoodSize));
}
/**
* 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 neighborhoodSize > 0;
}
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moRndWithReplNeighborhood";
}
};
#endif

View file

@ -0,0 +1,139 @@
/*
<moRndWithoutReplNeighborhood.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 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 _moRndWithoutReplNeighborhood_h
#define _moRndWithoutReplNeighborhood_h
#include <neighborhood/moIndexNeighborhood.h>
#include <neighborhood/moRndNeighborhood.h>
#include <utils/eoRNG.h>
/**
* A Random without replacement Neighborhood
*/
template< class N >
class moRndWithoutReplNeighborhood : public moIndexNeighborhood<N>, public moRndNeighborhood<N>
{
public:
/**
* Define type of a solution corresponding to Neighbor
*/
typedef N Neighbor;
typedef typename Neighbor::EOT EOT;
using moIndexNeighborhood<Neighbor>::neighborhoodSize;
/**
* Constructor
* @param _neighborhoodSize the size of the neighborhood
*/
moRndWithoutReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize), maxIndex(0){
for(unsigned int i=0; i < neighborhoodSize; i++)
indexVector.push_back(i);
}
/**
* Test if it exist a neighbor
* @param _solution the solution to explore
* @return true if the neighborhood was not empty
*/
virtual bool hasNeighbor(EOT& _solution) {
return neighborhoodSize > 0;
}
/**
* Initialization of the neighborhood
* @param _solution the solution to explore
* @param _neighbor the first neighbor
*/
virtual void init(EOT & _solution, Neighbor & _neighbor) {
unsigned int i, tmp;
maxIndex = neighborhoodSize ;
i = rng.random(maxIndex);
_neighbor.index(indexVector[i]);
tmp=indexVector[i];
indexVector[i]=indexVector[maxIndex-1];
indexVector[maxIndex-1]=tmp;
maxIndex--;
}
/**
* Give the next neighbor
* @param _solution the solution to explore
* @param _neighbor the next neighbor
*/
virtual void next(EOT & _solution, Neighbor & _neighbor) {
unsigned int i, tmp;
i = rng.random(maxIndex);
_neighbor.index(indexVector[i]);
tmp=indexVector[i];
indexVector[i]=indexVector[maxIndex-1];
indexVector[maxIndex-1]=tmp;
maxIndex--;
}
/**
* test if all neighbors are explore or not,if false, there is no neighbor left to explore
* maxIndex is number of neighbors
* @param _solution the solution to explore
* @return true if there is again a neighbor to explore
*/
virtual bool cont(EOT & _solution) {
return (maxIndex > 0) ;
}
/**
* Getter
* @return the position in the Neighborhood
*/
unsigned int position(){
return indexVector[maxIndex];
}
/**
* Return the class id.
* @return the class name as a std::string
*/
virtual std::string className() const {
return "moRndWithoutReplNeighborhood";
}
private:
unsigned int maxIndex;
std::vector<unsigned int> indexVector;
};
#endif