paradiseo new mo added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1712 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
e2546ca8d5
commit
d7496cafff
116 changed files with 12034 additions and 0 deletions
1
trunk/paradiseo-mo/tutorial/oneMax/CMakeLists.txt
Normal file
1
trunk/paradiseo-mo/tutorial/oneMax/CMakeLists.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
ADD_SUBDIRECTORY(application)
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
INCLUDE_DIRECTORIES(${EO_SRC_DIR}/src
|
||||
${MO_SRC_DIR}/src
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../src)
|
||||
|
||||
LINK_DIRECTORIES(${EO_BIN_DIR}/lib)
|
||||
|
||||
ADD_EXECUTABLE(testSimpleHC testSimpleHC.cpp)
|
||||
ADD_EXECUTABLE(testFirstImpr testFirstImpr.cpp)
|
||||
ADD_EXECUTABLE(testRandomWalk testRandomWalk.cpp)
|
||||
ADD_EXECUTABLE(testSimpleHCneutral testSimpleHCneutral.cpp)
|
||||
ADD_EXECUTABLE(testHCneutral testHCneutral.cpp)
|
||||
ADD_EXECUTABLE(testMetropolisHasting testMetropolisHasting.cpp)
|
||||
#ADD_EXECUTABLE(testWithMove testWithMove.cpp)
|
||||
ADD_EXECUTABLE(testSimpleTS testSimpleTS.cpp)
|
||||
ADD_EXECUTABLE(testRandomNeutralWalk testRandomNeutralWalk.cpp)
|
||||
|
||||
TARGET_LINK_LIBRARIES(testSimpleHC eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testFirstImpr eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testRandomWalk eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testSimpleHCneutral eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testHCneutral eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testMetropolisHasting eoutils ga eo)
|
||||
#TARGET_LINK_LIBRARIES(testWithMove eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testSimpleTS eoutils ga eo)
|
||||
TARGET_LINK_LIBRARIES(testRandomNeutralWalk eoutils ga eo)
|
||||
197
trunk/paradiseo-mo/tutorial/oneMax/application/testFirstImpr.cpp
Normal file
197
trunk/paradiseo-mo/tutorial/oneMax/application/testFirstImpr.cpp
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testFirstImpr.cpp
|
||||
*
|
||||
* SV - 12/01/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moRndWithoutReplNeighborhood.h>
|
||||
#include <oneMaxBitNeighbor.h>
|
||||
|
||||
#include <eval/moFullEvalByModif.h>
|
||||
#include <eval/moFullEvalByCopy.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
#include <algo/moLocalSearch.h>
|
||||
#include <explorer/moFirstImprExplorer.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoBit<unsigned> Indi;
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
||||
typedef moRndWithoutReplNeighborhood<Neighbor> Neighborhood ;
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// 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
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "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" );
|
||||
|
||||
// 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
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalByModif<Neighbor> fulleval(eval);
|
||||
|
||||
//An eval by copy can be used instead of the eval by modif
|
||||
//moFullEvalByCopy<Neighbor> fulleval(eval);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Comparator of neighbors
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moNeighborComparator<Neighbor> comparator;
|
||||
moSolNeighborComparator<Neighbor> solComparator;
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Neighborhood neighborhood(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorer solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFirstImprExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;//always continue
|
||||
|
||||
moLocalSearch< moFirstImprExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||
//eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e){
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
201
trunk/paradiseo-mo/tutorial/oneMax/application/testHCneutral.cpp
Normal file
201
trunk/paradiseo-mo/tutorial/oneMax/application/testHCneutral.cpp
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testHCneutral.cpp
|
||||
*
|
||||
* SV - 24/01/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moOrderNeighborhood.h>
|
||||
#include <oneMaxBitNeighbor.h>
|
||||
|
||||
#include <eval/moFullEvalByModif.h>
|
||||
#include <eval/moFullEvalByCopy.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
#include <algo/moLocalSearch.h>
|
||||
#include <explorer/moHCneutralExplorer.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoBit<unsigned> Indi;
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
||||
typedef moOrderNeighborhood<Neighbor> Neighborhood ;
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// 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
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n');
|
||||
parser.processParam( stepParam, "Representation" );
|
||||
unsigned nbStep = 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" );
|
||||
|
||||
// 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
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalByModif<Neighbor> fulleval(eval);
|
||||
|
||||
//An eval by copy can be used instead of the eval by modif
|
||||
//moFullEvalByCopy<Neighbor> fulleval(eval);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Comparator of neighbors
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moNeighborComparator<Neighbor> comparator;
|
||||
moSolNeighborComparator<Neighbor> solComparator;
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Neighborhood neighborhood(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorer solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moHCneutralExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator, nbStep);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;//always continue
|
||||
|
||||
moLocalSearch< moHCneutralExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||
//eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e){
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,201 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testMetropolisHasting.cpp
|
||||
*
|
||||
* SV - 22/01/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moRndWithReplNeighborhood.h>
|
||||
#include <oneMaxBitNeighbor.h>
|
||||
|
||||
#include <eval/moFullEvalByModif.h>
|
||||
#include <eval/moFullEvalByCopy.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
#include <algo/moLocalSearch.h>
|
||||
#include <explorer/moMetropolisHastingExplorer.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoBit<unsigned> Indi;
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
||||
typedef moRndWithReplNeighborhood<Neighbor> Neighborhood ;
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// 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
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n');
|
||||
parser.processParam( stepParam, "Representation" );
|
||||
unsigned nbStep = 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" );
|
||||
|
||||
// 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
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalByModif<Neighbor> fulleval(eval);
|
||||
|
||||
//An eval by copy can be used instead of the eval by modif
|
||||
//moFullEvalByCopy<Neighbor> fulleval(eval);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Comparator of neighbors
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moNeighborComparator<Neighbor> comparator;
|
||||
moSolNeighborComparator<Neighbor> solComparator;
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Neighborhood neighborhood(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorer solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moMetropolisHastingExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator, nbStep);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;//always continue
|
||||
|
||||
moLocalSearch< moMetropolisHastingExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||
//eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e){
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testRandomNeutralWalk.cpp
|
||||
*
|
||||
* SV - 22/02/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcRoyalRoad.h>
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moRndWithoutReplNeighborhood.h>
|
||||
#include <neighborhood/moBitNeighbor.h>
|
||||
|
||||
#include <eval/moFullEvalByModif.h>
|
||||
#include <eval/moFullEvalByCopy.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
#include <algo/moLocalSearch.h>
|
||||
#include <explorer/moRandomNeutralWalkExplorer.h>
|
||||
|
||||
#include <continuator/moCheckpoint.h>
|
||||
#include <continuator/moFitnessStat.h>
|
||||
#include <utils/eoDistance.h>
|
||||
#include <continuator/moDistanceStat.h>
|
||||
#include <neighborhood/moOrderNeighborhood.h>
|
||||
#include <continuator/moNeighborhoodStat.h>
|
||||
#include <continuator/moMinNeighborStat.h>
|
||||
#include <continuator/moMaxNeighborStat.h>
|
||||
#include <continuator/moSecondMomentNeighborStat.h>
|
||||
#include <continuator/moNbInfNeighborStat.h>
|
||||
#include <continuator/moNbSupNeighborStat.h>
|
||||
#include <continuator/moNeutralDegreeNeighborStat.h>
|
||||
#include <continuator/moSizeNeighborStat.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoBit<unsigned> Indi;
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
||||
typedef moRndWithoutReplNeighborhood<Neighbor> Neighborhood ;
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// 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
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
eoValueParam<unsigned int> blockSizeParam(2, "blockSize", "Size of block in the royal road", 'k');
|
||||
parser.processParam( blockSizeParam, "Representation" );
|
||||
unsigned blockSize = blockSizeParam.value();
|
||||
|
||||
eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n');
|
||||
parser.processParam( stepParam, "Representation" );
|
||||
unsigned nbStep = 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" );
|
||||
|
||||
// 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
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncRoyalRoad<Indi> eval(vecSize / blockSize, blockSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisazor of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalByModif<Neighbor> nhEval(eval);
|
||||
|
||||
//An eval by copy can be used instead of the eval by modif
|
||||
//moFullEvalByCopy<Neighbor> nhEval(eval);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Comparator of neighbors
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moNeighborComparator<Neighbor> comparator;
|
||||
moSolNeighborComparator<Neighbor> solComparator;
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Neighborhood neighborhood(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorer solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moRandomNeutralWalkExplorer<Neighborhood> explorer(neighborhood, nhEval, solComparator, nbStep);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* initial random solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||
eval(solution);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the continuator and the checkpoint
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;//always continue
|
||||
|
||||
moCheckpoint<Neighborhood> checkpoint(continuator);
|
||||
|
||||
moFitnessStat<Indi, unsigned> fStat;
|
||||
|
||||
eoHammingDistance<Indi> distance;
|
||||
moDistanceStat<Indi, unsigned> distStat(distance, solution); // distance from the intial solution
|
||||
|
||||
moOrderNeighborhood<Neighbor> nh(vecSize);
|
||||
moNeighborhoodStat< moOrderNeighborhood<Neighbor> > neighborhoodStat(nh, nhEval, comparator, solComparator);
|
||||
moMinNeighborStat< moOrderNeighborhood<Neighbor> > minStat(neighborhoodStat);
|
||||
moSecondMomentNeighborStat< moOrderNeighborhood<Neighbor> > secondMomentStat(neighborhoodStat);
|
||||
moMaxNeighborStat< moOrderNeighborhood<Neighbor> > maxStat(neighborhoodStat);
|
||||
|
||||
moNbSupNeighborStat< moOrderNeighborhood<Neighbor> > nbSupStat(neighborhoodStat);
|
||||
moNbInfNeighborStat< moOrderNeighborhood<Neighbor> > nbInfStat(neighborhoodStat);
|
||||
moNeutralDegreeNeighborStat< moOrderNeighborhood<Neighbor> > ndStat(neighborhoodStat);
|
||||
moSizeNeighborStat< moOrderNeighborhood<Neighbor> > sizeStat(neighborhoodStat);
|
||||
|
||||
eoValueParam<unsigned int> genCounter(-1,"Gen");
|
||||
eoIncrementor<unsigned int> increm(genCounter.value());
|
||||
|
||||
checkpoint.add(fStat);
|
||||
checkpoint.add(distStat);
|
||||
checkpoint.add(neighborhoodStat);
|
||||
checkpoint.add(minStat);
|
||||
checkpoint.add(secondMomentStat);
|
||||
checkpoint.add(maxStat);
|
||||
checkpoint.add(nbInfStat);
|
||||
checkpoint.add(ndStat);
|
||||
checkpoint.add(nbSupStat);
|
||||
checkpoint.add(sizeStat);
|
||||
checkpoint.add(increm);
|
||||
|
||||
eoFileMonitor outputfile("out.dat", " ");
|
||||
checkpoint.add(outputfile);
|
||||
|
||||
outputfile.add(genCounter);
|
||||
outputfile.add(fStat);
|
||||
outputfile.add(distStat);
|
||||
outputfile.add(minStat);
|
||||
outputfile.add(secondMomentStat);
|
||||
outputfile.add(maxStat);
|
||||
outputfile.add(nbInfStat);
|
||||
outputfile.add(ndStat);
|
||||
outputfile.add(nbSupStat);
|
||||
outputfile.add(sizeStat);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moLocalSearch< moRandomNeutralWalkExplorer<Neighborhood> > localSearch(explorer, checkpoint, eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e){
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,243 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testRandomWalk.cpp
|
||||
*
|
||||
* SV - 22/01/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moRndWithReplNeighborhood.h>
|
||||
#include <oneMaxBitNeighbor.h>
|
||||
|
||||
#include <eval/moFullEvalByModif.h>
|
||||
#include <eval/moFullEvalByCopy.h>
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
#include <algo/moLocalSearch.h>
|
||||
#include <explorer/moRandomWalkExplorer.h>
|
||||
#include <continuator/moCheckpoint.h>
|
||||
#include <continuator/moFitnessStat.h>
|
||||
#include <continuator/moSolutionStat.h>
|
||||
#include <utils/eoDistance.h>
|
||||
#include <continuator/moDistanceStat.h>
|
||||
|
||||
#include <utils/eoFileMonitor.h>
|
||||
#include <utils/eoUpdater.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoBit<unsigned> Indi;
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
||||
typedef moRndWithReplNeighborhood<Neighbor> Neighborhood ;
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// 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
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
eoValueParam<unsigned int> stepParam(10, "nbStep", "Number of steps of the random walk", 'n');
|
||||
parser.processParam( stepParam, "Representation" );
|
||||
unsigned nbStep = 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" );
|
||||
|
||||
// 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
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalByModif<Neighbor> nhEval(eval);
|
||||
|
||||
//An eval by copy can be used instead of the eval by modif
|
||||
//moFullEvalByCopy<Neighbor> nhEval(eval);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Neighborhood neighborhood(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorer solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moRandomWalkExplorer<Neighborhood> explorer(neighborhood, nhEval, nbStep);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the continuator and the checkpoint
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;//always continue
|
||||
|
||||
moCheckpoint<Neighborhood> checkpoint(continuator);
|
||||
|
||||
moFitnessStat<Indi, unsigned> fStat;
|
||||
eoHammingDistance<Indi> distance;
|
||||
Indi bestSolution(vecSize, true);
|
||||
moDistanceStat<Indi, unsigned> distStat(distance, bestSolution);
|
||||
// moSolutionStat<Indi> solStat;
|
||||
|
||||
checkpoint.add(fStat);
|
||||
checkpoint.add(distStat);
|
||||
// checkpoint.add(solStat);
|
||||
|
||||
eoValueParam<unsigned int> genCounter(-1,"Gen");
|
||||
eoIncrementor<unsigned int> increm(genCounter.value());
|
||||
checkpoint.add(increm);
|
||||
|
||||
eoFileMonitor outputfile("out.dat", " ");
|
||||
checkpoint.add(outputfile);
|
||||
|
||||
outputfile.add(genCounter);
|
||||
outputfile.add(fStat);
|
||||
outputfile.add(distStat);
|
||||
// outputfile.add(solStat);
|
||||
|
||||
Indi solution; // current solution of the search process
|
||||
|
||||
/*
|
||||
// to save the solution at each iteration
|
||||
eoState outState;
|
||||
|
||||
// Register the algorithm into the state (so it has something to save!!
|
||||
|
||||
outState.registerObject(solution);
|
||||
|
||||
// and feed the state to state savers
|
||||
// save state every 10th iteration
|
||||
eoCountedStateSaver stateSaver(10, outState, "iteration");
|
||||
|
||||
// Don't forget to add the two savers to the checkpoint
|
||||
checkpoint.add(stateSaver);
|
||||
*/
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moLocalSearch< moRandomWalkExplorer<Neighborhood> > localSearch(explorer, checkpoint, eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
random(solution);
|
||||
|
||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||
//eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e){
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
197
trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHC.cpp
Normal file
197
trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleHC.cpp
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testSimpleHC.cpp
|
||||
*
|
||||
* SV - 12/01/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moOrderNeighborhood.h>
|
||||
#include <oneMaxBitNeighbor.h>
|
||||
|
||||
#include <eval/moFullEvalByModif.h>
|
||||
#include <eval/moFullEvalByCopy.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
#include <algo/moLocalSearch.h>
|
||||
#include <explorer/moSimpleHCexplorer.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoBit<unsigned> Indi;
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
||||
typedef moOrderNeighborhood<Neighbor> Neighborhood ;
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// 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
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "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" );
|
||||
|
||||
// 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
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalByModif<Neighbor> fulleval(eval);
|
||||
|
||||
//An eval by copy can be used instead of the eval by modif
|
||||
//moFullEvalByCopy<Neighbor> fulleval(eval);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Comparator of neighbors
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moNeighborComparator<Neighbor> comparator;
|
||||
moSolNeighborComparator<Neighbor> solComparator;
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Neighborhood neighborhood(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorer solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHCexplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;//always continue
|
||||
|
||||
moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator, eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||
//eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e){
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,197 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testSimpleHCneutral.cpp
|
||||
*
|
||||
* SV - 24/01/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moOrderNeighborhood.h>
|
||||
#include <oneMaxBitNeighbor.h>
|
||||
|
||||
#include <eval/moFullEvalByModif.h>
|
||||
#include <eval/moFullEvalByCopy.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
#include <algo/moLocalSearch.h>
|
||||
#include <explorer/moSimpleHCneutralExplorer.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoBit<unsigned> Indi;
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
||||
typedef moOrderNeighborhood<Neighbor> Neighborhood ;
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// 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
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "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" );
|
||||
|
||||
// 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
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalByModif<Neighbor> fulleval(eval);
|
||||
|
||||
//An eval by copy can be used instead of the eval by modif
|
||||
//moFullEvalByCopy<Neighbor> fulleval(eval);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Comparator of neighbors
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moNeighborComparator<Neighbor> comparator;
|
||||
moSolNeighborComparator<Neighbor> solComparator;
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Neighborhood neighborhood(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorer solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHCneutralExplorer<Neighborhood> explorer(neighborhood, fulleval, comparator, solComparator);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;//always continue
|
||||
|
||||
moLocalSearch< moSimpleHCneutralExplorer<Neighborhood> > localSearch(explorer, continuator, eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||
//eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e){
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
203
trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleTS.cpp
Normal file
203
trunk/paradiseo-mo/tutorial/oneMax/application/testSimpleTS.cpp
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testSimpleHC.cpp
|
||||
*
|
||||
* SV - 12/01/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include <ga.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
#include <eoInt.h>
|
||||
#include <neighborhood/moOrderNeighborhood.h>
|
||||
#include <oneMaxBitNeighbor.h>
|
||||
|
||||
#include <newmo>
|
||||
|
||||
#include <eval/moFullEvalByModif.h>
|
||||
#include <eval/moFullEvalByCopy.h>
|
||||
#include <comparator/moNeighborComparator.h>
|
||||
#include <comparator/moSolNeighborComparator.h>
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
#include <algo/moLocalSearch.h>
|
||||
#include <explorer/moSimpleHCexplorer.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
typedef eoBit<unsigned> Indi;
|
||||
typedef moBitNeighbor<unsigned int> Neighbor ; // incremental evaluation
|
||||
typedef moOrderNeighborhood<Neighbor> Neighborhood ;
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// 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
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "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" );
|
||||
|
||||
// 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
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> fulleval(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moFullEvalByModif<Neighbor> eval(fulleval);
|
||||
|
||||
//An eval by copy can be used instead of the eval by modif
|
||||
//moFullEvalByCopy<Neighbor> fulleval(eval);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Comparator of neighbors
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moNeighborComparator<Neighbor> comparator;
|
||||
moSolNeighborComparator<Neighbor> solComparator;
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Neighborhood neighborhood(vecSize);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorer solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSolVectorTabuList<Neighbor> tl(10,10);
|
||||
moDummyIntensification<Neighbor> inten;
|
||||
moDummyDiversification<Neighbor> div;
|
||||
moBestImprAspiration<Neighbor> asp;
|
||||
moTSExplorer<Neighborhood> explorer(neighborhood, eval, comparator, solComparator, tl, inten, div, asp);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;//always continue
|
||||
|
||||
moLocalSearch< moTSExplorer<Neighborhood> > localSearch(explorer, continuator, fulleval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
//Can be eval here, else it will be done at the beginning of the localSearch
|
||||
//eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e){
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
214
trunk/paradiseo-mo/tutorial/oneMax/application/testWithMove.cpp
Normal file
214
trunk/paradiseo-mo/tutorial/oneMax/application/testWithMove.cpp
Normal file
|
|
@ -0,0 +1,214 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
/** testSimpleHC.cpp
|
||||
*
|
||||
* SV - 12/01/10
|
||||
*
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// standard includes
|
||||
#define HAVE_SSTREAM
|
||||
|
||||
#include <stdexcept> // runtime_error
|
||||
#include <iostream> // cout
|
||||
#include <sstream> // ostrstream, istrstream
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
|
||||
// the general include for eo
|
||||
#include <eo>
|
||||
#include "ga.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// fitness function
|
||||
#include <funcOneMax.h>
|
||||
|
||||
//#include <eoInt.h>
|
||||
//#include <moEmptyNeighbor.h>
|
||||
|
||||
#include <continuator/moTrueContinuator.h>
|
||||
|
||||
// local search algorithm
|
||||
#include <algo/moLocalSearch.h>
|
||||
|
||||
// the simple HC explorer
|
||||
#include <explorer/moSimpleHCexplorer.h>
|
||||
|
||||
// explore the neighborhood of a bit string in order
|
||||
#include <neighborhood/moMoveNeighborhood.h>
|
||||
|
||||
//#include <moFullEvalBitNeighbor.h>
|
||||
|
||||
#include <neighborhood/moMoveNeighbor.h>
|
||||
|
||||
#include <bitMove.h>
|
||||
#include <bitMove_init.h>
|
||||
#include <bitMoveIncrEval.h>
|
||||
#include <bitMove_next.h>
|
||||
|
||||
// REPRESENTATION
|
||||
//-----------------------------------------------------------------------------
|
||||
// define your individuals
|
||||
typedef eoBit<unsigned> Indi;
|
||||
//typedef OneMaxBitNeighbor<unsigned> Neighbor ; // incremental evaluation
|
||||
typedef moMoveNeighbor<BitMove<Indi>, unsigned> Neighbor ; // full evaluation
|
||||
typedef moMoveNeighborhood<BitMove<Indi>, unsigned> Neighborhood ;
|
||||
|
||||
// GENERAL
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void main_function(int argc, char **argv)
|
||||
{
|
||||
/* =========================================================
|
||||
*
|
||||
* Parameters
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// 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
|
||||
|
||||
eoValueParam<uint32_t> seedParam(time(0), "seed", "Random number seed", 'S');
|
||||
parser.processParam( seedParam );
|
||||
unsigned seed = seedParam.value();
|
||||
|
||||
// description of genotype
|
||||
eoValueParam<unsigned int> vecSizeParam(8, "vecSize", "Genotype size", 'V');
|
||||
parser.processParam( vecSizeParam, "Representation" );
|
||||
unsigned vecSize = vecSizeParam.value();
|
||||
|
||||
string fileOut("out.dat");
|
||||
eoValueParam<string> fileStatParam(fileOut.c_str(), "out", "A file to export results", 'o');
|
||||
parser.processParam( fileStatParam, "Persistence" );
|
||||
fileOut = fileStatParam.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
|
||||
}
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Random seed
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
//reproducible random seed: if you don't change SEED above,
|
||||
// you'll aways get the same result, NOT a random run
|
||||
rng.reseed(seed);
|
||||
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Eval fitness function
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
FuncOneMax<Indi> eval(vecSize);
|
||||
|
||||
OneMaxIncrEval<Indi> incrEval;
|
||||
Neighbor::setIncrEval(incrEval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* Initilisation of the solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// a Indi random initializer
|
||||
eoUniformGenerator<bool> uGen;
|
||||
eoInitFixedLength<Indi> random(vecSize, uGen);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* evaluation of a neighbor solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
// no need if incremental evaluation with OneMaxBitNeighbor
|
||||
// Neighbor::setFullEvalFunc(eval);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the neighborhood of a solution
|
||||
*
|
||||
* ========================================================= */
|
||||
BitMove_init<Indi> init;
|
||||
BitMove_next<Indi> next;
|
||||
|
||||
|
||||
Neighborhood neighborhood(init, next);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* a neighborhood explorator solution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moSimpleHCexplorer<Neighborhood> explorer(neighborhood);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* the local search algorithm
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
moTrueContinuator<Neighborhood> continuator;
|
||||
|
||||
moLocalSearch< moSimpleHCexplorer<Neighborhood> > localSearch(explorer, continuator);
|
||||
|
||||
/* =========================================================
|
||||
*
|
||||
* execute the local search from random sollution
|
||||
*
|
||||
* ========================================================= */
|
||||
|
||||
Indi solution;
|
||||
|
||||
random(solution);
|
||||
|
||||
eval(solution);
|
||||
|
||||
std::cout << "initial: " << solution << std::endl ;
|
||||
|
||||
localSearch(solution);
|
||||
|
||||
std::cout << "final: " << solution << std::endl ;
|
||||
|
||||
}
|
||||
|
||||
// A main that catches the exceptions
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
main_function(argc, argv);
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
cout << "Exception: " << e.what() << '\n';
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
34
trunk/paradiseo-mo/tutorial/oneMax/src/bitMove.h
Normal file
34
trunk/paradiseo-mo/tutorial/oneMax/src/bitMove.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
// "bitMove.h"
|
||||
|
||||
#ifndef __bitMove
|
||||
#define __bitMove
|
||||
|
||||
#include <utility>
|
||||
#include <move/moMove.h>
|
||||
|
||||
template <class EOT>
|
||||
class BitMove : public moMove <EOT> {
|
||||
|
||||
public :
|
||||
|
||||
typedef EOT EOType;
|
||||
|
||||
unsigned bit;
|
||||
|
||||
BitMove() {
|
||||
bit = 0;
|
||||
}
|
||||
|
||||
BitMove(unsigned _bit) : bit(_bit) { }
|
||||
|
||||
|
||||
void operator () (EOT & chrom)
|
||||
{
|
||||
chrom[bit] = !chrom[bit];
|
||||
};
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
27
trunk/paradiseo-mo/tutorial/oneMax/src/bitMoveIncrEval.h
Normal file
27
trunk/paradiseo-mo/tutorial/oneMax/src/bitMoveIncrEval.h
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
// "incrEval_funcNK.h"
|
||||
|
||||
#ifndef __incr_eval_funcNK_h
|
||||
#define __incr_eval_funcNK_h
|
||||
|
||||
#include <move/moMoveIncrEval.h>
|
||||
#include "bitMove.h"
|
||||
|
||||
template <class EOT>
|
||||
class OneMaxIncrEval : public moMoveIncrEval < BitMove<EOT> > {
|
||||
|
||||
public :
|
||||
OneMaxIncrEval(){ };
|
||||
|
||||
typename EOT::Fitness operator () (const BitMove<EOT> & move, const EOT & chrom) {
|
||||
if(chrom[move.bit]==0){
|
||||
return chrom.fitness()+1;
|
||||
}
|
||||
else{
|
||||
return chrom.fitness()-1;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
21
trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_init.h
Normal file
21
trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_init.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
// "bitMove_init.h"
|
||||
#ifndef __bitMove_init
|
||||
#define __bitMove_init
|
||||
|
||||
#include <move/moMoveInit.h>
|
||||
#include "bitMove.h"
|
||||
|
||||
template <class EOT>
|
||||
class BitMove_init : public moMoveInit < BitMove<EOT> > {
|
||||
|
||||
public :
|
||||
|
||||
void operator () (BitMove<EOT> & __move, const EOT & genome) {
|
||||
__move.bit = 0 ;
|
||||
};
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
33
trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_next.h
Normal file
33
trunk/paradiseo-mo/tutorial/oneMax/src/bitMove_next.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
// "bitMove_next.h"
|
||||
|
||||
#ifndef __bitMove_next_h
|
||||
#define __bitMove_next_h
|
||||
|
||||
#include <move/moNextMove.h>
|
||||
#include "bitMove.h"
|
||||
|
||||
template <class EOT>
|
||||
class BitMove_next : public moNextMove < BitMove<EOT> > {
|
||||
|
||||
public:
|
||||
BitMove_next()
|
||||
{
|
||||
};
|
||||
|
||||
bool operator () (BitMove<EOT> & __move, const EOT & genome) {
|
||||
|
||||
if (__move.bit >= (genome.size() - 1)){
|
||||
return false ;
|
||||
}
|
||||
else {
|
||||
__move.bit++;
|
||||
return true ;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
33
trunk/paradiseo-mo/tutorial/oneMax/src/funcOneMax.h
Normal file
33
trunk/paradiseo-mo/tutorial/oneMax/src/funcOneMax.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// funcOneMax.h
|
||||
// 25/11/2009 : copy from FuncU.h
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __FuncOneMax
|
||||
#define __FuncOneMax
|
||||
|
||||
template< class EOT >
|
||||
class FuncOneMax : public eoEvalFunc<EOT>
|
||||
{
|
||||
private:
|
||||
unsigned N;
|
||||
|
||||
public:
|
||||
FuncOneMax(unsigned n) : N(n) {};
|
||||
|
||||
~FuncOneMax(void) {} ;
|
||||
|
||||
void operator() (EOT & genome) {
|
||||
unsigned sum = 0;
|
||||
|
||||
for (int i = 0; i < N; i++)
|
||||
sum += genome[i];
|
||||
|
||||
genome.fitness(sum);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
40
trunk/paradiseo-mo/tutorial/oneMax/src/funcRoyalRoad.h
Normal file
40
trunk/paradiseo-mo/tutorial/oneMax/src/funcRoyalRoad.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
#ifndef __funcRoyalRoad
|
||||
#define __funcRoyalRoad
|
||||
|
||||
#include <eoEvalFunc.h>
|
||||
|
||||
template< class EOT >
|
||||
class FuncRoyalRoad : public eoEvalFunc<EOT>
|
||||
{
|
||||
// number of blocks
|
||||
unsigned n;
|
||||
|
||||
// size of a block
|
||||
unsigned k;
|
||||
|
||||
public:
|
||||
FuncRoyalRoad(unsigned _n, unsigned _k) : n(_n), k(_k) {};
|
||||
|
||||
~FuncRoyalRoad(void) {} ;
|
||||
|
||||
virtual void operator() (EOT & _solution)
|
||||
{
|
||||
unsigned sum = 0;
|
||||
unsigned i, j;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
j = 0;
|
||||
while (_solution[i * n + j] && j < k) j++;
|
||||
|
||||
if (j == k)
|
||||
sum++;
|
||||
}
|
||||
|
||||
_solution.fitness(sum);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
38
trunk/paradiseo-mo/tutorial/oneMax/src/oneMaxBitNeighbor.h
Normal file
38
trunk/paradiseo-mo/tutorial/oneMax/src/oneMaxBitNeighbor.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef _oneMaxBitNeighbor_h
|
||||
#define _oneMaxBitNeighbor_h
|
||||
|
||||
#include <neighborhood/moBitNeighbor.h>
|
||||
#include <ga.h>
|
||||
|
||||
/*
|
||||
contener of the neighbor information
|
||||
*/
|
||||
template< class Fitness >
|
||||
class OneMaxBitNeighbor : public moBitNeighbor<Fitness>
|
||||
{
|
||||
public:
|
||||
typedef eoBit<Fitness> EOType ;
|
||||
|
||||
using moBitNeighbor<Fitness>::bit ;
|
||||
|
||||
/*
|
||||
* incremental evaluation of the solution for the oneMax problem
|
||||
*/
|
||||
virtual void eval(EOType & solution) {
|
||||
if (solution[bit] == 0)
|
||||
fitness(solution.fitness() + 1);
|
||||
else
|
||||
fitness(solution.fitness() - 1);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Local Variables:
|
||||
// coding: iso-8859-1
|
||||
// mode: C++
|
||||
// c-file-offsets: ((c . 0))
|
||||
// c-file-style: "Stroustrup"
|
||||
// fill-column: 80
|
||||
// End:
|
||||
Loading…
Add table
Add a link
Reference in a new issue