Commit 55df3941 authored by Alexis Lebis's avatar Alexis Lebis

init of EA for CEAO

parent 3a8291e5
......@@ -28,7 +28,7 @@ ADD_DEPENDENCIES(tryEval lQueen)
# 3) Link the librairies for your executable
TARGET_LINK_LIBRARIES(ceao ${PARADISEO_LIBRARIES} lQueen lModel)
TARGET_LINK_LIBRARIES(ceao ${PARADISEO_LIBRARIES} lQueen lModel lEA)
TARGET_LINK_LIBRARIES(ceao_competency ${PARADISEO_LIBRARIES} lQueen lModel)
TARGET_LINK_LIBRARIES(ceao_course ${PARADISEO_LIBRARIES} lQueen lModel)
TARGET_LINK_LIBRARIES(ceao_profession ${PARADISEO_LIBRARIES} lQueen lModel)
......
......@@ -7,6 +7,13 @@
#include <model/magnitude.h>
#include <model/competency.h>
#include <model/ea/cursus.h>
#include <model/ea/initializer.h>
#include <model/ea/mutation.h>
#include <model/ea/crossover.h>
#include <model/ea/evaluator.h>
#include <model/exception/magnitudeException.h>
#include <model/exception/competencyEvolvingException.h>
......@@ -47,73 +54,115 @@ int main(int argc, char* argv[]){
// ================================= END TEST ZONE =====================================
//Define a QUEEN -> 1 line
QUEEN s1;
// ================================= CEAO ZONE ===================================
Cursus c1;
CursusInit init(8,1);
CursusEval eval;
CursusMutation mut;
CursusCrossover xOver;
eoGenContinue<Cursus> cont(100); // runs for 100 gen
//xOver, xOver rate, mutation, mutation rate
eoSGATransform<Cursus> transform(xOver, 0.1, mut, 0.1);
eoDetTournamentSelect<Cursus> selectOne(2); //selection method by tournament, here against 2
eoSelectPerc<Cursus> select(selectOne);
eoGenerationalReplacement<Cursus> replace;
eoPop<Cursus> pop;
/**@todo make size of the pb accessible as well as size of an individu*/
int size_of_the_pb = 100;
for(int i = 0; i < size_of_the_pb; i++)
{
init(c1);
eval(c1);
pop.push_back(c1);
}
//Define an initializer -> 1 line
queenInit init(8,1);
std::cout << "===== CURRENT POP =====" << std::endl;
pop.printOn(std::cout);
std::cout << "===== =====" << std::endl;
//Define the evaluation function -> 1 line
queenEval eval;
eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace);
//Define mutation -> 1 line
queenMutation mut;
algo(pop);
//Define crossover -> 1 line
queenCrossover cross;
std::cout << "===== BEST INDIVIDU =====" << std::endl;
pop.best_element().printOn(std::cout);
std::cout << " fitness:" << pop.best_element().fitness() << std::endl;
std::cout << "===============" << std::endl;
//Define a generational continuator (put 100 generation for example) -> 1 line
eoGenContinue<QUEEN> cont(100);
// ================================= END CEAO ZONE ===============================
//Define the transformation object (it contains, the crossover, the crossover rate, the mutation and the mutation rate) -> 1 line
eoSGATransform<QUEEN> transform(cross, 0.1, mut, 0.1);
//Define a selection method that selects ONE individual by deterministic tournament(put the tournament size at 2 for example) -> 1 line
eoDetTournamentSelect<QUEEN> selectOne(2);
//Define a "eoSelectPerc" with the tournament with default parameter (allow to select the good size of individuals) -> 1 line
eoSelectPerc<QUEEN> select(selectOne);
// //Define a QUEEN -> 1 line
// QUEEN s1;
//Define a generational replacement strategy -> 1 line
eoGenerationalReplacement<QUEEN> replace;
// //Define an initializer -> 1 line
// queenInit init(8,1);
//Define a pop of QUEEN -> 1 line
eoPop<QUEEN> pop;
// //Define the evaluation function -> 1 line
// queenEval eval;
//Fill the pop with 100 initialized and evaluated QUEEN
//Use the initializer, the evaluation function and the push_back operator's vector -> A "for" included three insrtuctions
for(unsigned int i=0; i<100; i++){
init(s1);
eval(s1);
pop.push_back(s1);
}
// //Define mutation -> 1 line
// queenMutation mut;
//Print the pop -> 1 line
pop.printOn(std::cout);
// //Define crossover -> 1 line
// queenCrossover cross;
// //Define a generational continuator (put 100 generation for example) -> 1 line
// eoGenContinue<QUEEN> cont(100);
// //Define the transformation object (it contains, the crossover, the crossover rate, the mutation and the mutation rate) -> 1 line
// eoSGATransform<QUEEN> transform(cross, 0.1, mut, 0.1);
// //Define a selection method that selects ONE individual by deterministic tournament(put the tournament size at 2 for example) -> 1 line
// eoDetTournamentSelect<QUEEN> selectOne(2);
// //Define a "eoSelectPerc" with the tournament with default parameter (allow to select the good size of individuals) -> 1 line
// eoSelectPerc<QUEEN> select(selectOne);
// //Define a generational replacement strategy -> 1 line
// eoGenerationalReplacement<QUEEN> replace;
// //Define a pop of QUEEN -> 1 line
// eoPop<QUEEN> pop;
// //Fill the pop with 100 initialized and evaluated QUEEN
// //Use the initializer, the evaluation function and the push_back operator's vector -> A "for" included three insrtuctions
// for(unsigned int i=0; i<100; i++){
// init(s1);
// eval(s1);
// pop.push_back(s1);
// }
// //Print the pop -> 1 line
// pop.printOn(std::cout);
//HERE you can test whether you succeded in initializing the population by compiling and executing this part of the program.
//Print end of line (endl)
std::cout << std::endl;
/*Define an eoEasyEA with good parameter:
- continuator
- evaluation function
- eoSelectPerc
- transformation object
- replacement
*/
// -> 1 line
eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace);
// std::cout << std::endl;
//run the algorithm on the initialized population -> 1 line
algo(pop);
// /*Define an eoEasyEA with good parameter:
// - continuator
// - evaluation function
// - eoSelectPerc
// - transformation object
// - replacement
// */
// // -> 1 line
// eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace);
//Print the best element -> 1 line
pop.best_element().printOn(std::cout);
// //run the algorithm on the initialized population -> 1 line
// algo(pop);
// //Print the best element -> 1 line
// pop.best_element().printOn(std::cout);
//If the fitness value is equal to 0, the best solution is found. Else try again.
// //If the fitness value is equal to 0, the best solution is found. Else try again.
std::cout << std::endl;
// std::cout << std::endl;
return EXIT_SUCCESS;
}
......@@ -15,3 +15,4 @@ ADD_LIBRARY(lModel STATIC ${EXERCICE_SOURCES})
add_subdirectory(exception)
add_subdirectory(scale)
add_subdirectory(ea)
\ No newline at end of file
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ea)
include_directories(${PARADISEO_INCLUDE_DIR})
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
SET (EXERCICE_SOURCES
evaluator.cpp
)
ADD_LIBRARY(lEA STATIC ${EXERCICE_SOURCES})
\ No newline at end of file
#ifndef SRC_MODEL_EA_CROSSOVER_H_
#define SRC_MODEL_EA_CROSSOVER_H_
#include <eoOrderXover.h>
#include "cursus.h"
typedef eoOrderXover<Cursus> CursusCrossover;
#endif // SRC_MODEL_EA_CROSSOVER_H_
\ No newline at end of file
#ifndef SRC_MODEL_EA_CURSUS_H_
#define SRC_MODEL_EA_CURSUS_H_
#include <eoInt.h>
#include <eoScalarFitness.h>
/**
* Represents a cursus of a student. It is equivalent to an individu in a EA.
* Here, it is defined as an eoVector of int: eoInt with a "eoMinimizingFitness" template. Each int represents a course.
* In version 1, the representation is based on the course's ID. In further version, this could become deprecated and be based on the course's position inside the problem's vector.
* @version 1
*/
typedef eoInt<eoMinimizingFitness> Cursus;
#endif // SRC_MODEL_EA_CURSUS_H_
\ No newline at end of file
#include "evaluator.h"
void CursusEval::operator()(Cursus & _cursus){
double fit=0.0;
fit = 1.0;
_cursus.fitness(fit);
}
#ifndef SRC_MODEL_EA_EVALUATOR_H_
#define SRC_MODEL_EA_EVALUATOR_H_
#include <eoEvalFunc.h>
#include "cursus.h"
class CursusEval : public eoEvalFunc<Cursus>
{
public:
void operator()(Cursus & _cursus);
};
#endif // SRC_MODEL_EA_EVALUATOR_H_
\ No newline at end of file
#ifndef SRC_MODEL_EA_INITIALIZER_H_
#define SRC_MODEL_EA_INITIALIZER_H_
#include <eoInit.h>
#include "cursus.h"
typedef eoInitPermutation<Cursus> CursusInit;
#endif // SRC_MODEL_EA_INITIALIZER_H_
\ No newline at end of file
#ifndef SRC_MODEL_EA_MUTATION_H_
#define SRC_MODEL_EA_MUTATION_H_
#include <eoSwapMutation.h>
#include <eoShiftMutation.h>
#include "cursus.h"
typedef eoSwapMutation<Cursus> CursusMutation;
#endif // SRC_MODEL_EA_MUTATION_H_
\ No newline at end of file
#ifndef SRC_MODEL_PARCOURS_H_
#define SRC_MODEL_PARCOURS_H_
/**
* Represents a cursus of a student. It is equivalent to an individu in a EA.
*/
#endif // SRC_MODEL_PARCOURS_H_
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment