diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/FlowShop.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/FlowShop.h deleted file mode 100644 index 336ebd831..000000000 --- a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/FlowShop.h +++ /dev/null @@ -1,114 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// FlowShop.h -// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 -/* - This library... - - Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr - */ -//----------------------------------------------------------------------------- - -#ifndef FLOWSHOP_H_ -#define FLOWSHOP_H_ - -#include -#include -#include - - -/** - * definition of the objective vector for multi-objective flow-shop problems - */ -typedef moeoObjectiveVectorDouble FlowShopObjectiveVector; - - -/** - * Structure of the genotype for the flow-shop scheduling problem - */ -class FlowShop: public MOEO { - -public: - - /** - * default constructor - */ - FlowShop() {} - - /** - * destructor - */ - virtual ~FlowShop() {} - - /** - * class name - */ - virtual string className() const { - return "FlowShop"; - } - - /** - * set scheduling vector - * @param vector & _scheduling the new scheduling to set - */ - void setScheduling(vector & _scheduling) { - scheduling = _scheduling; - } - - /** - * get scheduling vector - */ - const vector & getScheduling() const { - return scheduling; - } - - /** - * printing... - */ - void printOn(ostream& _os) const { - // fitness - MOEO::printOn(_os); - // size - _os << scheduling.size() << "\t" ; - // scheduling - for (unsigned i=0; i::readFrom(_is); - // size - unsigned size; - _is >> size; - // scheduling - scheduling.resize(size); - bool tmp; - for (unsigned i=0; i> tmp; - scheduling[i] = tmp; - } - } - - - bool operator==(const FlowShop& _other) const { return scheduling == _other.getScheduling(); } - bool operator!=(const FlowShop& _other) const { return scheduling != _other.getScheduling(); } - bool operator< (const FlowShop& _other) const { return scheduling < _other.getScheduling(); } - bool operator> (const FlowShop& _other) const { return scheduling > _other.getScheduling(); } - bool operator<=(const FlowShop& _other) const { return scheduling <= _other.getScheduling(); } - bool operator>=(const FlowShop& _other) const { return scheduling >= _other.getScheduling(); } - - -private: - - /** scheduling (order of operations) */ - std::vector scheduling; - -}; - - -#endif /*FLOWSHOP_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/FlowShopBenchmarkParser.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/FlowShopBenchmarkParser.h deleted file mode 100644 index b4e4b13ab..000000000 --- a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/FlowShopBenchmarkParser.h +++ /dev/null @@ -1,140 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// FlowShopBenchmarkParser.h -// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 -/* - This library... - - Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr - */ -//----------------------------------------------------------------------------- - -#ifndef FLOWSHOPBENCHMARKPARSER_H_ -#define FLOWSHOPBENCHMARKPARSER_H_ -#include -#include - -/** Web site to download benchmarks */ -const static std::string BENCHMARKS_WEB_SITE = "www.lifl.fr/~basseur/BenchsUncertain/"; - - -/** - * Class to handle parameters of a flow-shop instance from a benchmark file - * benchmark files are available at www.lifl.fr/~basseur/BenchsUncertain/ - */ -class FlowShopBenchmarkParser { - -public: - - /** - * constructor - * @param const string _benchmarkFileName the name of the benchmark file - */ - FlowShopBenchmarkParser(const string _benchmarkFileName) { - init(_benchmarkFileName); - } - - /** - * the number of machines - */ - const unsigned getM() { - return M; - } - - /** - * the number of jobs - */ - const unsigned getN() { - return N; - } - - /** - * the processing times - */ - const std::vector< std::vector > getP() { - return p; - } - - /** - * the due-dates - */ - const std::vector getD() { - return d; - } - - /** - * printing... - */ - void printOn(ostream& _os) const { - _os << "M=" << M << " N=" << N << endl; - _os << "*** processing times" << endl; - for (unsigned i=0; i > p; - /** d[j] = due-date of the job j */ - std::vector d; - - - /** - * Initialisation of the parameters with the data contained in the benchmark file - * @param const string _benchmarkFileName the name of the benchmark file - */ - void init(const string _benchmarkFileName) { - string buffer; - string::size_type start, end; - ifstream inputFile(_benchmarkFileName.data(), ios::in); - // opening of the benchmark file - if (! inputFile) - cerr << "*** ERROR : Unable to open the benchmark file '" << _benchmarkFileName << "'" << endl; - // 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 > (M,N); - d = std::vector (N); - // for each job... - for (unsigned j=0 ; j 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 i=0 ; i - -/** - * Functor - * Computation of the multi-objective evaluation of a FlowShop object - */ -class FlowShopEval : public moeoEvalFunc { - -public: - - /** - * constructor - * @param _M the number of machines - * @param _N the number of jobs to schedule - * @param _p the processing times - * @param _d the due dates - */ - FlowShopEval(const unsigned _M, const unsigned _N, const vector< vector > & _p, const vector & _d) : - M(_M), N (_N), p(_p), d(_d){ - - unsigned nObjs = 2; - std::vector bObjs(nObjs, true); - moeoObjectiveVectorTraits::setup(nObjs, bObjs); - } - - - - /** - * computation of the multi-objective evaluation of an eoFlowShop object - * @param FlowShop & _eo the FlowShop object to evaluate - */ - void operator()(FlowShop & _eo) { - FlowShopObjectiveVector objVector; - objVector[0] = tardiness(_eo); - objVector[1] = makespan(_eo); - _eo.objectiveVector(objVector); - } - - - - - -private: - - /** number of machines */ - unsigned M; - /** number of jobs */ - unsigned N; - /** p[i][j] = processing time of job j on machine i */ - std::vector< std::vector > p; - /** d[j] = due-date of the job j */ - std::vector d; - - - - /** - * computation of the makespan - * @param FlowShop _eo the FlowShop object to evaluate - */ - double makespan(FlowShop _eo) { - // the scheduling to evaluate - vector scheduling = _eo.getScheduling(); - // 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 > C = completionTime(_eo); - // fitness == C[M-1][scheduling[N-1]]; - return C[M-1][scheduling[N-1]]; - } - - - - /** - * computation of the tardiness - * @param _eo the FlowShop object to evaluate - */ - double tardiness(FlowShop _eo) { - // the scheduling to evaluate - vector scheduling = _eo.getScheduling(); - // 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 > C = completionTime(_eo); - // tardiness computation - unsigned long sum = 0; - for (unsigned j=0 ; j > completionTime(FlowShop _eo) { - vector scheduling = _eo.getScheduling(); - std::vector< std::vector > C(M,N); - C[0][scheduling[0]] = p[0][scheduling[0]]; - for (unsigned j=1; j -#include "FlowShop.h" - -/** - * Functor - * Initialisation of a random genotype built by the default constructor of the eoFlowShop class - */ -class FlowShopInit: public eoInit { - -public: - - /** - * constructor - * @param const unsigned _N the number of jobs to schedule - */ - FlowShopInit(const unsigned _N) { - N = _N; - } - - /** - * randomize a genotype - * @param FlowShop & _genotype a genotype that has been default-constructed - */ - void operator()(FlowShop & _genotype) { - // scheduling vector - vector scheduling(N); - // initialisation of possible values - vector possibles(N); - for (unsigned i=0 ; i -#include "FlowShop.h" - -/** - * Functor - * Quadratic crossover operator for flow-shop (modify the both genotypes) - */ -class FlowShopOpCrossoverQuad: public eoQuadOp { - -public: - - /** - * default constructor - */ - FlowShopOpCrossoverQuad() {} - - /** - * the class name (used to display statistics) - */ - string className() const { - return "FlowShopOpCrossoverQuad"; - } - - /** - * eoQuad crossover - _genotype1 and _genotype2 are the (future) offspring, i.e. _copies_ of the parents - * @param FlowShop & _genotype1 the first parent - * @param FlowShop & _genotype2 the second parent - */ - bool operator()(FlowShop & _genotype1, FlowShop & _genotype2) { - bool oneAtLeastIsModified; - - // parents - vector parent1 = _genotype1.getScheduling(); - vector parent2 = _genotype2.getScheduling(); - - // computation of the 2 random points - unsigned point1, point2; - do { - point1 = rng.random(min(parent1.size(), parent2.size())); - point2 = rng.random(min(parent1.size(), parent2.size())); - } while (fabs((double) point1-point2) <= 2); - - // computation of the offspring - vector offspring1 = generateOffspring(parent1, parent2, point1, point2); - vector offspring2 = generateOffspring(parent2, parent1, point1, point2); - - // does at least one genotype has been modified ? - if ((parent1 != offspring1) || (parent2 != offspring2)) { - // update - _genotype1.setScheduling(offspring1); - _genotype2.setScheduling(offspring2); - // at least one genotype has been modified - oneAtLeastIsModified = true; - } - else { - // no genotype has been modified - oneAtLeastIsModified = false; - } - - // return 'true' if at least one genotype has been modified - return oneAtLeastIsModified; - } - - -private: - - /** - * generation of an offspring by a 2 points crossover - * @param vector _parent1 the first parent - * @param vector _parent2 the second parent - * @param unsigned_point1 the first point - * @param unsigned_point2 the second point - */ - vector generateOffspring(vector _parent1, vector _parent2, unsigned _point1, unsigned _point2) { - vector result = _parent1; - vector taken_values(result.size(), false); - if (_point1 > _point2) swap(_point1, _point2); - - /* first parent */ - for (unsigned i=0 ; i<=_point1 ; i++) { - // result[i] == _parent1[i] - taken_values[_parent1[i]] = true; - } - for (unsigned i=_point2 ; i -#include "FlowShop.h" - -/** - * Functor - * Exchange mutation operator for flow-shop - */ -class FlowShopOpMutationExchange: public eoMonOp { - -public: - - /** - * default constructor - */ - FlowShopOpMutationExchange() {} - - /** - * the class name (used to display statistics) - */ - string className() const { - return "FlowShopOpMutationExchange"; - } - - /** - * modifies the parent with an exchange mutation - * @param FlowShop & _genotype the parent genotype (will be modified) - */ - bool operator()(FlowShop & _genotype) { - bool isModified; - - // schedulings - vector initScheduling = _genotype.getScheduling(); - vector resultScheduling = _genotype.getScheduling(); - - // computation of the 2 random points - unsigned point1, point2; - do { - point1 = rng.random(resultScheduling.size()); - point2 = rng.random(resultScheduling.size()); - } while (point1 == point2); - - // swap - swap (resultScheduling[point1], resultScheduling[point2]); - - // update (if necessary) - if (resultScheduling != initScheduling) { - // update - _genotype.setScheduling(resultScheduling); - // the genotype has been modified - isModified = true; - } - else { - // the genotype has not been modified - isModified = false; - } - - // return 'true' if the genotype has been modified - return isModified; - } - -}; - -#endif /*FLOWSHOPOPMUTATIONEXCHANGE_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/FlowShopOpMutationShift.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/FlowShopOpMutationShift.h deleted file mode 100644 index b27e21e0f..000000000 --- a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/FlowShopOpMutationShift.h +++ /dev/null @@ -1,86 +0,0 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// FlowShopOpMutationShift.h -// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 -/* - This library... - - Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr - */ -//----------------------------------------------------------------------------- - -#ifndef FLOWSHOPOPMUTATIONSHIFT_H_ -#define FLOWSHOPOPMUTATIONSHIFT_H_ - -#include -#include "FlowShop.h" - -/** - * Functor - * Shift mutation operator for flow-shop - */ -class FlowShopOpMutationShift: public eoMonOp { - -public: - - /** - * default constructor - */ - FlowShopOpMutationShift() {} - - /** - * the class name (used to display statistics) - */ - string className() const { - return "FlowShopOpMutationShift"; - } - - /** - * modifies the parent with a shift mutation - * @param FlowShop & _genotype the parent genotype (will be modified) - */ - bool operator()(FlowShop & _genotype) { - bool isModified; - int direction; - unsigned tmp; - - // schedulings - vector initScheduling = _genotype.getScheduling(); - vector resultScheduling = initScheduling; - - // computation of the 2 random points - unsigned point1, point2; - do { - point1 = rng.random(resultScheduling.size()); - point2 = rng.random(resultScheduling.size()); - } while (point1 == point2); - - // direction - if (point1 < point2) direction = 1; - else direction = -1; - // mutation - tmp = resultScheduling[point1]; - for (unsigned i=point1 ; i!=point2 ; i+=direction) - resultScheduling[i] = resultScheduling[i+direction]; - resultScheduling[point2] = tmp; - - // update (if necessary) - if (resultScheduling != initScheduling) { - // update - _genotype.setScheduling(resultScheduling); - // the genotype has been modified - isModified = true; - } - else { - // the genotype has not been modified - isModified = false; - } - - // return 'true' if the genotype has been modified - return isModified; - } - -}; - -#endif /*FLOWSHOPOPMUTATIONSHIFT_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShop.cpp b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShop.cpp new file mode 100644 index 000000000..1ee6b9d0d --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShop.cpp @@ -0,0 +1,18 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShop.cpp +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#include + +std::string FlowShop::className() const +{ + return "FlowShop"; +} diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShop.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShop.h new file mode 100644 index 000000000..232ff8b64 --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShop.h @@ -0,0 +1,33 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShop.h +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#ifndef FLOWSHOP_H_ +#define FLOWSHOP_H_ + +#include +#include + +/** + * 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: + + /** + * class name + */ + std::string className() const; + +}; + +#endif /*FLOWSHOP_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopBenchmarkParser.cpp b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopBenchmarkParser.cpp new file mode 100644 index 000000000..0ca8c857e --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopBenchmarkParser.cpp @@ -0,0 +1,101 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopBenchmarkParser.cpp +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#include +#include + +FlowShopBenchmarkParser::FlowShopBenchmarkParser(const std::string _benchmarkFileName) +{ + init(_benchmarkFileName); +} + + +const unsigned int FlowShopBenchmarkParser::getM() +{ + return M; +} + + +const unsigned int FlowShopBenchmarkParser::getN() +{ + return N; +} + + +const std::vector< std::vector > FlowShopBenchmarkParser::getP() +{ + return p; +} + + +const std::vector FlowShopBenchmarkParser::getD() +{ + 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,N); + d = std::vector (N); + // for each job... + for (unsigned int j=0 ; j 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 +#include + +/** + * Class to handle parameters of a flow-shop instance from a benchmark file + */ +class FlowShopBenchmarkParser +{ +public: + + /** + * Ctor + * @param _benchmarkFileName the name of the benchmark file + */ + FlowShopBenchmarkParser(const std::string _benchmarkFileName); + + + /** + * the number of machines + */ + const unsigned int getM(); + + + /** + * the number of jobs + */ + const unsigned int getN(); + + + /** + * the processing times + */ + const std::vector < std::vector < unsigned int > > getP(); + + + /** + * the due-dates + */ + const std::vector < unsigned int > getD(); + + + /** + * printing... + */ + void printOn(std::ostream & _os) const; + + +private: + + /** number of machines */ + unsigned int M; + /** number of jobs */ + unsigned int N; + /** p[i][j] = processing time of job j on machine i */ + std::vector < std::vector < unsigned int > > p; + /** d[j] = due-date of the job j */ + std::vector < unsigned int > d; + + + /** + * Initialisation of the parameters with the data contained in the benchmark file + * @param _benchmarkFileName the name of the benchmark file + */ + void init(const std::string _benchmarkFileName); + +}; + +#endif /*FLOWSHOPBENCHMARKPARSER_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopEval.cpp b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopEval.cpp new file mode 100644 index 000000000..579d0bfc8 --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopEval.cpp @@ -0,0 +1,64 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopEval.cpp +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#include + + +FlowShopEval::FlowShopEval(unsigned int _M, unsigned int _N, const std::vector< std::vector > & _p, const std::vector & _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); +} + + + +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 > 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 > C = completionTime(_flowshop); + // tardiness computation + unsigned int long sum = 0; + for (unsigned int j=0 ; j > FlowShopEval::completionTime(const FlowShop & _flowshop) { + std::vector< std::vector > C(M,N); + C[0][_flowshop[0]] = p[0][_flowshop[0]]; + for (unsigned int j=1; j +#include +#include + +/** + * Evaluation of the objective vector a (multi-objective) FlowShop object + */ +class FlowShopEval : public moeoEvalFunc +{ +public: + + /** + * Ctor + * @param _M the number of machines + * @param _N the number of jobs to schedule + * @param _p the processing times + * @param _d the due dates + */ + FlowShopEval(unsigned int _M, unsigned int _N, const std::vector< std::vector > & _p, const std::vector & _d); + + + /** + * computation of the multi-objective evaluation of a FlowShop object + * @param _flowshop the FlowShop object to evaluate + */ + void operator()(FlowShop & _flowshop); + + +private: + + /** number of machines */ + unsigned int M; + /** number of jobs */ + unsigned int N; + /** p[i][j] = processing time of job j on machine i */ + std::vector< std::vector < unsigned int > > p; + /** d[j] = due-date of the job j */ + std::vector < unsigned int > d; + + + /** + * computation of the makespan + * @param _flowshop the genotype to evaluate + */ + double makespan(const FlowShop & _flowshop); + + + /** + * computation of the tardiness + * @param _flowshop the genotype to evaluate + */ + double tardiness(const FlowShop & _flowshop); + + + /** + * computation of the completion times of a scheduling (for each job on each machine) + * C[i][j] = completion of the jth job of the scheduling on the ith machine + * @param _flowshop the genotype to evaluate + */ + std::vector< std::vector > completionTime (const FlowShop & _flowshop); + +}; + +#endif /*FLOWSHOPEVAL_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopInit.cpp b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopInit.cpp new file mode 100644 index 000000000..d3877fb64 --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopInit.cpp @@ -0,0 +1,39 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopInit.cpp +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#include + + +FlowShopInit::FlowShopInit(unsigned int _N) : N(_N) +{} + + +void FlowShopInit::operator()(FlowShop & _flowshop) +{ + // scheduling vector + std::vector scheduling(N); + // initialisation of possible values + std::vector possibles(N); + for (unsigned int i=0 ; i +#include + +/** + * Initialization of a random genotype built by the default constructor of the FlowShop class + */ +class FlowShopInit : public eoInit +{ +public: + + /** + * Ctor + * @param _N the number of jobs to schedule + */ + FlowShopInit(unsigned int _N); + + + /** + * builds a random genotype + * @param _flowshop a genotype that has been default-constructed + */ + void operator()(FlowShop & _flowshop); + + +private: + + /** the number of jobs (size of a scheduling vector) */ + unsigned int N; + +}; + +#endif /*FLOWSHOPINIT_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopObjectiveVector.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopObjectiveVector.h new file mode 100644 index 000000000..53006f43e --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopObjectiveVector.h @@ -0,0 +1,24 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopObjectiveVector.h +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#ifndef FLOWSHOPOBJECTIVEVECTOR_H_ +#define FLOWSHOPOBJECTIVEVECTOR_H_ + +#include +#include + +/** + * Definition of the objective vector for multi-objective flow-shop problems: a vector of doubles + */ +typedef moeoObjectiveVectorDouble < FlowShopObjectiveVectorTraits > FlowShopObjectiveVector; + +#endif /*FLOWSHOPOBJECTIVEVECTOR_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopObjectiveVectorTraits.cpp b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopObjectiveVectorTraits.cpp new file mode 100644 index 000000000..b12d33aae --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopObjectiveVectorTraits.cpp @@ -0,0 +1,27 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopObjectiveVectorTraits.cpp +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#include + + +bool FlowShopObjectiveVectorTraits::minimizing (int _i) +{ + // minimizing both + return true; +} + + +unsigned int FlowShopObjectiveVectorTraits::nObjectives () +{ + // 2 objectives + return 2; +} diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopObjectiveVectorTraits.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopObjectiveVectorTraits.h new file mode 100644 index 000000000..dac46aab0 --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopObjectiveVectorTraits.h @@ -0,0 +1,39 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopObjectiveVectorTraits.h +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#ifndef FLOWSHOPOBJECTIVEVECTORTRAITS_H_ +#define FLOWSHOPOBJECTIVEVECTORTRAITS_H_ + +#include + +/** + * Definition of the objective vector traits for multi-objective flow-shop problems + */ +class FlowShopObjectiveVectorTraits : public moeoObjectiveVectorTraits +{ +public: + + /** + * Returns true if the _ith objective have to be minimzed + * @param _i index of the objective + */ + static bool minimizing (int _i); + + + /** + * Returns the number of objectives + */ + static unsigned int nObjectives (); + +}; + +#endif /*FLOWSHOPOBJECTIVEVECTORTRAITS_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpCrossoverQuad.cpp b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpCrossoverQuad.cpp new file mode 100644 index 000000000..d1aee2351 --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpCrossoverQuad.cpp @@ -0,0 +1,84 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopOpCrossoverQuad.cpp +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#include + + +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 + { + 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; + } + 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 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; + } + for (unsigned int i=_point2 ; i +#include + +/** + * Quadratic crossover operator for flow-shop (modify the both genotypes) + */ +class FlowShopOpCrossoverQuad : public eoQuadOp < FlowShop > +{ +public: + + /** + * the class name (used to display statistics) + */ + std::string className() const; + + + /** + * eoQuad crossover - _flowshop1 and _flowshop2 are the (future) offspring, i.e. _copies_ of the parents + * @param _flowshop1 the first parent + * @param _flowshop2 the second parent + */ + bool operator()(FlowShop & _flowshop1, FlowShop & _flowshop2); + + +private: + + /** + * generation of an offspring by a 2 points crossover + * @param _parent1 the first parent + * @param _parent2 the second parent + * @param _point1 the first point + * @param _point2 the second point + */ + FlowShop generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2); + +}; + +#endif /*FLOWSHOPOPCROSSOVERQUAD_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationExchange.cpp b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationExchange.cpp new file mode 100644 index 000000000..b99535c53 --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationExchange.cpp @@ -0,0 +1,50 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopOpCrossoverQuad.cpp +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#include + + +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 + { + 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; + } + else + { + // the genotype has not been modified + isModified = false; + } + // return 'true' if the genotype has been modified + return isModified; +} diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationExchange.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationExchange.h new file mode 100644 index 000000000..e63a3884b --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationExchange.h @@ -0,0 +1,40 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopOpCrossoverQuad.h +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#ifndef FLOWSHOPOPMUTATIONEXCHANGE_H_ +#define FLOWSHOPOPMUTATIONEXCHANGE_H_ + +#include +#include + +/** + * Exchange mutation operator for the flow-shop + */ +class FlowShopOpMutationExchange : public eoMonOp +{ +public: + + /** + * the class name (used to display statistics) + */ + std::string className() const; + + + /** + * modifies the parent with an exchange mutation + * @param _flowshop the parent genotype (will be modified) + */ + bool operator()(FlowShop & _flowshop); + +}; + +#endif /*FLOWSHOPOPMUTATIONEXCHANGE_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationShift.cpp b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationShift.cpp new file mode 100644 index 000000000..4da8d0b09 --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationShift.cpp @@ -0,0 +1,60 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopOpMutationShift.cpp +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#include + + +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 + { + 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; + } + else + { + // the genotype has not been modified + isModified = false; + } + // return 'true' if the genotype has been modified + return isModified; +} diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationShift.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationShift.h new file mode 100644 index 000000000..cc6ecdeee --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/FlowShopOpMutationShift.h @@ -0,0 +1,40 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// FlowShopOpMutationShift.h +// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007 +/* + This library... + + Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr + */ +//----------------------------------------------------------------------------- + +#ifndef FLOWSHOPOPMUTATIONSHIFT_H_ +#define FLOWSHOPOPMUTATIONSHIFT_H_ + +#include +#include + +/** + * Shift mutation operator for flow-shop + */ +class FlowShopOpMutationShift : public eoMonOp < FlowShop > +{ +public: + + /** + * the class name (used to display statistics) + */ + std::string className() const; + + + /** + * modifies the parent with a shift mutation + * @param _flowshop the parent genotype (will be modified) + */ + bool operator()(FlowShop & _flowshop); + +}; + +#endif /*FLOWSHOPOPMUTATIONSHIFT_H_*/ diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/Makefile.am b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/Makefile.am new file mode 100644 index 000000000..6845a342d --- /dev/null +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/Makefile.am @@ -0,0 +1,26 @@ +lib_LIBRARIES = libflowshop.a + +libflowshop_a_SOURCES = \ + FlowShop.cpp \ + FlowShopBenchmarkParser.cpp \ + FlowShopEval.cpp \ + FlowShopInit.cpp \ + FlowShopObjectiveVectorTraits.cpp \ + FlowShopOpCrossoverQuad.cpp \ + FlowShopOpMutationExchange.cpp \ + FlowShopOpMutationShift.cpp + +pkginclude_HEADERS = \ + FlowShop.h \ + FlowShopBenchmarkParser.h \ + FlowShopEval.h \ + FlowShopInit.h \ + FlowShopObjectiveVector.h \ + FlowShopObjectiveVectorTraits.h \ + FlowShopOpCrossoverQuad.h \ + FlowShopOpMutationExchange.h \ + FlowShopOpMutationShift.h + +INCLUDES = -I$(EO_DIR)/src/ -I$(top_srcdir)/src/ + +AM_CXXFLAGS = -Wall -ansi -pedantic diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/make_eval_FlowShop.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/make_eval_FlowShop.h similarity index 72% rename from branches/paradiseo-moeo-1.0/tutorial/Lesson1/make_eval_FlowShop.h rename to branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/make_eval_FlowShop.h index 32f92526e..3ab516109 100644 --- a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/make_eval_FlowShop.h +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/make_eval_FlowShop.h @@ -16,32 +16,32 @@ #include #include -#include "FlowShop.h" -#include "FlowShopBenchmarkParser.h" -#include "FlowShopEval.h" +#include +#include +#include +#include /* * This function creates an eoEvalFuncCounter that can later be used to evaluate an individual. * @param eoParser& _parser to get user parameters * @param eoState& _state to store the memory */ -eoEvalFuncCounter & do_make_eval(eoParser& _parser, eoState& _state) { - +eoEvalFuncCounter & do_make_eval(eoParser& _parser, eoState& _state) +{ // benchmark file name - string benchmarkFileName = _parser.getORcreateParam(string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at " + BENCHMARKS_WEB_SITE + ")", 'B',"Representation", true).value(); + 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 " + BENCHMARKS_WEB_SITE; + 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 M = fParser.getM(); - unsigned N = fParser.getN(); - std::vector< std::vector > p = fParser.getP(); - std::vector d = fParser.getD(); - + unsigned int M = fParser.getM(); + unsigned int N = fParser.getN(); + std::vector< std::vector > p = fParser.getP(); + std::vector 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 diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/make_genotype_FlowShop.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/make_genotype_FlowShop.h similarity index 77% rename from branches/paradiseo-moeo-1.0/tutorial/Lesson1/make_genotype_FlowShop.h rename to branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/make_genotype_FlowShop.h index 717231411..e59cb2206 100644 --- a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/make_genotype_FlowShop.h +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/make_genotype_FlowShop.h @@ -15,29 +15,28 @@ #include #include -#include "FlowShop.h" -#include "FlowShopInit.h" -#include "FlowShopBenchmarkParser.h" +#include +#include +#include /* * This function creates an eoInit that can later be used to initialize the population (see make_pop.h). * @param eoParser& _parser to get user parameters * @param eoState& _state to store the memory */ -eoInit & do_make_genotype(eoParser& _parser, eoState& _state) { - +eoInit & do_make_genotype(eoParser& _parser, eoState& _state) +{ // benchmark file name - string benchmarkFileName = _parser.getORcreateParam(string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at " + BENCHMARKS_WEB_SITE + ")", 'B',"Representation", true).value(); + 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 " + BENCHMARKS_WEB_SITE; + 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 N = fParser.getN(); - + unsigned int N = fParser.getN(); // build of the initializer (a pointer, stored in the eoState) eoInit* init = new FlowShopInit(N); // store in state diff --git a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/make_op_FlowShop.h b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/make_op_FlowShop.h similarity index 94% rename from branches/paradiseo-moeo-1.0/tutorial/Lesson1/make_op_FlowShop.h rename to branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/make_op_FlowShop.h index 232dbd79f..7abadd9e4 100644 --- a/branches/paradiseo-moeo-1.0/tutorial/Lesson1/make_op_FlowShop.h +++ b/branches/paradiseo-moeo-1.0/tutorial/Lesson1/flowshop/make_op_FlowShop.h @@ -20,16 +20,17 @@ #include #include #include -#include "FlowShopOpCrossoverQuad.h" -#include "FlowShopOpMutationShift.h" -#include "FlowShopOpMutationExchange.h" +#include +#include +#include /* * This function builds the operators that will be applied to the eoFlowShop * @param eoParameterLoader& _parser to get user parameters * @param eoState& _state to store the memory */ -eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state) { +eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state) +{ ///////////////////////////// // Variation operators @@ -78,12 +79,12 @@ eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state) { eoValueParam& pCrossParam = _parser.createParam(0.25, "pCross", "Probability of Crossover", 'c', "Variation Operators" ); // minimum check if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) ) - throw runtime_error("Invalid pCross"); + throw std::runtime_error("Invalid pCross"); eoValueParam& pMutParam = _parser.createParam(0.35, "pMut", "Probability of Mutation", 'm', "Variation Operators" ); // minimum check if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) ) - throw runtime_error("Invalid pMut"); + throw std::runtime_error("Invalid pMut"); // the crossover - with probability pCross eoProportionalOp * propOp = new eoProportionalOp ;