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) ...@@ -28,7 +28,7 @@ ADD_DEPENDENCIES(tryEval lQueen)
# 3) Link the librairies for your executable # 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_competency ${PARADISEO_LIBRARIES} lQueen lModel)
TARGET_LINK_LIBRARIES(ceao_course ${PARADISEO_LIBRARIES} lQueen lModel) TARGET_LINK_LIBRARIES(ceao_course ${PARADISEO_LIBRARIES} lQueen lModel)
TARGET_LINK_LIBRARIES(ceao_profession ${PARADISEO_LIBRARIES} lQueen lModel) TARGET_LINK_LIBRARIES(ceao_profession ${PARADISEO_LIBRARIES} lQueen lModel)
......
...@@ -7,6 +7,13 @@ ...@@ -7,6 +7,13 @@
#include <model/magnitude.h> #include <model/magnitude.h>
#include <model/competency.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/magnitudeException.h>
#include <model/exception/competencyEvolvingException.h> #include <model/exception/competencyEvolvingException.h>
...@@ -47,73 +54,115 @@ int main(int argc, char* argv[]){ ...@@ -47,73 +54,115 @@ int main(int argc, char* argv[]){
// ================================= END TEST ZONE ===================================== // ================================= END TEST ZONE =====================================
//Define a QUEEN -> 1 line // ================================= CEAO ZONE ===================================
QUEEN s1; Cursus c1;
CursusInit init(8,1);
CursusEval eval;
CursusMutation mut;
CursusCrossover xOver;
//Define an initializer -> 1 line eoGenContinue<Cursus> cont(100); // runs for 100 gen
queenInit init(8,1);
//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 the evaluation function -> 1 line std::cout << "===== CURRENT POP =====" << std::endl;
queenEval eval; pop.printOn(std::cout);
std::cout << "===== =====" << std::endl;
//Define mutation -> 1 line eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace);
queenMutation mut;
//Define crossover -> 1 line algo(pop);
queenCrossover cross;
//Define a generational continuator (put 100 generation for example) -> 1 line std::cout << "===== BEST INDIVIDU =====" << std::endl;
eoGenContinue<QUEEN> cont(100); pop.best_element().printOn(std::cout);
std::cout << " fitness:" << pop.best_element().fitness() << std::endl;
std::cout << "===============" << std::endl;
//Define the transformation object (it contains, the crossover, the crossover rate, the mutation and the mutation rate) -> 1 line // ================================= END CEAO ZONE ===============================
eoSGATransform<QUEEN> transform(cross, 0.1, mut, 0.1);
// //Define a QUEEN -> 1 line
// QUEEN s1;
//Define a selection method that selects ONE individual by deterministic tournament(put the tournament size at 2 for example) -> 1 line // //Define an initializer -> 1 line
eoDetTournamentSelect<QUEEN> selectOne(2); // queenInit init(8,1);
//Define a "eoSelectPerc" with the tournament with default parameter (allow to select the good size of individuals) -> 1 line // //Define the evaluation function -> 1 line
eoSelectPerc<QUEEN> select(selectOne); // queenEval eval;
//Define a generational replacement strategy -> 1 line // //Define mutation -> 1 line
eoGenerationalReplacement<QUEEN> replace; // queenMutation mut;
//Define a pop of QUEEN -> 1 line // //Define crossover -> 1 line
eoPop<QUEEN> pop; // queenCrossover cross;
//Fill the pop with 100 initialized and evaluated QUEEN // //Define a generational continuator (put 100 generation for example) -> 1 line
//Use the initializer, the evaluation function and the push_back operator's vector -> A "for" included three insrtuctions // eoGenContinue<QUEEN> cont(100);
for(unsigned int i=0; i<100; i++){
init(s1); // //Define the transformation object (it contains, the crossover, the crossover rate, the mutation and the mutation rate) -> 1 line
eval(s1); // eoSGATransform<QUEEN> transform(cross, 0.1, mut, 0.1);
pop.push_back(s1);
} // //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 // //Print the pop -> 1 line
pop.printOn(std::cout); // pop.printOn(std::cout);
//HERE you can test whether you succeded in initializing the population by compiling and executing this part of the program. //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) //Print end of line (endl)
std::cout << std::endl; // std::cout << std::endl;
/*Define an eoEasyEA with good parameter: // /*Define an eoEasyEA with good parameter:
- continuator // - continuator
- evaluation function // - evaluation function
- eoSelectPerc // - eoSelectPerc
- transformation object // - transformation object
- replacement // - replacement
*/ // */
// -> 1 line // // -> 1 line
eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace); // eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace);
//run the algorithm on the initialized population -> 1 line // //run the algorithm on the initialized population -> 1 line
algo(pop); // algo(pop);
//Print the best element -> 1 line // //Print the best element -> 1 line
pop.best_element().printOn(std::cout); // 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; return EXIT_SUCCESS;
} }
...@@ -14,4 +14,5 @@ SET (EXERCICE_SOURCES ...@@ -14,4 +14,5 @@ SET (EXERCICE_SOURCES
ADD_LIBRARY(lModel STATIC ${EXERCICE_SOURCES}) ADD_LIBRARY(lModel STATIC ${EXERCICE_SOURCES})
add_subdirectory(exception) add_subdirectory(exception)
add_subdirectory(scale) add_subdirectory(scale)
\ No newline at end of file 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