Commit 74d3cc48 authored by jeremie.humeau's avatar jeremie.humeau

ajout contrainte dans l'eval

parent aac66378
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <model/profession.h> #include <model/profession.h>
#include <model/magnitude.h> #include <model/magnitude.h>
#include <model/tools.h> #include <model/tools.h>
#include <model/competency.h>
#include <model/ea/cursus.h> #include <model/ea/cursus.h>
#include <model/ea/initializer.h> #include <model/ea/initializer.h>
...@@ -68,35 +69,42 @@ int main(int argc, char* argv[]){ ...@@ -68,35 +69,42 @@ int main(int argc, char* argv[]){
CSDVP pb; CSDVP pb;
Profession job; Profession job;
// ===== PB CONFIG ZONE ===== // ===== PB CONFIG ZONE =====
pb.set_cfg_quantityCourses(10); pb.set_cfg_quantityCourses(25);
pb.set_cfg_quantityCompetencies(5); pb.set_cfg_quantityCompetencies(40);
pb.set_cfg_minimalTimeFrames(1); pb.set_cfg_minimalTimeFrames(1);
pb.set_cfg_maximalTimeFrames(6); //Just "Licence" pb.set_cfg_maximalTimeFrames(6); //Just "Licence"
pb.set_cfg_ectsMin(1); pb.set_cfg_ectsMin(1);
pb.set_cfg_ectsMax(5); pb.set_cfg_ectsMax(5);
pb.set_cfg_courseByTFMin(3); pb.set_cfg_courseByTFMin(3);
pb.set_cfg_courseByTFMax(5); pb.set_cfg_courseByTFMax(8);
pb.set_cfg_minimalMagnitude(0.2); pb.set_cfg_minimalMagnitude(0.2);
pb.set_cfg_maximalMagnitude(0.75); pb.set_cfg_maximalMagnitude(0.75);
pb.set_cfg_minimalCompetencyByCourse(1); pb.set_cfg_minimalCompetencyByCourse(1);
pb.set_cfg_maximalCompetencyByCourse(3); pb.set_cfg_maximalCompetencyByCourse(5);
pb.set_cfg_minimalPrerequisiteByCourse(0); pb.set_cfg_minimalPrerequisiteByCourse(0);
pb.set_cfg_maximalPrerequisiteByCourse(1); pb.set_cfg_maximalPrerequisiteByCourse(3);
pb.set_cfg_pickedCoursesByTimeFrame(2); pb.set_cfg_pickedCoursesByTimeFrame(2);
CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777); CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777);
assert(pb.checkConfig()); assert(pb.checkConfig());
job.setRequiredECTS(4 * 6); job.setRequiredECTS(4 * 6);
Competency tmpC = pb.competencyCatalogue().at(0); 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); job.addPrerequisite(tmpC);
tmpC = pb.competencyCatalogue().at(1); tmpC = pb.competencyCatalogue().at(20);
tmpC = Competency::buildTMP(0.8, tmpC.c_name());
job.addPrerequisite(tmpC); job.addPrerequisite(tmpC);
//tmpC = Competency::build(0.5,"Wesh"); //tmpC = Competency::build(0.5,"Wesh");
//job.addPrerequisite(tmpC); //job.addPrerequisite(tmpC);
tmpC = pb.competencyCatalogue().at(8); //tmpC = pb.competencyCatalogue().at(8);
job.addPrerequisite(tmpC); //job.addPrerequisite(tmpC);
// ===== END PB CONFIG ===== // ===== END PB CONFIG =====
Cursus c1; Cursus c1;
...@@ -117,15 +125,15 @@ int main(int argc, char* argv[]){ ...@@ -117,15 +125,15 @@ int main(int argc, char* argv[]){
//CursusInit init(pb.getQuantityCoursesToPick(),pb.coursesCatalogue().size(),pb.seed()); //CursusInit init(pb.getQuantityCoursesToPick(),pb.coursesCatalogue().size(),pb.seed());
CursusInitConstraint init(pb); CursusInitConstraint init(pb);
//pb.cfg_quantityCourses());//pb.getQuantityCoursesToPick(),pb.cfg_quantityCourses(), pb.seed()); //pb.cfg_quantityCourses());//pb.getQuantityCoursesToPick(),pb.cfg_quantityCourses(), pb.seed());
CursusEval eval(ctrRep, ctrJob, ctrECTS); CursusEval eval(ctrPrq, ctrRep, ctrJob, ctrECTS);
CursusCrossover cross(pb, ctrRep, init); CursusCrossover cross(pb, ctrRep, init);
CursusMutation mut(pb, ctrRep); CursusMutation mut(pb, ctrRep);
eoGenContinue<Cursus> cont(10000); // runs for 100 gen eoGenContinue<Cursus> cont(1000); // runs for 100 gen
//xOver, xOver rate, mutation, mutation rate //xOver, xOver rate, mutation, mutation rate
eoSGATransform<Cursus> transform(cross, 0.1, mut, 0.7); eoSGATransform<Cursus> transform(cross, 0.5, mut, 0.8);
eoDetTournamentSelect<Cursus> selectOne(5); //selection method by tournament, here against 2 eoDetTournamentSelect<Cursus> selectOne(5); //selection method by tournament, here against 2
eoSelectPerc<Cursus> select(selectOne); eoSelectPerc<Cursus> select(selectOne);
eoGenerationalReplacement<Cursus> replace; eoGenerationalReplacement<Cursus> replace;
...@@ -137,6 +145,7 @@ int main(int argc, char* argv[]){ ...@@ -137,6 +145,7 @@ int main(int argc, char* argv[]){
{ {
init(c1); init(c1);
eval(c1); eval(c1);
/*
res = ctrECTS.integrityCheck(c1); res = ctrECTS.integrityCheck(c1);
std::cout << "ECTS Metric" << std::to_string(res.second) << std::endl; std::cout << "ECTS Metric" << std::to_string(res.second) << std::endl;
//res = ctrRep.integrityCheck(c1); //res = ctrRep.integrityCheck(c1);
...@@ -155,9 +164,10 @@ int main(int argc, char* argv[]){ ...@@ -155,9 +164,10 @@ int main(int argc, char* argv[]){
{ {
std::cout << pb.coursesCatalogue().at(c1.at(i)) << std::endl; std::cout << pb.coursesCatalogue().at(c1.at(i)) << std::endl;
} }
*/
pop.push_back(c1); pop.push_back(c1);
} }
//MUTATION TEST //MUTATION TEST
/* /*
pop[0].printOn(std::cout); pop[0].printOn(std::cout);
...@@ -191,7 +201,7 @@ int main(int argc, char* argv[]){ ...@@ -191,7 +201,7 @@ int main(int argc, char* argv[]){
std::cout << "===== CURRENT POP =====" << std::endl; std::cout << "===== CURRENT POP =====" << std::endl;
pop.printOn(std::cout); pop.best_element().printOn(std::cout);
std::cout << "===== =====" << std::endl; std::cout << "===== =====" << std::endl;
eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace); eoEasyEA<QUEEN> algo(cont,eval,select,transform,replace);
......
...@@ -112,10 +112,12 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -112,10 +112,12 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
} }
bool isOK = ((notFound == 0) && (notRespected == 0)); bool isOK = ((notFound == 0) && (notRespected == 0));
/*
std::cout << "========== PREREQ CSTR RES ==========" << std::endl; std::cout << "========== PREREQ CSTR RES ==========" << std::endl;
std::cout << "Not Found: " << std::to_string(notFound) << std::endl; std::cout << "Not Found: " << std::to_string(notFound) << std::endl;
std::cout << "Not Respected: " << std::to_string(notRespected) << std::endl; std::cout << "Not Respected: " << std::to_string(notRespected) << std::endl;
std::cout << "Nb Prereq: " << std::to_string(nbPrereq) << std::endl; std::cout << "Nb Prereq: " << std::to_string(nbPrereq) << std::endl;
*/
double metric = 0; double metric = 0;
if(nbPrereq > 0) if(nbPrereq > 0)
{ {
...@@ -128,8 +130,8 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -128,8 +130,8 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
else else
metric = 0; metric = 0;
} }
std::cout << "Metric: " << std::to_string(metric) << std::endl; //std::cout << "Metric: " << std::to_string(metric) << std::endl;
std::cout << "====================" << std::endl; //std::cout << "====================" << std::endl;
return std::pair<bool, double>(isOK, metric); return std::pair<bool, double>(isOK, metric);
} }
......
...@@ -3,22 +3,31 @@ ...@@ -3,22 +3,31 @@
void CursusEval::operator()(Cursus & _cursus){ void CursusEval::operator()(Cursus & _cursus){
double fit=0.0; double fit=0.0;
int pCE, pCP, pCR; int pCE, pCP, pCR, pCPR;
pCE=1; pCE=1;
pCR=1; pCR=1;
pCP=1; pCP=1;
pCPR=1;
std::pair<bool, double> resCE; std::pair<bool, double> resCE;
std::pair<bool, double> resCP; std::pair<bool, double> resCP;
std::pair<bool, double> resCR; std::pair<bool, double> resCR;
std::pair<bool, double> resCPR;
resCE=ce.integrityCheck(_cursus); resCE=ce.integrityCheck(_cursus);
resCP=cp.integrityCheck(_cursus); resCP=cp.integrityCheck(_cursus);
resCR=cr.integrityCheck(_cursus); resCR=cr.integrityCheck(_cursus);
//std::cout << resCP.first << " " << resCP.second << std::endl; resCPR=cpr.integrityCheck(_cursus);
/*
double sum=pCE*resCE.second + pCR*resCR.second + pCP*resCP.second; std::cout << "EVAL: ";
std::cout << resCE.first << " " << resCE.second << std::endl;
std::cout << resCP.first << " " << resCP.second << std::endl;
std::cout << resCR.first << " " << resCR.second << std::endl;
std::cout << resCPR.first << " " << resCPR.second << std::endl;
std::cout << std::endl << std::endl;
*/
double sum=pCE*resCE.second + pCR*resCR.second + pCP*resCP.second + pCPR*resCPR.second;
fit=1.0/(1+sum)*100; fit=1.0/(1+sum)*100;
_cursus.fitness(fit); _cursus.fitness(fit);
......
...@@ -13,12 +13,13 @@ class CursusEval : public eoEvalFunc<Cursus> ...@@ -13,12 +13,13 @@ class CursusEval : public eoEvalFunc<Cursus>
{ {
public: public:
CursusEval(ConstraintsRepetition& _cr, ConstraintsProfession& _cp, ConstraintsECTS& _ce): cr(_cr), cp(_cp), ce(_ce){} CursusEval(ConstraintsPrerequisites& _cpr, ConstraintsRepetition& _cr, ConstraintsProfession& _cp, ConstraintsECTS& _ce):cpr(_cpr), cr(_cr), cp(_cp), ce(_ce){}
void operator()(Cursus & _cursus); void operator()(Cursus & _cursus);
private: private:
ConstraintsPrerequisites cpr;
ConstraintsRepetition cr; ConstraintsRepetition cr;
ConstraintsProfession cp; ConstraintsProfession cp;
ConstraintsECTS ce; ConstraintsECTS ce;
......
...@@ -47,11 +47,11 @@ class eoInitConstraintCSDVP: public eoInit<EOT> ...@@ -47,11 +47,11 @@ class eoInitConstraintCSDVP: public eoInit<EOT>
virtual void operator()(EOT& chrom){ virtual void operator()(EOT& chrom){
int cpt=0; int cpt=0;
// std::cout << "Enter init" << std::endl; std::cout << "Enter init" << std::endl;
unsigned int r=eo::rng.random(possibleIDbyTF[0].size()); unsigned int r=eo::rng.random(possibleIDbyTF[0].size());
chrom.resize(0); chrom.resize(0);
chrom.push_back(possibleIDbyTF[0][r]); chrom.push_back(possibleIDbyTF[0][r]);
//std::cout << "push " << possibleIDbyTF[0][r] << std::endl; std::cout << "push " << possibleIDbyTF[0][r] << std::endl;
for(int i = 1; i < chromSize; i++){ for(int i = 1; i < chromSize; i++){
cpt=0; cpt=0;
r=eo::rng.random(possibleIDbyTF[i/sizeTF].size()); r=eo::rng.random(possibleIDbyTF[i/sizeTF].size());
...@@ -62,14 +62,14 @@ class eoInitConstraintCSDVP: public eoInit<EOT> ...@@ -62,14 +62,14 @@ class eoInitConstraintCSDVP: public eoInit<EOT>
if(cpt<maxVal){ if(cpt<maxVal){
std::cout << i << " " << r << " "; std::cout << i << " " << r << " ";
chrom.push_back(possibleIDbyTF[i/sizeTF][r]); chrom.push_back(possibleIDbyTF[i/sizeTF][r]);
//std::cout << "push " << possibleIDbyTF[i/sizeTF][r] << std::endl; std::cout << "push " << possibleIDbyTF[i/sizeTF][r] << std::endl;
} }
else{ else{
r=eo::rng.random(maxVal); r=eo::rng.random(maxVal);
while(!notin(chrom, r, i)) while(!notin(chrom, r, i))
r=eo::rng.random(maxVal); r=eo::rng.random(maxVal);
chrom.push_back(r); chrom.push_back(r);
//std::cout << "push with error " << r << std::endl; std::cout << "push with error " << r << std::endl;
} }
} }
......
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