update lesson1 new version
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@268 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
5df71ee73a
commit
97b9338bef
14 changed files with 454 additions and 689 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// FlowShop.h
|
// FlowShop.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,41 +10,41 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _FlowShop_h
|
#ifndef FLOWSHOP_H_
|
||||||
#define _FlowShop_h
|
#define FLOWSHOP_H_
|
||||||
|
|
||||||
#include <EO.h>
|
#include <MOEO.h>
|
||||||
// Fitness for multi-objective flow-shop
|
#include <moeoObjectiveVector.h>
|
||||||
#include "FlowShopFitness.h"
|
#include <moeoObjectiveVectorTraits.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* definition of the objective vector for multi-objective flow-shop problems
|
||||||
|
*/
|
||||||
|
typedef moeoObjectiveVectorDouble<moeoObjectiveVectorTraits> FlowShopObjectiveVector;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Structure of the genotype for the flow-shop scheduling problem
|
* Structure of the genotype for the flow-shop scheduling problem
|
||||||
*/
|
*/
|
||||||
class FlowShop:public EO < FlowShopFitness >
|
class FlowShop: public MOEO<FlowShopObjectiveVector, double, double> {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default constructor
|
* default constructor
|
||||||
*/
|
*/
|
||||||
FlowShop ()
|
FlowShop() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destructor
|
* destructor
|
||||||
*/
|
*/
|
||||||
virtual ~ FlowShop ()
|
virtual ~FlowShop() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class name
|
* class name
|
||||||
*/
|
*/
|
||||||
virtual string className () const
|
virtual string className() const {
|
||||||
{
|
|
||||||
return "FlowShop";
|
return "FlowShop";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,86 +52,63 @@ public:
|
||||||
* set scheduling vector
|
* set scheduling vector
|
||||||
* @param vector<unsigned> & _scheduling the new scheduling to set
|
* @param vector<unsigned> & _scheduling the new scheduling to set
|
||||||
*/
|
*/
|
||||||
void setScheduling (vector < unsigned >&_scheduling)
|
void setScheduling(vector<unsigned> & _scheduling) {
|
||||||
{
|
|
||||||
scheduling = _scheduling;
|
scheduling = _scheduling;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get scheduling vector
|
* get scheduling vector
|
||||||
*/
|
*/
|
||||||
const vector < unsigned >&getScheduling () const
|
const vector<unsigned> & getScheduling() const {
|
||||||
{
|
|
||||||
return scheduling;
|
return scheduling;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* printing...
|
* printing...
|
||||||
*/
|
*/
|
||||||
void printOn (ostream & _os) const
|
void printOn(ostream& _os) const {
|
||||||
{
|
|
||||||
// fitness
|
// fitness
|
||||||
EO < FlowShopFitness >::printOn (_os);
|
MOEO<FlowShopObjectiveVector, double, double>::printOn(_os);
|
||||||
_os << "\t";
|
|
||||||
// size
|
// size
|
||||||
_os << scheduling.size () << "\t";
|
_os << scheduling.size() << "\t" ;
|
||||||
// scheduling
|
// scheduling
|
||||||
for (unsigned i = 0; i < scheduling.size (); i++)
|
for (unsigned i=0; i<scheduling.size(); i++)
|
||||||
_os << scheduling[i] << ' ';
|
_os << scheduling[i] << ' ' ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reading...
|
* reading...
|
||||||
*/
|
*/
|
||||||
void readFrom (istream & _is)
|
void readFrom(istream& _is) {
|
||||||
{
|
|
||||||
// fitness
|
// fitness
|
||||||
EO < FlowShopFitness >::readFrom (_is);
|
MOEO<FlowShopObjectiveVector, double, double>::readFrom(_is);
|
||||||
// size
|
// size
|
||||||
unsigned size;
|
unsigned size;
|
||||||
_is >> size;
|
_is >> size;
|
||||||
// scheduling
|
// scheduling
|
||||||
scheduling.resize (size);
|
scheduling.resize(size);
|
||||||
bool tmp;
|
bool tmp;
|
||||||
for (unsigned i = 0; i < size; i++)
|
for (unsigned i=0; i<size; i++) {
|
||||||
{
|
_is >> tmp;
|
||||||
_is >> tmp;
|
scheduling[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 ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
private:
|
||||||
|
|
||||||
/** scheduling (order of operations) */
|
/** scheduling (order of operations) */
|
||||||
std::vector < unsigned >scheduling;
|
std::vector<unsigned> scheduling;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
#endif /*FLOWSHOP_H_*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// FlowShopBenchmarkParser.h
|
// FlowShopBenchmarkParser.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,26 +10,20 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _FlowShopBenchmarkParser_h
|
#ifndef FLOWSHOPBENCHMARKPARSER_H_
|
||||||
#define _FlowShopBenchmarkParser_h
|
#define FLOWSHOPBENCHMARKPARSER_H_
|
||||||
|
|
||||||
// general include
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
/** Web site to download benchmarks */
|
/** Web site to download benchmarks */
|
||||||
const static
|
const static std::string BENCHMARKS_WEB_SITE = "www.lifl.fr/~basseur/BenchsUncertain/";
|
||||||
std::string
|
|
||||||
BENCHMARKS_WEB_SITE = "www.lifl.fr/~liefooga/benchmarks/";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to handle parameters of a flow-shop instance from a benchmark file
|
* Class to handle parameters of a flow-shop instance from a benchmark file
|
||||||
* benchmark files are available at www.lifl.fr/~basseur/BenchsUncertain/
|
* benchmark files are available at www.lifl.fr/~basseur/BenchsUncertain/
|
||||||
*/
|
*/
|
||||||
class
|
class FlowShopBenchmarkParser {
|
||||||
FlowShopBenchmarkParser
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -37,146 +31,110 @@ public:
|
||||||
* constructor
|
* constructor
|
||||||
* @param const string _benchmarkFileName the name of the benchmark file
|
* @param const string _benchmarkFileName the name of the benchmark file
|
||||||
*/
|
*/
|
||||||
FlowShopBenchmarkParser (const string _benchmarkFileName)
|
FlowShopBenchmarkParser(const string _benchmarkFileName) {
|
||||||
{
|
init(_benchmarkFileName);
|
||||||
init (_benchmarkFileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the number of machines
|
* the number of machines
|
||||||
*/
|
*/
|
||||||
const unsigned
|
const unsigned getM() {
|
||||||
getM ()
|
|
||||||
{
|
|
||||||
return M;
|
return M;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the number of jobs
|
* the number of jobs
|
||||||
*/
|
*/
|
||||||
const unsigned
|
const unsigned getN() {
|
||||||
getN ()
|
|
||||||
{
|
|
||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the processing times
|
* the processing times
|
||||||
*/
|
*/
|
||||||
const
|
const std::vector< std::vector<unsigned> > getP() {
|
||||||
std::vector <
|
|
||||||
std::vector < unsigned > >
|
|
||||||
getP ()
|
|
||||||
{
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the due-dates
|
* the due-dates
|
||||||
*/
|
*/
|
||||||
const
|
const std::vector<unsigned> getD() {
|
||||||
std::vector < unsigned >
|
|
||||||
getD ()
|
|
||||||
{
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* printing...
|
* printing...
|
||||||
*/
|
*/
|
||||||
void
|
void printOn(ostream& _os) const {
|
||||||
printOn (ostream & _os) const
|
_os << "M=" << M << " N=" << N << endl;
|
||||||
{
|
_os << "*** processing times" << endl;
|
||||||
_os <<
|
for (unsigned i=0; i<M; i++) {
|
||||||
"M=" <<
|
for (unsigned j=0; j<N; j++) {
|
||||||
M <<
|
_os << p[i][j] << " ";
|
||||||
" N=" <<
|
|
||||||
N <<
|
|
||||||
endl;
|
|
||||||
_os <<
|
|
||||||
"*** processing times" <<
|
|
||||||
endl;
|
|
||||||
for (unsigned i = 0; i < M; i++)
|
|
||||||
{
|
|
||||||
for (unsigned j = 0; j < N; j++)
|
|
||||||
{
|
|
||||||
_os << p[i][j] << " ";
|
|
||||||
}
|
|
||||||
_os <<
|
|
||||||
endl;
|
|
||||||
}
|
}
|
||||||
|
_os << endl;
|
||||||
|
}
|
||||||
_os << "*** due-dates" << endl;
|
_os << "*** due-dates" << endl;
|
||||||
for (unsigned j = 0; j < N; j++)
|
for (unsigned j=0; j<N; j++) {
|
||||||
{
|
_os << d[j] << " ";
|
||||||
_os << d[j] << " ";
|
}
|
||||||
}
|
|
||||||
_os << endl << endl;
|
_os << endl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** number of machines */
|
/** number of machines */
|
||||||
unsigned
|
unsigned M;
|
||||||
M;
|
|
||||||
/** number of jobs */
|
/** number of jobs */
|
||||||
unsigned
|
unsigned N;
|
||||||
N;
|
|
||||||
/** p[i][j] = processing time of job j on machine i */
|
/** p[i][j] = processing time of job j on machine i */
|
||||||
std::vector < std::vector < unsigned > >
|
std::vector< std::vector<unsigned> > p;
|
||||||
p;
|
|
||||||
/** d[j] = due-date of the job j */
|
/** d[j] = due-date of the job j */
|
||||||
std::vector < unsigned >
|
std::vector<unsigned> d;
|
||||||
d;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialisation of the parameters with the data contained in the benchmark file
|
* Initialisation of the parameters with the data contained in the benchmark file
|
||||||
* @param const string _benchmarkFileName the name of the benchmark file
|
* @param const string _benchmarkFileName the name of the benchmark file
|
||||||
*/
|
*/
|
||||||
void
|
void init(const string _benchmarkFileName) {
|
||||||
init (const string _benchmarkFileName)
|
string buffer;
|
||||||
{
|
|
||||||
string
|
|
||||||
buffer;
|
|
||||||
string::size_type start, end;
|
string::size_type start, end;
|
||||||
ifstream
|
ifstream inputFile(_benchmarkFileName.data(), ios::in);
|
||||||
inputFile (_benchmarkFileName.data (), ios::in);
|
|
||||||
// opening of the benchmark file
|
// opening of the benchmark file
|
||||||
if (!inputFile)
|
if (! inputFile)
|
||||||
cerr << "*** ERROR : Unable to open the benchmark file '" <<
|
cerr << "*** ERROR : Unable to open the benchmark file '" << _benchmarkFileName << "'" << endl;
|
||||||
_benchmarkFileName << "'" << endl;
|
|
||||||
// number of jobs (N)
|
// number of jobs (N)
|
||||||
getline (inputFile, buffer, '\n');
|
getline(inputFile, buffer, '\n');
|
||||||
N = atoi (buffer.data ());
|
N = atoi(buffer.data());
|
||||||
// number of machines M
|
// number of machines M
|
||||||
getline (inputFile, buffer, '\n');
|
getline(inputFile, buffer, '\n');
|
||||||
M = atoi (buffer.data ());
|
M = atoi(buffer.data());
|
||||||
// initial and current seeds (not used)
|
// initial and current seeds (not used)
|
||||||
getline (inputFile, buffer, '\n');
|
getline(inputFile, buffer, '\n');
|
||||||
// processing times and due-dates
|
// processing times and due-dates
|
||||||
p = std::vector < std::vector < unsigned > > (M, N);
|
p = std::vector< std::vector<unsigned> > (M,N);
|
||||||
d = std::vector < unsigned >(N);
|
d = std::vector<unsigned> (N);
|
||||||
// for each job...
|
// for each job...
|
||||||
for (unsigned j = 0; j < N; j++)
|
for (unsigned j=0 ; j<N ; j++) {
|
||||||
{
|
// index of the job (<=> j)
|
||||||
// index of the job (<=> j)
|
getline(inputFile, buffer, '\n');
|
||||||
getline (inputFile, buffer, '\n');
|
// due-date of the job j
|
||||||
// due-date of the job j
|
getline(inputFile, buffer, '\n');
|
||||||
getline (inputFile, buffer, '\n');
|
d[j] = atoi(buffer.data());
|
||||||
d[j] = atoi (buffer.data ());
|
// processing times of the job j on each machine
|
||||||
// processing times of the job j on each machine
|
getline(inputFile, buffer, '\n');
|
||||||
getline (inputFile, buffer, '\n');
|
start = buffer.find_first_not_of(" ");
|
||||||
start = buffer.find_first_not_of (" ");
|
for (unsigned i=0 ; i<M ; i++) {
|
||||||
for (unsigned i = 0; i < M; i++)
|
end = buffer.find_first_of(" ", start);
|
||||||
{
|
p[i][j] = atoi(buffer.substr(start, end-start).data());
|
||||||
end = buffer.find_first_of (" ", start);
|
start = buffer.find_first_not_of(" ", end);
|
||||||
p[i][j] = atoi (buffer.substr (start, end - start).data ());
|
|
||||||
start = buffer.find_first_not_of (" ", end);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// closing of the input file
|
// closing of the input file
|
||||||
inputFile.close ();
|
inputFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /*FLOWSHOPBENCHMARKPARSER_H_*/
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// FlowShopEA.cpp
|
// FlowShopEA.cpp
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -14,9 +14,9 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
/* EO */
|
/* EO + MOEO */
|
||||||
// eo general include
|
// moeo general include
|
||||||
#include "eo"
|
#include <moeo>
|
||||||
// for the creation of an evaluator
|
// for the creation of an evaluator
|
||||||
#include "make_eval_FlowShop.h"
|
#include "make_eval_FlowShop.h"
|
||||||
// for the creation of an initializer
|
// for the creation of an initializer
|
||||||
|
|
@ -26,42 +26,25 @@ using namespace std;
|
||||||
// how to initialize the population
|
// how to initialize the population
|
||||||
#include <do/make_pop.h>
|
#include <do/make_pop.h>
|
||||||
// the stopping criterion
|
// the stopping criterion
|
||||||
#include <do/make_continue_pareto.h>
|
#include <do/make_continue_moeo.h>
|
||||||
// outputs (stats, population dumps, ...)
|
// outputs (stats, population dumps, ...)
|
||||||
#include <do/make_checkpoint_pareto.h>
|
#include <do/make_checkpoint_moeo.h>
|
||||||
|
// evolution engine (selection and replacement)
|
||||||
|
#include <do/make_ea_moeo.h>
|
||||||
// simple call to the algo
|
// simple call to the algo
|
||||||
#include <do/make_run.h>
|
#include <do/make_run.h>
|
||||||
|
|
||||||
// checks for help demand, and writes the status file and make_help; in libutils
|
// checks for help demand, and writes the status file and make_help; in libutils
|
||||||
void make_help (eoParser & _parser);
|
void make_help(eoParser & _parser);
|
||||||
|
|
||||||
|
|
||||||
/* MOEO */
|
|
||||||
#include <moeoArchive.h>
|
|
||||||
#include <moeoArchiveUpdater.h>
|
|
||||||
#include <moeoArchiveFitnessSavingUpdater.h>
|
|
||||||
#include <metric/moeoContributionMetric.h>
|
|
||||||
#include <metric/moeoEntropyMetric.h>
|
|
||||||
#include <metric/moeoBinaryMetricSavingUpdater.h>
|
|
||||||
// evolution engine (selection and replacement)
|
|
||||||
#include <old/make_algo_MOEO.h>
|
|
||||||
|
|
||||||
/* FLOW-SHOP */
|
/* FLOW-SHOP */
|
||||||
// definition of representation
|
// definition of representation
|
||||||
#include "FlowShop.h"
|
#include "FlowShop.h"
|
||||||
// definition of fitness
|
|
||||||
#include "FlowShopFitness.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
int
|
try {
|
||||||
main (int argc, char *argv[])
|
|
||||||
{
|
eoParser parser(argc, argv); // for user-parameter reading
|
||||||
try
|
eoState state; // to keep all things allocated
|
||||||
{
|
|
||||||
|
|
||||||
eoParser parser (argc, argv); // for user-parameter reading
|
|
||||||
eoState state; // to keep all things allocated
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -70,11 +53,11 @@ main (int argc, char *argv[])
|
||||||
/*** the representation-dependent things ***/
|
/*** the representation-dependent things ***/
|
||||||
|
|
||||||
// The fitness evaluation
|
// The fitness evaluation
|
||||||
eoEvalFuncCounter < FlowShop > &eval = do_make_eval (parser, state);
|
eoEvalFuncCounter<FlowShop>& eval = do_make_eval(parser, state);
|
||||||
// the genotype (through a genotype initializer)
|
// the genotype (through a genotype initializer)
|
||||||
eoInit < FlowShop > &init = do_make_genotype (parser, state);
|
eoInit<FlowShop>& init = do_make_genotype(parser, state);
|
||||||
// the variation operators
|
// the variation operators
|
||||||
eoGenOp < FlowShop > &op = do_make_op (parser, state);
|
eoGenOp<FlowShop>& op = do_make_op(parser, state);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,43 +66,16 @@ main (int argc, char *argv[])
|
||||||
/*** the representation-independent things ***/
|
/*** the representation-independent things ***/
|
||||||
|
|
||||||
// initialization of the population
|
// initialization of the population
|
||||||
eoPop < FlowShop > &pop = do_make_pop (parser, state, init);
|
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
|
||||||
// definition of the archive
|
// definition of the archive
|
||||||
moeoArchive < FlowShop > arch;
|
moeoArchive<FlowShop> arch;
|
||||||
// stopping criteria
|
// stopping criteria
|
||||||
eoContinue < FlowShop > &term =
|
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
|
||||||
do_make_continue_pareto (parser, state, eval);
|
|
||||||
// output
|
// output
|
||||||
eoCheckPoint < FlowShop > &checkpoint =
|
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
|
||||||
do_make_checkpoint_pareto (parser, state, eval, term);
|
|
||||||
// algorithm
|
// algorithm
|
||||||
eoAlgo < FlowShop > &algo =
|
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
|
||||||
do_make_algo_MOEO (parser, state, eval, checkpoint, op, arch);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*** archive-related features ***/
|
|
||||||
// update the archive every generation
|
|
||||||
moeoArchiveUpdater < FlowShop > updater (arch, pop);
|
|
||||||
checkpoint.add (updater);
|
|
||||||
// save the archive every generation in 'Res/Arch*'
|
|
||||||
moeoArchiveFitnessSavingUpdater < FlowShop > save_updater (arch);
|
|
||||||
checkpoint.add (save_updater);
|
|
||||||
// save the contribution of the non-dominated solutions in 'Res/Contribution.txt'
|
|
||||||
moeoVectorVsVectorBM < FlowShop, double >*contribution =
|
|
||||||
new moeoContributionMetric < FlowShop > ();
|
|
||||||
moeoBinaryMetricSavingUpdater < FlowShop >
|
|
||||||
contribution_updater (*contribution, arch, "Res/Contribution.txt");
|
|
||||||
checkpoint.add (contribution_updater);
|
|
||||||
// save the entropy of the non-dominated solutions in 'Res/Entropy.txt'
|
|
||||||
moeoVectorVsVectorBM < FlowShop, double >*entropy =
|
|
||||||
new moeoEntropyMetric < FlowShop > ();
|
|
||||||
moeoBinaryMetricSavingUpdater < FlowShop > entropy_updater (*entropy,
|
|
||||||
arch,
|
|
||||||
"Res/Entropy.txt");
|
|
||||||
checkpoint.add (entropy_updater);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -127,32 +83,36 @@ main (int argc, char *argv[])
|
||||||
/*** Go ! ***/
|
/*** Go ! ***/
|
||||||
|
|
||||||
// help ?
|
// help ?
|
||||||
make_help (parser);
|
make_help(parser);
|
||||||
|
|
||||||
// first evalution
|
// first evalution
|
||||||
apply < FlowShop > (eval, pop);
|
apply<FlowShop>(eval, pop);
|
||||||
|
|
||||||
|
pop.sort();
|
||||||
|
arch.update(pop);
|
||||||
|
|
||||||
// printing of the initial population
|
// printing of the initial population
|
||||||
cout << "Initial Population\n";
|
cout << "Initial Population\n";
|
||||||
pop.sortedPrintOn (cout);
|
pop.sortedPrintOn(cout);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
// run the algo
|
// run the algo
|
||||||
do_run (algo, pop);
|
do_run(algo, pop);
|
||||||
|
|
||||||
// printing of the final population
|
// printing of the final population
|
||||||
cout << "Final Population\n";
|
cout << "Final Population\n";
|
||||||
pop.sortedPrintOn (cout);
|
pop.sortedPrintOn(cout);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
// printing of the final archive
|
// printing of the final archive
|
||||||
cout << "Final Archive\n";
|
cout << "Final Archive\n";
|
||||||
arch.sortedPrintOn (cout);
|
arch.sortedPrintOn(cout);
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
} catch (exception & e)
|
|
||||||
{
|
|
||||||
cout << e.what () << endl;
|
} catch(exception& e) {
|
||||||
|
cout << e.what() << endl;
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,50 +2,47 @@
|
||||||
###### General ######
|
###### General ######
|
||||||
# --help=0 # -h : Prints this message
|
# --help=0 # -h : Prints this message
|
||||||
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
# --stopOnUnknownParam=1 # Stop if unkown param entered
|
||||||
# --seed=1165485212 # -S : Random number seed
|
# --seed=1176819700 # -S : Random number seed
|
||||||
|
|
||||||
###### Evolution Engine ######
|
###### Evolution Engine ######
|
||||||
--popSize=20 # -P : Population Size
|
# --popSize=20 # -P : Population Size
|
||||||
--selCrit=NSGA-II # -S : Multi-objective selection criterion: NSGA, NSGA-II, IBEA, ParetoRanking, ParetoSharing
|
# --updateArch=1 # Update the archive at each gen.
|
||||||
--nicheSize=1 # -n : Size of niche for NSGA-I or ParetoSharing
|
# --fitness=FastNonDominatedSorting # -F : Fitness assignment scheme: Dummy, FastNonDominatedSorting or IndicatorBased
|
||||||
--kappa=0.05 # -k : Scaling factor kappa for IBEA
|
# --indicator=Epsilon # -i : Binary indicator for IndicatorBased: Epsilon, Hypervolume
|
||||||
--indicator=Epsilon # -I : Binary quality indicator for IBEA : Epsilon, Hypervolume
|
# --rho=1.1 # -r : reference point for the hypervolume indicator
|
||||||
--rho=1.1 # -r : reference point for the hypervolume calculation (must not be smaller than 1)
|
# --kappa=0.05 # -k : Scaling factor kappa for IndicatorBased
|
||||||
--selection=DetTour(2) # -s : Selection: Roulette, DetTour(T), StochTour(t) or Random
|
# --diversity=Dummy # -D : Diversity assignment scheme: Dummy or CrowdingDistance
|
||||||
--elitism=0 # -E : Use elitism in the selection process (individuals from the archive are randomly selected)
|
# --comparator=FitnessThenDiversity # -C : Comparator scheme: FitnessThenDiversity or DiversityThenFitness
|
||||||
--ratio=0.8 # Ratio from the population for elitism (must not be greater than 1)
|
# --selection=DetTour(2) # -S : Selection scheme: DetTour(T), StochTour(t) or Random
|
||||||
--nbOffspring=100% # -O : Nb of offspring (percentage or absolute)
|
# --replacement=Elitist # -R : Replacement scheme: Elitist, Environmental or Generational
|
||||||
--replacement=Plus # -R : Replacement: Plus, DistinctPlus or Generational
|
# --nbOffspring=100% # -O : Number of offspring (percentage or absolute)
|
||||||
|
|
||||||
###### Output ######
|
###### Output ######
|
||||||
--useEval=1 # Use nb of eval. as counter (vs nb of gen.)
|
# --resDir=Res # Directory to store DISK outputs
|
||||||
--printPop=0 # Print sorted pop. every gen.
|
# --eraseDir=1 # erase files in dirName if any
|
||||||
|
# --printPop=0 # Print sorted pop. every gen.
|
||||||
###### Output - Disk ######
|
# --storeArch=0 # Store the archive's objective vectors at each gen.
|
||||||
--resDir=Res # Directory to store DISK outputs
|
# --contribution=0 # Store the contribution of the archive at each gen.
|
||||||
--eraseDir=1 # erase files in dirName if any
|
# --entropy=0 # Store the entropy of the archive at each gen.
|
||||||
--frontFileFrequency=1(0,1) # File save frequency in objective spaces (std::pairs of comma-separated objectives in 1 single parentheses std::pair)
|
|
||||||
|
|
||||||
###### Output - Graphical ######
|
|
||||||
--plotFront=0 # Objective plots (requires corresponding files - see frontFileFrequency
|
|
||||||
|
|
||||||
###### Persistence ######
|
###### Persistence ######
|
||||||
# --Load= # -L : A save file to restart from
|
# --Load= # -L : A save file to restart from
|
||||||
--recomputeFitness=0 # -r : Recompute the fitness after re-loading the pop.?
|
# --recomputeFitness=0 # -r : Recompute the fitness after re-loading the pop.?
|
||||||
--saveFrequency=0 # Save every F generation (0 = only final state, absent = never)
|
# --saveFrequency=0 # Save every F generation (0 = only final state, absent = never)
|
||||||
--saveTimeInterval=0 # Save every T seconds (0 or absent = never)
|
# --saveTimeInterval=0 # Save every T seconds (0 or absent = never)
|
||||||
--status=./FlowShopEA.status # Status file
|
# --status=./FlowShopEA.status # Status file
|
||||||
|
|
||||||
###### Representation ######
|
###### Representation ######
|
||||||
--BenchmarkFile=benchmarks/020_05_01.txt # -B : Benchmark file name (benchmarks are available at www.lifl.fr/~basseur/BenchsUncertain/) REQUIRED
|
--BenchmarkFile=benchmarks/020_10_01.txt # -B : Benchmark file name (benchmarks are available at www.lifl.fr/~basseur/BenchsUncertain/) REQUIRED
|
||||||
|
|
||||||
###### Stopping criterion ######
|
###### Stopping criterion ######
|
||||||
--maxGen=100 # -G : Maximum number of generations () = none)
|
# --maxGen=100 # -G : Maximum number of generations (0 = none)
|
||||||
--CtrlC=1 # -C : Terminate current generation upon Ctrl C
|
# --maxEval=0 # -E : Maximum number of evaluations (0 = none)
|
||||||
|
# --CtrlC=1 # -C : Terminate current generation upon Ctrl C
|
||||||
|
|
||||||
###### Variation Operators ######
|
###### Variation Operators ######
|
||||||
--crossRate=1 # Relative rate for the only crossover
|
# --crossRate=1 # Relative rate for the only crossover
|
||||||
--shiftMutRate=0.5 # Relative rate for shift mutation
|
# --shiftMutRate=0.5 # Relative rate for shift mutation
|
||||||
--exchangeMutRate=0.5 # Relative rate for exchange mutation
|
# --exchangeMutRate=0.5 # Relative rate for exchange mutation
|
||||||
--pCross=0.25 # -c : Probability of Crossover
|
# --pCross=0.25 # -c : Probability of Crossover
|
||||||
--pMut=0.35 # -m : Probability of Mutation
|
# --pMut=0.35 # -m : Probability of Mutation
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// FlowShopEval.h
|
// FlowShopEval.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,22 +10,17 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _FlowShopEval_h
|
#ifndef FLOWSHOPEVAL_H_
|
||||||
#define _FlowShopEval_h
|
#define FLOWSHOPEVAL_H_
|
||||||
|
|
||||||
// Flow-shop fitness
|
|
||||||
#include "FlowShopFitness.h"
|
|
||||||
// include the base definition of eoEvalFunc
|
|
||||||
#include <eoEvalFunc.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "FlowShop.h"
|
||||||
|
#include <moeoEvalFunc.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor
|
* Functor
|
||||||
* Computation of the multi-objective evaluation of a FlowShop object
|
* Computation of the multi-objective evaluation of a FlowShop object
|
||||||
*/
|
*/
|
||||||
class FlowShopEval:public eoEvalFunc < FlowShop >
|
class FlowShopEval : public moeoEvalFunc<FlowShop> {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -36,60 +31,56 @@ public:
|
||||||
* @param _p the processing times
|
* @param _p the processing times
|
||||||
* @param _d the due dates
|
* @param _d the due dates
|
||||||
*/
|
*/
|
||||||
FlowShopEval (const unsigned _M, const unsigned _N,
|
FlowShopEval(const unsigned _M, const unsigned _N, const vector< vector<unsigned> > & _p, const vector<unsigned> & _d) :
|
||||||
const vector < vector < unsigned > >&_p,
|
M(_M), N (_N), p(_p), d(_d){
|
||||||
const vector < unsigned >&_d):M (_M), N (_N), p (_p), d (_d)
|
|
||||||
{
|
|
||||||
|
|
||||||
unsigned nObjs = 2;
|
unsigned nObjs = 2;
|
||||||
std::vector < bool > bObjs (nObjs, false);
|
std::vector<bool> bObjs(nObjs, true);
|
||||||
eoVariableParetoTraits::setUp (nObjs, bObjs);
|
moeoObjectiveVectorTraits::setup(nObjs, bObjs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* computation of the multi-objective evaluation of an eoFlowShop object
|
* computation of the multi-objective evaluation of an eoFlowShop object
|
||||||
* @param FlowShop & _eo the FlowShop object to evaluate
|
* @param FlowShop & _eo the FlowShop object to evaluate
|
||||||
*/
|
*/
|
||||||
void operator () (FlowShop & _eo)
|
void operator()(FlowShop & _eo) {
|
||||||
{
|
FlowShopObjectiveVector objVector;
|
||||||
FlowShopFitness fitness;
|
objVector[0] = tardiness(_eo);
|
||||||
fitness[0] = tardiness (_eo);
|
objVector[1] = makespan(_eo);
|
||||||
fitness[1] = makespan (_eo);
|
_eo.objectiveVector(objVector);
|
||||||
_eo.fitness (fitness);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
private:
|
|
||||||
|
|
||||||
/** number of machines */
|
/** number of machines */
|
||||||
unsigned M;
|
unsigned M;
|
||||||
/** number of jobs */
|
/** number of jobs */
|
||||||
unsigned N;
|
unsigned N;
|
||||||
/** p[i][j] = processing time of job j on machine i */
|
/** p[i][j] = processing time of job j on machine i */
|
||||||
std::vector < std::vector < unsigned > >p;
|
std::vector< std::vector<unsigned> > p;
|
||||||
/** d[j] = due-date of the job j */
|
/** d[j] = due-date of the job j */
|
||||||
std::vector < unsigned >d;
|
std::vector<unsigned> d;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* computation of the makespan
|
* computation of the makespan
|
||||||
* @param FlowShop _eo the FlowShop object to evaluate
|
* @param FlowShop _eo the FlowShop object to evaluate
|
||||||
*/
|
*/
|
||||||
double makespan (FlowShop _eo)
|
double makespan(FlowShop _eo) {
|
||||||
{
|
|
||||||
// the scheduling to evaluate
|
// the scheduling to evaluate
|
||||||
vector < unsigned >scheduling = _eo.getScheduling ();
|
vector<unsigned> scheduling = _eo.getScheduling();
|
||||||
// completion times computation for each job on each machine
|
// completion times computation for each job on each machine
|
||||||
// C[i][j] = completion of the jth job of the scheduling on the ith machine
|
// C[i][j] = completion of the jth job of the scheduling on the ith machine
|
||||||
std::vector < std::vector < unsigned > >C = completionTime (_eo);
|
std::vector< std::vector<unsigned> > C = completionTime(_eo);
|
||||||
// fitness == C[M-1][scheduling[N-1]];
|
// fitness == C[M-1][scheduling[N-1]];
|
||||||
return C[M - 1][scheduling[N - 1]];
|
return C[M-1][scheduling[N-1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -98,49 +89,41 @@ private:
|
||||||
* computation of the tardiness
|
* computation of the tardiness
|
||||||
* @param _eo the FlowShop object to evaluate
|
* @param _eo the FlowShop object to evaluate
|
||||||
*/
|
*/
|
||||||
double tardiness (FlowShop _eo)
|
double tardiness(FlowShop _eo) {
|
||||||
{
|
|
||||||
// the scheduling to evaluate
|
// the scheduling to evaluate
|
||||||
vector < unsigned >scheduling = _eo.getScheduling ();
|
vector<unsigned> scheduling = _eo.getScheduling();
|
||||||
// completion times computation for each job on each machine
|
// completion times computation for each job on each machine
|
||||||
// C[i][j] = completion of the jth job of the scheduling on the ith machine
|
// C[i][j] = completion of the jth job of the scheduling on the ith machine
|
||||||
std::vector < std::vector < unsigned > >C = completionTime (_eo);
|
std::vector< std::vector<unsigned> > C = completionTime(_eo);
|
||||||
// tardiness computation
|
// tardiness computation
|
||||||
unsigned long sum = 0;
|
unsigned long sum = 0;
|
||||||
for (unsigned j = 0; j < N; j++)
|
for (unsigned j=0 ; j<N ; j++)
|
||||||
sum +=
|
sum += (unsigned) std::max (0, (int) (C[M-1][scheduling[j]] - d[scheduling[j]]));
|
||||||
(unsigned) std::max (0,
|
|
||||||
(int) (C[M - 1][scheduling[j]] -
|
|
||||||
d[scheduling[j]]));
|
|
||||||
// fitness == sum
|
// fitness == sum
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* computation of the completion times of a scheduling (for each job on each machine)
|
* 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
|
* C[i][j] = completion of the jth job of the scheduling on the ith machine
|
||||||
* @param const FlowShop _eo the genotype to evaluate
|
* @param const FlowShop _eo the genotype to evaluate
|
||||||
*/
|
*/
|
||||||
std::vector < std::vector < unsigned > >completionTime (FlowShop _eo)
|
std::vector< std::vector<unsigned> > completionTime(FlowShop _eo) {
|
||||||
{
|
vector<unsigned> scheduling = _eo.getScheduling();
|
||||||
vector < unsigned >scheduling = _eo.getScheduling ();
|
std::vector< std::vector<unsigned> > C(M,N);
|
||||||
std::vector < std::vector < unsigned > >C (M, N);
|
|
||||||
C[0][scheduling[0]] = p[0][scheduling[0]];
|
C[0][scheduling[0]] = p[0][scheduling[0]];
|
||||||
for (unsigned j = 1; j < N; j++)
|
for (unsigned j=1; j<N; j++)
|
||||||
C[0][scheduling[j]] = C[0][scheduling[j - 1]] + p[0][scheduling[j]];
|
C[0][scheduling[j]] = C[0][scheduling[j-1]] + p[0][scheduling[j]];
|
||||||
for (unsigned i = 1; i < M; i++)
|
for (unsigned i=1; i<M; i++)
|
||||||
C[i][scheduling[0]] = C[i - 1][scheduling[0]] + p[i][scheduling[0]];
|
C[i][scheduling[0]] = C[i-1][scheduling[0]] + p[i][scheduling[0]];
|
||||||
for (unsigned i = 1; i < M; i++)
|
for (unsigned i=1; i<M; i++)
|
||||||
for (unsigned j = 1; j < N; j++)
|
for (unsigned j=1; j<N; j++)
|
||||||
C[i][scheduling[j]] =
|
C[i][scheduling[j]] = std::max(C[i][scheduling[j-1]], C[i-1][scheduling[j]]) + p[i][scheduling[j]];
|
||||||
std::max (C[i][scheduling[j - 1]],
|
return C;
|
||||||
C[i - 1][scheduling[j]]) + p[i][scheduling[j]];
|
|
||||||
return C;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /*FLOWSHOPEVAL_H_*/
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// FlowShopFitness.h
|
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
|
||||||
/*
|
|
||||||
This library...
|
|
||||||
|
|
||||||
Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
|
|
||||||
*/
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifndef _FlowShopFitness_h
|
|
||||||
#define _FlowShopFitness_h
|
|
||||||
|
|
||||||
#include <eoParetoFitness.h>
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* definition of the fitness for multi-objective flow-shop problems
|
|
||||||
*/
|
|
||||||
typedef eoParetoFitness < eoVariableParetoTraits > FlowShopFitness;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// FlowShopInit.h
|
// FlowShopInit.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,18 +10,17 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _FlowShopInit_h
|
#ifndef FLOWSHOPINIT_H_
|
||||||
#define _FlowShopInit_h
|
#define FLOWSHOPINIT_H_
|
||||||
|
|
||||||
#include <eoInit.h>
|
#include <eoInit.h>
|
||||||
|
#include "FlowShop.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor
|
* Functor
|
||||||
* Initialisation of a random genotype built by the default constructor of the eoFlowShop class
|
* Initialisation of a random genotype built by the default constructor of the eoFlowShop class
|
||||||
*/
|
*/
|
||||||
class FlowShopInit:public eoInit < FlowShop >
|
class FlowShopInit: public eoInit<FlowShop> {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -29,40 +28,37 @@ public:
|
||||||
* constructor
|
* constructor
|
||||||
* @param const unsigned _N the number of jobs to schedule
|
* @param const unsigned _N the number of jobs to schedule
|
||||||
*/
|
*/
|
||||||
FlowShopInit (const unsigned _N)
|
FlowShopInit(const unsigned _N) {
|
||||||
{
|
|
||||||
N = _N;
|
N = _N;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* randomize a genotype
|
* randomize a genotype
|
||||||
* @param FlowShop & _genotype a genotype that has been default-constructed
|
* @param FlowShop & _genotype a genotype that has been default-constructed
|
||||||
*/
|
*/
|
||||||
void operator () (FlowShop & _genotype)
|
void operator()(FlowShop & _genotype) {
|
||||||
{
|
|
||||||
// scheduling vector
|
// scheduling vector
|
||||||
vector < unsigned >scheduling (N);
|
vector<unsigned> scheduling(N);
|
||||||
// initialisation of possible values
|
// initialisation of possible values
|
||||||
vector < unsigned >possibles (N);
|
vector<unsigned> possibles(N);
|
||||||
for (unsigned i = 0; i < N; i++)
|
for(unsigned i=0 ; i<N ; i++)
|
||||||
possibles[i] = i;
|
possibles[i] = i;
|
||||||
// random initialization
|
// random initialization
|
||||||
unsigned rInd; // random index
|
unsigned rInd; // random index
|
||||||
for (unsigned i = 0; i < N; i++)
|
for (unsigned i=0; i<N; i++) {
|
||||||
{
|
rInd = (unsigned) rng.uniform(N-i);
|
||||||
rInd = (unsigned) rng.uniform (N - i);
|
scheduling[i] = possibles[rInd];
|
||||||
scheduling[i] = possibles[rInd];
|
possibles[rInd] = possibles[N-i-1];
|
||||||
possibles[rInd] = possibles[N - i - 1];
|
}
|
||||||
}
|
_genotype.setScheduling(scheduling);
|
||||||
_genotype.setScheduling (scheduling);
|
_genotype.invalidate(); // IMPORTANT in case the _genotype is old
|
||||||
_genotype.invalidate (); // IMPORTANT in case the _genotype is old
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** the number of jobs (size of a scheduling vector) */
|
/** the number of jobs (size of a scheduling vector) */
|
||||||
unsigned N;
|
unsigned N;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /*FLOWSHOPINIT_H_*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// FlowShopOpCrossoverQuad.h
|
// FlowShopOpCrossoverQuad.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,85 +10,75 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _FlowShopOpCrossoverQuad_h
|
#ifndef FLOWSHOPOPCROSSOVERQUAD_H_
|
||||||
#define _FlowShopOpCrossoverQuad_h
|
#define FLOWSHOPOPCROSSOVERQUAD_H_
|
||||||
|
|
||||||
#include <eoOp.h>
|
#include <eoOp.h>
|
||||||
|
#include "FlowShop.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor
|
* Functor
|
||||||
* Quadratic crossover operator for flow-shop (modify the both genotypes)
|
* Quadratic crossover operator for flow-shop (modify the both genotypes)
|
||||||
*/
|
*/
|
||||||
class FlowShopOpCrossoverQuad:public eoQuadOp < FlowShop >
|
class FlowShopOpCrossoverQuad: public eoQuadOp<FlowShop> {
|
||||||
{
|
|
||||||
|
public:
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default constructor
|
* default constructor
|
||||||
*/
|
*/
|
||||||
FlowShopOpCrossoverQuad ()
|
FlowShopOpCrossoverQuad() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the class name (used to display statistics)
|
* the class name (used to display statistics)
|
||||||
*/
|
*/
|
||||||
string className () const
|
string className() const {
|
||||||
{
|
|
||||||
return "FlowShopOpCrossoverQuad";
|
return "FlowShopOpCrossoverQuad";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* eoQuad crossover - _genotype1 and _genotype2 are the (future) offspring, i.e. _copies_ of the parents
|
* eoQuad crossover - _genotype1 and _genotype2 are the (future) offspring, i.e. _copies_ of the parents
|
||||||
* @param FlowShop & _genotype1 the first parent
|
* @param FlowShop & _genotype1 the first parent
|
||||||
* @param FlowShop & _genotype2 the second parent
|
* @param FlowShop & _genotype2 the second parent
|
||||||
*/
|
*/
|
||||||
bool operator () (FlowShop & _genotype1, FlowShop & _genotype2)
|
bool operator()(FlowShop & _genotype1, FlowShop & _genotype2) {
|
||||||
{
|
|
||||||
bool oneAtLeastIsModified;
|
bool oneAtLeastIsModified;
|
||||||
|
|
||||||
// parents
|
// parents
|
||||||
vector < unsigned >parent1 = _genotype1.getScheduling ();
|
vector<unsigned> parent1 = _genotype1.getScheduling();
|
||||||
vector < unsigned >parent2 = _genotype2.getScheduling ();
|
vector<unsigned> parent2 = _genotype2.getScheduling();
|
||||||
|
|
||||||
// computation of the 2 random points
|
// computation of the 2 random points
|
||||||
unsigned point1, point2;
|
unsigned point1, point2;
|
||||||
do
|
do {
|
||||||
{
|
point1 = rng.random(min(parent1.size(), parent2.size()));
|
||||||
point1 = rng.random (min (parent1.size (), parent2.size ()));
|
point2 = rng.random(min(parent1.size(), parent2.size()));
|
||||||
point2 = rng.random (min (parent1.size (), parent2.size ()));
|
} while (fabs((double) point1-point2) <= 2);
|
||||||
}
|
|
||||||
while (fabs ((double) point1 - point2) <= 1);
|
|
||||||
|
|
||||||
// computation of the offspring
|
// computation of the offspring
|
||||||
vector < unsigned >offspring1 =
|
vector<unsigned> offspring1 = generateOffspring(parent1, parent2, point1, point2);
|
||||||
generateOffspring (parent1, parent2, point1, point2);
|
vector<unsigned> offspring2 = generateOffspring(parent2, parent1, point1, point2);
|
||||||
vector < unsigned >offspring2 =
|
|
||||||
generateOffspring (parent2, parent1, point1, point2);
|
|
||||||
|
|
||||||
// does at least one genotype has been modified ?
|
// does at least one genotype has been modified ?
|
||||||
if ((parent1 != offspring1) || (parent2 != offspring2))
|
if ((parent1 != offspring1) || (parent2 != offspring2)) {
|
||||||
{
|
// update
|
||||||
// update
|
_genotype1.setScheduling(offspring1);
|
||||||
_genotype1.setScheduling (offspring1);
|
_genotype2.setScheduling(offspring2);
|
||||||
_genotype2.setScheduling (offspring2);
|
// at least one genotype has been modified
|
||||||
// at least one genotype has been modified
|
oneAtLeastIsModified = true;
|
||||||
oneAtLeastIsModified = true;
|
}
|
||||||
}
|
else {
|
||||||
else
|
// no genotype has been modified
|
||||||
{
|
oneAtLeastIsModified = false;
|
||||||
// no genotype has been modified
|
}
|
||||||
oneAtLeastIsModified = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return 'true' if at least one genotype has been modified
|
// return 'true' if at least one genotype has been modified
|
||||||
return oneAtLeastIsModified;
|
return oneAtLeastIsModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generation of an offspring by a 2 points crossover
|
* generation of an offspring by a 2 points crossover
|
||||||
* @param vector<unsigned> _parent1 the first parent
|
* @param vector<unsigned> _parent1 the first parent
|
||||||
|
|
@ -96,43 +86,35 @@ private:
|
||||||
* @param unsigned_point1 the first point
|
* @param unsigned_point1 the first point
|
||||||
* @param unsigned_point2 the second point
|
* @param unsigned_point2 the second point
|
||||||
*/
|
*/
|
||||||
vector < unsigned >generateOffspring (vector < unsigned >_parent1,
|
vector<unsigned> generateOffspring(vector<unsigned> _parent1, vector<unsigned> _parent2, unsigned _point1, unsigned _point2) {
|
||||||
vector < unsigned >_parent2,
|
vector<unsigned> result = _parent1;
|
||||||
unsigned _point1, unsigned _point2)
|
vector<bool> taken_values(result.size(), false);
|
||||||
{
|
if (_point1 > _point2) swap(_point1, _point2);
|
||||||
vector < unsigned >result = _parent1;
|
|
||||||
vector < bool > taken_values (result.size (), false);
|
|
||||||
if (_point1 > _point2)
|
|
||||||
swap (_point1, _point2);
|
|
||||||
|
|
||||||
/* first parent */
|
/* first parent */
|
||||||
for (unsigned i = 0; i <= _point1; i++)
|
for (unsigned i=0 ; i<=_point1 ; i++) {
|
||||||
{
|
// result[i] == _parent1[i]
|
||||||
// result[i] == _parent1[i]
|
taken_values[_parent1[i]] = true;
|
||||||
taken_values[_parent1[i]] = true;
|
}
|
||||||
}
|
for (unsigned i=_point2 ; i<result.size() ; i++) {
|
||||||
for (unsigned 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 */
|
/* second parent */
|
||||||
unsigned i = _point1 + 1;
|
unsigned i = _point1+1;
|
||||||
unsigned j = 0;
|
unsigned j = 0;
|
||||||
while (i < _point2 && j < _parent2.size ())
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /*FLOWSHOPOPCROSSOVERQUAD_H_*/
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// FlowShopOpMutationExchange.h
|
// FlowShopOpCrossoverQuad.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,33 +10,29 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _FlowShopOpMutationExchange_h
|
#ifndef FLOWSHOPOPMUTATIONEXCHANGE_H_
|
||||||
#define _FlowShopOpMutationExchange_h
|
#define FLOWSHOPOPMUTATIONEXCHANGE_H_
|
||||||
|
|
||||||
#include <eoOp.h>
|
#include <eoOp.h>
|
||||||
|
#include "FlowShop.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor
|
* Functor
|
||||||
* Exchange mutation operator for flow-shop
|
* Exchange mutation operator for flow-shop
|
||||||
*/
|
*/
|
||||||
class FlowShopOpMutationExchange:public eoMonOp < FlowShop >
|
class FlowShopOpMutationExchange: public eoMonOp<FlowShop> {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default constructor
|
* default constructor
|
||||||
*/
|
*/
|
||||||
FlowShopOpMutationExchange ()
|
FlowShopOpMutationExchange() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the class name (used to display statistics)
|
* the class name (used to display statistics)
|
||||||
*/
|
*/
|
||||||
string className () const
|
string className() const {
|
||||||
{
|
|
||||||
return "FlowShopOpMutationExchange";
|
return "FlowShopOpMutationExchange";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,39 +40,34 @@ public:
|
||||||
* modifies the parent with an exchange mutation
|
* modifies the parent with an exchange mutation
|
||||||
* @param FlowShop & _genotype the parent genotype (will be modified)
|
* @param FlowShop & _genotype the parent genotype (will be modified)
|
||||||
*/
|
*/
|
||||||
bool operator () (FlowShop & _genotype)
|
bool operator()(FlowShop & _genotype) {
|
||||||
{
|
|
||||||
bool isModified;
|
bool isModified;
|
||||||
|
|
||||||
// schedulings
|
// schedulings
|
||||||
vector < unsigned >initScheduling = _genotype.getScheduling ();
|
vector<unsigned> initScheduling = _genotype.getScheduling();
|
||||||
vector < unsigned >resultScheduling = _genotype.getScheduling ();
|
vector<unsigned> resultScheduling = _genotype.getScheduling();
|
||||||
|
|
||||||
// computation of the 2 random points
|
// computation of the 2 random points
|
||||||
unsigned point1, point2;
|
unsigned point1, point2;
|
||||||
do
|
do {
|
||||||
{
|
point1 = rng.random(resultScheduling.size());
|
||||||
point1 = rng.random (resultScheduling.size ());
|
point2 = rng.random(resultScheduling.size());
|
||||||
point2 = rng.random (resultScheduling.size ());
|
} while (point1 == point2);
|
||||||
}
|
|
||||||
while (point1 == point2);
|
|
||||||
|
|
||||||
// swap
|
// swap
|
||||||
swap (resultScheduling[point1], resultScheduling[point2]);
|
swap (resultScheduling[point1], resultScheduling[point2]);
|
||||||
|
|
||||||
// update (if necessary)
|
// update (if necessary)
|
||||||
if (resultScheduling != initScheduling)
|
if (resultScheduling != initScheduling) {
|
||||||
{
|
// update
|
||||||
// update
|
_genotype.setScheduling(resultScheduling);
|
||||||
_genotype.setScheduling (resultScheduling);
|
// the genotype has been modified
|
||||||
// the genotype has been modified
|
isModified = true;
|
||||||
isModified = true;
|
}
|
||||||
}
|
else {
|
||||||
else
|
// the genotype has not been modified
|
||||||
{
|
isModified = false;
|
||||||
// the genotype has not been modified
|
}
|
||||||
isModified = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return 'true' if the genotype has been modified
|
// return 'true' if the genotype has been modified
|
||||||
return isModified;
|
return isModified;
|
||||||
|
|
@ -84,4 +75,4 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /*FLOWSHOPOPMUTATIONEXCHANGE_H_*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// FlowShopOpMutationShift.h
|
// FlowShopOpMutationShift.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,33 +10,29 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _FlowShopOpMutationShift_h
|
#ifndef FLOWSHOPOPMUTATIONSHIFT_H_
|
||||||
#define _FlowShopOpMutationShift_h
|
#define FLOWSHOPOPMUTATIONSHIFT_H_
|
||||||
|
|
||||||
#include <eoOp.h>
|
#include <eoOp.h>
|
||||||
|
#include "FlowShop.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functor
|
* Functor
|
||||||
* Shift mutation operator for flow-shop
|
* Shift mutation operator for flow-shop
|
||||||
*/
|
*/
|
||||||
class FlowShopOpMutationShift:public eoMonOp < FlowShop >
|
class FlowShopOpMutationShift: public eoMonOp<FlowShop> {
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default constructor
|
* default constructor
|
||||||
*/
|
*/
|
||||||
FlowShopOpMutationShift ()
|
FlowShopOpMutationShift() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the class name (used to display statistics)
|
* the class name (used to display statistics)
|
||||||
*/
|
*/
|
||||||
string className () const
|
string className() const {
|
||||||
{
|
|
||||||
return "FlowShopOpMutationShift";
|
return "FlowShopOpMutationShift";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,49 +40,42 @@ public:
|
||||||
* modifies the parent with a shift mutation
|
* modifies the parent with a shift mutation
|
||||||
* @param FlowShop & _genotype the parent genotype (will be modified)
|
* @param FlowShop & _genotype the parent genotype (will be modified)
|
||||||
*/
|
*/
|
||||||
bool operator () (FlowShop & _genotype)
|
bool operator()(FlowShop & _genotype) {
|
||||||
{
|
|
||||||
bool isModified;
|
bool isModified;
|
||||||
int direction;
|
int direction;
|
||||||
unsigned tmp;
|
unsigned tmp;
|
||||||
|
|
||||||
// schedulings
|
// schedulings
|
||||||
vector < unsigned >initScheduling = _genotype.getScheduling ();
|
vector<unsigned> initScheduling = _genotype.getScheduling();
|
||||||
vector < unsigned >resultScheduling = initScheduling;
|
vector<unsigned> resultScheduling = initScheduling;
|
||||||
|
|
||||||
// computation of the 2 random points
|
// computation of the 2 random points
|
||||||
unsigned point1, point2;
|
unsigned point1, point2;
|
||||||
do
|
do {
|
||||||
{
|
point1 = rng.random(resultScheduling.size());
|
||||||
point1 = rng.random (resultScheduling.size ());
|
point2 = rng.random(resultScheduling.size());
|
||||||
point2 = rng.random (resultScheduling.size ());
|
} while (point1 == point2);
|
||||||
}
|
|
||||||
while (point1 == point2);
|
|
||||||
|
|
||||||
// direction
|
// direction
|
||||||
if (point1 < point2)
|
if (point1 < point2) direction = 1;
|
||||||
direction = 1;
|
else direction = -1;
|
||||||
else
|
|
||||||
direction = -1;
|
|
||||||
// mutation
|
// mutation
|
||||||
tmp = resultScheduling[point1];
|
tmp = resultScheduling[point1];
|
||||||
for (unsigned i = point1; i != point2; i += direction)
|
for(unsigned i=point1 ; i!=point2 ; i+=direction)
|
||||||
resultScheduling[i] = resultScheduling[i + direction];
|
resultScheduling[i] = resultScheduling[i+direction];
|
||||||
resultScheduling[point2] = tmp;
|
resultScheduling[point2] = tmp;
|
||||||
|
|
||||||
// update (if necessary)
|
// update (if necessary)
|
||||||
if (resultScheduling != initScheduling)
|
if (resultScheduling != initScheduling) {
|
||||||
{
|
// update
|
||||||
// update
|
_genotype.setScheduling(resultScheduling);
|
||||||
_genotype.setScheduling (resultScheduling);
|
// the genotype has been modified
|
||||||
// the genotype has been modified
|
isModified = true;
|
||||||
isModified = true;
|
}
|
||||||
}
|
else {
|
||||||
else
|
// the genotype has not been modified
|
||||||
{
|
isModified = false;
|
||||||
// the genotype has not been modified
|
}
|
||||||
isModified = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return 'true' if the genotype has been modified
|
// return 'true' if the genotype has been modified
|
||||||
return isModified;
|
return isModified;
|
||||||
|
|
@ -94,4 +83,4 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif /*FLOWSHOPOPMUTATIONSHIFT_H_*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// make_eval_FlowShop.h
|
// make_eval_FlowShop.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,56 +10,46 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _make_eval_FlowShop_h
|
#ifndef MAKE_EVAL_FLOWSHOP_H_
|
||||||
#define _make_eval_FlowShop_h
|
#define MAKE_EVAL_FLOWSHOP_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <utils/eoParser.h>
|
||||||
|
#include <utils/eoState.h>
|
||||||
#include "FlowShop.h"
|
#include "FlowShop.h"
|
||||||
#include "FlowShopBenchmarkParser.h"
|
#include "FlowShopBenchmarkParser.h"
|
||||||
#include "FlowShopEval.h"
|
#include "FlowShopEval.h"
|
||||||
// also need the parser and param includes
|
|
||||||
#include <utils/eoParser.h>
|
|
||||||
#include <utils/eoState.h>
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function creates an eoEvalFuncCounter<eoFlowShop> that can later be used to evaluate an individual.
|
* This function creates an eoEvalFuncCounter<eoFlowShop> that can later be used to evaluate an individual.
|
||||||
* @param eoParser& _parser to get user parameters
|
* @param eoParser& _parser to get user parameters
|
||||||
* @param eoState& _state to store the memory
|
* @param eoState& _state to store the memory
|
||||||
*/
|
*/
|
||||||
eoEvalFuncCounter < FlowShop > &do_make_eval (eoParser & _parser,
|
eoEvalFuncCounter<FlowShop> & do_make_eval(eoParser& _parser, eoState& _state) {
|
||||||
eoState & _state)
|
|
||||||
{
|
|
||||||
|
|
||||||
// benchmark file name
|
// benchmark file name
|
||||||
string benchmarkFileName =
|
string benchmarkFileName = _parser.getORcreateParam(string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at " + BENCHMARKS_WEB_SITE + ")", 'B',"Representation", true).value();
|
||||||
_parser.getORcreateParam (string (), "BenchmarkFile",
|
if (benchmarkFileName == "") {
|
||||||
"Benchmark file name (benchmarks are available at "
|
std::string stmp = "*** Missing name of the benchmark file\n";
|
||||||
+ BENCHMARKS_WEB_SITE + ")", 'B',
|
stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n";
|
||||||
"Representation", true).value ();
|
stmp += " Benchmarks files are available at " + BENCHMARKS_WEB_SITE;
|
||||||
if (benchmarkFileName == "")
|
throw std::runtime_error(stmp.c_str());
|
||||||
{
|
}
|
||||||
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;
|
|
||||||
throw std::runtime_error (stmp.c_str ());
|
|
||||||
}
|
|
||||||
// reading of the parameters contained in the benchmark file
|
// reading of the parameters contained in the benchmark file
|
||||||
FlowShopBenchmarkParser fParser (benchmarkFileName);
|
FlowShopBenchmarkParser fParser(benchmarkFileName);
|
||||||
unsigned M = fParser.getM ();
|
unsigned M = fParser.getM();
|
||||||
unsigned N = fParser.getN ();
|
unsigned N = fParser.getN();
|
||||||
std::vector < std::vector < unsigned > >p = fParser.getP ();
|
std::vector< std::vector<unsigned> > p = fParser.getP();
|
||||||
std::vector < unsigned >d = fParser.getD ();
|
std::vector<unsigned> d = fParser.getD();
|
||||||
|
|
||||||
// build of the initializer (a pointer, stored in the eoState)
|
// build of the initializer (a pointer, stored in the eoState)
|
||||||
FlowShopEval *plainEval = new FlowShopEval (M, N, p, d);
|
FlowShopEval* plainEval = new FlowShopEval(M, N, p, d);
|
||||||
// turn that object into an evaluation counter
|
// turn that object into an evaluation counter
|
||||||
eoEvalFuncCounter < FlowShop > *eval =
|
eoEvalFuncCounter<FlowShop>* eval = new eoEvalFuncCounter<FlowShop> (* plainEval);
|
||||||
new eoEvalFuncCounter < FlowShop > (*plainEval);
|
|
||||||
// store in state
|
// store in state
|
||||||
_state.storeFunctor (eval);
|
_state.storeFunctor(eval);
|
||||||
// and return a reference
|
// and return a reference
|
||||||
return *eval;
|
return *eval;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /*MAKE_EVAL_FLOWSHOP_H_*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// make_genotype_FlowShop.h
|
// make_genotype_FlowShop.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,49 +10,40 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _make_genotype_FlowShop_h
|
#ifndef MAKE_GENOTYPE_FLOWSHOP_H_
|
||||||
#define _make_genotype_FlowShop_h
|
#define MAKE_GENOTYPE_FLOWSHOP_H_
|
||||||
|
|
||||||
|
#include <utils/eoParser.h>
|
||||||
|
#include <utils/eoState.h>
|
||||||
#include "FlowShop.h"
|
#include "FlowShop.h"
|
||||||
#include "FlowShopInit.h"
|
#include "FlowShopInit.h"
|
||||||
#include "FlowShopBenchmarkParser.h"
|
#include "FlowShopBenchmarkParser.h"
|
||||||
// also need the parser and param includes
|
|
||||||
#include <utils/eoParser.h>
|
|
||||||
#include <utils/eoState.h>
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function creates an eoInit<eoFlowShop> that can later be used to initialize the population (see make_pop.h).
|
* This function creates an eoInit<eoFlowShop> that can later be used to initialize the population (see make_pop.h).
|
||||||
* @param eoParser& _parser to get user parameters
|
* @param eoParser& _parser to get user parameters
|
||||||
* @param eoState& _state to store the memory
|
* @param eoState& _state to store the memory
|
||||||
*/
|
*/
|
||||||
eoInit < FlowShop > &do_make_genotype (eoParser & _parser, eoState & _state)
|
eoInit<FlowShop> & do_make_genotype(eoParser& _parser, eoState& _state) {
|
||||||
{
|
|
||||||
|
|
||||||
// benchmark file name
|
// benchmark file name
|
||||||
string benchmarkFileName =
|
string benchmarkFileName = _parser.getORcreateParam(string(), "BenchmarkFile", "Benchmark file name (benchmarks are available at " + BENCHMARKS_WEB_SITE + ")", 'B',"Representation", true).value();
|
||||||
_parser.getORcreateParam (string (), "BenchmarkFile",
|
if (benchmarkFileName == "") {
|
||||||
"Benchmark file name (benchmarks are available at "
|
std::string stmp = "*** Missing name of the benchmark file\n";
|
||||||
+ BENCHMARKS_WEB_SITE + ")", 'B',
|
stmp += " Type '-B=the_benchmark_file_name' or '--BenchmarkFile=the_benchmark_file_name'\n";
|
||||||
"Representation", true).value ();
|
stmp += " Benchmarks files are available at " + BENCHMARKS_WEB_SITE;
|
||||||
if (benchmarkFileName == "")
|
throw std::runtime_error(stmp.c_str());
|
||||||
{
|
}
|
||||||
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;
|
|
||||||
throw std::runtime_error (stmp.c_str ());
|
|
||||||
}
|
|
||||||
// reading of number of jobs to schedule contained in the benchmark file
|
// reading of number of jobs to schedule contained in the benchmark file
|
||||||
FlowShopBenchmarkParser fParser (benchmarkFileName);
|
FlowShopBenchmarkParser fParser(benchmarkFileName);
|
||||||
unsigned N = fParser.getN ();
|
unsigned N = fParser.getN();
|
||||||
|
|
||||||
// build of the initializer (a pointer, stored in the eoState)
|
// build of the initializer (a pointer, stored in the eoState)
|
||||||
eoInit < FlowShop > *init = new FlowShopInit (N);
|
eoInit<FlowShop>* init = new FlowShopInit(N);
|
||||||
// store in state
|
// store in state
|
||||||
_state.storeFunctor (init);
|
_state.storeFunctor(init);
|
||||||
// and return a reference
|
// and return a reference
|
||||||
return *init;
|
return *init;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /*MAKE_GENOTYPE_FLOWSHOP_H_*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// make_op_FlowShop.h
|
// make_op_FlowShop.h
|
||||||
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006
|
// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
|
||||||
/*
|
/*
|
||||||
This library...
|
This library...
|
||||||
|
|
||||||
|
|
@ -10,122 +10,97 @@
|
||||||
*/
|
*/
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef _make_op_FlowShop_h
|
#ifndef MAKE_OP_FLOWSHOP_H_
|
||||||
#define _make_op_FlowShop_h
|
#define MAKE_OP_FLOWSHOP_H_
|
||||||
|
|
||||||
// the operators
|
#include <utils/eoParser.h>
|
||||||
|
#include <utils/eoState.h>
|
||||||
#include <eoOp.h>
|
#include <eoOp.h>
|
||||||
#include <eoGenOp.h>
|
#include <eoGenOp.h>
|
||||||
#include <eoCloneOps.h>
|
#include <eoCloneOps.h>
|
||||||
#include <eoOpContainer.h>
|
#include <eoOpContainer.h>
|
||||||
// combinations of simple eoOps (eoMonOp and eoQuadOp)
|
|
||||||
#include <eoProportionalCombinedOp.h>
|
#include <eoProportionalCombinedOp.h>
|
||||||
|
|
||||||
// definition of crossover
|
|
||||||
#include "FlowShopOpCrossoverQuad.h"
|
#include "FlowShopOpCrossoverQuad.h"
|
||||||
// definition of mutation
|
|
||||||
#include "FlowShopOpMutationShift.h"
|
#include "FlowShopOpMutationShift.h"
|
||||||
#include "FlowShopOpMutationExchange.h"
|
#include "FlowShopOpMutationExchange.h"
|
||||||
|
|
||||||
// also need the parser and state includes
|
|
||||||
#include <utils/eoParser.h>
|
|
||||||
#include <utils/eoState.h>
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function builds the operators that will be applied to the eoFlowShop
|
* This function builds the operators that will be applied to the eoFlowShop
|
||||||
* @param eoParameterLoader& _parser to get user parameters
|
* @param eoParameterLoader& _parser to get user parameters
|
||||||
* @param eoState& _state to store the memory
|
* @param eoState& _state to store the memory
|
||||||
*/
|
*/
|
||||||
eoGenOp < FlowShop > &do_make_op (eoParameterLoader & _parser,
|
eoGenOp<FlowShop> & do_make_op(eoParameterLoader& _parser, eoState& _state) {
|
||||||
eoState & _state)
|
|
||||||
{
|
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// Variation operators
|
// Variation operators
|
||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
// the crossover
|
// the crossover
|
||||||
////////////////
|
////////////////
|
||||||
|
|
||||||
// a first crossover
|
// a first crossover
|
||||||
eoQuadOp < FlowShop > *cross = new FlowShopOpCrossoverQuad;
|
eoQuadOp<FlowShop> *cross = new FlowShopOpCrossoverQuad;
|
||||||
// store in the state
|
// store in the state
|
||||||
_state.storeFunctor (cross);
|
_state.storeFunctor(cross);
|
||||||
|
|
||||||
// relative rate in the combination
|
// relative rate in the combination
|
||||||
double cross1Rate = _parser.createParam (1.0, "crossRate",
|
double cross1Rate = _parser.createParam(1.0, "crossRate", "Relative rate for the only crossover", 0, "Variation Operators").value();
|
||||||
"Relative rate for the only crossover",
|
|
||||||
0,
|
|
||||||
"Variation Operators").value ();
|
|
||||||
// creation of the combined operator with this one
|
// creation of the combined operator with this one
|
||||||
eoPropCombinedQuadOp < FlowShop > *propXover =
|
eoPropCombinedQuadOp<FlowShop> *propXover = new eoPropCombinedQuadOp<FlowShop>(*cross, cross1Rate);
|
||||||
new eoPropCombinedQuadOp < FlowShop > (*cross, cross1Rate);
|
|
||||||
// store in the state
|
// store in the state
|
||||||
_state.storeFunctor (propXover);
|
_state.storeFunctor(propXover);
|
||||||
|
|
||||||
|
|
||||||
// the mutation
|
// the mutation
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
// a first mutation : the shift mutation
|
// a first mutation : the shift mutation
|
||||||
eoMonOp < FlowShop > *mut = new FlowShopOpMutationShift;
|
eoMonOp<FlowShop> *mut = new FlowShopOpMutationShift;
|
||||||
_state.storeFunctor (mut);
|
_state.storeFunctor(mut);
|
||||||
// its relative rate in the combination
|
// its relative rate in the combination
|
||||||
double mut1Rate = _parser.createParam (0.5, "shiftMutRate",
|
double mut1Rate = _parser.createParam(0.5, "shiftMutRate", "Relative rate for shift mutation", 0, "Variation Operators").value();
|
||||||
"Relative rate for shift mutation",
|
|
||||||
0,
|
|
||||||
"Variation Operators").value ();
|
|
||||||
// creation of the combined operator with this one
|
// creation of the combined operator with this one
|
||||||
eoPropCombinedMonOp < FlowShop > *propMutation =
|
eoPropCombinedMonOp<FlowShop> *propMutation = new eoPropCombinedMonOp<FlowShop>(*mut, mut1Rate);
|
||||||
new eoPropCombinedMonOp < FlowShop > (*mut, mut1Rate);
|
_state.storeFunctor(propMutation);
|
||||||
_state.storeFunctor (propMutation);
|
|
||||||
|
|
||||||
// a second mutation : the exchange mutation
|
// a second mutation : the exchange mutation
|
||||||
mut = new FlowShopOpMutationExchange;
|
mut = new FlowShopOpMutationExchange;
|
||||||
_state.storeFunctor (mut);
|
_state.storeFunctor(mut);
|
||||||
// its relative rate in the combination
|
// its relative rate in the combination
|
||||||
double mut2Rate = _parser.createParam (0.5, "exchangeMutRate",
|
double mut2Rate = _parser.createParam(0.5, "exchangeMutRate", "Relative rate for exchange mutation", 0, "Variation Operators").value();
|
||||||
"Relative rate for exchange mutation",
|
|
||||||
0,
|
|
||||||
"Variation Operators").value ();
|
|
||||||
// addition of this one to the combined operator
|
// addition of this one to the combined operator
|
||||||
propMutation->add (*mut, mut2Rate);
|
propMutation -> add(*mut, mut2Rate);
|
||||||
|
|
||||||
// end of crossover and mutation definitions
|
// end of crossover and mutation definitions
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
|
|
||||||
// First read the individual level parameters
|
// First read the individual level parameters
|
||||||
eoValueParam < double >&pCrossParam =
|
eoValueParam<double>& pCrossParam = _parser.createParam(0.25, "pCross", "Probability of Crossover", 'c', "Variation Operators" );
|
||||||
_parser.createParam (0.25, "pCross", "Probability of Crossover", 'c',
|
|
||||||
"Variation Operators");
|
|
||||||
// minimum check
|
// minimum check
|
||||||
if ((pCrossParam.value () < 0) || (pCrossParam.value () > 1))
|
if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
|
||||||
throw runtime_error ("Invalid pCross");
|
throw runtime_error("Invalid pCross");
|
||||||
|
|
||||||
eoValueParam < double >&pMutParam =
|
eoValueParam<double>& pMutParam = _parser.createParam(0.35, "pMut", "Probability of Mutation", 'm', "Variation Operators" );
|
||||||
_parser.createParam (0.35, "pMut", "Probability of Mutation", 'm',
|
|
||||||
"Variation Operators");
|
|
||||||
// minimum check
|
// minimum check
|
||||||
if ((pMutParam.value () < 0) || (pMutParam.value () > 1))
|
if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
|
||||||
throw runtime_error ("Invalid pMut");
|
throw runtime_error("Invalid pMut");
|
||||||
|
|
||||||
// the crossover - with probability pCross
|
// the crossover - with probability pCross
|
||||||
eoProportionalOp < FlowShop > *propOp = new eoProportionalOp < FlowShop >;
|
eoProportionalOp<FlowShop> * propOp = new eoProportionalOp<FlowShop> ;
|
||||||
_state.storeFunctor (propOp);
|
_state.storeFunctor(propOp);
|
||||||
eoQuadOp < FlowShop > *ptQuad = new eoQuadCloneOp < FlowShop >;
|
eoQuadOp<FlowShop> *ptQuad = new eoQuadCloneOp<FlowShop>;
|
||||||
_state.storeFunctor (ptQuad);
|
_state.storeFunctor(ptQuad);
|
||||||
propOp->add (*propXover, pCrossParam.value ()); // crossover, with proba pcross
|
propOp -> add(*propXover, pCrossParam.value()); // crossover, with proba pcross
|
||||||
propOp->add (*ptQuad, 1 - pCrossParam.value ()); // nothing, with proba 1-pcross
|
propOp -> add(*ptQuad, 1-pCrossParam.value()); // nothing, with proba 1-pcross
|
||||||
|
|
||||||
// now the sequential
|
// now the sequential
|
||||||
eoSequentialOp < FlowShop > *op = new eoSequentialOp < FlowShop >;
|
eoSequentialOp<FlowShop> *op = new eoSequentialOp<FlowShop>;
|
||||||
_state.storeFunctor (op);
|
_state.storeFunctor(op);
|
||||||
op->add (*propOp, 1.0); // always do combined crossover
|
op -> add(*propOp, 1.0); // always do combined crossover
|
||||||
op->add (*propMutation, pMutParam.value ()); // then mutation, with proba pmut
|
op -> add(*propMutation, pMutParam.value()); // then mutation, with proba pmut
|
||||||
|
|
||||||
// return a reference
|
// return a reference
|
||||||
return *op;
|
return *op;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /*MAKE_OP_FLOWSHOP_H_*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue