Merge branch 'master' of git://scm.gforge.inria.fr/paradiseo/paradiseo
This commit is contained in:
commit
b7426894b0
27 changed files with 617 additions and 67 deletions
4
INSTALL
4
INSTALL
|
|
@ -183,9 +183,9 @@ Easy, isn't it ?
|
||||||
|
|
||||||
By performing tests, you can check your installation.
|
By performing tests, you can check your installation.
|
||||||
Testing is disable by default, except if you build with the full install type.
|
Testing is disable by default, except if you build with the full install type.
|
||||||
To enable testing, define -DENABLE_TESTING when you launch cmake.
|
To enable testing, define -DENABLE_CMAKE_TESTING=true when you launch cmake.
|
||||||
|
|
||||||
To perform tests simply type ctest ou make test.
|
To perform tests simply type ctest or make test.
|
||||||
|
|
||||||
------------------------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------
|
||||||
5.2 REPORTING
|
5.2 REPORTING
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ install(DIRECTORY do es ga gp other utils
|
||||||
add_subdirectory(es)
|
add_subdirectory(es)
|
||||||
add_subdirectory(ga)
|
add_subdirectory(ga)
|
||||||
add_subdirectory(utils)
|
add_subdirectory(utils)
|
||||||
add_subdirectory(serial)
|
#add_subdirectory(serial)
|
||||||
|
|
||||||
if(ENABLE_PYEO)
|
if(ENABLE_PYEO)
|
||||||
add_subdirectory(pyeo)
|
add_subdirectory(pyeo)
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@ private :
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
typedef typename EOT::Fitness::fitness_traits traits;
|
//typedef typename EOT::Fitness::fitness_traits traits;
|
||||||
|
|
||||||
std::vector<std::vector<unsigned> > S(_pop.size()); // which individuals does guy i dominate
|
std::vector<std::vector<unsigned> > S(_pop.size()); // which individuals does guy i dominate
|
||||||
std::vector<unsigned> n(_pop.size(), 0); // how many individuals dominate guy i
|
std::vector<unsigned> n(_pop.size(), 0); // how many individuals dominate guy i
|
||||||
|
|
|
||||||
126
eo/src/eoPartiallyMappedXover.h
Normal file
126
eo/src/eoPartiallyMappedXover.h
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
/*
|
||||||
|
<eoPartiallyMappedXover.h>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
|
Sébastien Verel
|
||||||
|
|
||||||
|
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 eoPartiallyMappedXover__h
|
||||||
|
#define eoPartiallyMappedXover__h
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <utils/eoRNG.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Partially Mapped CrossOver (PMX)
|
||||||
|
* for permutation representation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template <class EOT>
|
||||||
|
class eoPartiallyMappedXover : public eoQuadOp<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param _solution1 The first solution
|
||||||
|
* @param _solution2 The second solution
|
||||||
|
* @return true if the solution has changed
|
||||||
|
*/
|
||||||
|
bool operator()(EOT & _solution1, EOT & _solution2) {
|
||||||
|
if (_solution1.size() > 1) {
|
||||||
|
// random indexes such that i1 < i2
|
||||||
|
int i1 = rng.random(_solution1.size());
|
||||||
|
int i2 = rng.random(_solution1.size());
|
||||||
|
|
||||||
|
while (i1 == i2)
|
||||||
|
i2 = rng.random(_solution1.size());
|
||||||
|
|
||||||
|
if (i1 > i2) {
|
||||||
|
int tmp = i1;
|
||||||
|
i1 = i2;
|
||||||
|
i2 = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the permutations between s1 and s2
|
||||||
|
int * p1 = new int[_solution1.size()];
|
||||||
|
int * p2 = new int[_solution1.size()];
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < _solution1.size(); i++) {
|
||||||
|
p1[i] = -1;
|
||||||
|
p2[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = i1; i <= i2; i++) {
|
||||||
|
p1[ _solution2[i] ] = _solution1[i] ;
|
||||||
|
p2[ _solution1[i] ] = _solution2[i] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace if necessary
|
||||||
|
for(i = 0; i < i1; i++) {
|
||||||
|
while (p1[ _solution1[i] ] != -1)
|
||||||
|
_solution1[i] = p1[_solution1[i]];
|
||||||
|
while (p2[ _solution2[i] ] != -1)
|
||||||
|
_solution2[i] = p2[_solution2[i]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// swap between solution1 and solution2 for [i1..i2]
|
||||||
|
for(i = i1; i <= i2; i++) {
|
||||||
|
_solution1[i] = p2[ _solution1[i] ];
|
||||||
|
_solution2[i] = p1[ _solution2[i] ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace if necessary
|
||||||
|
for(i = i2 + 1; i < _solution1.size(); i++) {
|
||||||
|
while (p1[ _solution1[i] ] != -1)
|
||||||
|
_solution1[i] = p1[_solution1[i]];
|
||||||
|
while (p2[ _solution2[i] ] != -1)
|
||||||
|
_solution2[i] = p2[_solution2[i]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// invalidate the solutions because they have been modified
|
||||||
|
_solution1.invalidate();
|
||||||
|
_solution2.invalidate();
|
||||||
|
|
||||||
|
delete [] p1;
|
||||||
|
delete [] p2;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class name.
|
||||||
|
*/
|
||||||
|
virtual std::string className() const {
|
||||||
|
return "eoPartiallyMappedXover";
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -56,6 +56,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool operator() (const eoPop < EOT > & _pop)
|
virtual bool operator() (const eoPop < EOT > & _pop)
|
||||||
{
|
{
|
||||||
|
(void)_pop;
|
||||||
time_t elapsed = (time_t) difftime(time(NULL), start);
|
time_t elapsed = (time_t) difftime(time(NULL), start);
|
||||||
if (elapsed >= max)
|
if (elapsed >= max)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,15 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
SV: from eoHammingDistance, it is in fact the L1 distance
|
||||||
|
|
||||||
This is a generic class for L1 distance computation:
|
This is a generic class for L1 distance computation:
|
||||||
assumes the 2 things are std::vectors of something
|
assumes the 2 things are std::vectors of something
|
||||||
that is double-castable
|
that is double-castable
|
||||||
For bitstrings, this is the Hamming distance
|
For bitstrings, this is the Hamming distance
|
||||||
*/
|
*/
|
||||||
template< class EOT >
|
template< class EOT >
|
||||||
class eoHammingDistance : public eoDistance<EOT>
|
class eoL1Distance : public eoDistance<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
double operator()(const EOT & _v1, const EOT & _v2)
|
double operator()(const EOT & _v1, const EOT & _v2)
|
||||||
|
|
@ -83,6 +85,27 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
SV: change to have the Hamming (number of differences)
|
||||||
|
|
||||||
|
For bitstrings, this is the Hamming distance
|
||||||
|
*/
|
||||||
|
template< class EOT >
|
||||||
|
class eoHammingDistance : public eoDistance<EOT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
double operator()(const EOT & _v1, const EOT & _v2)
|
||||||
|
{
|
||||||
|
double sum=0.0;
|
||||||
|
for (unsigned i=0; i<_v1.size(); i++)
|
||||||
|
{
|
||||||
|
if (_v1[i] != _v2[i])
|
||||||
|
sum++;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* this distance measures the difference in fitness
|
/* this distance measures the difference in fitness
|
||||||
* I am not sure it can be of any use, though ...
|
* I am not sure it can be of any use, though ...
|
||||||
* except for some testing
|
* except for some testing
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ set (TEST_LIST
|
||||||
#t-openmp # does not work anymore since functions used in this test were removed from EO
|
#t-openmp # does not work anymore since functions used in this test were removed from EO
|
||||||
#t-eoDualFitness
|
#t-eoDualFitness
|
||||||
t-eoParser
|
t-eoParser
|
||||||
|
t-eoPartiallyMappedXover
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
71
eo/test/t-eoPartiallyMappedXover.cpp
Normal file
71
eo/test/t-eoPartiallyMappedXover.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
<t-eoPartiallyMappedXover.cpp>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
|
#include <eoInt.h>
|
||||||
|
|
||||||
|
#include <eoPartiallyMappedXover.h>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef eoInt<int> Solution;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
std::cout << "[t-eoPartiallyMappedXover] => START" << std::endl;
|
||||||
|
|
||||||
|
Solution sol1, sol2;
|
||||||
|
sol1.resize(9);
|
||||||
|
sol2.resize(9);
|
||||||
|
|
||||||
|
for(int i = 0; i < sol1.size(); i++)
|
||||||
|
sol1[i] = i;
|
||||||
|
|
||||||
|
sol2[0] = 3;
|
||||||
|
sol2[1] = 4;
|
||||||
|
sol2[2] = 1;
|
||||||
|
sol2[3] = 0;
|
||||||
|
sol2[4] = 7;
|
||||||
|
sol2[5] = 6;
|
||||||
|
sol2[6] = 5;
|
||||||
|
sol2[7] = 8;
|
||||||
|
sol2[8] = 2;
|
||||||
|
|
||||||
|
std::cout << sol1 << std::endl;
|
||||||
|
std::cout << sol2 << std::endl;
|
||||||
|
|
||||||
|
eoPartiallyMappedXover<Solution> xover;
|
||||||
|
xover(sol1, sol2);
|
||||||
|
|
||||||
|
std::cout << "apres" << std::endl;
|
||||||
|
std::cout << sol1 << std::endl;
|
||||||
|
std::cout << sol2 << std::endl;
|
||||||
|
|
||||||
|
int verif[9];
|
||||||
|
for(int i = 0; i < sol1.size(); i++)
|
||||||
|
verif[i] = -1;
|
||||||
|
|
||||||
|
for(int i = 0; i < sol1.size(); i++)
|
||||||
|
verif[ sol1[i] ] = 1;
|
||||||
|
|
||||||
|
for(int i = 0; i < sol1.size(); i++)
|
||||||
|
assert(verif[i] != -1);
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0; i < sol2.size(); i++)
|
||||||
|
verif[i] = -1;
|
||||||
|
|
||||||
|
for(int i = 0; i < sol2.size(); i++)
|
||||||
|
verif[ sol2[i] ] = 1;
|
||||||
|
|
||||||
|
for(int i = 0; i < sol2.size(); i++)
|
||||||
|
assert(verif[i] != -1);
|
||||||
|
|
||||||
|
std::cout << "[t-eoPartiallyMappedXover] => OK" << std::endl;
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -60,7 +60,7 @@ public:
|
||||||
*/
|
*/
|
||||||
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
|
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
|
||||||
moLocalSearch<Neighbor>(explorer, iterCont, _fullEval),
|
moLocalSearch<Neighbor>(explorer, iterCont, _fullEval),
|
||||||
iterCont(_nbStepMax),
|
iterCont(_nbStepMax, false),
|
||||||
explorer(_neighborhood, _eval)
|
explorer(_neighborhood, _eval)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public:
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param _param the parameter of type double to save in the vector
|
* @param _param the parameter of type double to save in the vector
|
||||||
*/
|
*/
|
||||||
moVectorMonitor(eoValueParam<double> & _param) : doubleParam(&_param), intParam(NULL), eotParam(NULL)
|
moVectorMonitor(eoValueParam<double> & _param) : doubleParam(&_param), intParam(NULL), intLongParam(NULL), eotParam(NULL)
|
||||||
{
|
{
|
||||||
// precision of the output by default
|
// precision of the output by default
|
||||||
precisionOutput = std::cout.precision();
|
precisionOutput = std::cout.precision();
|
||||||
|
|
@ -63,7 +63,17 @@ public:
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _param the parameter of type unsigned int to save in the vector
|
* @param _param the parameter of type unsigned int to save in the vector
|
||||||
*/
|
*/
|
||||||
moVectorMonitor(eoValueParam<unsigned int> & _param) : doubleParam(NULL), intParam(&_param), eotParam(NULL)
|
moVectorMonitor(eoValueParam<unsigned int> & _param) : doubleParam(NULL), intParam(&_param), intLongParam(NULL), eotParam(NULL)
|
||||||
|
{
|
||||||
|
// precision of the output by default
|
||||||
|
precisionOutput = std::cout.precision();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default Constructor
|
||||||
|
* @param _param the parameter of type unsigned int to save in the vector
|
||||||
|
*/
|
||||||
|
moVectorMonitor(eoValueParam<unsigned long> & _param) : doubleParam(NULL), intParam(NULL), intLongParam(&_param), eotParam(NULL)
|
||||||
{
|
{
|
||||||
// precision of the output by default
|
// precision of the output by default
|
||||||
precisionOutput = std::cout.precision();
|
precisionOutput = std::cout.precision();
|
||||||
|
|
@ -73,7 +83,7 @@ public:
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param _param the parameter of type EOT to save in the vector
|
* @param _param the parameter of type EOT to save in the vector
|
||||||
*/
|
*/
|
||||||
moVectorMonitor(eoValueParam<EOT> & _param) : doubleParam(NULL), intParam(NULL), eotParam(&_param)
|
moVectorMonitor(eoValueParam<EOT> & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), eotParam(&_param)
|
||||||
{
|
{
|
||||||
// precision of the output by default
|
// precision of the output by default
|
||||||
precisionOutput = std::cout.precision();
|
precisionOutput = std::cout.precision();
|
||||||
|
|
@ -84,7 +94,7 @@ public:
|
||||||
* @param _param the parameter of type eoScalarFitness to save in the vector
|
* @param _param the parameter of type eoScalarFitness to save in the vector
|
||||||
*/
|
*/
|
||||||
template <class ScalarType, class Compare>
|
template <class ScalarType, class Compare>
|
||||||
moVectorMonitor(eoValueParam<eoScalarFitness<ScalarType, Compare> > & _param) : doubleParam( & (eoValueParam<double>&)_param), intParam(NULL), eotParam(NULL)
|
moVectorMonitor(eoValueParam<eoScalarFitness<ScalarType, Compare> > & _param) : doubleParam( & (eoValueParam<double>&)_param), intParam(NULL), intLongParam(NULL), eotParam(NULL)
|
||||||
{
|
{
|
||||||
// precision of the output by default
|
// precision of the output by default
|
||||||
precisionOutput = std::cout.precision();
|
precisionOutput = std::cout.precision();
|
||||||
|
|
@ -95,7 +105,7 @@ public:
|
||||||
* @param _param unvalid Parameter
|
* @param _param unvalid Parameter
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
moVectorMonitor(eoValueParam<T> & _param) : doubleParam(NULL), intParam(NULL), eotParam(NULL)
|
moVectorMonitor(eoValueParam<T> & _param) : doubleParam(NULL), intParam(NULL), intLongParam(NULL), eotParam(NULL)
|
||||||
{
|
{
|
||||||
std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl;
|
std::cerr << "Sorry the type can not be in a vector of moVectorMonitor" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
@ -120,8 +130,11 @@ public:
|
||||||
else
|
else
|
||||||
if (intParam != NULL)
|
if (intParam != NULL)
|
||||||
valueVec.push_back((double) intParam->value());
|
valueVec.push_back((double) intParam->value());
|
||||||
else
|
else
|
||||||
eotVec.push_back(eotParam->value());
|
if (intLongParam != NULL)
|
||||||
|
valueVec.push_back((double) intLongParam->value());
|
||||||
|
else
|
||||||
|
eotVec.push_back(eotParam->value());
|
||||||
return *this ;
|
return *this ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,6 +240,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
eoValueParam<double> * doubleParam ;
|
eoValueParam<double> * doubleParam ;
|
||||||
eoValueParam<unsigned int> * intParam ;
|
eoValueParam<unsigned int> * intParam ;
|
||||||
|
eoValueParam<unsigned long> * intLongParam ;
|
||||||
eoValueParam<EOT> * eotParam ;
|
eoValueParam<EOT> * eotParam ;
|
||||||
|
|
||||||
std::vector<double> valueVec;
|
std::vector<double> valueVec;
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,19 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#ifndef _moIndexedVectorTabuList_h
|
#ifndef _moIndexedVectorTabuList_h
|
||||||
#define _moIndexedVectorTabuList_h
|
#define _moIndexedVectorTabuList_h
|
||||||
|
|
||||||
|
#include <utils/eoRndGenerators.h>
|
||||||
#include <memory/moTabuList.h>
|
#include <memory/moTabuList.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* Tabu List of indexed neighbors save in a vector
|
* Tabu List of indexed neighbors save in a vector
|
||||||
* each neighbor can not used during howlong iterations
|
* each neighbor can not used during howlong iterations
|
||||||
|
*
|
||||||
|
* The tabu tenure could be random between two bounds
|
||||||
|
* such as in robust tabu search
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
template<class Neighbor >
|
template<class Neighbor >
|
||||||
class moIndexedVectorTabuList : public moTabuList<Neighbor>
|
class moIndexedVectorTabuList : public moTabuList<Neighbor>
|
||||||
|
|
@ -49,7 +55,17 @@ public:
|
||||||
* @param _maxSize maximum size of the tabu list
|
* @param _maxSize maximum size of the tabu list
|
||||||
* @param _howlong how many iteration a move is tabu
|
* @param _howlong how many iteration a move is tabu
|
||||||
*/
|
*/
|
||||||
moIndexedVectorTabuList(unsigned int _maxSize, unsigned int _howlong) : maxSize(_maxSize), howlong(_howlong) {
|
moIndexedVectorTabuList(unsigned int _maxSize, unsigned int _howlong) : maxSize(_maxSize), howlong(_howlong), robust(false) {
|
||||||
|
tabuList.resize(_maxSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param _maxSize maximum size of the tabu list
|
||||||
|
* @param _howlongMin minimal number of iterations during a move is tabu
|
||||||
|
* @param _howlongMax maximal number of iterations during a move is tabu
|
||||||
|
*/
|
||||||
|
moIndexedVectorTabuList(unsigned int _maxSize, unsigned int _howlongMin, unsigned int _howlongMax) : maxSize(_maxSize), howlongMin(_howlongMin), howlongMax(_howlongMax), robust(true) {
|
||||||
tabuList.resize(_maxSize);
|
tabuList.resize(_maxSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,8 +84,13 @@ public:
|
||||||
* @param _neighbor the current neighbor
|
* @param _neighbor the current neighbor
|
||||||
*/
|
*/
|
||||||
virtual void add(EOT & _sol, Neighbor & _neighbor) {
|
virtual void add(EOT & _sol, Neighbor & _neighbor) {
|
||||||
if (_neighbor.index() < maxSize)
|
if (_neighbor.index() < maxSize) {
|
||||||
|
if (robust)
|
||||||
|
// random value between min and max
|
||||||
|
howlong = howlongMin + rng.random(howlongMax - howlongMin);
|
||||||
|
|
||||||
tabuList[_neighbor.index()] = howlong;
|
tabuList[_neighbor.index()] = howlong;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -115,7 +136,12 @@ protected:
|
||||||
unsigned int maxSize;
|
unsigned int maxSize;
|
||||||
//how many iteration a move is tabu
|
//how many iteration a move is tabu
|
||||||
unsigned int howlong;
|
unsigned int howlong;
|
||||||
|
// Minimum number of iterations during a move is tabu
|
||||||
|
unsigned int howlongMin;
|
||||||
|
// Maximum number of iterations during a move is tabu
|
||||||
|
unsigned int howlongMax;
|
||||||
|
// true: robust tabu search way
|
||||||
|
bool robust;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,7 @@
|
||||||
//#include <problems/eval/moUBQPSimpleIncrEval.h>
|
//#include <problems/eval/moUBQPSimpleIncrEval.h>
|
||||||
//#include <problems/eval/moUBQPdoubleIncrEvaluation.h>
|
//#include <problems/eval/moUBQPdoubleIncrEvaluation.h>
|
||||||
//#include <problems/eval/moUBQPBitsIncrEval.h>
|
//#include <problems/eval/moUBQPBitsIncrEval.h>
|
||||||
|
#include <problems/eval/moNKlandscapesIncrEval.h>
|
||||||
|
|
||||||
|
|
||||||
#include <sampling/moAdaptiveWalkSampling.h>
|
#include <sampling/moAdaptiveWalkSampling.h>
|
||||||
|
|
|
||||||
|
|
@ -109,9 +109,9 @@ public:
|
||||||
* @param _solution solution from which the neighborhood is visited
|
* @param _solution solution from which the neighborhood is visited
|
||||||
* @param _key index of the IndexNeighbor
|
* @param _key index of the IndexNeighbor
|
||||||
*/
|
*/
|
||||||
virtual void index(EOT & _solution, unsigned int _key) {
|
virtual void index(EOT & _solution, unsigned int _key) {
|
||||||
key = _key;
|
key = _key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param _neighbor a neighbor
|
* @param _neighbor a neighbor
|
||||||
|
|
@ -121,6 +121,22 @@ public:
|
||||||
return (key == _neighbor.index());
|
return (key == _neighbor.index());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write object with its index
|
||||||
|
* @param _os A std::ostream.
|
||||||
|
*/
|
||||||
|
virtual void printOn(std::ostream& _os) const {
|
||||||
|
if (this->invalid()) {
|
||||||
|
_os << "INVALID ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_os << this->fitness() << ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
_os << key ;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// key allowing to describe the neighbor
|
// key allowing to describe the neighbor
|
||||||
unsigned int key;
|
unsigned int key;
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ public:
|
||||||
return "moRndWithoutReplNeighborhood";
|
return "moRndWithoutReplNeighborhood";
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
unsigned int maxIndex;
|
unsigned int maxIndex;
|
||||||
std::vector<unsigned int> indexVector;
|
std::vector<unsigned int> indexVector;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,16 @@ public:
|
||||||
* @param _fullEval a full evaluation function
|
* @param _fullEval a full evaluation function
|
||||||
* @param _nbPerturbation number of operator executions for perturbation
|
* @param _nbPerturbation number of operator executions for perturbation
|
||||||
*/
|
*/
|
||||||
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval, unsigned int _nbPerturbation = 1):monOp(_monOp), fullEval(_fullEval), nbPerturbation(_nbPerturbation) {}
|
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval, unsigned int _nbPerturbation = 1):monOp(_monOp), fullEval(_fullEval), nbPerturbation(_nbPerturbation), rndPerturb(false) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor with random value at each iteration of the number of perturbation moves
|
||||||
|
* @param _monOp an eoMonOp (pertubation operator)
|
||||||
|
* @param _fullEval a full evaluation function
|
||||||
|
* @param _nbPerturbationMin minimum number of operator executions for perturbation
|
||||||
|
* @param _nbPerturbationMax maximum number of operator executions for perturbation
|
||||||
|
*/
|
||||||
|
moMonOpPerturb(eoMonOp<EOT>& _monOp, eoEvalFunc<EOT>& _fullEval, unsigned int _nbPerturbationMin, unsigned int _nbPerturbationMax):monOp(_monOp), fullEval(_fullEval), nbPerturbationMin(_nbPerturbationMin), nbPerturbationMax(_nbPerturbationMax), rndPerturb(true) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply monOp on the solution
|
* Apply monOp on the solution
|
||||||
|
|
@ -60,6 +69,9 @@ public:
|
||||||
bool operator()(EOT& _solution) {
|
bool operator()(EOT& _solution) {
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
|
||||||
|
if (rndPerturb)
|
||||||
|
nbPerturbation = nbPerturbationMin + rng.random(nbPerturbationMax - nbPerturbationMin);
|
||||||
|
|
||||||
for(unsigned int i = 0; i < nbPerturbation; i++)
|
for(unsigned int i = 0; i < nbPerturbation; i++)
|
||||||
res = monOp(_solution) || res;
|
res = monOp(_solution) || res;
|
||||||
|
|
||||||
|
|
@ -74,6 +86,9 @@ private:
|
||||||
eoMonOp<EOT>& monOp;
|
eoMonOp<EOT>& monOp;
|
||||||
eoEvalFunc<EOT>& fullEval;
|
eoEvalFunc<EOT>& fullEval;
|
||||||
unsigned int nbPerturbation;
|
unsigned int nbPerturbation;
|
||||||
|
unsigned int nbPerturbationMin;
|
||||||
|
unsigned int nbPerturbationMax;
|
||||||
|
bool rndPerturb;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
131
mo/src/problems/eval/moNKlandscapesIncrEval.h
Normal file
131
mo/src/problems/eval/moNKlandscapesIncrEval.h
Normal file
|
|
@ -0,0 +1,131 @@
|
||||||
|
/*
|
||||||
|
<moNKlandscapesIncrEval.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 _moNKlandscapesIncrEval_H
|
||||||
|
#define _moNKlandscapesIncrEval_H
|
||||||
|
|
||||||
|
#include <eval/moEval.h>
|
||||||
|
#include <eval/nkLandscapesEval.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Incremental evaluation function (1 bit flip, Hamming distance 1)
|
||||||
|
* for the NK-landscapes problem
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template< class Neighbor >
|
||||||
|
class moNKlandscapesIncrEval : public moEval<Neighbor>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename Neighbor::EOT EOT;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param _nk fitness function of the NK landscapes
|
||||||
|
*/
|
||||||
|
moNKlandscapesIncrEval(nkLandscapesEval<EOT> & _nk) : nk(_nk) {
|
||||||
|
inverseLinks = new std::vector<unsigned>[ nk.N ];
|
||||||
|
|
||||||
|
// compute the contributions which are modified by flipping one bit
|
||||||
|
for(unsigned int i = 0; i < nk.N; i++)
|
||||||
|
for(unsigned int j = 0; j < nk.K + 1; j++) {
|
||||||
|
inverseLinks[ nk.links[i][j] ].push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Destructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
~moNKlandscapesIncrEval() {
|
||||||
|
delete [] inverseLinks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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) {
|
||||||
|
unsigned bit = _neighbor.index() ;
|
||||||
|
unsigned sig, nonSig;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
double delta = 0 ;
|
||||||
|
|
||||||
|
for(unsigned int j = 0; j < inverseLinks[bit].size(); j++) {
|
||||||
|
i = inverseLinks[bit][j];
|
||||||
|
sigma(_solution, i, bit, sig, nonSig);
|
||||||
|
delta += nk.tables[i][nonSig] - nk.tables[i][sig];
|
||||||
|
}
|
||||||
|
|
||||||
|
_neighbor.fitness(_solution.fitness() + delta / (double) nk.N);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Original nk fitness function
|
||||||
|
nkLandscapesEval<EOT> & nk;
|
||||||
|
|
||||||
|
// give the list of contributions which are modified when the corresponding bit is flipped
|
||||||
|
std::vector<unsigned> * inverseLinks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the mask of the linked bits, and the mask when the bit is flipped
|
||||||
|
*
|
||||||
|
* @param _solution the solution to evaluate
|
||||||
|
* @param i the bit of the contribution
|
||||||
|
* @param _bit the bit to flip
|
||||||
|
* @param sig value of the mask of contribution i
|
||||||
|
* @param nonSig value of the mask of contribution i when the bit _bit is flipped
|
||||||
|
*/
|
||||||
|
void sigma(EOT & _solution, int i, unsigned _bit, unsigned & sig, unsigned & nonSig) {
|
||||||
|
sig = 0;
|
||||||
|
nonSig = 0;
|
||||||
|
|
||||||
|
unsigned int n = 1;
|
||||||
|
for(int j = 0; j < nk.K + 1; j++) {
|
||||||
|
if (_solution[ nk.links[i][j] ] == 1)
|
||||||
|
sig = sig | n;
|
||||||
|
|
||||||
|
if (nk.links[i][j] == _bit)
|
||||||
|
nonSig = n;
|
||||||
|
|
||||||
|
n = n << 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
nonSig = sig ^ nonSig;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
@ -46,6 +46,33 @@ public:
|
||||||
using moIndexNeighbor<EOT>::index;
|
using moIndexNeighbor<EOT>::index;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Default Constructor
|
||||||
|
*/
|
||||||
|
moIndexedSwapNeighbor() : moIndexNeighbor<EOT, Fitness>() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy Constructor
|
||||||
|
* @param _n the neighbor to copy
|
||||||
|
*/
|
||||||
|
moIndexedSwapNeighbor(const moIndexedSwapNeighbor<EOT, Fitness> & _n) : moIndexNeighbor<EOT, Fitness>(_n)
|
||||||
|
{
|
||||||
|
indices.first = _n.first();
|
||||||
|
indices.second = _n.second();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assignment operator
|
||||||
|
* @param _source the source neighbor
|
||||||
|
*/
|
||||||
|
moIndexedSwapNeighbor<EOT, Fitness> & operator=(const moIndexedSwapNeighbor<EOT, Fitness> & _source) {
|
||||||
|
moIndexNeighbor<EOT, Fitness>::operator=(_source);
|
||||||
|
indices.first = _source.first();
|
||||||
|
indices.second = _source.second();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Apply the swap
|
* Apply the swap
|
||||||
* @param _solution the solution to move
|
* @param _solution the solution to move
|
||||||
*/
|
*/
|
||||||
|
|
@ -111,7 +138,7 @@ public:
|
||||||
* Getter of the firt location
|
* Getter of the firt location
|
||||||
* @return first indice
|
* @return first indice
|
||||||
*/
|
*/
|
||||||
unsigned int first() {
|
unsigned int first() const {
|
||||||
return indices.first;
|
return indices.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,11 +146,11 @@ public:
|
||||||
* Getter of the second location
|
* Getter of the second location
|
||||||
* @return second indice
|
* @return second indice
|
||||||
*/
|
*/
|
||||||
unsigned int second() {
|
unsigned int second() const {
|
||||||
return indices.second;
|
return indices.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
std::pair<unsigned int, unsigned int> indices;
|
std::pair<unsigned int, unsigned int> indices;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ set (TEST_LIST
|
||||||
t-moOrderNeighborhood
|
t-moOrderNeighborhood
|
||||||
t-moFullEvalByCopy
|
t-moFullEvalByCopy
|
||||||
t-moFullEvalByModif
|
t-moFullEvalByModif
|
||||||
|
t-moNKlandscapesIncrEval
|
||||||
t-moNeighborComparator
|
t-moNeighborComparator
|
||||||
t-moSolNeighborComparator
|
t-moSolNeighborComparator
|
||||||
t-moTrueContinuator
|
t-moTrueContinuator
|
||||||
|
|
|
||||||
89
mo/test/t-moNKlandscapesIncrEval.cpp
Normal file
89
mo/test/t-moNKlandscapesIncrEval.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
<t-moNKlandscapesIncrEval.cpp>
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ga/eoBit.h>
|
||||||
|
#include <eoInit.h>
|
||||||
|
#include <problems/bitString/moBitNeighbor.h>
|
||||||
|
#include <eval/nkLandscapesEval.h>
|
||||||
|
#include <problems/eval/moNKlandscapesIncrEval.h>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
typedef eoBit<double> Solution;
|
||||||
|
typedef moBitNeighbor<double> Neighbor ;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
std::cout << "[t-moNKlandscapesIncrEval] => START" << std::endl;
|
||||||
|
|
||||||
|
// nk fitness function
|
||||||
|
int N = 18;
|
||||||
|
int K = 4;
|
||||||
|
rng.reseed(0); // random seed = 0
|
||||||
|
|
||||||
|
nkLandscapesEval<Solution> eval(N, K);
|
||||||
|
|
||||||
|
// init
|
||||||
|
eoUniformGenerator<bool> uGen;
|
||||||
|
eoInitFixedLength<Solution> init(N, uGen);
|
||||||
|
|
||||||
|
// verif constructor
|
||||||
|
moNKlandscapesIncrEval<Neighbor> neighborEval(eval);
|
||||||
|
|
||||||
|
Solution solution;
|
||||||
|
|
||||||
|
// random initialization
|
||||||
|
rng.reseed(1); // random seed = 1
|
||||||
|
|
||||||
|
init(solution);
|
||||||
|
|
||||||
|
// evaluation
|
||||||
|
eval(solution);
|
||||||
|
|
||||||
|
Neighbor n ;
|
||||||
|
n.index(0);
|
||||||
|
|
||||||
|
neighborEval(solution, n);
|
||||||
|
|
||||||
|
n.move(solution);
|
||||||
|
eval(solution);
|
||||||
|
|
||||||
|
// verif incremental eval
|
||||||
|
assert(solution.fitness() == n.fitness());
|
||||||
|
|
||||||
|
std::cout << "[t-moNKlandscapesIncrEval] => OK" << std::endl;
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -85,6 +85,7 @@ void main_function(int argc, char **argv)
|
||||||
string str_out = "out.dat"; // default value
|
string str_out = "out.dat"; // default value
|
||||||
eoValueParam<string> outParam(str_out.c_str(), "out", "Output file of the sampling", 'o');
|
eoValueParam<string> outParam(str_out.c_str(), "out", "Output file of the sampling", 'o');
|
||||||
parser.processParam(outParam, "Persistence" );
|
parser.processParam(outParam, "Persistence" );
|
||||||
|
str_out = outParam.value();
|
||||||
|
|
||||||
// the name of the "status" file where all actual parameter values will be saved
|
// the name of the "status" file where all actual parameter values will be saved
|
||||||
string str_status = parser.ProgramName() + ".status"; // default value
|
string str_status = parser.ProgramName() + ".status"; // default value
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ void main_function(int argc, char **argv)
|
||||||
string str_out = "out.dat"; // default value
|
string str_out = "out.dat"; // default value
|
||||||
eoValueParam<string> outParam(str_out.c_str(), "out", "Output file of the sampling", 'o');
|
eoValueParam<string> outParam(str_out.c_str(), "out", "Output file of the sampling", 'o');
|
||||||
parser.processParam(outParam, "Persistence" );
|
parser.processParam(outParam, "Persistence" );
|
||||||
|
str_out = outParam.value();
|
||||||
|
|
||||||
// the name of the "status" file where all actual parameter values will be saved
|
// the name of the "status" file where all actual parameter values will be saved
|
||||||
string str_status = parser.ProgramName() + ".status"; // default value
|
string str_status = parser.ProgramName() + ".status"; // default value
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,7 @@ void main_function(int argc, char **argv)
|
||||||
string str_out = "out.dat"; // default value
|
string str_out = "out.dat"; // default value
|
||||||
eoValueParam<string> outParam(str_out.c_str(), "out", "Output file of the sampling", 'o');
|
eoValueParam<string> outParam(str_out.c_str(), "out", "Output file of the sampling", 'o');
|
||||||
parser.processParam(outParam, "Persistence" );
|
parser.processParam(outParam, "Persistence" );
|
||||||
|
str_out = outParam.value();
|
||||||
|
|
||||||
// the name of the "status" file where all actual parameter values will be saved
|
// the name of the "status" file where all actual parameter values will be saved
|
||||||
string str_status = parser.ProgramName() + ".status"; // default value
|
string str_status = parser.ProgramName() + ".status"; // default value
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ class moeoHyperVolumeMetric : public moeoVectorUnaryMetric < ObjectiveVector , d
|
||||||
* @param _ref_point the reference point
|
* @param _ref_point the reference point
|
||||||
* @param _bounds bounds value
|
* @param _bounds bounds value
|
||||||
*/
|
*/
|
||||||
moeoHyperVolumeMetric(ObjectiveVector& _ref_point=NULL, std::vector < eoRealInterval >& _bounds=NULL): normalize(false), rho(0.0), ref_point(_ref_point), bounds(_bounds){}
|
moeoHyperVolumeMetric(ObjectiveVector& _ref_point, std::vector < eoRealInterval >& _bounds): normalize(false), rho(0.0), ref_point(_ref_point), bounds(_bounds){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* calculates and returns the HyperVolume value of a pareto front
|
* calculates and returns the HyperVolume value of a pareto front
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ class moeoRouletteSelect:public moeoSelectOne < MOEOT >
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** size */
|
/** size */
|
||||||
double & tSize;
|
unsigned int & tSize;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class moeoBinaryMetricSavingUpdater : public eoUpdater
|
||||||
* @param _filename the target filename
|
* @param _filename the target filename
|
||||||
*/
|
*/
|
||||||
moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) :
|
moeoBinaryMetricSavingUpdater (moeoVectorVsVectorBinaryMetric < ObjectiveVector, double > & _metric, const eoPop < MOEOT > & _pop, std::string _filename) :
|
||||||
metric(_metric), pop(_pop), filename(_filename), counter(1), firstGen(true)
|
metric(_metric), pop(_pop), filename(_filename), firstGen(true), counter(1)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#define __nkLandscapesEval_H
|
#define __nkLandscapesEval_H
|
||||||
|
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
template< class EOT >
|
template< class EOT >
|
||||||
class nkLandscapesEval : public eoEvalFunc<EOT> {
|
class nkLandscapesEval : public eoEvalFunc<EOT> {
|
||||||
|
|
@ -79,7 +80,7 @@ public:
|
||||||
*/
|
*/
|
||||||
nkLandscapesEval(const char * _fileName)
|
nkLandscapesEval(const char * _fileName)
|
||||||
{
|
{
|
||||||
string fname(_fileName);
|
std::string fname(_fileName);
|
||||||
load(fname);
|
load(fname);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -132,16 +133,16 @@ public:
|
||||||
*
|
*
|
||||||
* @param _fileName file name of the instance
|
* @param _fileName file name of the instance
|
||||||
*/
|
*/
|
||||||
virtual void load(const string _fileName)
|
virtual void load(const std::string _fileName)
|
||||||
{
|
{
|
||||||
fstream file;
|
std::fstream file;
|
||||||
file.open(_fileName.c_str(), ios::in);
|
file.open(_fileName.c_str(), std::fstream::in);
|
||||||
|
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
string s;
|
std::string s;
|
||||||
|
|
||||||
// Read the commentairies
|
// Read the commentairies
|
||||||
string line;
|
std::string line;
|
||||||
file >> s;
|
file >> s;
|
||||||
while (s[0] == 'c') {
|
while (s[0] == 'c') {
|
||||||
getline(file,line,'\n');
|
getline(file,line,'\n');
|
||||||
|
|
@ -150,14 +151,14 @@ public:
|
||||||
|
|
||||||
// Read the parameters
|
// Read the parameters
|
||||||
if (s[0] != 'p') {
|
if (s[0] != 'p') {
|
||||||
string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ;
|
std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ;
|
||||||
throw runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
file >> s;
|
file >> s;
|
||||||
if (s != "NK") {
|
if (s != "NK") {
|
||||||
string str = "nkLandscapesEval.load: -- NK -- expected in [" + _fileName + "] at the begining." ;
|
std::string str = "nkLandscapesEval.load: -- NK -- expected in [" + _fileName + "] at the begining." ;
|
||||||
throw runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// read parameters N and K
|
// read parameters N and K
|
||||||
|
|
@ -166,22 +167,22 @@ public:
|
||||||
|
|
||||||
// read the links
|
// read the links
|
||||||
if (s[0] != 'p') {
|
if (s[0] != 'p') {
|
||||||
string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N and K." ;
|
std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N and K." ;
|
||||||
throw runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
file >> s;
|
file >> s;
|
||||||
if (s == "links") {
|
if (s == "links") {
|
||||||
loadLinks(file);
|
loadLinks(file);
|
||||||
} else {
|
} else {
|
||||||
string str = "nkLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N and K." ;
|
std::string str = "nkLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N and K." ;
|
||||||
throw runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// lecture des tables
|
// lecture des tables
|
||||||
if (s[0] != 'p') {
|
if (s[0] != 'p') {
|
||||||
string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ;
|
std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ;
|
||||||
throw runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
file >> s;
|
file >> s;
|
||||||
|
|
@ -189,14 +190,14 @@ public:
|
||||||
if (s == "tables") {
|
if (s == "tables") {
|
||||||
loadTables(file);
|
loadTables(file);
|
||||||
} else {
|
} else {
|
||||||
string str = "nkLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ;
|
std::string str = "nkLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ;
|
||||||
throw runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
} else {
|
} else {
|
||||||
string str = "nkLandscapesEval.load: Could not open file [" + _fileName + "]." ;
|
std::string str = "nkLandscapesEval.load: Could not open file [" + _fileName + "]." ;
|
||||||
throw runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -206,7 +207,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param file the file to read
|
* @param file the file to read
|
||||||
*/
|
*/
|
||||||
void loadLinks(fstream & file) {
|
void loadLinks(std::fstream & file) {
|
||||||
for(int j = 0; j < K+1; j++)
|
for(int j = 0; j < K+1; j++)
|
||||||
for(int i = 0; i < N; i++) {
|
for(int i = 0; i < N; i++) {
|
||||||
file >> links[i][j];
|
file >> links[i][j];
|
||||||
|
|
@ -218,7 +219,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param file the file to read
|
* @param file the file to read
|
||||||
*/
|
*/
|
||||||
void loadTables(fstream & file) {
|
void loadTables(std::fstream & file) {
|
||||||
for(int j = 0; j < (1<<(K+1)); j++)
|
for(int j = 0; j < (1<<(K+1)); j++)
|
||||||
for(int i = 0; i < N; i++)
|
for(int i = 0; i < N; i++)
|
||||||
file >> tables[i][j];
|
file >> tables[i][j];
|
||||||
|
|
@ -230,29 +231,29 @@ public:
|
||||||
* @param _fileName the file name of instance
|
* @param _fileName the file name of instance
|
||||||
*/
|
*/
|
||||||
virtual void save(const char * _fileName) {
|
virtual void save(const char * _fileName) {
|
||||||
fstream file;
|
std::fstream file;
|
||||||
file.open(_fileName, ios::out);
|
file.open(_fileName, std::fstream::out);
|
||||||
|
|
||||||
if (file.is_open()) {
|
if (file.is_open()) {
|
||||||
file << "c name of the file : " << _fileName << endl;
|
file << "c name of the file : " << _fileName << std::endl;
|
||||||
file << "p NK " << N << " " << K <<endl;
|
file << "p NK " << N << " " << K <<std::endl;
|
||||||
|
|
||||||
file << "p links" << endl;
|
file << "p links" << std::endl;
|
||||||
for(int j=0; j<K+1; j++)
|
for(int j=0; j<K+1; j++)
|
||||||
for(int i=0; i<N; i++)
|
for(int i=0; i<N; i++)
|
||||||
file << links[i][j] << endl;
|
file << links[i][j] << std::endl;
|
||||||
|
|
||||||
file << "p tables" << endl;
|
file << "p tables" << std::endl;
|
||||||
for(int j=0; j<(1<<(K+1)); j++) {
|
for(int j=0; j<(1<<(K+1)); j++) {
|
||||||
for(int i=0; i<N; i++)
|
for(int i=0; i<N; i++)
|
||||||
file << tables[i][j] << " ";
|
file << tables[i][j] << " ";
|
||||||
file << endl;
|
file << std::endl;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
} else {
|
} else {
|
||||||
string fname(_fileName);
|
std::string fname(_fileName);
|
||||||
string str = "nkLandscapesEval.save: Could not open file [" + fname + "]." ;
|
std::string str = "nkLandscapesEval.save: Could not open file [" + fname + "]." ;
|
||||||
throw runtime_error(str);
|
throw std::runtime_error(str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,17 +67,21 @@ void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, e
|
||||||
indice = i*nbIndi+j;
|
indice = i*nbIndi+j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned i = 0; i < remaining; i++)
|
if(nbIndi != 0) // Handle the offset if there is less individuals than workers
|
||||||
popPackages[i].push_back(&pop[indice+i+1]);
|
indice++;
|
||||||
|
for(unsigned i = 0; i < remaining; i++)
|
||||||
|
popPackages[i].push_back(&pop[indice+i]);
|
||||||
|
|
||||||
// Starting threads
|
// Starting threads
|
||||||
for(unsigned i = 0; i < workers.size(); i++)
|
for(unsigned i = 0; i < workers.size(); i++)
|
||||||
workers[i] = std::thread(&Scheduler<EOT,Policy>::applyLinearPolicy, this, std::ref(func), std::ref(popPackages[i]));
|
if(!popPackages[i].empty())
|
||||||
|
workers[i] = std::thread(&Scheduler<EOT,Policy>::applyLinearPolicy, this, std::ref(func), std::ref(popPackages[i]));
|
||||||
|
|
||||||
// Wait the end of tasks
|
// Wait the end of tasks
|
||||||
for(unsigned i = 0; i < workers.size(); i++)
|
for(unsigned i = 0; i < workers.size(); i++)
|
||||||
workers[i].join();
|
if(!popPackages[i].empty() && workers[i].joinable())
|
||||||
|
workers[i].join();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class EOT, class Policy>
|
template<class EOT, class Policy>
|
||||||
|
|
@ -117,7 +121,7 @@ void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, e
|
||||||
}
|
}
|
||||||
|
|
||||||
done = true;
|
done = true;
|
||||||
|
|
||||||
for(unsigned i = 0; i < workers.size(); i++)
|
for(unsigned i = 0; i < workers.size(); i++)
|
||||||
workers[i].join();
|
workers[i].join();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue