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

@ -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,8 +130,11 @@ public:
else
if (intParam != NULL)
valueVec.push_back((double) intParam->value());
else
eotVec.push_back(eotParam->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

@ -109,9 +109,9 @@ public:
* @param _solution solution from which the neighborhood is visited
* @param _key index of the IndexNeighbor
*/
virtual void index(EOT & _solution, unsigned int _key) {
key = _key;
}
virtual void index(EOT & _solution, unsigned int _key) {
key = _key;
}
/**
* @param _neighbor a neighbor
@ -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

@ -46,6 +46,33 @@ public:
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