Nettoyage des tutos ce coup ci c'est bon :)
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1815 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
02e5cfb6c0
commit
961dcba259
21 changed files with 2697 additions and 2697 deletions
|
|
@ -1,7 +1,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** firstImprHC_maxSAT.cpp
|
||||
*
|
||||
* SV - 05/05/10
|
||||
* SV - 05/05/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -45,7 +45,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -54,157 +54,157 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// Number of clauses of the max SAT problem
|
||||
eoValueParam<unsigned int> ncParam(10, "nbClauses", "Number of clauses", 'm');
|
||||
parser.processParam( ncParam, "Representation" );
|
||||
unsigned nbClause = ncParam.value();
|
||||
// Number of clauses of the max SAT problem
|
||||
eoValueParam<unsigned int> ncParam(10, "nbClauses", "Number of clauses", 'm');
|
||||
parser.processParam( ncParam, "Representation" );
|
||||
unsigned nbClause = ncParam.value();
|
||||
|
||||
// Number of litteral by clauses
|
||||
eoValueParam<unsigned int> kParam(3, "nbLitt", "Number of litteral by clauses", 'k');
|
||||
parser.processParam( kParam, "Representation" );
|
||||
unsigned nbLitteral = kParam.value();
|
||||
// Number of litteral by clauses
|
||||
eoValueParam<unsigned int> kParam(3, "nbLitt", "Number of litteral by clauses", 'k');
|
||||
parser.processParam( kParam, "Representation" );
|
||||
unsigned nbLitteral = kParam.value();
|
||||
|
||||
// the name of the instance file
|
||||
string str_in = "" ; // default value
|
||||
eoValueParam<string> inParam(str_in.c_str(), "in", "Input file of the file in ncf format", 'f');
|
||||
parser.processParam(inParam, "Persistence" );
|
||||
str_in = inParam.value();
|
||||
// the name of the instance file
|
||||
string str_in = "" ; // default value
|
||||
eoValueParam<string> inParam(str_in.c_str(), "in", "Input file of the file in ncf format", 'f');
|
||||
parser.processParam(inParam, "Persistence" );
|
||||
str_in = inParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
// the max SAT evaluation
|
||||
MaxSATeval<Indi> * fullEval;
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
if (str_in.compare("") == 0)
|
||||
fullEval = new MaxSATeval<Indi>(vecSize, nbClause, nbLitteral);
|
||||
else {
|
||||
fullEval = new MaxSATeval<Indi>(str_in);
|
||||
vecSize = fullEval->nbVar ;
|
||||
}
|
||||
// the max SAT evaluation
|
||||
MaxSATeval<Indi> * fullEval;
|
||||
|
||||
// string out = "cnf.dat";
|
||||
// fullEval->save(out);
|
||||
if (str_in.compare("") == 0)
|
||||
fullEval = new MaxSATeval<Indi>(vecSize, nbClause, nbLitteral);
|
||||
else {
|
||||
fullEval = new MaxSATeval<Indi>(str_in);
|
||||
vecSize = fullEval->nbVar ;
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
// string out = "cnf.dat";
|
||||
// fullEval->save(out);
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(*fullEval);
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Incremental evaluation of the neighbor:
|
||||
moMaxSATincrEval<Neighbor> neighborEval(*fullEval);
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(*fullEval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
// Incremental evaluation of the neighbor:
|
||||
moMaxSATincrEval<Neighbor> neighborEval(*fullEval);
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
// Exploration of the neighborhood in random order of the neigbor's index:
|
||||
// each neighbor is visited only once
|
||||
moRndWithoutReplNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
// Exploration of the neighborhood in random order of the neigbor's index:
|
||||
// each neighbor is visited only once
|
||||
moRndWithoutReplNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
moFirstImprHC<Neighbor> hc(neighborhood, *fullEval, neighborEval);
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
moFirstImprHC<Neighbor> hc(neighborhood, *fullEval, neighborEval);
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
(*fullEval)(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
(*fullEval)(solution);
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -212,11 +212,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -64,176 +64,176 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// maximum number of full evaluation
|
||||
eoValueParam<unsigned int> fevalParam(2, "fulleval", "Maximum number of full evaluation");
|
||||
parser.processParam( fevalParam, "Representation" );
|
||||
unsigned fullevalMax = fevalParam.value();
|
||||
// maximum number of full evaluation
|
||||
eoValueParam<unsigned int> fevalParam(2, "fulleval", "Maximum number of full evaluation");
|
||||
parser.processParam( fevalParam, "Representation" );
|
||||
unsigned fullevalMax = fevalParam.value();
|
||||
|
||||
// maximum number of full evaluation
|
||||
eoValueParam<unsigned int> evalParam(30, "eval", "Maximum number of neighbor evaluation", 'e');
|
||||
parser.processParam( evalParam, "Representation" );
|
||||
unsigned evalMax = evalParam.value();
|
||||
// maximum number of full evaluation
|
||||
eoValueParam<unsigned int> evalParam(30, "eval", "Maximum number of neighbor evaluation", 'e');
|
||||
parser.processParam( evalParam, "Representation" );
|
||||
unsigned evalMax = evalParam.value();
|
||||
|
||||
// maximum fitness to reach
|
||||
eoValueParam<unsigned int> fitParam(16, "fitness", "Maximum fitness value to reach", 'f');
|
||||
parser.processParam( fitParam, "Representation" );
|
||||
unsigned fitnessMax = fitParam.value();
|
||||
// maximum fitness to reach
|
||||
eoValueParam<unsigned int> fitParam(16, "fitness", "Maximum fitness value to reach", 'f');
|
||||
parser.processParam( fitParam, "Representation" );
|
||||
unsigned fitnessMax = fitParam.value();
|
||||
|
||||
// maximum number of iterations
|
||||
eoValueParam<unsigned int> iterParam(10, "iter", "Maximum number of iterations", 'i');
|
||||
parser.processParam( iterParam, "Representation" );
|
||||
unsigned iterMax = iterParam.value();
|
||||
// maximum number of iterations
|
||||
eoValueParam<unsigned int> iterParam(10, "iter", "Maximum number of iterations", 'i');
|
||||
parser.processParam( iterParam, "Representation" );
|
||||
unsigned iterMax = iterParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEvalTmp;
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEvalTmp;
|
||||
|
||||
// to count the number of full evaluation
|
||||
eoEvalFuncCounter<Indi> fullEval(fullEvalTmp);
|
||||
// to count the number of full evaluation
|
||||
eoEvalFuncCounter<Indi> fullEval(fullEvalTmp);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEvalTmp;
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEvalTmp;
|
||||
|
||||
// to count the number of neighbor evaluation
|
||||
moEvalCounter<Neighbor> neighborEval(neighborEvalTmp);
|
||||
// to count the number of neighbor evaluation
|
||||
moEvalCounter<Neighbor> neighborEval(neighborEvalTmp);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moIterContinuator<Neighbor> iterCont(iterMax);
|
||||
moFitContinuator<Neighbor> fitCont(fitnessMax);
|
||||
moFullEvalContinuator<Neighbor> fullevalCont(fullEval, fullevalMax);
|
||||
moNeighborEvalContinuator<Neighbor> evalCont(neighborEval, evalMax);
|
||||
moIterContinuator<Neighbor> iterCont(iterMax);
|
||||
moFitContinuator<Neighbor> fitCont(fitnessMax);
|
||||
moFullEvalContinuator<Neighbor> fullevalCont(fullEval, fullevalMax);
|
||||
moNeighborEvalContinuator<Neighbor> evalCont(neighborEval, evalMax);
|
||||
|
||||
moCombinedContinuator<Neighbor> continuator(iterCont);
|
||||
continuator.add(fitCont);
|
||||
continuator.add(fullevalCont);
|
||||
continuator.add(evalCont);
|
||||
moCombinedContinuator<Neighbor> continuator(iterCont);
|
||||
continuator.add(fitCont);
|
||||
continuator.add(fullevalCont);
|
||||
continuator.add(evalCont);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
std::cout << "number of iteration: " << iterCont.value() << std::endl ;
|
||||
std::cout << "Number of full evaluations during the local search: " << fullevalCont.value() << std::endl ;
|
||||
std::cout << "Number of neighbor evaluations during the local search: " << evalCont.value() << std::endl ;
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
std::cout << "number of iteration: " << iterCont.value() << std::endl ;
|
||||
std::cout << "Number of full evaluations during the local search: " << fullevalCont.value() << std::endl ;
|
||||
std::cout << "Number of neighbor evaluations during the local search: " << evalCont.value() << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -241,11 +241,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -59,148 +59,148 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// maximum number of full evaluation
|
||||
eoValueParam<unsigned int> evalParam(30, "eval", "Maximum number of neighbor evaluation", 'e');
|
||||
parser.processParam( evalParam, "Representation" );
|
||||
unsigned evalMax = evalParam.value();
|
||||
// maximum number of full evaluation
|
||||
eoValueParam<unsigned int> evalParam(30, "eval", "Maximum number of neighbor evaluation", 'e');
|
||||
parser.processParam( evalParam, "Representation" );
|
||||
unsigned evalMax = evalParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEvalTmp;
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEvalTmp;
|
||||
|
||||
// to count the number of neighbor evaluation
|
||||
moEvalCounter<Neighbor> neighborEval(neighborEvalTmp);
|
||||
// to count the number of neighbor evaluation
|
||||
moEvalCounter<Neighbor> neighborEval(neighborEvalTmp);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moNeighborEvalContinuator<Neighbor> continuator(neighborEval, evalMax);
|
||||
moNeighborEvalContinuator<Neighbor> continuator(neighborEval, evalMax);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
std::cout << "Number of neighbor evaluations during the local search: " << continuator.value() << std::endl ;
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
std::cout << "Number of neighbor evaluations during the local search: " << continuator.value() << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -208,11 +208,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -54,131 +54,131 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Exploration of the neighborhood in random order of the neigbor's index:
|
||||
// each neighbor is visited only once
|
||||
moRndWithoutReplNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
// Exploration of the neighborhood in random order of the neigbor's index:
|
||||
// each neighbor is visited only once
|
||||
moRndWithoutReplNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFirstImprHC<Neighbor> hc(neighborhood, fullEval, neighborEval);
|
||||
moFirstImprHC<Neighbor> hc(neighborhood, fullEval, neighborEval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -186,11 +186,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -58,144 +58,144 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// maximum fitness to reach
|
||||
eoValueParam<unsigned int> fitParam(16, "fitness", "Maximum fitness value to reach", 'f');
|
||||
parser.processParam( fitParam, "Representation" );
|
||||
unsigned fitnessMax = fitParam.value();
|
||||
// maximum fitness to reach
|
||||
eoValueParam<unsigned int> fitParam(16, "fitness", "Maximum fitness value to reach", 'f');
|
||||
parser.processParam( fitParam, "Representation" );
|
||||
unsigned fitnessMax = fitParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFitContinuator<Neighbor> continuator(fitnessMax);
|
||||
moFitContinuator<Neighbor> continuator(fitnessMax);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -203,11 +203,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -59,148 +59,148 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// maximum number of full evaluation
|
||||
eoValueParam<unsigned int> evalParam(2, "fulleval", "Maximum number of full evaluation", 'e');
|
||||
parser.processParam( evalParam, "Representation" );
|
||||
unsigned fullevalMax = evalParam.value();
|
||||
// maximum number of full evaluation
|
||||
eoValueParam<unsigned int> evalParam(2, "fulleval", "Maximum number of full evaluation", 'e');
|
||||
parser.processParam( evalParam, "Representation" );
|
||||
unsigned fullevalMax = evalParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEvalTmp;
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEvalTmp;
|
||||
|
||||
// to count the number of full evaluation
|
||||
eoEvalFuncCounter<Indi> fullEval(fullEvalTmp);
|
||||
// to count the number of full evaluation
|
||||
eoEvalFuncCounter<Indi> fullEval(fullEvalTmp);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalContinuator<Neighbor> continuator(fullEval, fullevalMax);
|
||||
moFullEvalContinuator<Neighbor> continuator(fullEval, fullevalMax);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
std::cout << "Number of full evaluations during the local search: " << continuator.value() << std::endl ;
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
std::cout << "Number of full evaluations during the local search: " << continuator.value() << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -208,11 +208,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -58,146 +58,146 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// maximum number of iterations
|
||||
eoValueParam<unsigned int> iterParam(10, "iter", "Maximum number of iterations", 'i');
|
||||
parser.processParam( iterParam, "Representation" );
|
||||
unsigned iterMax = iterParam.value();
|
||||
// maximum number of iterations
|
||||
eoValueParam<unsigned int> iterParam(10, "iter", "Maximum number of iterations", 'i');
|
||||
parser.processParam( iterParam, "Representation" );
|
||||
unsigned iterMax = iterParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the external continuators
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moIterContinuator<Neighbor> continuator(iterMax);
|
||||
moIterContinuator<Neighbor> continuator(iterMax);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval, continuator);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
std::cout << "number of iteration: " << continuator.value() << std::endl ;
|
||||
std::cout << "number of iteration: " << continuator.value() << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -205,11 +205,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -54,135 +54,135 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
eoValueParam<unsigned int> stepParam(10, "nbStepMax", "Number of steps of the random walk", 'n');
|
||||
parser.processParam( stepParam, "Representation" );
|
||||
unsigned nbStepMax = stepParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
eoValueParam<unsigned int> stepParam(10, "nbStepMax", "Number of steps of the random walk", 'n');
|
||||
parser.processParam( stepParam, "Representation" );
|
||||
unsigned nbStepMax = stepParam.value();
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
moNeutralHC<Neighbor> hc(neighborhood, fullEval, neighborEval, nbStepMax);
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
moNeutralHC<Neighbor> hc(neighborhood, fullEval, neighborEval, nbStepMax);
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -190,11 +190,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -54,131 +54,131 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moRandomBestHC<Neighbor> hc(neighborhood, fullEval, neighborEval);
|
||||
moRandomBestHC<Neighbor> hc(neighborhood, fullEval, neighborEval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -186,11 +186,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ using namespace std;
|
|||
// Indi is the typedef of the solution type like in paradisEO-eo
|
||||
typedef eoBit<unsigned int> Indi; // bit string with unsigned fitness type
|
||||
// Neighbor is the typedef of the neighbor type,
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// Neighbor = How to compute the neighbor from the solution + information on it (i.e. fitness)
|
||||
// all classes from paradisEO-mo use this template type
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor with unsigned fitness type
|
||||
|
||||
|
|
@ -54,131 +54,131 @@ typedef moBitNeighbor<unsigned int> Neighbor ; // bit string neighbor wi
|
|||
//-----------------------------------------------------------------------------
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters from parser
|
||||
*
|
||||
* ========================================================= */
|
||||
// more information on the input parameters: see EO tutorial lesson 3
|
||||
// but don't care at first it just read the parameters of the bit string size and the random seed.
|
||||
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
// First define a parser from the command-line arguments
|
||||
eoParser parser(argc, argv);
|
||||
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
// For each parameter, define Parameter, read it through the parser,
|
||||
// and assign the value to the variable
|
||||
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
// random seed parameter
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
// length of the bit string
|
||||
eoValueParam<unsigned int> vecSizeParam(20, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
// the name of the "status" file where all actual parameter values will be saved
|
||||
string str_status = parser.ProgramName() + ".status"; // default value
|
||||
eoValueParam<string> statusParam(str_status.c_str(), "status", "Status file");
|
||||
parser.processParam( statusParam, "Persistence" );
|
||||
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
// do the following AFTER ALL PARAMETERS HAVE BEEN PROCESSED
|
||||
// i.e. in case you need parameters somewhere else, postpone these
|
||||
if (parser.userNeedsHelp()) {
|
||||
parser.printHelp(cout);
|
||||
exit(1);
|
||||
}
|
||||
if (statusParam.value() != "") {
|
||||
ofstream os(statusParam.value().c_str());
|
||||
os << parser;// and you can use that file as parameter file
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
// reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
rng.reseed(seed);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Initialization of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
// a Indi random initializer: each bit is random
|
||||
// more information: see EO tutorial lesson 1 (FirstBitGA.cpp)
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function (full evaluation)
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
// the fitness function is just the number of 1 in the bit string
|
||||
oneMaxEval<Indi> fullEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
// Use it if there is no incremental evaluation: a neighbor is evaluated by the full evaluation of a solution
|
||||
// moFullEvalByModif<Neighbor> neighborEval(fullEval);
|
||||
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
// Incremental evaluation of the neighbor: fitness is modified by +/- 1
|
||||
moOneMaxIncrEval<Neighbor> neighborEval;
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
// Exploration of the neighborhood in increasing order of the neigbor's index:
|
||||
// bit-flip from bit 0 to bit (vecSize - 1)
|
||||
moOrderNeighborhood<Neighbor> neighborhood(vecSize);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval);
|
||||
moSimpleHC<Neighbor> hc(neighborhood, fullEval, neighborEval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
/* =========================================================
|
||||
*
|
||||
* executes the local search from a random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// The current solution
|
||||
Indi solution;
|
||||
// The current solution
|
||||
Indi solution;
|
||||
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
// Apply random initialization
|
||||
random(solution);
|
||||
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
// Evaluation of the initial solution:
|
||||
// can be evaluated here, or else it will be done at the beginning of the local search
|
||||
fullEval(solution);
|
||||
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
// Output: the intial solution
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
// Apply the local search on the solution !
|
||||
hc(solution);
|
||||
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
// Output: the final solution
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -186,11 +186,11 @@ void main_function(int argc, char **argv)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
try {
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch (exception& e) {
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue