Small modif in moIndexedSwapNeighbor

This commit is contained in:
verel 2014-06-25 17:02:38 +02:00
commit edefae4b28
17 changed files with 141 additions and 54 deletions

View file

@ -183,9 +183,9 @@ Easy, isn't it ?
By performing tests, you can check your installation.
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

View file

@ -47,7 +47,7 @@ install(DIRECTORY do es ga gp other utils
add_subdirectory(es)
add_subdirectory(ga)
add_subdirectory(utils)
add_subdirectory(serial)
#add_subdirectory(serial)
if(ENABLE_PYEO)
add_subdirectory(pyeo)

View file

@ -62,12 +62,35 @@ public:
};
/**
SV: from eoHammingDistance, it is in fact the L1 distance
This is a generic class for L1 distance computation:
assumes the 2 things are std::vectors of something
that is double-castable
For bitstrings, this is the Hamming distance
*/
template< class EOT >
class eoL1Distance : public eoDistance<EOT>
{
public:
double operator()(const EOT & _v1, const EOT & _v2)
{
double sum=0.0;
for (unsigned i=0; i<_v1.size(); i++)
{
double r = static_cast<double> (_v1[i]) - static_cast<double> (_v2[i]);
sum += fabs(r);
}
return sum;
}
};
/**
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:
@ -76,8 +99,8 @@ public:
double sum=0.0;
for (unsigned i=0; i<_v1.size(); i++)
{
double r = static_cast<double> (_v1[i]) - static_cast<double> (_v2[i]);
sum += fabs(r);
if (_v1[i] != _v2[i])
sum++;
}
return sum;
}

View file

@ -69,6 +69,7 @@ set (TEST_LIST
#t-openmp # does not work anymore since functions used in this test were removed from EO
#t-eoDualFitness
t-eoParser
t-eoPartiallyMappedXover
)

View file

@ -60,7 +60,7 @@ public:
*/
moRandomWalk(Neighborhood& _neighborhood, eoEvalFunc<EOT>& _fullEval, moEval<Neighbor>& _eval, unsigned _nbStepMax):
moLocalSearch<Neighbor>(explorer, iterCont, _fullEval),
iterCont(_nbStepMax),
iterCont(_nbStepMax, false),
explorer(_neighborhood, _eval)
{}

View file

@ -53,7 +53,7 @@ public:
* Constructor
* @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
precisionOutput = std::cout.precision();
@ -63,7 +63,17 @@ public:
* Default Constructor
* @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
precisionOutput = std::cout.precision();
@ -73,7 +83,7 @@ public:
* Default Constructor
* @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
precisionOutput = std::cout.precision();
@ -84,7 +94,7 @@ public:
* @param _param the parameter of type eoScalarFitness to save in the vector
*/
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
precisionOutput = std::cout.precision();
@ -95,7 +105,7 @@ public:
* @param _param unvalid Parameter
*/
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;
}
@ -120,6 +130,9 @@ public:
else
if (intParam != NULL)
valueVec.push_back((double) intParam->value());
else
if (intLongParam != NULL)
valueVec.push_back((double) intLongParam->value());
else
eotVec.push_back(eotParam->value());
return *this ;
@ -227,6 +240,7 @@ public:
protected:
eoValueParam<double> * doubleParam ;
eoValueParam<unsigned int> * intParam ;
eoValueParam<unsigned long> * intLongParam ;
eoValueParam<EOT> * eotParam ;
std::vector<double> valueVec;

View file

@ -190,6 +190,7 @@
//#include <problems/eval/moUBQPSimpleIncrEval.h>
//#include <problems/eval/moUBQPdoubleIncrEvaluation.h>
//#include <problems/eval/moUBQPBitsIncrEval.h>
#include <problems/eval/moNKlandscapesIncrEval.h>
#include <sampling/moAdaptiveWalkSampling.h>

View file

@ -121,6 +121,22 @@ public:
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:
// key allowing to describe the neighbor
unsigned int key;

View file

@ -130,7 +130,7 @@ public:
return "moRndWithoutReplNeighborhood";
}
private:
protected:
unsigned int maxIndex;
std::vector<unsigned int> indexVector;
};

View file

@ -45,6 +45,33 @@ public:
using moIndexNeighbor<EOT>::key;
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
* @param _solution the solution to move
@ -111,7 +138,7 @@ public:
* Getter of the firt location
* @return first indice
*/
unsigned int first() {
unsigned int first() const {
return indices.first;
}
@ -119,11 +146,11 @@ public:
* Getter of the second location
* @return second indice
*/
unsigned int second() {
unsigned int second() const {
return indices.second;
}
private:
protected:
std::pair<unsigned int, unsigned int> indices;
};

View file

@ -18,6 +18,7 @@ set (TEST_LIST
t-moOrderNeighborhood
t-moFullEvalByCopy
t-moFullEvalByModif
t-moNKlandscapesIncrEval
t-moNeighborComparator
t-moSolNeighborComparator
t-moTrueContinuator

View file

@ -85,6 +85,7 @@ void main_function(int argc, char **argv)
string str_out = "out.dat"; // default value
eoValueParam<string> outParam(str_out.c_str(), "out", "Output file of the sampling", 'o');
parser.processParam(outParam, "Persistence" );
str_out = outParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value

View file

@ -89,6 +89,7 @@ void main_function(int argc, char **argv)
string str_out = "out.dat"; // default value
eoValueParam<string> outParam(str_out.c_str(), "out", "Output file of the sampling", 'o');
parser.processParam(outParam, "Persistence" );
str_out = outParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value

View file

@ -83,6 +83,7 @@ void main_function(int argc, char **argv)
string str_out = "out.dat"; // default value
eoValueParam<string> outParam(str_out.c_str(), "out", "Output file of the sampling", 'o');
parser.processParam(outParam, "Persistence" );
str_out = outParam.value();
// the name of the "status" file where all actual parameter values will be saved
string str_status = parser.ProgramName() + ".status"; // default value

View file

@ -83,7 +83,7 @@ class moeoHyperVolumeMetric : public moeoVectorUnaryMetric < ObjectiveVector , d
* @param _ref_point the reference point
* @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

View file

@ -80,7 +80,7 @@ class moeoRouletteSelect:public moeoSelectOne < MOEOT >
protected:
/** size */
double & tSize;
unsigned int & tSize;
};

View file

@ -31,6 +31,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#define __nkLandscapesEval_H
#include <eoEvalFunc.h>
#include <fstream>
template< class EOT >
class nkLandscapesEval : public eoEvalFunc<EOT> {
@ -79,7 +80,7 @@ public:
*/
nkLandscapesEval(const char * _fileName)
{
string fname(_fileName);
std::string fname(_fileName);
load(fname);
};
@ -132,16 +133,16 @@ public:
*
* @param _fileName file name of the instance
*/
virtual void load(const string _fileName)
virtual void load(const std::string _fileName)
{
fstream file;
file.open(_fileName.c_str(), ios::in);
std::fstream file;
file.open(_fileName.c_str(), std::fstream::in);
if (file.is_open()) {
string s;
std::string s;
// Read the commentairies
string line;
std::string line;
file >> s;
while (s[0] == 'c') {
getline(file,line,'\n');
@ -150,14 +151,14 @@ public:
// Read the parameters
if (s[0] != 'p') {
string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ;
throw runtime_error(str);
std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] at the begining." ;
throw std::runtime_error(str);
}
file >> s;
if (s != "NK") {
string str = "nkLandscapesEval.load: -- NK -- expected in [" + _fileName + "] at the begining." ;
throw runtime_error(str);
std::string str = "nkLandscapesEval.load: -- NK -- expected in [" + _fileName + "] at the begining." ;
throw std::runtime_error(str);
}
// read parameters N and K
@ -166,22 +167,22 @@ public:
// read the links
if (s[0] != 'p') {
string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N and K." ;
throw runtime_error(str);
std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the parameters N and K." ;
throw std::runtime_error(str);
}
file >> s;
if (s == "links") {
loadLinks(file);
} else {
string str = "nkLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N and K." ;
throw runtime_error(str);
std::string str = "nkLandscapesEval.load: -- links -- expected in [" + _fileName + "] after the parameters N and K." ;
throw std::runtime_error(str);
}
// lecture des tables
if (s[0] != 'p') {
string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ;
throw runtime_error(str);
std::string str = "nkLandscapesEval.load: -- p -- expected in [" + _fileName + "] after the links." ;
throw std::runtime_error(str);
}
file >> s;
@ -189,14 +190,14 @@ public:
if (s == "tables") {
loadTables(file);
} else {
string str = "nkLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ;
throw runtime_error(str);
std::string str = "nkLandscapesEval.load: -- tables -- expected in [" + _fileName + "] after the links." ;
throw std::runtime_error(str);
}
file.close();
} else {
string str = "nkLandscapesEval.load: Could not open file [" + _fileName + "]." ;
throw runtime_error(str);
std::string str = "nkLandscapesEval.load: Could not open file [" + _fileName + "]." ;
throw std::runtime_error(str);
}
};
@ -206,7 +207,7 @@ public:
*
* @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 i = 0; i < N; i++) {
file >> links[i][j];
@ -218,7 +219,7 @@ public:
*
* @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 i = 0; i < N; i++)
file >> tables[i][j];
@ -230,29 +231,29 @@ public:
* @param _fileName the file name of instance
*/
virtual void save(const char * _fileName) {
fstream file;
file.open(_fileName, ios::out);
std::fstream file;
file.open(_fileName, std::fstream::out);
if (file.is_open()) {
file << "c name of the file : " << _fileName << endl;
file << "p NK " << N << " " << K <<endl;
file << "c name of the file : " << _fileName << std::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 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 i=0; i<N; i++)
file << tables[i][j] << " ";
file << endl;
file << std::endl;
}
file.close();
} else {
string fname(_fileName);
string str = "nkLandscapesEval.save: Could not open file [" + fname + "]." ;
throw runtime_error(str);
std::string fname(_fileName);
std::string str = "nkLandscapesEval.save: Could not open file [" + fname + "]." ;
throw std::runtime_error(str);
}
};