Migration from SVN
This commit is contained in:
parent
d7d6c3a217
commit
8cd56f37db
29069 changed files with 0 additions and 4096888 deletions
111
mo/src/problems/bitString/moBitNeighbor.h
Normal file
111
mo/src/problems/bitString/moBitNeighbor.h
Normal 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> >, public moIndexNeighbor<eoBit<Fitness> >
|
||||
{
|
||||
public:
|
||||
typedef eoBit<Fitness> EOT;
|
||||
|
||||
using moBackableNeighbor<EOT>::fitness;
|
||||
using moIndexNeighbor<EOT>::key;
|
||||
|
||||
/**
|
||||
* move the solution
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _solution) {
|
||||
_solution[key] = !_solution[key];
|
||||
_solution.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* move back the solution (useful for the evaluation by modif)
|
||||
* @param _solution the solution to move back
|
||||
*/
|
||||
virtual void moveBack(EOT & _solution) {
|
||||
move(_solution);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the class name
|
||||
* @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);
|
||||
_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
|
||||
149
mo/src/problems/bitString/moBitsNeighbor.h
Normal file
149
mo/src/problems/bitString/moBitsNeighbor.h
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
<moBitsNeighbor.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moBitsNeighbor_h
|
||||
#define _moBitsNeighbor_h
|
||||
|
||||
#include <neighborhood/moNeighbor.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* Neighbor to flip several bits
|
||||
* of a solution of type eoBit
|
||||
*/
|
||||
template< class EOT, class Fitness=typename EOT::Fitness >
|
||||
class moBitsNeighbor : virtual public moNeighbor<EOT, Fitness>, public moBackableNeighbor<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
// position of bits which are flipped
|
||||
std::vector<unsigned int> bits;
|
||||
|
||||
// number of bits to flip
|
||||
unsigned int nBits;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
moBitsNeighbor() : moNeighbor<EOT, Fitness>() {}
|
||||
|
||||
/**
|
||||
* Copy Constructor
|
||||
* @param _source the neighbor to copy
|
||||
*/
|
||||
moBitsNeighbor(const moBitsNeighbor& _source) : moNeighbor<EOT, Fitness>(_source) {
|
||||
bits.resize(_source.bits.size());
|
||||
|
||||
nBits = _source.nBits;
|
||||
|
||||
for(unsigned i = 0; i < bits.size(); i++)
|
||||
this->bits[i] = _source.bits[i] ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignment operator
|
||||
* @param _source the source neighbor
|
||||
*/
|
||||
moBitsNeighbor<EOT, Fitness> & operator=(const moBitsNeighbor<EOT, Fitness> & _source) {
|
||||
moNeighbor<EOT, Fitness>::operator=(_source);
|
||||
|
||||
if (bits.size() != _source.bits.size())
|
||||
bits.resize(_source.bits.size());
|
||||
|
||||
nBits = _source.nBits;
|
||||
|
||||
for(unsigned i = 0; i < bits.size(); i++)
|
||||
this->bits[i] = _source.bits[i] ;
|
||||
|
||||
return *this ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class Name
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moBitsNeighbor";
|
||||
}
|
||||
|
||||
/**
|
||||
* flipped the bits according to the bits vector
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT& _solution) {
|
||||
for(unsigned i = 0; i < nBits; i++)
|
||||
_solution[ this->bits[i] ] = !_solution[ this->bits[i] ];
|
||||
}
|
||||
|
||||
/**
|
||||
* flipped the bits according to the bits vector
|
||||
* @param _solution the solution to move back
|
||||
*/
|
||||
virtual void moveBack(EOT& _solution) {
|
||||
for(unsigned i = 0; i < nBits; i++)
|
||||
_solution[ this->bits[i] ] = !_solution[ this->bits[i] ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _neighbor a neighbor
|
||||
* @return if _neighbor and this one are equals
|
||||
*/
|
||||
virtual bool equals(moBitsNeighbor<EOT,Fitness> & _neighbor) {
|
||||
if (nBits != _neighbor.nBits)
|
||||
return false;
|
||||
else {
|
||||
unsigned int i = 0;
|
||||
|
||||
while ((i < nBits) && (bits[i] == _neighbor.bits[i])) i++;
|
||||
|
||||
if (i < nBits)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 << this->fitness() << " " << nBits ;
|
||||
for(unsigned int i = 0; i < nBits; i++)
|
||||
_os << " " << bits[i] ;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
125
mo/src/problems/bitString/moBitsNeighborhood.h
Normal file
125
mo/src/problems/bitString/moBitsNeighborhood.h
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
<moBitsNeighborhood.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moBitsNeighborhood_h
|
||||
#define _moBitsNeighborhood_h
|
||||
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* A neighborhood for bit string solutions
|
||||
* where several bits could be flipped
|
||||
* in a given Hamming distance
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moBitsNeighborhood : public moNeighborhood<Neighbor>
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Define type of a solution corresponding to Neighbor
|
||||
*/
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _length bit string length
|
||||
* @param _nBits maximum number of bits to flip (radius of the neighborhood)
|
||||
* @param _exactDistance when true, only neighbor with exactly k bits flip are considered, other neighbor <= Hamming distance k
|
||||
*/
|
||||
moBitsNeighborhood(unsigned _length, unsigned _nBits, bool _exactDistance = false): moNeighborhood<Neighbor>(), length(_length), nBits(_nBits) {
|
||||
// neighborhood size :
|
||||
// for distance == nBits : length \choose nBits = length! / ( (length - nBits)! * nBits!)
|
||||
// for distance <= nBits : sum of previous distances
|
||||
if (_exactDistance) {
|
||||
neighborhoodSize = numberOfNeighbors(nBits);
|
||||
} else {
|
||||
neighborhoodSize = 0;
|
||||
for(int d = 1; d <= nBits; d++)
|
||||
neighborhoodSize += numberOfNeighbors(d);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Number fo neighbors at Hamming distance d
|
||||
*
|
||||
* @param d Hamming distance
|
||||
*/
|
||||
unsigned int numberOfNeighbors(unsigned d) {
|
||||
unsigned int fact_nBits = 1;
|
||||
|
||||
for(unsigned k = 1; k <= d; k++)
|
||||
fact_nBits *= k;
|
||||
|
||||
unsigned int fact_length = 1;
|
||||
|
||||
for(unsigned k = length; k > length - d; k--)
|
||||
fact_length *= k;
|
||||
|
||||
return fact_length / fact_nBits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if it exist a neighbor
|
||||
* @param _solution the solution to explore
|
||||
* @return true if the neighborhood was not empty (bit string larger than 0)
|
||||
*/
|
||||
virtual bool hasNeighbor(EOT& _solution) {
|
||||
return _solution.size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class Name
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moBitsNeighborhood";
|
||||
}
|
||||
|
||||
protected:
|
||||
// length of the bit strings
|
||||
unsigned int length;
|
||||
|
||||
// radius of the neighborhood
|
||||
unsigned int nBits;
|
||||
|
||||
// size of the neighborhood
|
||||
unsigned int neighborhoodSize;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
199
mo/src/problems/bitString/moBitsWithReplNeighborhood.h
Normal file
199
mo/src/problems/bitString/moBitsWithReplNeighborhood.h
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
<moBitsWithReplNeighborhood.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moBitsWithReplNeighborhood_h
|
||||
#define _moBitsWithReplNeighborhood_h
|
||||
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
#include <problems/bitString/moBitsNeighborhood.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* A neighborhood for bit string solutions
|
||||
* where several bits could be flipped
|
||||
* under a given Hamming distance
|
||||
*
|
||||
* The neighborhood is explored in a random order
|
||||
* Each neighbors is visited once time
|
||||
* and the number of visited neighbors is a parameter
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moBitsWithReplNeighborhood : public moBitsNeighborhood<Neighbor>
|
||||
{
|
||||
using moBitsNeighborhood<Neighbor>::neighborhoodSize;
|
||||
using moBitsNeighborhood<Neighbor>::length;
|
||||
using moBitsNeighborhood<Neighbor>::nBits;
|
||||
using moBitsNeighborhood<Neighbor>::numberOfNeighbors;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Define type of a solution corresponding to Neighbor
|
||||
*/
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param _length bit string length
|
||||
* @param _nBits maximum number of bits to flip (radius of the neighborhood)
|
||||
* @param _sampleSize number of neighbor to sample in the neighborhood, if 0 all the neighborhood is sampled
|
||||
* @param _exactDistance when true, only neighbor with exactly k bits flip are considered, other neighbor <= Hamming distance k
|
||||
*/
|
||||
moBitsWithReplNeighborhood(unsigned _length, unsigned _nBits, unsigned _sampleSize, bool _exactDistance = false): moBitsNeighborhood<Neighbor>(_length, _nBits, _exactDistance), sampleSize(_sampleSize), exactDistance(_exactDistance) {
|
||||
if (sampleSize > neighborhoodSize || sampleSize == 0)
|
||||
sampleSize = neighborhoodSize;
|
||||
|
||||
indexVector.resize(length);
|
||||
|
||||
for(unsigned int i = 0; i < length; i++)
|
||||
indexVector[i] = i;
|
||||
|
||||
if (!exactDistance) {
|
||||
nSize.resize(nBits);
|
||||
nSize[0] = numberOfNeighbors(1);
|
||||
for(unsigned d = 2; d <= nBits; d++)
|
||||
nSize[d - 1] = nSize[d - 2] + numberOfNeighbors(d);
|
||||
}
|
||||
|
||||
nNeighbors = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* one random neighbor at Hamming distance _n
|
||||
*
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the first neighbor
|
||||
* @param _n Hamming distance of the neighbor
|
||||
*/
|
||||
virtual void randomNeighbor(EOT & _solution, Neighbor & _neighbor, unsigned _n) {
|
||||
_neighbor.bits.resize(_n);
|
||||
_neighbor.nBits = _n;
|
||||
|
||||
unsigned i;
|
||||
unsigned b;
|
||||
unsigned tmp;
|
||||
|
||||
for(unsigned k = 0; k < _n; k++) {
|
||||
i = rng.random(length - k);
|
||||
b = indexVector[i];
|
||||
|
||||
_neighbor.bits[k] = b;
|
||||
|
||||
indexVector[i] = indexVector[length - k - 1];
|
||||
indexVector[length - k - 1] = b;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* one random neighbor at maximal Hamming distance _n
|
||||
*
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the first neighbor
|
||||
*/
|
||||
virtual void randomNeighbor(EOT & _solution, Neighbor & _neighbor) {
|
||||
if (exactDistance)
|
||||
randomNeighbor(_solution, _neighbor, nBits);
|
||||
else {
|
||||
// equiprobability between neighbors at maximal Hamming distance nBits
|
||||
unsigned n = rng.random(neighborhoodSize);
|
||||
|
||||
unsigned d = 1;
|
||||
while (n < nSize[d - 1]) d++;
|
||||
|
||||
randomNeighbor(_solution, _neighbor, d);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization of the neighborhood:
|
||||
* one random neighbor
|
||||
*
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the first neighbor
|
||||
*/
|
||||
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
||||
randomNeighbor(_solution, _neighbor);
|
||||
|
||||
nNeighbors = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the next neighbor
|
||||
* apply several bit flips on the solution
|
||||
* @param _solution the solution to explore (population of solutions)
|
||||
* @param _neighbor the next neighbor which in order of distance
|
||||
*/
|
||||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||
randomNeighbor(_solution, _neighbor);
|
||||
|
||||
nNeighbors++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if all neighbors are explored 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: population size larger or equals than 1
|
||||
*/
|
||||
virtual bool cont(EOT & _solution) {
|
||||
return nNeighbors < sampleSize ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class Name
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moBitsWithReplNeighborhood";
|
||||
}
|
||||
|
||||
protected:
|
||||
// vector of possible bits
|
||||
std::vector<unsigned int> indexVector;
|
||||
|
||||
// maximum number of visited neighbor i.e. number of neighbor to sample in the neighborhood
|
||||
unsigned int sampleSize;
|
||||
|
||||
// number of visited neighbors
|
||||
unsigned nNeighbors;
|
||||
|
||||
// when true, only neighbors at Hamming distance nBits
|
||||
bool exactDistance;
|
||||
|
||||
// the number of neighbors below the given distance
|
||||
std::vector<unsigned int> nSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
229
mo/src/problems/bitString/moBitsWithoutReplNeighborhood.h
Normal file
229
mo/src/problems/bitString/moBitsWithoutReplNeighborhood.h
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
<moBitsWithoutReplNeighborhood.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moBitsWithoutReplNeighborhood_h
|
||||
#define _moBitsWithoutReplNeighborhood_h
|
||||
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
#include <problems/bitString/moBitsNeighborhood.h>
|
||||
#include <utils/eoRNG.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* A neighborhood for bit string solutions
|
||||
* where several bits could be flipped
|
||||
* under a given Hamming distance
|
||||
*
|
||||
* The neighborhood is explored in a random order
|
||||
* Each neighbors is visited once time
|
||||
* and the number of visited neighbors is a parameter
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moBitsWithoutReplNeighborhood : public moBitsNeighborhood<Neighbor>
|
||||
{
|
||||
using moBitsNeighborhood<Neighbor>::neighborhoodSize;
|
||||
using moBitsNeighborhood<Neighbor>::length;
|
||||
using moBitsNeighborhood<Neighbor>::nBits;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Define type of a solution corresponding to Neighbor
|
||||
*/
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _length bit string length
|
||||
* @param _nBits maximum number of bits to flip (radius of the neighborhood)
|
||||
* @param _sampleSize number of neighbor to sample in the neighborhood, if 0 all the neighborhood is sampled
|
||||
* @param _exactDistance when true, only neighbor with exactly k bits flip are considered, other neighbor <= Hamming distance k
|
||||
*/
|
||||
moBitsWithoutReplNeighborhood(unsigned _length, unsigned _nBits, unsigned _sampleSize, bool _exactDistance = false): moBitsNeighborhood<Neighbor>(_length, _nBits, _exactDistance), sampleSize(_sampleSize) {
|
||||
if (sampleSize > neighborhoodSize || sampleSize == 0)
|
||||
sampleSize = neighborhoodSize;
|
||||
|
||||
indexVector.resize(neighborhoodSize);
|
||||
|
||||
for(unsigned int i = 0; i < neighborhoodSize; i++)
|
||||
indexVector[i] = i;
|
||||
|
||||
/* all the neighbors */
|
||||
if (neighborhoodSize >= 1000000) {
|
||||
std::cout << "moBitsNeighborhood::Warning : the neighborhood size is larger than 10^6 : " << neighborhoodSize << std::endl;
|
||||
}
|
||||
|
||||
int j;
|
||||
bool last;
|
||||
|
||||
unsigned firstIndex;
|
||||
if (_exactDistance)
|
||||
firstIndex = nBits;
|
||||
else
|
||||
firstIndex = 1;
|
||||
|
||||
for(int d = firstIndex; d <= nBits; d++) {
|
||||
std::vector<unsigned int> bits(d);
|
||||
|
||||
// the first one for this Hamming distance
|
||||
for(unsigned i = 0; i < d; i++)
|
||||
bits[i] = i;
|
||||
|
||||
neighborsVec.push_back(bits);
|
||||
|
||||
// the others ones
|
||||
last = false;
|
||||
|
||||
while(!last) {
|
||||
j = d - 1;
|
||||
|
||||
if (bits[j] < length - 1) {
|
||||
bits[j]++;
|
||||
neighborsVec.push_back(bits);
|
||||
} else {
|
||||
j--;
|
||||
|
||||
while ( (j >= 0) && (bits[j] + 1 == bits[j+1]) )
|
||||
j--;
|
||||
|
||||
if (j < 0) {
|
||||
last = true;
|
||||
} else {
|
||||
bits[j]++;
|
||||
|
||||
for(unsigned i = j+1; i < d; i++)
|
||||
bits[i] = bits[i-1] + 1;
|
||||
|
||||
neighborsVec.push_back(bits);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (neighborhoodSize != neighborsVec.size())
|
||||
std::cout << "moBitsNeighborhood::Warning -> error in the neighborhood size computation, please check... : " << neighborhoodSize << " / " << neighborsVec.size() << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization of the neighborhood:
|
||||
* apply several bit flips on the solution
|
||||
* @param _solution the solution to explore
|
||||
* @param _neighbor the first neighbor
|
||||
*/
|
||||
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
||||
maxIndex = neighborhoodSize ;
|
||||
|
||||
unsigned i = rng.random(maxIndex);
|
||||
key = indexVector[i];
|
||||
|
||||
unsigned tmp = indexVector[i];
|
||||
indexVector[i] = indexVector[maxIndex - 1];
|
||||
indexVector[maxIndex - 1] = tmp;
|
||||
maxIndex--;
|
||||
|
||||
_neighbor.bits.resize(nBits);
|
||||
setNeighbor(key, _neighbor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the next neighbor
|
||||
* apply several bit flips on the solution
|
||||
* @param _solution the solution to explore (population of solutions)
|
||||
* @param _neighbor the next neighbor which in order of distance
|
||||
*/
|
||||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||
unsigned i = rng.random(maxIndex);
|
||||
key = indexVector[i];
|
||||
|
||||
unsigned tmp = indexVector[i];
|
||||
indexVector[i] = indexVector[maxIndex - 1];
|
||||
indexVector[maxIndex - 1] = tmp;
|
||||
maxIndex--;
|
||||
|
||||
setNeighbor(key, _neighbor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if all neighbors are explored 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: population size larger or equals than 1
|
||||
*/
|
||||
virtual bool cont(EOT & _solution) {
|
||||
return neighborhoodSize - maxIndex < sampleSize ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class Name
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moBitsWithoutReplNeighborhood";
|
||||
}
|
||||
|
||||
unsigned int index() {
|
||||
return key;
|
||||
}
|
||||
|
||||
protected:
|
||||
// number of remainded neighbors to sample
|
||||
unsigned int maxIndex;
|
||||
|
||||
// vector of possible index
|
||||
std::vector<unsigned int> indexVector;
|
||||
|
||||
// maximum number of visited neighbor i.e. number of neighbor to sample in the neighborhood
|
||||
unsigned int sampleSize;
|
||||
|
||||
// list of neighbors
|
||||
std::vector< std::vector<unsigned int> > neighborsVec;
|
||||
|
||||
// key of the neighbor which is currently explored
|
||||
unsigned int key;
|
||||
|
||||
/**
|
||||
* Set the neighbor to the correct neighbor
|
||||
* @param _key index in neighborVec of the neighbor to set
|
||||
* @param _neighbor neighbor to set
|
||||
*/
|
||||
virtual void setNeighbor(unsigned _key, Neighbor & _neighbor) {
|
||||
_neighbor.nBits = neighborsVec[_key].size();
|
||||
|
||||
for(unsigned i = 0; i < _neighbor.nBits; i++)
|
||||
_neighbor.bits[i] = neighborsVec[_key][i];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
121
mo/src/problems/eval/moMaxSATincrEval.h
Normal file
121
mo/src/problems/eval/moMaxSATincrEval.h
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
<moMaxSATincrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moMaxSATincrEval_h
|
||||
#define _moMaxSATincrEval_h
|
||||
|
||||
#include <eval/moEval.h>
|
||||
#include <eval/maxSATeval.h>
|
||||
|
||||
/**
|
||||
* Incremental evaluation Function for the max SAT problem
|
||||
*/
|
||||
template <class Neighbor>
|
||||
class moMaxSATincrEval : public moEval <Neighbor> {
|
||||
public :
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
moMaxSATincrEval(MaxSATeval<EOT> & _fulleval) : fulleval(_fulleval) {
|
||||
nbClauses = _fulleval.nbClauses;
|
||||
nbVar = _fulleval.nbVar;
|
||||
|
||||
clauses = _fulleval.clauses;
|
||||
variables = _fulleval.variables;
|
||||
}
|
||||
|
||||
/**
|
||||
* incremental evaluation of the neighbor for the max SAT problem
|
||||
* @param _solution the solution (of type bit string) to move
|
||||
* @param _neighbor the neighbor (of type moBitNeigbor) to consider
|
||||
*/
|
||||
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
|
||||
// the difference of fitness
|
||||
int delta = 0;
|
||||
|
||||
// the flipped bit
|
||||
unsigned int bit = _neighbor.index();
|
||||
|
||||
// clauses which can be modified by the flipped bit
|
||||
const std::vector<int> & modifiedClauses = variables[bit + 1] ; // remember that the variables start at index 1 and not 0
|
||||
unsigned int size = modifiedClauses.size();
|
||||
|
||||
int nc;
|
||||
bool litt;
|
||||
|
||||
for (unsigned int k = 0; k < size; k++) {
|
||||
// number of the clause
|
||||
nc = modifiedClauses[k];
|
||||
|
||||
// negative means that the not(variable) is in the clause
|
||||
if (nc < 0) {
|
||||
nc = - nc;
|
||||
litt = !_solution[bit];
|
||||
} else
|
||||
litt = _solution[bit];
|
||||
|
||||
if (litt) {
|
||||
// the litteral was true and becomes false
|
||||
_solution[bit] = !_solution[bit];
|
||||
|
||||
if (!fulleval.clauseEval(nc, _solution))
|
||||
// the clause was true and becomes false
|
||||
delta--;
|
||||
|
||||
_solution[bit] = !_solution[bit];
|
||||
} else {
|
||||
// the litteral was false and becomes true
|
||||
if (!fulleval.clauseEval(nc, _solution))
|
||||
// the clause was false and becomes true
|
||||
delta++;
|
||||
}
|
||||
}
|
||||
|
||||
_neighbor.fitness(_solution.fitness() + delta);
|
||||
}
|
||||
|
||||
protected:
|
||||
// number of variables
|
||||
unsigned int nbVar;
|
||||
// number of clauses
|
||||
unsigned int nbClauses;
|
||||
|
||||
// list of clauses:
|
||||
// each clause has the number of the variable (from 1 to nbVar)
|
||||
// when the value, litteral = not(variable)
|
||||
std::vector<int> * clauses;
|
||||
|
||||
// list of variables:
|
||||
// for each variable, the list of clauses
|
||||
std::vector<int> * variables;
|
||||
|
||||
//full eval of the max SAT
|
||||
MaxSATeval<EOT> & fulleval;
|
||||
};
|
||||
|
||||
#endif
|
||||
58
mo/src/problems/eval/moOneMaxIncrEval.h
Normal file
58
mo/src/problems/eval/moOneMaxIncrEval.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
<moOneMaxIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moOneMaxIncrEval_H
|
||||
#define _moOneMaxIncrEval_H
|
||||
|
||||
#include <eval/moEval.h>
|
||||
|
||||
/**
|
||||
* Incremental evaluation Function for the OneMax problem
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moOneMaxIncrEval : public moEval<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/*
|
||||
* incremental evaluation of the neighbor for the oneMax problem
|
||||
* @param _solution the solution to move (bit string)
|
||||
* @param _neighbor the neighbor to consider (of type moBitNeigbor)
|
||||
*/
|
||||
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
|
||||
if (_solution[_neighbor.index()] == 0)
|
||||
_neighbor.fitness(_solution.fitness() + 1);
|
||||
else
|
||||
_neighbor.fitness(_solution.fitness() - 1);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
92
mo/src/problems/eval/moQAPIncrEval.h
Normal file
92
mo/src/problems/eval/moQAPIncrEval.h
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
<moQAPIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moQAPIncrEval_H
|
||||
#define _moQAPIncrEval_H
|
||||
|
||||
#include <eval/moEval.h>
|
||||
#include <eval/qapEval.h>
|
||||
|
||||
/**
|
||||
* Incremental evaluation Function for the QAP problem
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moQAPIncrEval : public moEval<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
* @param _qapEval full evaluation of the QAP problem
|
||||
*/
|
||||
moQAPIncrEval(QAPeval<EOT> & _qapEval) {
|
||||
n = _qapEval.getNbVar();
|
||||
A = _qapEval.getA();
|
||||
B = _qapEval.getB();
|
||||
}
|
||||
|
||||
/*
|
||||
* incremental evaluation of the neighbor for the QAP problem
|
||||
* @param _solution the solution to move (permutation)
|
||||
* @param _neighbor the neighbor to consider (of type moSwapNeigbor)
|
||||
*/
|
||||
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
|
||||
int d;
|
||||
int k;
|
||||
|
||||
unsigned i, j;
|
||||
|
||||
_neighbor.getIndices(n, i, j);
|
||||
|
||||
d = (A[i][i]-A[j][j])*(B[_solution[j]][_solution[j]]-B[_solution[i]][_solution[i]]) +
|
||||
(A[i][j]-A[j][i])*(B[_solution[j]][_solution[i]]-B[_solution[i]][_solution[j]]);
|
||||
|
||||
for (k = 0; k < n; k++)
|
||||
if (k != i && k != j)
|
||||
d = d + (A[k][i]-A[k][j])*(B[_solution[k]][_solution[j]]-B[_solution[k]][_solution[i]]) +
|
||||
(A[i][k]-A[j][k])*(B[_solution[j]][_solution[k]]-B[_solution[i]][_solution[k]]);
|
||||
|
||||
_neighbor.fitness(_solution.fitness() + d);
|
||||
}
|
||||
|
||||
private:
|
||||
// number of variables
|
||||
int n;
|
||||
|
||||
// matrix A
|
||||
int ** A;
|
||||
|
||||
// matrix B
|
||||
int ** B;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
88
mo/src/problems/eval/moRoyalRoadIncrEval.h
Normal file
88
mo/src/problems/eval/moRoyalRoadIncrEval.h
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
<moRoyalRoadIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moRoyalRoadIncrEval_H
|
||||
#define _moRoyalRoadIncrEval_H
|
||||
|
||||
#include <eval/moEval.h>
|
||||
#include <eval/royalRoadEval.h>
|
||||
|
||||
/**
|
||||
* Incremental evaluation Function for the Royal Road problem
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moRoyalRoadIncrEval : public moEval<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param _rr full evaluation of the Royal Road (to have the same block size)
|
||||
*/
|
||||
moRoyalRoadIncrEval(RoyalRoadEval<EOT> & _rr) : k(_rr.blockSize()) {}
|
||||
|
||||
/**
|
||||
* incremental evaluation of the neighbor for the Royal Road problem
|
||||
* @param _solution the solution to move (bit string)
|
||||
* @param _neighbor the neighbor to consider (of type moBitNeigbor)
|
||||
*/
|
||||
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
|
||||
// which block can be changed?
|
||||
unsigned int n = _neighbor.index() / k;
|
||||
|
||||
// complete block?
|
||||
unsigned int offset = n * k;
|
||||
|
||||
unsigned int j = 0;
|
||||
while (j < k && _solution[offset + j]) j++;
|
||||
|
||||
if (j == k) // the block is complete, so the fitness decreases from one
|
||||
_neighbor.fitness(_solution.fitness() - 1);
|
||||
else {
|
||||
if ((_solution[_neighbor.index()] == 0) && (offset + j == _neighbor.index())) { // can the block be filled?
|
||||
j++; // next bit
|
||||
while ( j < k && _solution[offset + j]) j++;
|
||||
|
||||
if (j == k) // the block can be filled, so the fitness increases from one
|
||||
_neighbor.fitness(_solution.fitness() + 1);
|
||||
else
|
||||
_neighbor.fitness(_solution.fitness());
|
||||
} else
|
||||
_neighbor.fitness(_solution.fitness());
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
// size of the blocks
|
||||
unsigned int k;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
124
mo/src/problems/eval/moUBQPBitsIncrEval.h
Normal file
124
mo/src/problems/eval/moUBQPBitsIncrEval.h
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
<moUBQPBitsIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moUBQPBitsIncrEval_H
|
||||
#define _moUBQPBitsIncrEval_H
|
||||
|
||||
#include <eval/moEval.h>
|
||||
#include <eval/ubqpEval.h>
|
||||
|
||||
/**
|
||||
* Incremental evaluation Function for the UBQPSimple problem
|
||||
* when several bits are flipped (moBitsNeighbor)
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moUBQPBitsIncrEval : public moEval<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
* @param _ubqpEval full evaluation of the UBQP problem
|
||||
*/
|
||||
moUBQPBitsIncrEval(UbqpEval<EOT> & _ubqpEval) {
|
||||
n = _ubqpEval.getNbVar();
|
||||
Q = _ubqpEval.getQ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Incremental evaluation of the neighbor for the UBQP problem (complexity O(n * k) when k bits are flipped)
|
||||
* @param _solution the solution to move (bit string)
|
||||
* @param _neighbor the neighbor to consider of type moBitsNeighbor (several bits are flipped)
|
||||
*/
|
||||
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
|
||||
unsigned int b;
|
||||
unsigned int j;
|
||||
int d, delta;
|
||||
|
||||
delta = 0;
|
||||
for(unsigned i = 0; i < _neighbor.nBits; i++) {
|
||||
b = _neighbor.bits[i];
|
||||
d = Q[b][b];
|
||||
|
||||
for(j = 0; j < b; j++)
|
||||
if (_solution[j] == 1)
|
||||
d += Q[b][j];
|
||||
|
||||
for(j = b+1; j < n; j++)
|
||||
if (_solution[j] == 1)
|
||||
d += Q[j][b];
|
||||
|
||||
if (_solution[b] == 0)
|
||||
delta += d;
|
||||
else
|
||||
delta -= d;
|
||||
|
||||
// move the solution on this bit
|
||||
_solution[b] = !_solution[b];
|
||||
}
|
||||
|
||||
// move back the solution
|
||||
for(unsigned i = 0; i < _neighbor.nBits; i++) {
|
||||
b = _neighbor.bits[i];
|
||||
_solution[b] = !_solution[b];
|
||||
}
|
||||
|
||||
_neighbor.fitness(_solution.fitness() + delta);
|
||||
}
|
||||
|
||||
/*
|
||||
* to get the matrix Q
|
||||
*
|
||||
* @return matrix Q
|
||||
*/
|
||||
int** getQ() {
|
||||
return Q;
|
||||
}
|
||||
|
||||
/*
|
||||
* to get the number of variable (bit string length)
|
||||
*
|
||||
* @return bit string length
|
||||
*/
|
||||
int getNbVar() {
|
||||
return n;
|
||||
}
|
||||
|
||||
private:
|
||||
// number of variables
|
||||
int n;
|
||||
|
||||
// matrix Q (supposed to be in lower triangular form)
|
||||
int ** Q;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
108
mo/src/problems/eval/moUBQPSimpleIncrEval.h
Normal file
108
mo/src/problems/eval/moUBQPSimpleIncrEval.h
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
<moUBQPSimpleIncrEval.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 _moUBQPSimpleIncrEval_H
|
||||
#define _moUBQPSimpleIncrEval_H
|
||||
|
||||
#include <eval/moEval.h>
|
||||
#include <eval/ubqpEval.h>
|
||||
|
||||
/**
|
||||
* Incremental evaluation Function for the UBQPSimple problem
|
||||
*/
|
||||
template< class Neighbor >
|
||||
class moUBQPSimpleIncrEval : public moEval<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
* @param _ubqpEval full evaluation of the UBQP problem
|
||||
*/
|
||||
moUBQPSimpleIncrEval(UbqpEval<EOT> & _ubqpEval) {
|
||||
n = _ubqpEval.getNbVar();
|
||||
Q = _ubqpEval.getQ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Incremental evaluation of the neighbor for the UBQP problem (linear time complexity)
|
||||
* @param _solution the solution to move (bit string)
|
||||
* @param _neighbor the neighbor to consider (of type moBitNeighbor)
|
||||
*/
|
||||
virtual void operator()(EOT & _solution, Neighbor & _neighbor) {
|
||||
unsigned int i = _neighbor.index();
|
||||
unsigned int j;
|
||||
|
||||
int d = Q[i][i];
|
||||
|
||||
for(j = 0; j < i; j++)
|
||||
if (_solution[j] == 1)
|
||||
d += Q[i][j];
|
||||
|
||||
for(j = i+1; j < n; j++)
|
||||
if (_solution[j] == 1)
|
||||
d += Q[j][i];
|
||||
|
||||
if (_solution[i] == 0)
|
||||
_neighbor.fitness(_solution.fitness() + d);
|
||||
else
|
||||
_neighbor.fitness(_solution.fitness() - d);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* to get the matrix Q
|
||||
*
|
||||
* @return matrix Q
|
||||
*/
|
||||
int** getQ() {
|
||||
return Q;
|
||||
}
|
||||
|
||||
/*
|
||||
* to get the number of variable (bit string length)
|
||||
*
|
||||
* @return bit string length
|
||||
*/
|
||||
int getNbVar() {
|
||||
return n;
|
||||
}
|
||||
|
||||
private:
|
||||
// number of variables
|
||||
int n;
|
||||
|
||||
// matrix Q (supposed to be in lower triangular form)
|
||||
int ** Q;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
161
mo/src/problems/eval/moUBQPdoubleIncrEvaluation.h
Normal file
161
mo/src/problems/eval/moUBQPdoubleIncrEvaluation.h
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
<moUBQPdoubleIncrEvaluation.h>
|
||||
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||
|
||||
Sebastien Verel, Arnaud Liefooghe, Jeremie 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 moUBQPdoubleIncrEvaluation_H
|
||||
#define moUBQPdoubleIncrEvaluation_H
|
||||
|
||||
#include <eval/moDoubleIncrEvaluation.h>
|
||||
#include <explorer/moNeighborhoodExplorer.h>
|
||||
#include <eval/moEval.h>
|
||||
|
||||
/**
|
||||
* The neighborhood evaluation for the UBQP
|
||||
* The double incremental evaluation is used
|
||||
*
|
||||
* BECAREFULL: This object must be added to the moCheckpoint of the local search (init method)
|
||||
*/
|
||||
template<class Neighbor>
|
||||
class moUBQPdoubleIncrEvaluation : public moDoubleIncrEvaluation<Neighbor>
|
||||
{
|
||||
public:
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
typedef typename EOT::Fitness Fitness;
|
||||
|
||||
using moDoubleIncrEvaluation<Neighbor>::deltaFitness;
|
||||
using moDoubleIncrEvaluation<Neighbor>::firstEval;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param _neighborhoodSize the size of the neighborhood
|
||||
* @param _incrEval the incremental evaluation of the UBQP
|
||||
*/
|
||||
moUBQPdoubleIncrEvaluation(unsigned int _neighborhoodSize, moUBQPSimpleIncrEval<Neighbor> & _incrEval) : moDoubleIncrEvaluation<Neighbor>(_neighborhoodSize), searchExplorer(NULL)
|
||||
{
|
||||
n = _incrEval.getNbVar();
|
||||
Q = _incrEval.getQ();
|
||||
}
|
||||
|
||||
void neighborhoodExplorer(moNeighborhoodExplorer<Neighbor> & _searchExplorer) {
|
||||
searchExplorer = & _searchExplorer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluation of the neighborhood
|
||||
* Here nothing to do
|
||||
*
|
||||
* @param _solution the current solution
|
||||
*/
|
||||
virtual void operator()(EOT & _solution) {
|
||||
if (firstEval) {
|
||||
firstEval = false;
|
||||
|
||||
// compute the delta in the simple incremental way O(n)
|
||||
unsigned int j;
|
||||
int d;
|
||||
for(unsigned i = 0; i < n; i++) {
|
||||
d = Q[i][i];
|
||||
|
||||
for(j = 0; j < i; j++)
|
||||
if (_solution[j])
|
||||
d += Q[i][j];
|
||||
|
||||
for(j = i+1; j < n; j++)
|
||||
if (_solution[j])
|
||||
d += Q[j][i];
|
||||
|
||||
if (_solution[i])
|
||||
d = - d;
|
||||
|
||||
deltaFitness[i] = d;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (searchExplorer->moveApplied()) {
|
||||
// compute the new fitness only when the solution has moved
|
||||
// the selectedNeighbor is the neighbor which is selected in the neighborhood
|
||||
// the movement is made on this neighbor
|
||||
// we suppose that the neighborhood is bit string neighborhood (indexed neighbor)
|
||||
unsigned iMove = searchExplorer->getSelectedNeighbor().index();
|
||||
|
||||
for(unsigned i = 0; i < n; i++) {
|
||||
if (i == iMove)
|
||||
deltaFitness[i] = - deltaFitness[i] ;
|
||||
else {
|
||||
if (_solution[i] != _solution[iMove])
|
||||
if (i < iMove)
|
||||
deltaFitness[i] += Q[iMove][i];
|
||||
else
|
||||
deltaFitness[i] += Q[i][iMove];
|
||||
else
|
||||
if (i < iMove)
|
||||
deltaFitness[i] -= Q[iMove][i];
|
||||
else
|
||||
deltaFitness[i] -= Q[i][iMove];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* to get the matrix Q
|
||||
*
|
||||
* @return matrix Q
|
||||
*/
|
||||
int** getQ() {
|
||||
return Q;
|
||||
}
|
||||
|
||||
/*
|
||||
* to get the number of variable (bit string length)
|
||||
*
|
||||
* @return bit string length
|
||||
*/
|
||||
int getNbVar() {
|
||||
return n;
|
||||
}
|
||||
|
||||
private:
|
||||
// number of variables
|
||||
int n;
|
||||
|
||||
// matrix Q (supposed to be in lower triangular form)
|
||||
int ** Q;
|
||||
|
||||
/** The search explorer of the local search */
|
||||
moNeighborhoodExplorer<Neighbor> * searchExplorer;
|
||||
};
|
||||
|
||||
#endif
|
||||
99
mo/src/problems/permutation/moIndexedSwapNeighbor.h
Normal file
99
mo/src/problems/permutation/moIndexedSwapNeighbor.h
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
<moIndexedSwapNeighbor.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 _moIndexedSwapNeighbor_h
|
||||
#define _moIndexedSwapNeighbor_h
|
||||
|
||||
#include <neighborhood/moBackableNeighbor.h>
|
||||
#include <neighborhood/moIndexNeighbor.h>
|
||||
|
||||
/**
|
||||
* Indexed Swap Neighbor: the position of the swap are computed according to the index
|
||||
*/
|
||||
template <class EOT, class Fitness=typename EOT::Fitness>
|
||||
class moIndexedSwapNeighbor: public moBackableNeighbor<EOT, Fitness>, public moIndexNeighbor<EOT>
|
||||
{
|
||||
public:
|
||||
|
||||
using moBackableNeighbor<EOT>::fitness;
|
||||
using moIndexNeighbor<EOT>::key;
|
||||
|
||||
/**
|
||||
* Apply the swap
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT& _solution) {
|
||||
unsigned int tmp;
|
||||
unsigned i, j;
|
||||
|
||||
this->getIndices(_solution.size(), i, j);
|
||||
|
||||
tmp = _solution[i];
|
||||
_solution[i] = _solution[j];
|
||||
_solution[j] = tmp;
|
||||
|
||||
_solution.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class Name
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moIndexedSwapNeighbor";
|
||||
}
|
||||
|
||||
/**
|
||||
* apply the swap to restore the solution (use by moFullEvalByModif)
|
||||
* @param _solution the solution to move back
|
||||
*/
|
||||
virtual void moveBack(EOT& _solution) {
|
||||
|
||||
move(_solution);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the two indexes of the swap
|
||||
* @param N size of the permutation
|
||||
* @param _first first index
|
||||
* @param _second second index
|
||||
*/
|
||||
void getIndices(unsigned N, unsigned int & _first, unsigned int & _second) {
|
||||
unsigned int n = (unsigned int) ( (1 + sqrt(1 + 8 * key)) / 2);
|
||||
|
||||
_first = key - (n - 1) * n / 2;
|
||||
_second = N - 1 - (n - 1 - _first);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
115
mo/src/problems/permutation/moShiftNeighbor.h
Normal file
115
mo/src/problems/permutation/moShiftNeighbor.h
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
<moShiftNeighbor.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 _moShiftNeighbor_h
|
||||
#define _moShiftNeighbor_h
|
||||
|
||||
#include <neighborhood/moIndexNeighbor.h>
|
||||
|
||||
/**
|
||||
* Indexed Shift Neighbor
|
||||
*/
|
||||
template <class EOT, class Fitness=typename EOT::Fitness>
|
||||
class moShiftNeighbor: public moIndexNeighbor<EOT, Fitness>
|
||||
{
|
||||
public:
|
||||
|
||||
using moIndexNeighbor<EOT, Fitness>::key;
|
||||
|
||||
/**
|
||||
* Apply move on a solution regarding a key
|
||||
* @param _sol the solution to move
|
||||
*/
|
||||
virtual void move(EOT & _sol) {
|
||||
unsigned int tmp ;
|
||||
size=_sol.size();
|
||||
translate(key+1);
|
||||
// keep the first component to change
|
||||
tmp = _sol[first];
|
||||
// shift
|
||||
if (first < second) {
|
||||
for (unsigned int i=first; i<second-1; i++)
|
||||
_sol[i] = _sol[i+1];
|
||||
// shift the first component
|
||||
_sol[second-1] = tmp;
|
||||
}
|
||||
else { /* first > second*/
|
||||
for (unsigned int i=first; i>second; i--)
|
||||
_sol[i] = _sol[i-1];
|
||||
// shift the first component
|
||||
_sol[second] = tmp;
|
||||
}
|
||||
_sol.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* fix two indexes regarding a key
|
||||
* @param _key the key allowing to compute the two indexes for the shift
|
||||
*/
|
||||
void translate(unsigned int _key) {
|
||||
int step;
|
||||
int val = _key;
|
||||
int tmpSize = size * (size-1) / 2;
|
||||
// moves from left to right
|
||||
if (val <= tmpSize) {
|
||||
step = size - 1;
|
||||
first = 0;
|
||||
while ((val - step) > 0) {
|
||||
val = val - step;
|
||||
step--;
|
||||
first++;
|
||||
}
|
||||
second = first + val + 1;
|
||||
}
|
||||
// moves from right to left (equivalent moves are avoided)
|
||||
else { /* val > tmpSize */
|
||||
val = val - tmpSize;
|
||||
step = size - 2;
|
||||
second = 0;
|
||||
while ((val - step) > 0) {
|
||||
val = val - step;
|
||||
step--;
|
||||
second++;
|
||||
}
|
||||
first = second + val + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void print() {
|
||||
std::cout << key << ": [" << first << ", " << second << "] -> " << (*this).fitness() << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int first;
|
||||
unsigned int second;
|
||||
unsigned int size;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
105
mo/src/problems/permutation/moSwapNeighbor.h
Normal file
105
mo/src/problems/permutation/moSwapNeighbor.h
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
<moSwapNeighbor.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 _moSwapNeighbor_h
|
||||
#define _moSwapNeighbor_h
|
||||
|
||||
#include <neighborhood/moBackableNeighbor.h>
|
||||
|
||||
/**
|
||||
* Swap Neighbor
|
||||
*/
|
||||
template<class EOT, class Fitness = typename EOT::Fitness>
|
||||
class moSwapNeighbor: public moBackableNeighbor<EOT, Fitness> {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Apply the swap
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT& _solution) {
|
||||
EOT tmp(1);
|
||||
tmp[0] = _solution[indices.first];
|
||||
_solution[indices.first] = _solution[indices.second];
|
||||
_solution[indices.second] = tmp[0];
|
||||
_solution.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* apply the swap to restore the solution (use by moFullEvalByModif)
|
||||
* @param _solution the solution to move back
|
||||
*/
|
||||
virtual void moveBack(EOT& _solution) {
|
||||
move(_solution);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter to fix the two indexes to swap
|
||||
* @param _first first index
|
||||
* @param _second second index
|
||||
*/
|
||||
void setIndices(unsigned int _first, unsigned int _second) {
|
||||
indices.first = _first;
|
||||
indices.second = _second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the two indexes to swap
|
||||
* @param _first first index
|
||||
* @param _second second index
|
||||
*/
|
||||
void getIndices(unsigned int & _first, unsigned int & _second) {
|
||||
_first = indices.first;
|
||||
_second = indices.second;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _neighbor a neighbor
|
||||
* @return if _neighbor and this one are equals
|
||||
*/
|
||||
virtual bool equals(moSwapNeighbor<EOT,Fitness>& _neighbor) {
|
||||
unsigned f, s;
|
||||
_neighbor.getIndices(f, s);
|
||||
return (((indices.first == f) && (indices.second == s)) || ((indices.first == s) && (indices.second == f)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the Neighbor
|
||||
*/
|
||||
void print() {
|
||||
std::cout << "[" << indices.first << ", " << indices.second << "] -> "
|
||||
<< (*this).fitness() << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::pair<unsigned int, unsigned int> indices;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
100
mo/src/problems/permutation/moSwapNeighborhood.h
Normal file
100
mo/src/problems/permutation/moSwapNeighborhood.h
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
<moSwapNeighborhood.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 _moSwapNeighborhood_h
|
||||
#define _moSwapNeighborhood_h
|
||||
|
||||
#include <problems/permutation/moSwapNeighbor.h>
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
|
||||
/**
|
||||
* Swap Neighborhood
|
||||
*/
|
||||
template <class EOT, class Fitness=typename EOT::Fitness>
|
||||
class moSwapNeighborhood : public moNeighborhood<moSwapNeighbor<EOT, Fitness> >
|
||||
{
|
||||
public:
|
||||
typedef moSwapNeighbor<EOT, Fitness> Neighbor;
|
||||
|
||||
/**
|
||||
* @return true if there is at least an available neighbor
|
||||
*/
|
||||
virtual bool hasNeighbor(EOT& _solution) {
|
||||
return (_solution.size() > 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialization of the neighborhood
|
||||
* @param _solution the solution to explore
|
||||
* @param _current the first neighbor
|
||||
*/
|
||||
virtual void init(EOT& _solution, Neighbor& _current) {
|
||||
indices.first=0;
|
||||
indices.second=1;
|
||||
_current.setIndices(0,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the next neighbor
|
||||
* @param _solution the solution to explore
|
||||
* @param _current the next neighbor
|
||||
*/
|
||||
virtual void next(EOT& _solution, Neighbor& _current) {
|
||||
if (indices.second==_solution.size()-1) {
|
||||
indices.first++;
|
||||
indices.second=indices.first+1;
|
||||
}
|
||||
else
|
||||
indices.second++;
|
||||
_current.setIndices(indices.first, indices.second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if there is again a neighbor
|
||||
* @param _solution the solution to explore
|
||||
* @return true if there is again a neighbor not explored
|
||||
*/
|
||||
virtual bool cont(EOT& _solution) {
|
||||
return !((indices.first == (_solution.size()-2)) && (indices.second == (_solution.size()-1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class Name
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moSwapNeighborhood";
|
||||
}
|
||||
|
||||
private:
|
||||
std::pair<unsigned int, unsigned int> indices;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
104
mo/src/problems/permutation/moTwoOptExNeighbor.h
Executable file
104
mo/src/problems/permutation/moTwoOptExNeighbor.h
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
<moTwoOptExNeighbor.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 _moTwoOptExNeighbor_h
|
||||
#define _moTwoOptExNeighbor_h
|
||||
|
||||
#include <neighborhood/moBackableNeighbor.h>
|
||||
|
||||
/**
|
||||
* Two-opt exchange neighbor
|
||||
*/
|
||||
template<class EOT, class Fitness = typename EOT::Fitness>
|
||||
class moTwoOptExNeighbor: public moBackableNeighbor<EOT, Fitness> {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Apply the move
|
||||
* @param _solution the solution to move
|
||||
*/
|
||||
virtual void move(EOT& _solution) {
|
||||
unsigned int stop = (indices.second - indices.first + 1) / 2;
|
||||
for (unsigned int i=0; i<stop; i++) {
|
||||
std::swap(_solution[indices.first + i], _solution[indices.second - i]);
|
||||
}
|
||||
_solution.invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* apply the move to restore the solution (use by moFullEvalByModif)
|
||||
* @param _solution the solution to move back
|
||||
*/
|
||||
virtual void moveBack(EOT& _solution) {
|
||||
move(_solution);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter to fix the two indexes to move
|
||||
* @param _first first index
|
||||
* @param _second second index
|
||||
*/
|
||||
void setIndices(unsigned int _first, unsigned int _second) {
|
||||
indices.first = _first;
|
||||
indices.second = _second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the two indexes to move
|
||||
* @param _first first index
|
||||
* @param _second second index
|
||||
*/
|
||||
void getIndices(unsigned int & _first, unsigned int & _second) {
|
||||
_first = indices.first;
|
||||
_second = indices.second;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _neighbor a neighbor
|
||||
* @return if _neighbor and this one are equals
|
||||
*/
|
||||
virtual bool equals(moTwoOptExNeighbor<EOT,Fitness> & _neighbor) {
|
||||
unsigned f, s;
|
||||
_neighbor.getIndices(f, s);
|
||||
return ((indices.first == f) && (indices.second == s) || (indices.first == s) && (indices.second == f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the neighbor
|
||||
*/
|
||||
void print() {
|
||||
std::cout << "[" << indices.first << ", " << indices.second << "] -> " << (*this).fitness() << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::pair<unsigned int, unsigned int> indices;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
103
mo/src/problems/permutation/moTwoOptExNeighborhood.h
Executable file
103
mo/src/problems/permutation/moTwoOptExNeighborhood.h
Executable file
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
<moTwoOptExNeighborhood.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 _moTwoOptExNeighborhood_h
|
||||
#define _moTwoOptExNeighborhood_h
|
||||
|
||||
#include <problems/permutation/moTwoOptExNeighbor.h>
|
||||
#include <neighborhood/moNeighborhood.h>
|
||||
|
||||
#include <neighborhood/moIndexNeighborhood.h>
|
||||
|
||||
/**
|
||||
* Two-opt exchange neighborhood
|
||||
*/
|
||||
|
||||
template <class EOT, class Fitness=typename EOT::Fitness>
|
||||
class moTwoOptExNeighborhood : public moNeighborhood< moTwoOptExNeighbor<EOT,Fitness> >
|
||||
{
|
||||
public:
|
||||
typedef moTwoOptExNeighbor<EOT, Fitness> Neighbor;
|
||||
|
||||
/**
|
||||
* @return true if there is at least an available neighbor
|
||||
*/
|
||||
virtual bool hasNeighbor(EOT& _solution) {
|
||||
return (_solution.size() > 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialization of the neighborhood
|
||||
* @param _solution the solution to explore
|
||||
* @param _current the first neighbor
|
||||
*/
|
||||
virtual void init(EOT& _solution, Neighbor& _current) {
|
||||
indices.first=0;
|
||||
indices.second=1;
|
||||
_current.setIndices(0,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the next neighbor
|
||||
* @param _solution the solution to explore
|
||||
* @param _current the next neighbor
|
||||
*/
|
||||
virtual void next(EOT& _solution, Neighbor& _current) {
|
||||
if (indices.second==_solution.size()-1) {
|
||||
indices.first++;
|
||||
indices.second=indices.first+1;
|
||||
}
|
||||
else
|
||||
indices.second++;
|
||||
_current.setIndices(indices.first, indices.second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if there is again a neighbor
|
||||
* @param _solution the solution to explore
|
||||
* @return true if there is again a neighbor not explored
|
||||
*/
|
||||
virtual bool cont(EOT& _solution) {
|
||||
return !((indices.first == (_solution.size()-2)) && (indices.second == (_solution.size()-1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class Name
|
||||
* @return the class name as a std::string
|
||||
*/
|
||||
virtual std::string className() const {
|
||||
return "moTwoOptExNeighborhood";
|
||||
}
|
||||
|
||||
private:
|
||||
std::pair<unsigned int, unsigned int> indices;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue