IndexNeighborhoods rajoutées
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1668 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
a7c4dc4136
commit
1bd2d3e18b
12 changed files with 451 additions and 101 deletions
|
|
@ -41,7 +41,7 @@
|
||||||
* Neighbor with a move back function to use in a moFullEvalByModif
|
* Neighbor with a move back function to use in a moFullEvalByModif
|
||||||
*/
|
*/
|
||||||
template< class EOT , class Fitness >
|
template< class EOT , class Fitness >
|
||||||
class moBackableNeighbor : public moNeighbor<EOT, Fitness>
|
class moBackableNeighbor : virtual public moNeighbor<EOT, Fitness>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ public:
|
||||||
* the move back function
|
* the move back function
|
||||||
* @param _solution the solution to moveBack
|
* @param _solution the solution to moveBack
|
||||||
*/
|
*/
|
||||||
virtual void moveBack(EOT & _solution){}
|
virtual void moveBack(EOT & _solution)=0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,51 +37,26 @@
|
||||||
|
|
||||||
#include <ga/eoBit.h>
|
#include <ga/eoBit.h>
|
||||||
#include <neighborhood/moBackableNeighbor.h>
|
#include <neighborhood/moBackableNeighbor.h>
|
||||||
|
#include <neighborhood/moIndexNeighbor.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Neighbor related to a vector of Bit
|
* Neighbor related to a vector of Bit
|
||||||
*/
|
*/
|
||||||
template< class Fitness >
|
template< class Fitness >
|
||||||
class moBitNeighbor : public moBackableNeighbor<eoBit<Fitness>, Fitness>
|
class moBitNeighbor : public moBackableNeighbor<eoBit<Fitness>, Fitness>, public moIndexNeighbor<eoBit<Fitness>, Fitness>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef eoBit<Fitness> EOT ;
|
typedef eoBit<Fitness> EOT ;
|
||||||
|
|
||||||
using moNeighbor<eoBit<Fitness>, Fitness>::fitness;
|
using moBackableNeighbor<eoBit<Fitness>, Fitness>::fitness;
|
||||||
|
using moIndexNeighbor<eoBit<Fitness>, Fitness>::key;
|
||||||
/**
|
|
||||||
* Default Constructor
|
|
||||||
*/
|
|
||||||
moBitNeighbor() : moBackableNeighbor<eoBit<Fitness> , Fitness>(), bit(0) { } ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy Constructor
|
|
||||||
*/
|
|
||||||
moBitNeighbor(const moBitNeighbor& _n) : moBackableNeighbor<eoBit<Fitness> , Fitness>(_n) {
|
|
||||||
this->bit = _n.bit ;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
* @param _b index
|
|
||||||
*/
|
|
||||||
moBitNeighbor(unsigned int _b) : moBackableNeighbor<eoBit<Fitness> , Fitness>() , bit(_b) { } ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assignment operator
|
|
||||||
*/
|
|
||||||
virtual moBitNeighbor<Fitness> & operator=(const moBitNeighbor<Fitness> & _source) {
|
|
||||||
moNeighbor<EOT, Fitness>::operator=(_source);
|
|
||||||
this->bit = _source.bit ;
|
|
||||||
return *this ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move the solution
|
* move the solution
|
||||||
* @param _solution the solution to move
|
* @param _solution the solution to move
|
||||||
*/
|
*/
|
||||||
virtual void move(EOT & _solution) {
|
virtual void move(EOT & _solution) {
|
||||||
_solution[bit] = !_solution[bit];
|
_solution[key] = !_solution[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -89,7 +64,7 @@ public:
|
||||||
* @param _solution the solution to move back
|
* @param _solution the solution to move back
|
||||||
*/
|
*/
|
||||||
virtual void moveBack(EOT & _solution) {
|
virtual void moveBack(EOT & _solution) {
|
||||||
_solution[bit] = !_solution[bit];
|
_solution[key] = !_solution[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -119,7 +94,7 @@ public:
|
||||||
Fitness repFit ;
|
Fitness repFit ;
|
||||||
_is.seekg(pos); // rewind
|
_is.seekg(pos); // rewind
|
||||||
_is >> repFit;
|
_is >> repFit;
|
||||||
_is >> bit;
|
_is >> key;
|
||||||
fitness(repFit);
|
fitness(repFit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -129,29 +104,8 @@ public:
|
||||||
* @param _os A std::ostream.
|
* @param _os A std::ostream.
|
||||||
*/
|
*/
|
||||||
virtual void printOn(std::ostream& _os) const {
|
virtual void printOn(std::ostream& _os) const {
|
||||||
_os << fitness() << ' ' << bit << std::endl;
|
_os << fitness() << ' ' << key << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter
|
|
||||||
* @return index of the bitNeighbor
|
|
||||||
*/
|
|
||||||
unsigned int index(){
|
|
||||||
return bit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setter
|
|
||||||
* @param index of the bitNeighbor
|
|
||||||
*/
|
|
||||||
void index(unsigned int _bit){
|
|
||||||
bit=_bit;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
// describe the neighbor
|
|
||||||
unsigned int bit ;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
101
branches/newMo/src/neighborhood/moIndexNeighbor.h
Normal file
101
branches/newMo/src/neighborhood/moIndexNeighbor.h
Normal 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>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Neighbor related to a vector of Bit
|
||||||
|
*/
|
||||||
|
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 index of the IndexNeighbor
|
||||||
|
*/
|
||||||
|
void index(unsigned int _key){
|
||||||
|
key=_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// key allowing to describe the neighbor
|
||||||
|
unsigned int key;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
62
branches/newMo/src/neighborhood/moIndexNeighborhood.h
Normal file
62
branches/newMo/src/neighborhood/moIndexNeighborhood.h
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
<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 : public moNeighborhood<Neighbor>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Define type of a solution corresponding to Neighbor
|
||||||
|
*/
|
||||||
|
typedef typename Neighbor::EOT EOT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param _neighborhood the size of the neighborhood
|
||||||
|
*/
|
||||||
|
moIndexNeighborhood(unsigned int _neighborhoodSize):neighborhoodSize(_neighborhoodSize){}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
unsigned int neighborhoodSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
<moBitNeighborhood.h>
|
<moOrderNeighborhood.h>
|
||||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||||
|
|
@ -32,34 +32,42 @@
|
||||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _bitNeighborhood_h
|
#ifndef _moOrderNeighborhood_h
|
||||||
#define _bitNeighborhood_h
|
#define _moOrderNeighborhood_h
|
||||||
|
|
||||||
#include <neighborhood/moNeighborhood.h>
|
#include <neighborhood/moIndexNeighborhood.h>
|
||||||
#include <neighborhood/moBitNeighbor.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Neighborhood related to a vector of Bit
|
* A Ordered Neighborhood
|
||||||
*/
|
*/
|
||||||
template< class N >
|
template< class N >
|
||||||
class moBitNeighborhood : public moNeighborhood<N>
|
class moOrderNeighborhood : public moIndexNeighborhood<N>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define type of a solution corresponding to Neighbor
|
||||||
|
*/
|
||||||
typedef N Neighbor;
|
typedef N Neighbor;
|
||||||
typedef typename Neighbor::EOT EOT;
|
typedef typename Neighbor::EOT EOT;
|
||||||
|
|
||||||
|
|
||||||
|
using moIndexNeighborhood<Neighbor>::neighborhoodSize;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Constructor
|
||||||
|
* @param _neighborhood the size of the neighborhood
|
||||||
*/
|
*/
|
||||||
moBitNeighborhood() : moNeighborhood<Neighbor>(), currentBit(0) { }
|
moOrderNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize), currentIndex(0){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if it exist a neighbor
|
* Test if it exist a neighbor
|
||||||
* @param _solution the solution to explore
|
* @param _solution the solution to explore
|
||||||
* @return always True
|
* @return true if the neighborhood was not empty
|
||||||
*/
|
*/
|
||||||
virtual bool hasNeighbor(EOT& _solution) {
|
virtual bool hasNeighbor(EOT& _solution) {
|
||||||
return true;
|
return neighborhoodSize > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -68,8 +76,8 @@ public:
|
||||||
* @param _neighbor the first neighbor
|
* @param _neighbor the first neighbor
|
||||||
*/
|
*/
|
||||||
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
||||||
currentBit = 0 ;
|
currentIndex = 0 ;
|
||||||
_neighbor.index(currentBit) ;
|
_neighbor.index(currentIndex) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -78,8 +86,8 @@ public:
|
||||||
* @param _neighbor the next neighbor
|
* @param _neighbor the next neighbor
|
||||||
*/
|
*/
|
||||||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||||
currentBit++ ;
|
currentIndex++ ;
|
||||||
_neighbor.index(currentBit);
|
_neighbor.index(currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -88,7 +96,7 @@ public:
|
||||||
* @return true if there is again a neighbor to explore
|
* @return true if there is again a neighbor to explore
|
||||||
*/
|
*/
|
||||||
virtual bool cont(EOT & _solution) {
|
virtual bool cont(EOT & _solution) {
|
||||||
return (currentBit < _solution.size()) ;
|
return (currentIndex < neighborhoodSize) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -96,20 +104,12 @@ public:
|
||||||
* @return the position in the Neighborhood
|
* @return the position in the Neighborhood
|
||||||
*/
|
*/
|
||||||
unsigned int position(){
|
unsigned int position(){
|
||||||
return currentBit;
|
return currentIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the class id.
|
|
||||||
* @return the class name as a std::string
|
|
||||||
*/
|
|
||||||
virtual std::string className() const { return "moBitNeighborhood"; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//Position in the neighborhood
|
unsigned int currentIndex;
|
||||||
unsigned int currentBit;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
102
branches/newMo/src/neighborhood/moRndWithReplNeighborhood.h
Normal file
102
branches/newMo/src/neighborhood/moRndWithReplNeighborhood.h
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
<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 <utils/eoRng.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Random With replacement Neighborhood
|
||||||
|
*/
|
||||||
|
template< class N >
|
||||||
|
class moRndWithReplNeighborhood : 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 _neighborhood 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
129
branches/newMo/src/neighborhood/moRndWithoutReplNeighborhood.h
Normal file
129
branches/newMo/src/neighborhood/moRndWithoutReplNeighborhood.h
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
<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 <utils/eoRng.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Random without replacement Neighborhood
|
||||||
|
*/
|
||||||
|
template< class N >
|
||||||
|
class moRndWithoutReplNeighborhood : 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 _neighborhood 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
|
||||||
|
* @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];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned int maxIndex;
|
||||||
|
std::vector<unsigned int> indexVector;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -52,7 +52,11 @@
|
||||||
|
|
||||||
#include <neighborhood/moBackableNeighbor.h>
|
#include <neighborhood/moBackableNeighbor.h>
|
||||||
#include <neighborhood/moBitNeighbor.h>
|
#include <neighborhood/moBitNeighbor.h>
|
||||||
#include <neighborhood/moBitNeighborhood.h>
|
#include <neighborhood/moIndexNeighborhood.h>
|
||||||
|
#include <neighborhood/moIndexNeighbor.h>
|
||||||
|
#include <neighborhood/moOrderNeighborhood.h>
|
||||||
|
#include <neighborhood/moRndWithReplNeighborhood.h>
|
||||||
|
#include <neighborhood/moRndWithoutReplNeighborhood.h>
|
||||||
#include <neighborhood/moNeighbor.h>
|
#include <neighborhood/moNeighbor.h>
|
||||||
#include <neighborhood/moNeighborhood.h>
|
#include <neighborhood/moNeighborhood.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ LINK_DIRECTORIES(${PARADISEO_EO_BIN_DIR}/lib)
|
||||||
SET (TEST_LIST
|
SET (TEST_LIST
|
||||||
t-moNeighbor
|
t-moNeighbor
|
||||||
t-moBitNeighbor
|
t-moBitNeighbor
|
||||||
t-moBitNeighborhood
|
t-moOrderNeighborhood
|
||||||
t-moFullEvalByCopy
|
t-moFullEvalByCopy
|
||||||
t-moFullEvalByModif
|
t-moFullEvalByModif
|
||||||
t-moSimpleHCexplorer)
|
t-moSimpleHCexplorer)
|
||||||
|
|
|
||||||
|
|
@ -51,10 +51,6 @@ int main(){
|
||||||
moBitNeighbor<int> test1;
|
moBitNeighbor<int> test1;
|
||||||
assert(test1.index()==0);
|
assert(test1.index()==0);
|
||||||
|
|
||||||
//verif du constructeur indiquant le bit
|
|
||||||
moBitNeighbor<int> hop(34);
|
|
||||||
assert(hop.index()==34);
|
|
||||||
|
|
||||||
//verif du setter d'index et du constructeur de copy
|
//verif du setter d'index et du constructeur de copy
|
||||||
test1.index(6);
|
test1.index(6);
|
||||||
test1.fitness(2);
|
test1.fitness(2);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
<t-moBitNeighborhood.cpp>
|
<t-moOrderNeighborhood.cpp>
|
||||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
Sébastien Verel, Arnaud Liefooghe, Jérémie Humeau
|
||||||
|
|
@ -32,14 +32,16 @@
|
||||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <neighborhood/moBitNeighborhood.h>
|
#include <neighborhood/moOrderNeighborhood.h>
|
||||||
|
#include <neighborhood/moBitNeighbor.h>
|
||||||
|
#include <ga/eoBit.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
std::cout << "[t-moBitNeighborhood] => START" << std::endl;
|
std::cout << "[t-moOrderNeighborhood] => START" << std::endl;
|
||||||
|
|
||||||
//init sol
|
//init sol
|
||||||
eoBit<int> sol;
|
eoBit<int> sol;
|
||||||
|
|
@ -50,7 +52,7 @@ int main(){
|
||||||
moBitNeighbor<int> neighbor;
|
moBitNeighbor<int> neighbor;
|
||||||
|
|
||||||
//verif du constructeur vide
|
//verif du constructeur vide
|
||||||
moBitNeighborhood<moBitNeighbor<int> > test;
|
moOrderNeighborhood<moBitNeighbor<int> > test(3);
|
||||||
assert(test.position()==0);
|
assert(test.position()==0);
|
||||||
|
|
||||||
//verif du hasneighbor
|
//verif du hasneighbor
|
||||||
|
|
@ -72,6 +74,6 @@ int main(){
|
||||||
test.next(sol, neighbor);
|
test.next(sol, neighbor);
|
||||||
assert(!test.cont(sol));
|
assert(!test.cont(sol));
|
||||||
|
|
||||||
std::cout << "[t-moBitNeighborhood] => OK" << std::endl;
|
std::cout << "[t-moOrderNeighborhood] => OK" << std::endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +25,7 @@ using namespace std;
|
||||||
// fitness function
|
// fitness function
|
||||||
#include <funcOneMax.h>
|
#include <funcOneMax.h>
|
||||||
#include <eoInt.h>
|
#include <eoInt.h>
|
||||||
#include <neighborhood/moBitNeighborhood.h>
|
#include <neighborhood/moOrderNeighborhood.h>
|
||||||
#include <oneMaxBitNeighbor.h>
|
#include <oneMaxBitNeighbor.h>
|
||||||
|
|
||||||
#include <eval/moFullEvalByModif.h>
|
#include <eval/moFullEvalByModif.h>
|
||||||
|
|
@ -39,7 +39,7 @@ using namespace std;
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
typedef eoBit<unsigned> Indi;
|
typedef eoBit<unsigned> Indi;
|
||||||
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
||||||
typedef moBitNeighborhood<Neighbor> Neighborhood ;
|
typedef moOrderNeighborhood<Neighbor> Neighborhood ;
|
||||||
|
|
||||||
void main_function(int argc, char **argv)
|
void main_function(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
@ -138,7 +138,7 @@ void main_function(int argc, char **argv)
|
||||||
*
|
*
|
||||||
* ========================================================= */
|
* ========================================================= */
|
||||||
|
|
||||||
Neighborhood neighborhood ;
|
Neighborhood neighborhood(vecSize);
|
||||||
|
|
||||||
|
|
||||||
/* =========================================================
|
/* =========================================================
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue