git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@36 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
legrand 2006-12-12 14:46:07 +00:00
commit c7d3cc755c
29 changed files with 13175 additions and 0 deletions

View file

@ -0,0 +1 @@
SUBDIRS=lesson1

View file

@ -0,0 +1,148 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "FlowShop.h"
// (c) OPAC Team, LIFL, April 2006
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: Arnaud.Liefooghe@lifl.fr
*/
#ifndef _FlowShop_h
#define _FlowShop_h
#include <EO.h>
// Fitness for multi-objective flow-shop
#include "FlowShopFitness.h"
/**
* Structure of the genotype for the flow-shop scheduling problem
*/
class FlowShop:public EO < FlowShopFitness >
{
public:
/**
* default constructor
*/
FlowShop ()
{
}
/**
* destructor
*/
virtual ~ FlowShop ()
{
}
/**
* class name
*/
virtual string className () const
{
return "FlowShop";
}
/**
* set scheduling vector
* @param vector<unsigned> & _scheduling the new scheduling to set
*/
void setScheduling (vector < unsigned >&_scheduling)
{
scheduling = _scheduling;
}
/**
* get scheduling vector
*/
const vector < unsigned >&getScheduling () const
{
return scheduling;
}
/**
* printing...
*/
void printOn (ostream & _os) const
{
// fitness
EO < FlowShopFitness >::printOn (_os);
_os << "\t";
// size
_os << scheduling.size () << "\t";
// scheduling
for (unsigned i = 0; i < scheduling.size (); i++)
_os << scheduling[i] << ' ';
}
/**
* reading...
*/
void readFrom (istream & _is)
{
// fitness
EO < FlowShopFitness >::readFrom (_is);
// size
unsigned size;
_is >> size;
// scheduling
scheduling.resize (size);
bool tmp;
for (unsigned i = 0; i < size; i++)
{
_is >> 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 < unsigned >scheduling;
};
#endif

View file

@ -0,0 +1,189 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "FlowShopBenchmarkParser.h"
// (c) OPAC Team, LIFL, March 2006
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: Arnaud.Liefooghe@lifl.fr
*/
#ifndef _FlowShopBenchmarkParser_h
#define _FlowShopBenchmarkParser_h
// general include
#include <stdexcept>
#include <fstream>
/** Web site to download benchmarks */
const static
std::string
BENCHMARKS_WEB_SITE = "www.lifl.fr/~liefooga/benchmarks/";
/**
* 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 < unsigned > >
getP ()
{
return p;
}
/**
* the due-dates
*/
const
std::vector < unsigned >
getD ()
{
return d;
}
/**
* printing...
*/
void
printOn (ostream & _os) const
{
_os <<
"M=" <<
M <<
" 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 << "*** due-dates" << endl;
for (unsigned j = 0; j < N; j++)
{
_os << d[j] << " ";
}
_os << endl << endl;
}
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 < unsigned > >
p;
/** d[j] = due-date of the job j */
std::vector < unsigned >
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 < unsigned > > (M, N);
d = std::vector < unsigned > (N);
// for each job...
for (unsigned j = 0; j < N; j++)
{
// index of the job (<=> j)
getline (inputFile, buffer, '\n');
// due-date of the job j
getline (inputFile, buffer, '\n');
d[j] = atoi (buffer.data ());
// processing times of the job j on each machine
getline (inputFile, buffer, '\n');
start = buffer.find_first_not_of (" ");
for (unsigned i = 0; i < M; i++)
{
end = buffer.find_first_of (" ", start);
p[i][j] = atoi (buffer.substr (start, end - start).data ());
start = buffer.find_first_not_of (" ", end);
}
}
// closing of the input file
inputFile.close ();
}
};
#endif

Binary file not shown.

View file

@ -0,0 +1,170 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "FlowShopEA.cpp"
// (c) OPAC Team, LIFL, October 2006
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: Arnaud.Liefooghe@lifl.fr
*/
// Miscilaneous include and declaration
using namespace std;
/* EO */
// eo general include
#include "eo"
// for the creation of an evaluator
#include "make_eval_FlowShop.h"
// for the creation of an initializer
#include "make_genotype_FlowShop.h"
// for the creation of the variation operators
#include "make_op_FlowShop.h"
// how to initialize the population
#include <do/make_pop.h>
// the stopping criterion
#include <do/make_continue_pareto.h>
// outputs (stats, population dumps, ...)
#include <do/make_checkpoint_pareto.h>
// simple call to the algo
#include <do/make_run.h>
// checks for help demand, and writes the status file and make_help; in libutils
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 */
// definition of representation
#include "FlowShop.h"
// definition of fitness
#include "FlowShopFitness.h"
int
main (int argc, char *argv[])
{
try
{
eoParser parser (argc, argv); // for user-parameter reading
eoState state; // to keep all things allocated
/*** the representation-dependent things ***/
// The fitness evaluation
eoEvalFuncCounter < FlowShop > &eval = do_make_eval (parser, state);
// the genotype (through a genotype initializer)
eoInit < FlowShop > &init = do_make_genotype (parser, state);
// the variation operators
eoGenOp < FlowShop > &op = do_make_op (parser, state);
/*** the representation-independent things ***/
// initialization of the population
eoPop < FlowShop > &pop = do_make_pop (parser, state, init);
// definition of the archive
moeoArchive < FlowShop > arch;
// stopping criteria
eoContinue < FlowShop > &term =
do_make_continue_pareto (parser, state, eval);
// output
eoCheckPoint < FlowShop > &checkpoint =
do_make_checkpoint_pareto (parser, state, eval, term);
// algorithm
eoAlgo < FlowShop > &algo =
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);
/*** Go ! ***/
// help ?
make_help (parser);
// first evalution
apply < FlowShop > (eval, pop);
// printing of the initial population
cout << "Initial Population\n";
pop.sortedPrintOn (cout);
cout << endl;
// run the algo
do_run (algo, pop);
// printing of the final population
cout << "Final Population\n";
pop.sortedPrintOn (cout);
cout << endl;
// printing of the final archive
cout << "Final Archive\n";
arch.sortedPrintOn (cout);
cout << endl;
} catch (exception & e)
{
cout << e.what () << endl;
}
return EXIT_SUCCESS;
}

View file

@ -0,0 +1,51 @@
###### General ######
# --help=0 # -h : Prints this message
# --stopOnUnknownParam=1 # Stop if unkown param entered
# --seed=1165485212 # -S : Random number seed
###### Evolution Engine ######
--popSize=20 # -P : Population Size
--selCrit=NSGA-II # -S : Multi-objective selection criterion: NSGA, NSGA-II, IBEA, ParetoRanking, ParetoSharing
--nicheSize=1 # -n : Size of niche for NSGA-I or ParetoSharing
--kappa=0.05 # -k : Scaling factor kappa for IBEA
--indicator=Epsilon # -I : Binary quality indicator for IBEA : Epsilon, Hypervolume
--rho=1.1 # -r : reference point for the hypervolume calculation (must not be smaller than 1)
--selection=DetTour(2) # -s : Selection: Roulette, DetTour(T), StochTour(t) or Random
--elitism=0 # -E : Use elitism in the selection process (individuals from the archive are randomly selected)
--ratio=0.8 # Ratio from the population for elitism (must not be greater than 1)
--nbOffspring=100% # -O : Nb of offspring (percentage or absolute)
--replacement=Plus # -R : Replacement: Plus, DistinctPlus or Generational
###### Output ######
--useEval=1 # Use nb of eval. as counter (vs nb of gen.)
--printPop=0 # Print sorted pop. every gen.
###### Output - Disk ######
--resDir=Res # Directory to store DISK outputs
--eraseDir=1 # erase files in dirName if any
--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 ######
# --Load= # -L : A save file to restart from
--recomputeFitness=0 # -r : Recompute the fitness after re-loading the pop.?
--saveFrequency=0 # Save every F generation (0 = only final state, absent = never)
--saveTimeInterval=0 # Save every T seconds (0 or absent = never)
--status=./FlowShopEA.status # Status file
###### Representation ######
--BenchmarkFile=benchmarks/020_05_01.txt # -B : Benchmark file name (benchmarks are available at www.lifl.fr/~basseur/BenchsUncertain/) REQUIRED
###### Stopping criterion ######
--maxGen=100 # -G : Maximum number of generations () = none)
--CtrlC=1 # -C : Terminate current generation upon Ctrl C
###### Variation Operators ######
--crossRate=1 # Relative rate for the only crossover
--shiftMutRate=0.5 # Relative rate for shift mutation
--exchangeMutRate=0.5 # Relative rate for exchange mutation
--pCross=0.25 # -c : Probability of Crossover
--pMut=0.35 # -m : Probability of Mutation

View file

@ -0,0 +1,157 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "FlowShopEval.h"
// (c) OPAC Team, LIFL, March 2006
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: Arnaud.Liefooghe@lifl.fr
*/
#ifndef _FlowShopEval_h
#define _FlowShopEval_h
// Flow-shop fitness
#include "FlowShopFitness.h"
// include the base definition of eoEvalFunc
#include <eoEvalFunc.h>
/**
* Functor
* Computation of the multi-objective evaluation of a FlowShop object
*/
class FlowShopEval:public eoEvalFunc < FlowShop >
{
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 < unsigned > >&_p,
const vector < unsigned >&_d):M (_M), N (_N), p (_p), d (_d)
{
unsigned nObjs = 2;
std::vector < bool > bObjs (nObjs, false);
eoVariableParetoTraits::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)
{
FlowShopFitness fitness;
fitness[0] = tardiness (_eo);
fitness[1] = makespan (_eo);
_eo.fitness (fitness);
}
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 < unsigned > > p;
/** d[j] = due-date of the job j */
std::vector < unsigned > d;
/**
* computation of the makespan
* @param FlowShop _eo the FlowShop object to evaluate
*/
double makespan (FlowShop _eo)
{
// the scheduling to evaluate
vector < unsigned >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 < unsigned > > 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 < unsigned >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 < unsigned > > C = completionTime (_eo);
// tardiness computation
unsigned long sum = 0;
for (unsigned j = 0; j < N; j++)
sum +=
(unsigned) std::max (0,
(int) (C[M - 1][scheduling[j]] -
d[scheduling[j]]));
// fitness == sum
return sum;
}
/**
* 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 const FlowShop _eo the genotype to evaluate
*/
std::vector < std::vector < unsigned > > completionTime (FlowShop _eo)
{
vector < unsigned > scheduling = _eo.getScheduling ();
std::vector < std::vector < unsigned > > C (M, N);
C[0][scheduling[0]] = p[0][scheduling[0]];
for (unsigned j = 1; j < N; j++)
C[0][scheduling[j]] = C[0][scheduling[j - 1]] + p[0][scheduling[j]];
for (unsigned i = 1; i < M; i++)
C[i][scheduling[0]] = C[i - 1][scheduling[0]] + p[i][scheduling[0]];
for (unsigned i = 1; i < M; i++)
for (unsigned j = 1; j < N; j++)
C[i][scheduling[j]] =
std::max (C[i][scheduling[j - 1]],
C[i - 1][scheduling[j]]) + p[i][scheduling[j]];
return C;
}
};
#endif

View file

@ -0,0 +1,35 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "FlowShopFitness.h"
// (c) OPAC Team, LIFL, March 2006
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: Arnaud.Liefooghe@lifl.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

View file

@ -0,0 +1,79 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "FlowShopInit.h"
// (c) OPAC Team, LIFL, March 2006
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: Arnaud.Liefooghe@lifl.fr
*/
#ifndef _FlowShopInit_h
#define _FlowShopInit_h
#include <eoInit.h>
/**
* Functor
* Initialisation of a random genotype built by the default constructor of the eoFlowShop class
*/
class FlowShopInit:public eoInit < FlowShop >
{
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 < unsigned >scheduling (N);
// initialisation of possible values
vector < unsigned >possibles (N);
for (unsigned i = 0; i < N; i++)
possibles[i] = i;
// random initialization
unsigned rInd; // random index
for (unsigned i = 0; i < N; i++)
{
rInd = (unsigned) rng.uniform (N - i);
scheduling[i] = possibles[rInd];
possibles[rInd] = possibles[N - i - 1];
}
_genotype.setScheduling (scheduling);
_genotype.invalidate (); // IMPORTANT in case the _genotype is old
}
private:
/** the number of jobs (size of a scheduling vector) */
unsigned N;
};
#endif

View file

@ -0,0 +1,149 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "FlowShopOpCrossoverQuad.h"
// (c) OPAC Team, LIFL, April 2006
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: Arnaud.Liefooghe@lifl.fr
*/
#ifndef _FlowShopOpCrossoverQuad_h
#define _FlowShopOpCrossoverQuad_h
#include <eoOp.h>
/**
* Functor
* Quadratic crossover operator for flow-shop (modify the both genotypes)
*/
class FlowShopOpCrossoverQuad:public eoQuadOp < FlowShop >
{
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 < unsigned >parent1 = _genotype1.getScheduling ();
vector < unsigned >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) <= 1);
// computation of the offspring
vector < unsigned >offspring1 =
generateOffspring (parent1, parent2, point1, point2);
vector < unsigned >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<unsigned> _parent1 the first parent
* @param vector<unsigned> _parent2 the second parent
* @param unsigned_point1 the first point
* @param unsigned_point2 the second point
*/
vector < unsigned >generateOffspring (vector < unsigned >_parent1,
vector < unsigned >_parent2,
unsigned _point1, unsigned _point2)
{
vector < unsigned >result = _parent1;
vector < bool > 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 < result.size (); i++)
{
// result[i] == _parent1[i]
taken_values[_parent1[i]] = true;
}
/* second parent */
unsigned i = _point1 + 1;
unsigned j = 0;
while (i < _point2 && j < _parent2.size ())
{
if (!taken_values[_parent2[j]])
{
result[i] = _parent2[j];
i++;
}
j++;
}
return result;
}
};
#endif

View file

@ -0,0 +1,98 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "FlowShopOpMutationExchange.h"
// (c) OPAC Team, LIFL, March 2006
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: Arnaud.Liefooghe@lifl.fr
*/
#ifndef _FlowShopOpMutationExchange_h
#define _FlowShopOpMutationExchange_h
#include <eoOp.h>
/**
* Functor
* Exchange mutation operator for flow-shop
*/
class FlowShopOpMutationExchange:public eoMonOp < FlowShop >
{
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 < unsigned >initScheduling = _genotype.getScheduling ();
vector < unsigned >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

View file

@ -0,0 +1,108 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
// "FlowShopOpMutationShift.h"
// (c) OPAC Team, LIFL, March 2006
/* This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: Arnaud.Liefooghe@lifl.fr
*/
#ifndef _FlowShopOpMutationShift_h
#define _FlowShopOpMutationShift_h
#include <eoOp.h>
/**
* Functor
* Shift mutation operator for flow-shop
*/
class FlowShopOpMutationShift:public eoMonOp < FlowShop >
{
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 < unsigned >initScheduling = _genotype.getScheduling ();
vector < unsigned >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

View file

@ -0,0 +1,9 @@
noinst_PROGRAMS = FlowShopEA
FlowShopEA_SOURCES = FlowShopEA.cpp
LDADD = -L$(top_builddir)/src ${EO_DIR}/src/libeo.a ${EO_DIR}/src/utils/libeoutils.a
INCLUDES = -I${EO_DIR}/src/ -I$(top_srcdir)/src

View file

@ -0,0 +1,63 @@
20
5
873654221
0
468
54 79 16 66 58
1
325
83 3 89 58 56
2
923
15 11 49 31 20
3
513
71 99 15 68 85
4
1070
77 56 89 78 53
5
690
36 70 45 91 35
6
602
53 99 60 13 53
7
289
38 60 23 59 41
8
873
27 5 57 49 69
9
342
87 56 64 85 13
10
764
76 3 7 85 86
11
268
91 61 1 9 72
12
1158
14 73 63 39 8
13
646
29 75 41 41 49
14
1111
12 47 63 56 47
15
965
77 14 47 40 87
16
703
32 21 26 54 58
17
1205
87 86 75 77 18
18
334
68 5 77 51 68
19
1111
94 77 40 31 28

View file

@ -0,0 +1,63 @@
20
5
379008056
0
517
26 59 78 88 69
1
461
38 62 90 54 30
2
832
27 44 64 47 61
3
653
88 10 49 83 35
4
933
95 23 47 84 53
5
811
55 64 20 9 98
6
966
54 47 61 30 94
7
448
63 68 93 11 33
8
577
23 54 36 92 77
9
1122
45 9 47 63 31
10
666
86 30 70 62 54
11
1189
43 31 54 75 71
12
470
43 92 87 48 78
13
475
40 7 13 23 9
14
462
37 14 40 85 79
15
866
54 95 34 23 51
16
392
35 76 55 4 76
17
310
59 82 13 31 56
18
719
43 91 11 13 80
19
1221
50 37 5 98 72

View file

@ -0,0 +1,63 @@
20
10
587595453
0
1250
74 28 89 60 54 92 9 4 25 15
1
1371
21 3 52 88 66 11 8 18 15 84
2
637
58 27 56 26 12 54 88 25 91 8
3
616
4 61 13 58 57 97 72 28 49 30
4
917
21 34 7 76 70 57 27 95 56 95
5
937
28 76 32 98 82 53 22 51 10 79
6
1435
58 64 32 29 99 65 50 84 62 9
7
1197
83 87 98 47 84 77 2 18 70 91
8
1301
31 54 46 79 16 51 49 6 76 76
9
637
61 98 60 26 41 36 82 90 99 26
10
749
94 76 23 19 23 53 93 69 58 42
11
1223
44 41 87 48 11 19 96 61 83 66
12
887
97 70 7 95 68 54 43 57 84 70
13
1316
94 43 36 78 58 86 13 5 64 91
14
1330
66 42 26 77 30 40 60 75 74 67
15
1380
6 79 85 90 5 56 11 4 14 3
16
767
37 88 7 24 5 79 37 38 18 98
17
574
22 15 34 10 39 74 91 28 48 4
18
1398
99 49 36 85 58 24 84 4 96 71
19
1179
83 72 48 55 31 3 67 80 86 62

View file

@ -0,0 +1,63 @@
20
10
1401007982
0
1279
80 59 59 31 30 53 93 90 65 64
1
1481
13 83 70 64 88 19 79 92 97 38
2
1157
64 85 76 11 14 99 88 35 27 44
3
1391
77 85 10 9 22 62 77 13 25 46
4
763
17 70 65 32 93 88 94 75 61 66
5
1456
78 35 19 58 48 93 39 55 24 31
6
900
82 2 77 98 10 34 74 80 97 48
7
1047
4 76 86 95 7 72 46 67 61 27
8
1355
72 46 21 25 14 42 17 3 75 82
9
1262
93 72 75 4 91 65 30 93 92 51
10
1329
68 69 96 45 5 39 62 54 73 90
11
562
25 46 3 60 43 79 77 67 21 63
12
684
67 3 50 87 30 9 43 25 29 85
13
567
80 57 57 31 79 26 98 77 3 36
14
765
43 71 66 1 39 72 48 38 96 69
15
808
93 77 84 96 34 29 14 98 51 67
16
999
21 33 98 22 77 36 45 96 26 81
17
548
33 49 55 95 81 48 25 20 44 18
18
577
14 59 70 73 11 57 98 15 56 81
19
704
30 82 32 77 10 95 30 36 31 72

View file

@ -0,0 +1,63 @@
20
20
479340445
0
1696
50 78 36 85 9 75 46 73 71 7 49 3 60 12 75 31 70 20 88 9
1
1273
90 56 43 88 92 64 94 3 49 40 49 53 88 47 19 61 78 78 30 41
2
1546
39 9 10 60 98 96 6 56 36 33 15 59 15 46 60 47 41 38 34 22
3
1882
34 43 19 98 44 95 19 73 87 64 18 7 26 17 87 32 9 26 33 34
4
1117
66 84 55 4 51 22 20 80 8 5 65 65 11 43 27 34 47 64 21 83
5
1181
81 73 48 99 8 41 51 82 25 25 55 58 16 16 48 69 94 62 7 55
6
1416
27 66 85 53 31 26 85 36 76 89 1 24 55 91 72 32 26 11 94 3
7
1635
48 38 70 21 15 33 92 98 73 95 79 55 59 94 88 1 65 38 10 8
8
1723
46 83 82 33 47 68 43 90 80 58 10 26 81 73 48 1 17 68 73 75
9
1932
68 57 39 53 31 9 75 46 6 83 37 40 53 89 59 80 42 37 85 30
10
1219
48 97 91 63 80 81 70 10 6 28 77 89 92 12 74 19 59 74 82 57
11
1521
92 52 82 18 83 28 70 46 33 35 80 94 23 58 86 57 80 9 62 65
12
1322
78 77 85 45 20 61 36 65 79 74 79 51 55 25 49 98 7 65 99 89
13
1057
84 13 17 29 84 69 31 83 10 5 84 74 79 24 94 37 75 16 67 60
14
1922
93 12 6 43 69 37 76 75 93 6 93 54 13 55 15 31 63 38 61 90
15
1130
39 2 54 41 49 57 63 47 65 9 21 86 89 1 95 51 96 85 10 84
16
1411
43 65 87 80 93 36 89 61 26 3 85 22 2 67 41 66 7 50 4 74
17
1840
1 93 85 4 39 80 46 28 73 2 64 83 17 3 94 38 10 62 70 17
18
1741
65 39 4 31 13 96 25 59 42 35 46 19 97 1 15 62 47 39 31 2
19
1377
87 1 72 19 88 74 88 22 18 41 35 44 41 71 71 72 38 97 49 19

View file

@ -0,0 +1,153 @@
50
5
1328042058
0
1290
75 26 48 26 77
1
2352
87 37 4 67 94
2
362
13 25 92 4 9
3
305
11 95 92 14 57
4
262
41 49 72 93 29
5
1250
43 12 45 54 79
6
2170
93 59 5 21 55
7
1601
69 17 98 20 73
8
2039
80 46 93 6 65
9
1628
13 20 17 18 86
10
483
24 52 79 75 25
11
285
72 44 11 25 39
12
1092
38 92 16 16 76
13
936
81 75 89 77 24
14
2349
83 95 81 28 38
15
473
88 33 92 24 5
16
2325
26 10 45 15 91
17
747
6 45 61 77 29
18
970
89 2 39 36 22
19
434
67 62 28 16 27
20
1258
70 62 94 32 39
21
2405
30 82 87 46 31
22
862
89 29 23 21 46
23
298
30 29 1 81 18
24
2014
68 94 55 28 93
25
2608
21 20 91 70 58
26
1737
78 42 67 89 85
27
2214
46 80 91 54 58
28
1910
99 94 4 96 97
29
2245
10 35 60 62 10
30
2211
17 8 38 46 79
31
547
23 41 25 60 93
32
2237
83 65 90 19 2
33
1327
47 4 93 97 87
34
700
86 71 13 13 17
35
1011
18 30 65 7 18
36
2001
67 14 25 44 10
37
1230
46 32 34 7 50
38
1020
4 50 47 73 8
39
1918
14 30 98 15 26
40
1001
4 27 91 66 14
41
1383
20 98 11 70 21
42
1229
88 39 46 97 15
43
2594
50 84 50 33 10
44
403
84 65 77 97 85
45
1515
58 12 5 64 46
46
431
93 58 14 73 42
47
1971
76 45 47 28 18
48
939
50 49 80 4 36
49
2028
30 15 45 87 2

View file

@ -0,0 +1,153 @@
50
10
1958948863
0
793
46 61 3 51 37 79 83 22 27 24
1
2280
52 87 1 24 16 93 87 29 92 47
2
939
79 51 58 21 42 68 38 99 75 39
3
2591
45 25 85 57 47 75 38 25 94 66
4
1540
97 73 33 69 94 37 86 98 18 41
5
2386
10 93 71 51 14 44 67 55 41 46
6
812
44 28 58 50 94 34 23 80 37 24
7
2524
24 90 56 51 34 39 19 82 58 23
8
1370
85 94 64 21 72 76 97 33 56 68
9
1319
75 59 43 19 36 62 78 68 20 50
10
2388
66 64 48 63 88 74 66 47 2 93
11
961
49 2 69 91 51 28 67 74 39 22
12
2831
95 16 96 11 41 78 7 26 91 64
13
2790
61 35 35 6 71 43 23 61 81 81
14
2076
19 53 82 31 94 98 67 95 33 94
15
2519
47 40 53 63 99 83 8 55 14 97
16
1981
84 81 64 36 11 91 77 11 88 54
17
695
13 26 11 39 97 27 71 42 22 82
18
2133
11 85 61 57 44 6 85 72 36 11
19
1871
19 4 36 47 77 82 29 14 65 91
20
1495
98 4 53 56 69 60 49 8 79 23
21
754
2 10 87 65 91 44 3 98 23 32
22
783
85 63 88 59 38 43 94 90 66 26
23
984
44 96 10 4 25 76 76 36 5 22
24
2004
7 55 32 10 87 99 95 75 15 12
25
2269
73 71 38 12 7 66 48 69 51 23
26
1771
19 66 25 62 66 11 4 26 2 34
27
2030
69 94 24 43 54 35 37 24 81 87
28
2603
12 7 90 49 86 52 82 55 12 59
29
2150
73 15 7 54 49 8 57 98 40 2
30
2157
85 11 11 87 3 40 61 86 59 38
31
2187
23 99 49 29 48 62 6 30 32 84
32
937
53 37 2 2 44 25 97 92 16 62
33
728
16 50 76 18 93 24 5 94 87 10
34
510
88 56 17 75 37 30 27 66 78 11
35
2786
8 69 32 39 82 1 95 47 41 93
36
2134
26 22 39 77 31 73 46 3 43 57
37
1046
42 56 9 69 59 27 92 41 94 81
38
2849
58 67 83 15 78 16 46 41 1 10
39
1956
63 63 69 78 33 91 52 47 93 40
40
2456
7 96 67 68 36 33 8 89 22 62
41
1105
2 74 28 37 3 11 11 28 93 49
42
1560
44 4 88 22 58 99 7 39 62 90
43
1745
38 42 23 41 10 2 54 80 53 34
44
2216
24 40 91 92 98 60 72 47 30 11
45
1157
76 30 71 67 6 90 57 57 34 81
46
1317
85 93 3 24 44 36 85 74 27 51
47
2372
61 36 26 87 62 62 22 38 30 21
48
777
32 25 41 91 24 15 87 59 54 39
49
972
90 87 96 31 94 3 65 5 77 27

Some files were not shown because too many files have changed in this diff Show more