Commit 20682fed authored by jeremie.humeau's avatar jeremie.humeau

Ajout de la gestion de Paramètre et nettoyage du main

parent 74d3cc48
...@@ -26,266 +26,241 @@ ...@@ -26,266 +26,241 @@
#include <model/exception/magnitudeException.h> #include <model/exception/magnitudeException.h>
#include <model/exception/competencyEvolvingException.h> #include <model/exception/competencyEvolvingException.h>
void make_help(eoParser & _parser);
int main(int argc, char* argv[]){ int main(int argc, char* argv[]){
/*** init ***/
eoParser parser(argc, argv); // for user-parameter reading
eoState state; // to keep all things allocate
// ================================ TEST ZONE ===========================================
std::cout << "MAGNITUDE TEST ZONE" << std::endl;
Magnitude m = Magnitude::build(0.5);
Magnitude n = Magnitude::build(0.3);
Magnitude o = Magnitude::build(0.2);
o = m; // ================================= CEAO ZONE ===================================
//GENERAL PARAMATERS
eoValueParam<uint32_t>& _seedParam = parser.createParam(uint32_t(0), "seed", "Random number seed", 'S');
std::string _outputFile = parser.createParam(std::string("/scratch"), "outputfile", "", '\0', "Representation", true).value();
//PROBLEM PARAMETERS
unsigned int NBCOURSES = parser.createParam((unsigned int)(15), "nbCourses", "Nb of courses available in the cursus",'C',"Param").value();
unsigned int NBCOMP = parser.createParam((unsigned int)(10), "nbComp", "Nb of competencies available in the cursus",'c',"Param").value();
unsigned int MINTF = parser.createParam((unsigned int)(1), "minTF", "id of the first time frame",'t',"Param").value();
unsigned int MAXTF = parser.createParam((unsigned int)(6), "maxTF", "id of the first time frame",'T',"Param").value();
unsigned int MINECTS = parser.createParam((unsigned int)(1), "minECTS", "minimum number ECTS by course",'e',"Param").value();
unsigned int MAXECTS = parser.createParam((unsigned int)(5), "maxECTS", "maxmimum number ECTS by course",'E',"Param").value();
unsigned int MINCBYTF = parser.createParam((unsigned int)(3), "minCbyTF", "minimal course by time frame",'n',"Param").value();
unsigned int MAXCBYTF = parser.createParam((unsigned int)(8), "maxCbyTF", "maximal course by time frame",'N',"Param").value();
double MINMAGN = parser.createParam((double)(0.2), "minMagn", "miminal magnitude", 'm', "Param").value();
double MAXMAGN = parser.createParam((double)(0.75), "maxMagn", "maximal magnitude", 'M', "Param").value();
unsigned int MINCBYC = parser.createParam((unsigned int)(1), "minCbyC", "minimal competency by course",'r',"Param").value();
unsigned int MAXCBYC = parser.createParam((unsigned int)(5), "maxCbyC", "maximal competency by course",'R',"Param").value();
unsigned int MINPRE = parser.createParam((unsigned int)(0), "minPre", "minimal competency by course",'p',"Param").value();
unsigned int MAXPRE = parser.createParam((unsigned int)(3), "maxPre", "maximal competency by course",'P',"Param").value();
unsigned int CBYTF = parser.createParam((unsigned int)(2), "cbyTF", "course by time frame to pick",'A',"Param").value();
//EVOLUTION ENGINE PARAMETERS
unsigned int POPSIZE = parser.createParam((unsigned int)(100), "popSize", "Population size", 'P', "Evolution Engine").value();
double PMUT = parser.createParam((double)(0.5), "pMut", "mutation rate", 'x', "Evolution Engine").value();
double PCROSS = parser.createParam((double)(0.5), "pCross", "crossover rate", 'X', "Evolution Engine").value();
unsigned int NBGEN = parser.createParam((unsigned int)(100), "nbGen", "Number of generation",'G',"Param").value();
unsigned int SIZET = parser.createParam((unsigned int)(7), "sizeT", "Tournament Size",'S',"Param").value();
// ===== PB CONFIG ZONE =====
CSDVP pb;
Profession job;
pb.set_cfg_quantityCourses(NBCOURSES);
pb.set_cfg_quantityCompetencies(NBCOMP);
pb.set_cfg_minimalTimeFrames(MINTF);
pb.set_cfg_maximalTimeFrames(MAXTF); //Just "Licence"
pb.set_cfg_ectsMin(MINECTS);
pb.set_cfg_ectsMax(MAXECTS);
pb.set_cfg_courseByTFMin(MINCBYTF);
pb.set_cfg_courseByTFMax(MAXCBYTF);
pb.set_cfg_minimalMagnitude(MINMAGN);
pb.set_cfg_maximalMagnitude(MAXMAGN);
pb.set_cfg_minimalCompetencyByCourse(MINCBYC);
pb.set_cfg_maximalCompetencyByCourse(MAXCBYC);
pb.set_cfg_minimalPrerequisiteByCourse(MINPRE);
pb.set_cfg_maximalPrerequisiteByCourse(MAXPRE);
pb.set_cfg_pickedCoursesByTimeFrame(CBYTF);
CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777);
assert(pb.checkConfig());
job.setRequiredECTS(4 * 6);
Competency tmpC = pb.competencyCatalogue().at(0);
tmpC = Competency::buildTMP(0.8, tmpC.c_name());
job.addPrerequisite(tmpC);
tmpC = pb.competencyCatalogue().at(1);
tmpC = Competency::buildTMP(0.8, tmpC.c_name());
job.addPrerequisite(tmpC);
tmpC = pb.competencyCatalogue().at(2);
tmpC = Competency::buildTMP(0.8, tmpC.c_name());
job.addPrerequisite(tmpC);
//tmpC = Competency::build(0.5,"Wesh");
//job.addPrerequisite(tmpC);
//tmpC = pb.competencyCatalogue().at(8);
//job.addPrerequisite(tmpC);
// ===== END PB CONFIG =====
std::cout << "Magnitude" << o.value() << std::endl; ConstraintsECTS ctrECTS(pb, job);
ConstraintsRepetition ctrRep(pb, job);
ConstraintsProfession ctrJob(pb, job);
ConstraintsPrerequisites ctrPrq(pb, job);
std::cout << "Magnitude" << m.value() << std::endl;
//std::cout << "getQuantityCoursesToPick : " << std::to_string(pb.getQuantityCoursesToPick()) << std::endl;
//std::cout << "cfg_quantityCourses() : " << std::to_string(pb.cfg_quantityCourses()) << std::endl;
/**@todo make size of the pb accessible as well as size of an individu*/
m += n;
// ======================== AG CONFIG ZONE ========================
//PROBLEM DEPENDANT OPERATOR
CursusInitConstraint init(pb);
CursusEval eval(ctrPrq, ctrRep, ctrJob, ctrECTS);
CursusCrossover cross(pb, ctrRep, init);
CursusMutation mut(pb, ctrRep);
//PROBLEM INDEPENDANT OPERATOR
eoGenContinue<Cursus> cont(NBGEN);
eoSGATransform<Cursus> transform(cross, PCROSS, mut, PMUT);
eoDetTournamentSelect<Cursus> selectOne(SIZET);
eoSelectPerc<Cursus> select(selectOne);
eoGenerationalReplacement<Cursus> replace;
//POPULATION INITIALISATION
eoPop<Cursus> pop;
Cursus c1;
for(int i = 0; i < POPSIZE; i++){
init(c1);
eval(c1);
pop.push_back(c1);
}
std::cout << "New magnitude is " << m.value() << std::endl; // ======================== AG CONFIG ZONE END ========================
try{
std::cout << "After addition mag is : " << (m + m).value() << std::endl; // ================================ TEST ZONE ===========================================
} /*
catch(MagnitudeException & e) std::cout << "MAGNITUDE TEST ZONE" << std::endl;
{ Magnitude m = Magnitude::build(0.5);
std::cout << "\nEXCEPTION CATCH !\n"; Magnitude n = Magnitude::build(0.3);
std::cout << "Memory adr of m is : " << &m << std::endl; Magnitude o = Magnitude::build(0.2);
std::cout << "Memory adr of e is : " << &e.getMagnitude() << std::endl;
e.getMagnitude().rebase();
std::cout << "REBASE! New magnitude value is" << e.getMagnitude().rebase() << std::endl;
std::cout << "Accessing magnitude value : " << e.getMagnitude().value() << std::endl;
std::cout << "magnitude value of M : " << m.value() << std::endl;
m = e.getMagnitude();
std::cout << "before end catch" << m.value() << std::endl;
}
std::cout << "Inspect m value:" << m.value() << std::endl; o = m;
std::cout << "END MAGNITUDE TEST\n\n\n" << std::endl;
// ================================= END TEST ZONE ===================================== std::cout << "Magnitude" << o.value() << std::endl;
// ================================= CEAO ZONE =================================== std::cout << "Magnitude" << m.value() << std::endl;
CSDVP pb;
Profession job;
// ===== PB CONFIG ZONE =====
pb.set_cfg_quantityCourses(25);
pb.set_cfg_quantityCompetencies(40);
pb.set_cfg_minimalTimeFrames(1);
pb.set_cfg_maximalTimeFrames(6); //Just "Licence"
pb.set_cfg_ectsMin(1);
pb.set_cfg_ectsMax(5);
pb.set_cfg_courseByTFMin(3);
pb.set_cfg_courseByTFMax(8);
pb.set_cfg_minimalMagnitude(0.2);
pb.set_cfg_maximalMagnitude(0.75);
pb.set_cfg_minimalCompetencyByCourse(1);
pb.set_cfg_maximalCompetencyByCourse(5);
pb.set_cfg_minimalPrerequisiteByCourse(0);
pb.set_cfg_maximalPrerequisiteByCourse(3);
pb.set_cfg_pickedCoursesByTimeFrame(2);
CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777);
assert(pb.checkConfig());
m += n;
job.setRequiredECTS(4 * 6); std::cout << "New magnitude is " << m.value() << std::endl;
Competency tmpC = pb.competencyCatalogue().at(0);
tmpC = Competency::buildTMP(0.8, tmpC.c_name());
job.addPrerequisite(tmpC);
tmpC = pb.competencyCatalogue().at(10);
tmpC = Competency::buildTMP(0.8, tmpC.c_name());
job.addPrerequisite(tmpC);
tmpC = pb.competencyCatalogue().at(20);
tmpC = Competency::buildTMP(0.8, tmpC.c_name());
job.addPrerequisite(tmpC);
//tmpC = Competency::build(0.5,"Wesh");
//job.addPrerequisite(tmpC);
//tmpC = pb.competencyCatalogue().at(8);
//job.addPrerequisite(tmpC);
// ===== END PB CONFIG =====
Cursus c1;
std::cout << "getQuantityCoursesToPick : " << std::to_string(pb.getQuantityCoursesToPick()) << std::endl;
std::cout << "cfg_quantityCourses() : " << std::to_string(pb.cfg_quantityCourses()) << std::endl;
/**@todo make size of the pb accessible as well as size of an individu*/
int size_of_the_pb = 100;
ConstraintsECTS ctrECTS(pb, job);
ConstraintsRepetition ctrRep(pb, job);
ConstraintsProfession ctrJob(pb, job);
ConstraintsPrerequisites ctrPrq(pb, job);
std::pair<bool,double> res;
//CursusInit init(pb.getQuantityCoursesToPick()-5,0);
//CursusInit init(pb.getQuantityCoursesToPick(),pb.coursesCatalogue().size(),pb.seed());
CursusInitConstraint init(pb);
//pb.cfg_quantityCourses());//pb.getQuantityCoursesToPick(),pb.cfg_quantityCourses(), pb.seed());
CursusEval eval(ctrPrq, ctrRep, ctrJob, ctrECTS);
CursusCrossover cross(pb, ctrRep, init);
CursusMutation mut(pb, ctrRep);
eoGenContinue<Cursus> cont(1000); // runs for 100 gen
//xOver, xOver rate, mutation, mutation rate
eoSGATransform<Cursus> transform(cross, 0.5, mut, 0.8);
eoDetTournamentSelect<Cursus> selectOne(5); //selection method by tournament, here against 2
eoSelectPerc<Cursus> select(selectOne);
eoGenerationalReplacement<Cursus> replace;
eoPop<Cursus> pop;
try{
std::cout << "After addition mag is : " << (m + m).value() << std::endl;
}
catch(MagnitudeException & e)
{
std::cout << "\nEXCEPTION CATCH !\n";
std::cout << "Memory adr of m is : " << &m << std::endl;
std::cout << "Memory adr of e is : " << &e.getMagnitude() << std::endl;
e.getMagnitude().rebase();
std::cout << "REBASE! New magnitude value is" << e.getMagnitude().rebase() << std::endl;
std::cout << "Accessing magnitude value : " << e.getMagnitude().value() << std::endl;
std::cout << "magnitude value of M : " << m.value() << std::endl;
m = e.getMagnitude();
std::cout << "before end catch" << m.value() << std::endl;
}
std::cout << "Inspect m value:" << m.value() << std::endl;
std::cout << "END MAGNITUDE TEST\n\n\n" << std::endl;
*/
for(int i = 0; i < size_of_the_pb; i++)
{
init(c1);
eval(c1);
/* /*
res = ctrECTS.integrityCheck(c1); std::cout << "CONSTRAINT TEST ZONE" << std::endl;
std::cout << "ECTS Metric" << std::to_string(res.second) << std::endl; std::pair<bool,double> res;
//res = ctrRep.integrityCheck(c1); for(int i = 0; i < pop.size(); i++){
//res = ctrJob.integrityCheck(c1); res = ctrECTS.integrityCheck(pop[i]);
res = ctrPrq.integrityCheck(c1); std::cout << "ECTS Metric" << std::to_string(res.second) << std::endl;
std::cout << "IND#" << std::to_string(i) << "\nFirst: " << res.first << "\nSecond: " << std::to_string((double)res.second) << std::endl; //res = ctrRep.integrityCheck(pop[i]);
if(res.first) //res = ctrJob.integrityCheck(pop[i]);
{ res = ctrPrq.integrityCheck(pop[i]);
std::cout << "*************** OK PREREQ !! ***********" << std::endl; std::cout << "IND#" << std::to_string(i) << "\nFirst: " << res.first << "\nSecond: " << std::to_string((double)res.second) << std::endl;
if(res.first)
{
std::cout << "*************** OK PREREQ !! ***********" << std::endl;
}
else
{
std::cout << "$$$$$$$$$$$$$$$$ NON OK PREREQ !! $$$$$$$$$$$$$$$$$$$" << std::endl;
}
for(int i = 0 ; i < pop[i].size(); i++)
{
std::cout << pb.coursesCatalogue().at(pop[i].at(i)) << std::endl;
}
} }
else
{
std::cout << "$$$$$$$$$$$$$$$$ NON OK PREREQ !! $$$$$$$$$$$$$$$$$$$" << std::endl;
}
for(int i = 0 ; i < c1.size(); i++)
{
std::cout << pb.coursesCatalogue().at(c1.at(i)) << std::endl;
}
*/ */
pop.push_back(c1);
}
//MUTATION TEST //MUTATION TEST
/* /*
pop[0].printOn(std::cout); std::cout << "MUTATION TEST ZONE" << std::endl;
std::cout << std::endl; pop[0].printOn(std::cout);
for(int i=0; i<50; i++){ std::cout << std::endl;
mut(pop[0]); for(int i=0; i<50; i++){
pop[0].printOn(std::cout); mut(pop[0]);
std::cout << std::endl; pop[0].printOn(std::cout);
}*/ std::cout << std::endl;
}
//CROSS TEST */
/*
pop[0].printOn(std::cout);
std::cout << std::endl;
pop[1].printOn(std::cout);
std::cout << std::endl;
for(int i=0; i<50; i++){
cross(pop[0],pop[1]);
pop[0].printOn(std::cout);
std::cout << std::endl;
pop[1].printOn(std::cout);
std::cout << std::endl;
std::cout << std::endl;
}
*/
for(int i = 0; i < pb.coursesCatalogue().size(); i++)
{
//std::cout << pb.coursesCatalogue().at(i) << std::endl;
}
std::cout << "===== CURRENT POP =====" << std::endl;
pop.best_element().printOn(std::cout);
std::cout << "===== =====" << std::endl;
eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace);
algo(pop);
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;
std::cout << "cpt: " << cross.cpt << std::endl;
// ================================= END CEAO ZONE ===============================
// //Define a QUEEN -> 1 line //CROSS TEST
// QUEEN s1; /*
std::cout << "CROSSOVER TEST ZONE" << std::endl;
// //Define an initializer -> 1 line pop[0].printOn(std::cout);
// queenInit init(8,1); std::cout << std::endl;
pop[1].printOn(std::cout);
// //Define the evaluation function -> 1 line std::cout << std::endl;
// queenEval eval; for(int i=0; i<50; i++){
cross(pop[0],pop[1]);
// //Define mutation -> 1 line pop[0].printOn(std::cout);
// queenMutation mut; std::cout << std::endl;
pop[1].printOn(std::cout);
// //Define crossover -> 1 line std::cout << std::endl;
// queenCrossover cross; std::cout << std::endl;
}
// //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); for(int i = 0; i < pb.coursesCatalogue().size(); i++)
{
std::cout << pb.coursesCatalogue().at(i) << std::endl;
}
*/
// ======================== TEST ZONE END========================
// //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); // ================================= RUN ZONE ===============================
std::cout << "===== CURRENT POP =====" << std::endl;
pop.best_element().printOn(std::cout);
std::cout << "===== =====" << std::endl;
// //Define a generational replacement strategy -> 1 line eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace);
// eoGenerationalReplacement<QUEEN> replace;
// //Define a pop of QUEEN -> 1 line algo(pop);
// eoPop<QUEEN> pop;
// //Fill the pop with 100 initialized and evaluated QUEEN std::cout << "===== BEST INDIVIDU =====" << std::endl;
// //Use the initializer, the evaluation function and the push_back operator's vector -> A "for" included three insrtuctions pop.best_element().printOn(std::cout);
// for(unsigned int i=0; i<100; i++){ std::cout << " fitness:" << pop.best_element().fitness() << std::endl;
// init(s1); std::cout << "===============" << std::endl;
// 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. std::cout << "cpt: " << cross.cpt << std::endl;
//Print end of line (endl) // ================================= END RUN ZONE ===============================
// 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);
// //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.
// std::cout << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
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