New style for MOEO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@788 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2007-11-16 11:29:25 +00:00
commit 39709d3d12
103 changed files with 2607 additions and 2521 deletions

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopEA.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -65,68 +65,68 @@ using namespace std;
int main(int argc, char* argv[])
{
try
try
{
eoParser parser(argc, argv); // for user-parameter reading
eoState state; // to keep all things allocated
eoParser parser(argc, argv); // for user-parameter reading
eoState state; // to keep all things allocated
/*** the representation-dependent things ***/
/*** the representation-dependent things ***/
// The fitness evaluation
eoEvalFuncCounter<FlowShop>& eval = do_make_eval(parser, state);
// the genotype (through a genotype initializer)
eoInit<FlowShop>& init = do_make_genotype(parser, state);
// the variation operators
eoGenOp<FlowShop>& op = do_make_op(parser, state);
// The fitness evaluation
eoEvalFuncCounter<FlowShop>& eval = do_make_eval(parser, state);
// the genotype (through a genotype initializer)
eoInit<FlowShop>& init = do_make_genotype(parser, state);
// the variation operators
eoGenOp<FlowShop>& op = do_make_op(parser, state);
/*** the representation-independent things ***/
/*** the representation-independent things ***/
// initialization of the population
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
// definition of the archive
moeoArchive<FlowShop> arch;
// stopping criteria
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
// output
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
// algorithm
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
// initialization of the population
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
// definition of the archive
moeoArchive<FlowShop> arch;
// stopping criteria
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
// output
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
// algorithm
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
/*** Go ! ***/
/*** Go ! ***/
// help ?
make_help(parser);
// help ?
make_help(parser);
// first evalution
apply<FlowShop>(eval, pop);
// first evalution
apply<FlowShop>(eval, pop);
// printing of the initial population
cout << "Initial Population\n";
pop.sortedPrintOn(cout);
cout << endl;
// printing of the initial population
cout << "Initial Population\n";
pop.sortedPrintOn(cout);
cout << endl;
// run the algo
do_run(algo, pop);
// run the algo
do_run(algo, pop);
// printing of the final population
cout << "Final Population\n";
pop.sortedPrintOn(cout);
cout << endl;
// printing of the final population
cout << "Final Population\n";
pop.sortedPrintOn(cout);
cout << endl;
// printing of the final archive
cout << "Final Archive\n";
arch.sortedPrintOn(cout);
cout << endl;
// printing of the final archive
cout << "Final Archive\n";
arch.sortedPrintOn(cout);
cout << endl;
}
catch (exception& e)
catch (exception& e)
{
cout << e.what() << endl;
cout << e.what() << endl;
}
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}

View file

@ -1,4 +1,4 @@
/*
/*
* <Sch1.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -44,21 +44,21 @@ using namespace std;
// the moeoObjectiveVectorTraits : minimizing 2 objectives
class Sch1ObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
{
public:
static bool minimizing (int i)
{
return true;
return true;
}
static bool maximizing (int i)
{
return false;
return false;
}
static unsigned int nObjectives ()
{
return 2;
return 2;
}
};
};
// objective vector of real values
@ -67,66 +67,67 @@ typedef moeoRealObjectiveVector < Sch1ObjectiveVectorTraits > Sch1ObjectiveVecto
// multi-objective evolving object for the Sch1 problem
class Sch1 : public moeoRealVector < Sch1ObjectiveVector, double, double >
{
public:
Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1) {}
};
{
public:
Sch1() : moeoRealVector < Sch1ObjectiveVector, double, double > (1)
{}
};
// evaluation of objective functions
class Sch1Eval : public moeoEvalFunc < Sch1 >
{
public:
{
public:
void operator () (Sch1 & _sch1)
{
if (_sch1.invalidObjectiveVector())
if (_sch1.invalidObjectiveVector())
{
Sch1ObjectiveVector objVec;
double x = _sch1[0];
objVec[0] = x * x;
objVec[1] = (x - 2.0) * (x - 2.0);
_sch1.objectiveVector(objVec);
Sch1ObjectiveVector objVec;
double x = _sch1[0];
objVec[0] = x * x;
objVec[1] = (x - 2.0) * (x - 2.0);
_sch1.objectiveVector(objVec);
}
}
};
};
// main
int main (int argc, char *argv[])
{
// parameters
unsigned int POP_SIZE = 20;
unsigned int MAX_GEN = 100;
double M_EPSILON = 0.01;
double P_CROSS = 0.25;
double P_MUT = 0.35;
// parameters
unsigned int POP_SIZE = 20;
unsigned int MAX_GEN = 100;
double M_EPSILON = 0.01;
double P_CROSS = 0.25;
double P_MUT = 0.35;
// objective functions evaluation
Sch1Eval eval;
// objective functions evaluation
Sch1Eval eval;
// crossover and mutation
eoQuadCloneOp < Sch1 > xover;
eoUniformMutation < Sch1 > mutation (M_EPSILON);
// crossover and mutation
eoQuadCloneOp < Sch1 > xover;
eoUniformMutation < Sch1 > mutation (M_EPSILON);
// generate initial population
eoRealVectorBounds bounds (1, 0.0, 2.0); // [0, 2]
eoRealInitBounded < Sch1 > init (bounds);
eoPop < Sch1 > pop (POP_SIZE, init);
// generate initial population
eoRealVectorBounds bounds (1, 0.0, 2.0); // [0, 2]
eoRealInitBounded < Sch1 > init (bounds);
eoPop < Sch1 > pop (POP_SIZE, init);
// build NSGA-II
moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
// build NSGA-II
moeoNSGAII < Sch1 > nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
// run the algo
nsgaII (pop);
// run the algo
nsgaII (pop);
// extract first front of the final population using an moeoArchive (this is the output of nsgaII)
moeoArchive < Sch1 > arch;
arch.update (pop);
// extract first front of the final population using an moeoArchive (this is the output of nsgaII)
moeoArchive < Sch1 > arch;
arch.update (pop);
// printing of the final archive
cout << "Final Archive" << endl;
arch.sortedPrintOn (cout);
cout << endl;
// printing of the final archive
cout << "Final Archive" << endl;
arch.sortedPrintOn (cout);
cout << endl;
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShop.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -38,6 +38,6 @@
#include <FlowShop.h>
std::string FlowShop::className() const
{
{
return "FlowShop";
}
}

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShop.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -45,14 +45,14 @@
* Structure of the genotype for the flow-shop scheduling problem: a vector of unsigned int int.
*/
class FlowShop: public moeoVector < FlowShopObjectiveVector , double , double , unsigned int >
{
public:
{
public:
/**
* class name
*/
std::string className() const;
};
};
#endif /*FLOWSHOP_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopBenchmarkParser.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -40,87 +40,92 @@
FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName)
{
init(_benchmarkFileName);
init(_benchmarkFileName);
}
const unsigned int FlowShopBenchmarkParser::getM()
{
return M;
return M;
}
const unsigned int FlowShopBenchmarkParser::getN()
{
return N;
return N;
}
const std::vector< std::vector<unsigned int> > FlowShopBenchmarkParser::getP()
{
return p;
return p;
}
const std::vector<unsigned int> FlowShopBenchmarkParser::getD()
{
return d;
return d;
}
void FlowShopBenchmarkParser::printOn(std::ostream & _os) const
{
{
_os << "M=" << M << " N=" << N << std::endl;
_os << "*** processing times" << std::endl;
for (unsigned int i=0; i<M; i++) {
for (unsigned int j=0; j<N; j++) {
for (unsigned int i=0; i<M; i++)
{
for (unsigned int j=0; j<N; j++)
{
_os << p[i][j] << " ";
}
}
_os << std::endl;
}
}
_os << "*** due-dates" << std::endl;
for (unsigned int j=0; j<N; j++) {
for (unsigned int j=0; j<N; j++)
{
_os << d[j] << " ";
}
}
_os << std::endl << std::endl;
}
}
void FlowShopBenchmarkParser::init(const std::string _benchmarkFileName)
{
std::string buffer;
std::string::size_type start, end;
std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
// opening of the benchmark file
if (! inputFile)
throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
// number of jobs (N)
getline(inputFile, buffer, '\n');
N = atoi(buffer.data());
// number of machines M
getline(inputFile, buffer, '\n');
M = atoi(buffer.data());
// initial and current seeds (not used)
getline(inputFile, buffer, '\n');
// processing times and due-dates
p = std::vector< std::vector<unsigned int> > (M,N);
d = std::vector<unsigned int> (N);
// for each job...
for (unsigned int j=0 ; j<N ; j++) {
// index of the job (<=> j)
getline(inputFile, buffer, '\n');
// due-date of the job j
getline(inputFile, buffer, '\n');
d[j] = atoi(buffer.data());
// processing times of the job j on each machine
getline(inputFile, buffer, '\n');
start = buffer.find_first_not_of(" ");
for (unsigned int i=0 ; i<M ; i++) {
end = buffer.find_first_of(" ", start);
p[i][j] = atoi(buffer.substr(start, end-start).data());
start = buffer.find_first_not_of(" ", end);
std::string buffer;
std::string::size_type start, end;
std::ifstream inputFile(_benchmarkFileName.data(), std::ios::in);
// opening of the benchmark file
if (! inputFile)
throw std::runtime_error("*** ERROR : Unable to open the benchmark file");
// number of jobs (N)
getline(inputFile, buffer, '\n');
N = atoi(buffer.data());
// number of machines M
getline(inputFile, buffer, '\n');
M = atoi(buffer.data());
// initial and current seeds (not used)
getline(inputFile, buffer, '\n');
// processing times and due-dates
p = std::vector< std::vector<unsigned int> > (M,N);
d = std::vector<unsigned int> (N);
// for each job...
for (unsigned int j=0 ; j<N ; j++)
{
// index of the job (<=> j)
getline(inputFile, buffer, '\n');
// due-date of the job j
getline(inputFile, buffer, '\n');
d[j] = atoi(buffer.data());
// processing times of the job j on each machine
getline(inputFile, buffer, '\n');
start = buffer.find_first_not_of(" ");
for (unsigned int i=0 ; i<M ; i++)
{
end = buffer.find_first_of(" ", start);
p[i][j] = atoi(buffer.substr(start, end-start).data());
start = buffer.find_first_not_of(" ", end);
}
}
// closing of the input file
inputFile.close();
// closing of the input file
inputFile.close();
}

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopBenchmarkParser.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -46,8 +46,8 @@
* Class to handle parameters of a flow-shop instance from a benchmark file
*/
class FlowShopBenchmarkParser
{
public:
{
public:
/**
* Ctor
@ -86,7 +86,7 @@ public:
void printOn(std::ostream & _os) const;
private:
private:
/** number of machines */
unsigned int M;
@ -104,6 +104,6 @@ private:
*/
void init(const std::string _benchmarkFileName);
};
};
#endif /*FLOWSHOPBENCHMARKPARSER_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopEval.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -39,51 +39,52 @@
FlowShopEval::FlowShopEval(unsigned int _M, unsigned int _N, const std::vector< std::vector<unsigned int> > & _p, const std::vector<unsigned int> & _d) :
M(_M), N (_N), p(_p), d(_d)
M(_M), N (_N), p(_p), d(_d)
{}
void FlowShopEval::operator()(FlowShop & _flowshop)
{
FlowShopObjectiveVector objVector;
objVector[0] = makespan(_flowshop);
objVector[1] = tardiness(_flowshop);
_flowshop.objectiveVector(objVector);
FlowShopObjectiveVector objVector;
objVector[0] = makespan(_flowshop);
objVector[1] = tardiness(_flowshop);
_flowshop.objectiveVector(objVector);
}
double FlowShopEval::makespan(const FlowShop & _flowshop)
{
// completion times computation for each job on each machine
// C[i][j] = completion of the jth job of the scheduling on the ith machine
std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
return C[M-1][_flowshop[N-1]];
// completion times computation for each job on each machine
// C[i][j] = completion of the jth job of the scheduling on the ith machine
std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
return C[M-1][_flowshop[N-1]];
}
double FlowShopEval::tardiness(const FlowShop & _flowshop)
{
// completion times computation for each job on each machine
// C[i][j] = completion of the jth job of the scheduling on the ith machine
std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
// tardiness computation
unsigned int long sum = 0;
for (unsigned int j=0 ; j<N ; j++)
sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]]));
return sum;
// completion times computation for each job on each machine
// C[i][j] = completion of the jth job of the scheduling on the ith machine
std::vector< std::vector<unsigned int> > C = completionTime(_flowshop);
// tardiness computation
unsigned int long sum = 0;
for (unsigned int j=0 ; j<N ; j++)
sum += (unsigned int) std::max (0, (int) (C[M-1][_flowshop[j]] - d[_flowshop[j]]));
return sum;
}
std::vector< std::vector<unsigned int> > FlowShopEval::completionTime(const FlowShop & _flowshop) {
std::vector< std::vector<unsigned int> > C(M,N);
C[0][_flowshop[0]] = p[0][_flowshop[0]];
std::vector< std::vector<unsigned int> > FlowShopEval::completionTime(const FlowShop & _flowshop)
{
std::vector< std::vector<unsigned int> > C(M,N);
C[0][_flowshop[0]] = p[0][_flowshop[0]];
for (unsigned int j=1; j<N; j++)
C[0][_flowshop[j]] = C[0][_flowshop[j-1]] + p[0][_flowshop[j]];
for (unsigned int i=1; i<M; i++)
C[i][_flowshop[0]] = C[i-1][_flowshop[0]] + p[i][_flowshop[0]];
for (unsigned int i=1; i<M; i++)
for (unsigned int j=1; j<N; j++)
C[0][_flowshop[j]] = C[0][_flowshop[j-1]] + p[0][_flowshop[j]];
for (unsigned int i=1; i<M; i++)
C[i][_flowshop[0]] = C[i-1][_flowshop[0]] + p[i][_flowshop[0]];
for (unsigned int i=1; i<M; i++)
for (unsigned int j=1; j<N; j++)
C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]];
return C;
C[i][_flowshop[j]] = std::max(C[i][_flowshop[j-1]], C[i-1][_flowshop[j]]) + p[i][_flowshop[j]];
return C;
}

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopEval.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -46,8 +46,8 @@
* Evaluation of the objective vector a (multi-objective) FlowShop object
*/
class FlowShopEval : public moeoEvalFunc<FlowShop>
{
public:
{
public:
/**
* Ctor
@ -66,7 +66,7 @@ public:
void operator()(FlowShop & _flowshop);
private:
private:
/** number of machines */
unsigned int M;
@ -99,6 +99,6 @@ private:
*/
std::vector< std::vector<unsigned int> > completionTime (const FlowShop & _flowshop);
};
};
#endif /*FLOWSHOPEVAL_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopInit.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -44,21 +44,21 @@ FlowShopInit::FlowShopInit(unsigned int _N) : N(_N)
void FlowShopInit::operator()(FlowShop & _flowshop)
{
// scheduling vector
std::vector<unsigned int> scheduling(N);
// initialisation of possible values
std::vector<unsigned int> possibles(N);
for (unsigned int i=0 ; i<N ; i++)
possibles[i] = i;
// random initialization
unsigned int rInd; // random index
for (unsigned int i=0; i<N; i++)
// scheduling vector
std::vector<unsigned int> scheduling(N);
// initialisation of possible values
std::vector<unsigned int> possibles(N);
for (unsigned int i=0 ; i<N ; i++)
possibles[i] = i;
// random initialization
unsigned int rInd; // random index
for (unsigned int i=0; i<N; i++)
{
rInd = (unsigned int) rng.uniform(N-i);
scheduling[i] = possibles[rInd];
possibles[rInd] = possibles[N-i-1];
rInd = (unsigned int) rng.uniform(N-i);
scheduling[i] = possibles[rInd];
possibles[rInd] = possibles[N-i-1];
}
_flowshop.resize(N);
_flowshop.value(scheduling);
_flowshop.invalidate(); // IMPORTANT in case the _genotype is old
_flowshop.resize(N);
_flowshop.value(scheduling);
_flowshop.invalidate(); // IMPORTANT in case the _genotype is old
}

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopInit.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
* Initialization of a random genotype built by the default constructor of the FlowShop class
*/
class FlowShopInit : public eoInit<FlowShop>
{
public:
{
public:
/**
* Ctor
@ -62,11 +62,11 @@ public:
void operator()(FlowShop & _flowshop);
private:
private:
/** the number of jobs (size of a scheduling vector) */
unsigned int N;
};
};
#endif /*FLOWSHOPINIT_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopObjectiveVector.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopObjectiveVectorTraits.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -40,18 +40,18 @@
bool FlowShopObjectiveVectorTraits::minimizing (int _i)
{
// minimizing both
return true;
// minimizing both
return true;
}
bool FlowShopObjectiveVectorTraits::maximizing (int _i)
{
// minimizing both
return false;
// minimizing both
return false;
}
unsigned int FlowShopObjectiveVectorTraits::nObjectives ()
{
// 2 objectives
return 2;
// 2 objectives
return 2;
}

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopObjectiveVectorTraits.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -44,8 +44,8 @@
* Definition of the objective vector traits for multi-objective flow-shop problems
*/
class FlowShopObjectiveVectorTraits : public moeoObjectiveVectorTraits
{
public:
{
public:
/**
* Returns true if the _ith objective have to be minimzed
@ -66,6 +66,6 @@ public:
*/
static unsigned int nObjectives ();
};
};
#endif /*FLOWSHOPOBJECTIVEVECTORTRAITS_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopOpCrossoverQuad.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -39,71 +39,72 @@
std::string FlowShopOpCrossoverQuad::className() const
{
{
return "FlowShopOpCrossoverQuad";
}
}
bool FlowShopOpCrossoverQuad::operator()(FlowShop & _flowshop1, FlowShop & _flowshop2)
{
bool oneAtLeastIsModified;
// computation of the 2 random points
unsigned int point1, point2;
do
bool oneAtLeastIsModified;
// computation of the 2 random points
unsigned int point1, point2;
do
{
point1 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
point2 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
} while (fabs((double) point1-point2) <= 2);
// computation of the offspring
FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2);
FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2);
// does at least one genotype has been modified ?
if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2))
{
// update
_flowshop1.value(offspring1);
_flowshop2.value(offspring2);
// at least one genotype has been modified
oneAtLeastIsModified = true;
point1 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
point2 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
}
else
while (fabs((double) point1-point2) <= 2);
// computation of the offspring
FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2);
FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2);
// does at least one genotype has been modified ?
if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2))
{
// no genotype has been modified
oneAtLeastIsModified = false;
// update
_flowshop1.value(offspring1);
_flowshop2.value(offspring2);
// at least one genotype has been modified
oneAtLeastIsModified = true;
}
// return 'true' if at least one genotype has been modified
return oneAtLeastIsModified;
else
{
// no genotype has been modified
oneAtLeastIsModified = false;
}
// return 'true' if at least one genotype has been modified
return oneAtLeastIsModified;
}
FlowShop FlowShopOpCrossoverQuad::generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2)
{
FlowShop result = _parent1;
std::vector<bool> taken_values(result.size(), false);
if (_point1 > _point2)
std::swap(_point1, _point2);
/* first parent */
for (unsigned int i=0 ; i<=_point1 ; i++)
FlowShop result = _parent1;
std::vector<bool> taken_values(result.size(), false);
if (_point1 > _point2)
std::swap(_point1, _point2);
/* first parent */
for (unsigned int i=0 ; i<=_point1 ; i++)
{
// result[i] == _parent1[i]
taken_values[_parent1[i]] = true;
// result[i] == _parent1[i]
taken_values[_parent1[i]] = true;
}
for (unsigned int i=_point2 ; i<result.size() ; i++)
for (unsigned int i=_point2 ; i<result.size() ; i++)
{
// result[i] == _parent1[i]
taken_values[_parent1[i]] = true;
// result[i] == _parent1[i]
taken_values[_parent1[i]] = true;
}
/* second parent */
unsigned int i = _point1+1;
unsigned int j = 0;
while (i<_point2 && j<_parent2.size())
/* second parent */
unsigned int i = _point1+1;
unsigned int j = 0;
while (i<_point2 && j<_parent2.size())
{
if (! taken_values[_parent2[j]])
if (! taken_values[_parent2[j]])
{
result[i] = _parent2[j];
i++;
result[i] = _parent2[j];
i++;
}
j++;
j++;
}
return result;
return result;
}

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopOpCrossoverQuad.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
* Quadratic crossover operator for flow-shop (modify the both genotypes)
*/
class FlowShopOpCrossoverQuad : public eoQuadOp < FlowShop >
{
public:
{
public:
/**
* the class name (used to display statistics)
@ -62,7 +62,7 @@ public:
bool operator()(FlowShop & _flowshop1, FlowShop & _flowshop2);
private:
private:
/**
* generation of an offspring by a 2 points crossover
@ -73,6 +73,6 @@ private:
*/
FlowShop generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2);
};
};
#endif /*FLOWSHOPOPCROSSOVERQUAD_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopOpMutationExchange.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -39,37 +39,38 @@
std::string FlowShopOpMutationExchange::className() const
{
{
return "FlowShopOpMutationExchange";
}
}
bool FlowShopOpMutationExchange::operator()(FlowShop & _flowshop)
{
bool isModified;
FlowShop result = _flowshop;
// computation of the 2 random points
unsigned int point1, point2;
do
bool isModified;
FlowShop result = _flowshop;
// computation of the 2 random points
unsigned int point1, point2;
do
{
point1 = rng.random(result.size());
point2 = rng.random(result.size());
} while (point1 == point2);
// swap
std::swap (result[point1], result[point2]);
// update (if necessary)
if (result != _flowshop)
{
// update
_flowshop.value(result);
// the genotype has been modified
isModified = true;
point1 = rng.random(result.size());
point2 = rng.random(result.size());
}
else
while (point1 == point2);
// swap
std::swap (result[point1], result[point2]);
// update (if necessary)
if (result != _flowshop)
{
// the genotype has not been modified
isModified = false;
// update
_flowshop.value(result);
// the genotype has been modified
isModified = true;
}
// return 'true' if the genotype has been modified
return isModified;
else
{
// the genotype has not been modified
isModified = false;
}
// return 'true' if the genotype has been modified
return isModified;
}

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopOpMutationExchange.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
* Exchange mutation operator for the flow-shop
*/
class FlowShopOpMutationExchange : public eoMonOp<FlowShop>
{
public:
{
public:
/**
* the class name (used to display statistics)
@ -60,6 +60,6 @@ public:
*/
bool operator()(FlowShop & _flowshop);
};
};
#endif /*FLOWSHOPOPMUTATIONEXCHANGE_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopOpMutationShift.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -39,47 +39,48 @@
std::string FlowShopOpMutationShift::className() const
{
{
return "FlowShopOpMutationShift";
}
}
bool FlowShopOpMutationShift::operator()(FlowShop & _flowshop)
{
bool isModified;
int direction;
unsigned int tmp;
FlowShop result = _flowshop;
// computation of the 2 random points
unsigned int point1, point2;
do
bool isModified;
int direction;
unsigned int tmp;
FlowShop result = _flowshop;
// computation of the 2 random points
unsigned int point1, point2;
do
{
point1 = rng.random(result.size());
point2 = rng.random(result.size());
} while (point1 == point2);
// direction
if (point1 < point2)
direction = 1;
else
direction = -1;
// mutation
tmp = result[point1];
for (unsigned int i=point1 ; i!=point2 ; i+=direction)
result[i] = result[i+direction];
result[point2] = tmp;
// update (if necessary)
if (result != _flowshop)
{
// update
_flowshop.value(result);
// the genotype has been modified
isModified = true;
point1 = rng.random(result.size());
point2 = rng.random(result.size());
}
else
while (point1 == point2);
// direction
if (point1 < point2)
direction = 1;
else
direction = -1;
// mutation
tmp = result[point1];
for (unsigned int i=point1 ; i!=point2 ; i+=direction)
result[i] = result[i+direction];
result[point2] = tmp;
// update (if necessary)
if (result != _flowshop)
{
// the genotype has not been modified
isModified = false;
// update
_flowshop.value(result);
// the genotype has been modified
isModified = true;
}
// return 'true' if the genotype has been modified
return isModified;
else
{
// the genotype has not been modified
isModified = false;
}
// return 'true' if the genotype has been modified
return isModified;
}

View file

@ -1,4 +1,4 @@
/*
/*
* <FlowShopOpMutationShift.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -45,8 +45,8 @@
* Shift mutation operator for flow-shop
*/
class FlowShopOpMutationShift : public eoMonOp < FlowShop >
{
public:
{
public:
/**
* the class name (used to display statistics)
@ -60,6 +60,6 @@ public:
*/
bool operator()(FlowShop & _flowshop);
};
};
#endif /*FLOWSHOPOPMUTATIONSHIFT_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <make_eval_FlowShop.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -53,28 +53,29 @@
*/
eoEvalFuncCounter<FlowShop> & do_make_eval(eoParser& _parser, eoState& _state)
{
// benchmark file name
std::string benchmarkFileName = _parser.getORcreateParam(std::string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at www.lifl.fr/~liefooga/benchmarks)", 'B',"Representation", true).value();
if (benchmarkFileName == "") {
std::string stmp = "*** Missing name of the benchmark file\n";
stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n";
stmp += " Benchmarks files are available at www.lifl.fr/~liefooga/benchmarks";
throw std::runtime_error(stmp.c_str());
// benchmark file name
std::string benchmarkFileName = _parser.getORcreateParam(std::string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at www.lifl.fr/~liefooga/benchmarks)", 'B',"Representation", true).value();
if (benchmarkFileName == "")
{
std::string stmp = "*** Missing name of the benchmark file\n";
stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n";
stmp += " Benchmarks files are available at www.lifl.fr/~liefooga/benchmarks";
throw std::runtime_error(stmp.c_str());
}
// reading of the parameters contained in the benchmark file
FlowShopBenchmarkParser fParser(benchmarkFileName);
unsigned int M = fParser.getM();
unsigned int N = fParser.getN();
std::vector< std::vector<unsigned int> > p = fParser.getP();
std::vector<unsigned int> d = fParser.getD();
// build of the initializer (a pointer, stored in the eoState)
FlowShopEval* plainEval = new FlowShopEval(M, N, p, d);
// turn that object into an evaluation counter
eoEvalFuncCounter<FlowShop>* eval = new eoEvalFuncCounter<FlowShop> (* plainEval);
// store in state
_state.storeFunctor(eval);
// and return a reference
return *eval;
// reading of the parameters contained in the benchmark file
FlowShopBenchmarkParser fParser(benchmarkFileName);
unsigned int M = fParser.getM();
unsigned int N = fParser.getN();
std::vector< std::vector<unsigned int> > p = fParser.getP();
std::vector<unsigned int> d = fParser.getD();
// build of the initializer (a pointer, stored in the eoState)
FlowShopEval* plainEval = new FlowShopEval(M, N, p, d);
// turn that object into an evaluation counter
eoEvalFuncCounter<FlowShop>* eval = new eoEvalFuncCounter<FlowShop> (* plainEval);
// store in state
_state.storeFunctor(eval);
// and return a reference
return *eval;
}
#endif /*MAKE_EVAL_FLOWSHOP_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <make_genotype_FlowShop.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -51,23 +51,24 @@
*/
eoInit<FlowShop> & do_make_genotype(eoParser& _parser, eoState& _state)
{
// benchmark file name
std::string benchmarkFileName = _parser.getORcreateParam(std::string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at www.lifl.fr/~liefooga/benchmarks/)", 'B',"Representation", true).value();
if (benchmarkFileName == "") {
std::string stmp = "*** Missing name of the benchmark file\n";
stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n";
stmp += " Benchmarks files are available at www.lifl.fr/~liefooga/benchmarks";
throw std::runtime_error(stmp.c_str());
// benchmark file name
std::string benchmarkFileName = _parser.getORcreateParam(std::string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at www.lifl.fr/~liefooga/benchmarks/)", 'B',"Representation", true).value();
if (benchmarkFileName == "")
{
std::string stmp = "*** Missing name of the benchmark file\n";
stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n";
stmp += " Benchmarks files are available at www.lifl.fr/~liefooga/benchmarks";
throw std::runtime_error(stmp.c_str());
}
// reading of number of jobs to schedule contained in the benchmark file
FlowShopBenchmarkParser fParser(benchmarkFileName);
unsigned int N = fParser.getN();
// build of the initializer (a pointer, stored in the eoState)
eoInit<FlowShop>* init = new FlowShopInit(N);
// store in state
_state.storeFunctor(init);
// and return a reference
return *init;
// reading of number of jobs to schedule contained in the benchmark file
FlowShopBenchmarkParser fParser(benchmarkFileName);
unsigned int N = fParser.getN();
// build of the initializer (a pointer, stored in the eoState)
eoInit<FlowShop>* init = new FlowShopInit(N);
// store in state
_state.storeFunctor(init);
// and return a reference
return *init;
}
#endif /*MAKE_GENOTYPE_FLOWSHOP_H_*/

View file

@ -1,4 +1,4 @@
/*
/*
* <make_op_FlowShop.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -57,76 +57,76 @@
eoGenOp<FlowShop> & do_make_op(eoParameterLoader& _parser, eoState& _state)
{
/////////////////////////////
// Variation operators
////////////////////////////
/////////////////////////////
// Variation operators
////////////////////////////
// the crossover
////////////////
// the crossover
////////////////
// a first crossover
eoQuadOp<FlowShop> *cross = new FlowShopOpCrossoverQuad;
// store in the state
_state.storeFunctor(cross);
// a first crossover
eoQuadOp<FlowShop> *cross = new FlowShopOpCrossoverQuad;
// store in the state
_state.storeFunctor(cross);
// relative rate in the combination
double cross1Rate = _parser.createParam(1.0, "crossRate", "Relative rate for the only crossover", 0, "Variation Operators").value();
// creation of the combined operator with this one
eoPropCombinedQuadOp<FlowShop> *propXover = new eoPropCombinedQuadOp<FlowShop>(*cross, cross1Rate);
// store in the state
_state.storeFunctor(propXover);
// relative rate in the combination
double cross1Rate = _parser.createParam(1.0, "crossRate", "Relative rate for the only crossover", 0, "Variation Operators").value();
// creation of the combined operator with this one
eoPropCombinedQuadOp<FlowShop> *propXover = new eoPropCombinedQuadOp<FlowShop>(*cross, cross1Rate);
// store in the state
_state.storeFunctor(propXover);
// the mutation
///////////////
// the mutation
///////////////
// a first mutation : the shift mutation
eoMonOp<FlowShop> *mut = new FlowShopOpMutationShift;
_state.storeFunctor(mut);
// its relative rate in the combination
double mut1Rate = _parser.createParam(0.5, "shiftMutRate", "Relative rate for shift mutation", 0, "Variation Operators").value();
// creation of the combined operator with this one
eoPropCombinedMonOp<FlowShop> *propMutation = new eoPropCombinedMonOp<FlowShop>(*mut, mut1Rate);
_state.storeFunctor(propMutation);
// a first mutation : the shift mutation
eoMonOp<FlowShop> *mut = new FlowShopOpMutationShift;
_state.storeFunctor(mut);
// its relative rate in the combination
double mut1Rate = _parser.createParam(0.5, "shiftMutRate", "Relative rate for shift mutation", 0, "Variation Operators").value();
// creation of the combined operator with this one
eoPropCombinedMonOp<FlowShop> *propMutation = new eoPropCombinedMonOp<FlowShop>(*mut, mut1Rate);
_state.storeFunctor(propMutation);
// a second mutation : the exchange mutation
mut = new FlowShopOpMutationExchange;
_state.storeFunctor(mut);
// its relative rate in the combination
double mut2Rate = _parser.createParam(0.5, "exchangeMutRate", "Relative rate for exchange mutation", 0, "Variation Operators").value();
// addition of this one to the combined operator
propMutation -> add(*mut, mut2Rate);
// a second mutation : the exchange mutation
mut = new FlowShopOpMutationExchange;
_state.storeFunctor(mut);
// its relative rate in the combination
double mut2Rate = _parser.createParam(0.5, "exchangeMutRate", "Relative rate for exchange mutation", 0, "Variation Operators").value();
// addition of this one to the combined operator
propMutation -> add(*mut, mut2Rate);
// end of crossover and mutation definitions
////////////////////////////////////////////
// end of crossover and mutation definitions
////////////////////////////////////////////
// First read the individual level parameters
eoValueParam<double>& pCrossParam = _parser.createParam(0.25, "pCross", "Probability of Crossover", 'c', "Variation Operators" );
// minimum check
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
throw std::runtime_error("Invalid pCross");
// First read the individual level parameters
eoValueParam<double>& pCrossParam = _parser.createParam(0.25, "pCross", "Probability of Crossover", 'c', "Variation Operators" );
// minimum check
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
throw std::runtime_error("Invalid pCross");
eoValueParam<double>& pMutParam = _parser.createParam(0.35, "pMut", "Probability of Mutation", 'm', "Variation Operators" );
// minimum check
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
throw std::runtime_error("Invalid pMut");
eoValueParam<double>& pMutParam = _parser.createParam(0.35, "pMut", "Probability of Mutation", 'm', "Variation Operators" );
// minimum check
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
throw std::runtime_error("Invalid pMut");
// the crossover - with probability pCross
eoProportionalOp<FlowShop> * propOp = new eoProportionalOp<FlowShop> ;
_state.storeFunctor(propOp);
eoQuadOp<FlowShop> *ptQuad = new eoQuadCloneOp<FlowShop>;
_state.storeFunctor(ptQuad);
propOp -> add(*propXover, pCrossParam.value()); // crossover, with proba pcross
propOp -> add(*ptQuad, 1-pCrossParam.value()); // nothing, with proba 1-pcross
// the crossover - with probability pCross
eoProportionalOp<FlowShop> * propOp = new eoProportionalOp<FlowShop> ;
_state.storeFunctor(propOp);
eoQuadOp<FlowShop> *ptQuad = new eoQuadCloneOp<FlowShop>;
_state.storeFunctor(ptQuad);
propOp -> add(*propXover, pCrossParam.value()); // crossover, with proba pcross
propOp -> add(*ptQuad, 1-pCrossParam.value()); // nothing, with proba 1-pcross
// now the sequential
eoSequentialOp<FlowShop> *op = new eoSequentialOp<FlowShop>;
_state.storeFunctor(op);
op -> add(*propOp, 1.0); // always do combined crossover
op -> add(*propMutation, pMutParam.value()); // then mutation, with proba pmut
// now the sequential
eoSequentialOp<FlowShop> *op = new eoSequentialOp<FlowShop>;
_state.storeFunctor(op);
op -> add(*propOp, 1.0); // always do combined crossover
op -> add(*propMutation, pMutParam.value()); // then mutation, with proba pmut
// return a reference
return *op;
// return a reference
return *op;
}
#endif /*MAKE_OP_FLOWSHOP_H_*/