Commit fa4eea0f authored by Alexis Lebis's avatar Alexis Lebis

add new repetition constraitns (and metric)

parent 85bd4bcb
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <queenEval.h> #include <queenEval.h>
#include <model/problem.h> #include <model/problem.h>
#include <model/profession.h>
#include <model/magnitude.h> #include <model/magnitude.h>
#include <model/ea/cursus.h> #include <model/ea/cursus.h>
...@@ -14,6 +15,9 @@ ...@@ -14,6 +15,9 @@
#include <model/ea/crossover.h> #include <model/ea/crossover.h>
#include <model/ea/evaluator.h> #include <model/ea/evaluator.h>
#include <model/constraints/ectsConstraints.h>
#include <model/constraints/repetitionConstraints.h>
#include <model/exception/magnitudeException.h> #include <model/exception/magnitudeException.h>
#include <model/exception/competencyEvolvingException.h> #include <model/exception/competencyEvolvingException.h>
...@@ -58,12 +62,13 @@ int main(int argc, char* argv[]){ ...@@ -58,12 +62,13 @@ int main(int argc, char* argv[]){
// ================================= CEAO ZONE =================================== // ================================= CEAO ZONE ===================================
CSDVP pb; CSDVP pb;
Profession job;
// ===== PB CONFIG ZONE ===== // ===== PB CONFIG ZONE =====
pb.set_cfg_quantityCourses(15); pb.set_cfg_quantityCourses(15);
pb.set_cfg_quantityCompetencies(15); pb.set_cfg_quantityCompetencies(15);
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(3); 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(5);
...@@ -78,11 +83,15 @@ int main(int argc, char* argv[]){ ...@@ -78,11 +83,15 @@ int main(int argc, char* argv[]){
CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777); CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777);
assert(pb.checkConfig()); assert(pb.checkConfig());
job.setRequiredECTS(4 * 6);
// ===== END PB CONFIG ===== // ===== END PB CONFIG =====
Cursus c1; Cursus c1;
CursusInit init(pb.getQuantityCoursesToPick(),pb.cfg_quantityCourses(), pb.seed()); std::cout << "getQuantityCoursesToPick : " << std::to_string(pb.getQuantityCoursesToPick()) << std::endl;
std::cout << "cfg_quantityCourses() : " << std::to_string(pb.cfg_quantityCourses()) << std::endl;
CursusInit init(pb.getQuantityCoursesToPick()-5,0);//pb.cfg_quantityCourses());//pb.getQuantityCoursesToPick(),pb.cfg_quantityCourses(), pb.seed());
CursusEval eval; CursusEval eval;
CursusMutation mut; CursusMutation mut;
CursusCrossover xOver; CursusCrossover xOver;
...@@ -97,14 +106,27 @@ int main(int argc, char* argv[]){ ...@@ -97,14 +106,27 @@ int main(int argc, char* argv[]){
eoPop<Cursus> pop; eoPop<Cursus> pop;
/**@todo make size of the pb accessible as well as size of an individu*/ /**@todo make size of the pb accessible as well as size of an individu*/
int size_of_the_pb = 100; int size_of_the_pb = 30;
ConstraintsECTS ctrECTS(pb, job);
ConstraintsRepetition ctrRep(pb, job);
std::pair<bool,double> res;
for(int i = 0; i < size_of_the_pb; i++) for(int i = 0; i < size_of_the_pb; i++)
{ {
init(c1); init(c1);
eval(c1); eval(c1);
res = ctrECTS.integrityCheck(c1);
res = ctrRep.integrityCheck(c1);
std::cout << "IND#" << std::to_string(i) << "\nFirst: " << res.first << "\nSecond: " << std::to_string(res.second) << std::endl;
pop.push_back(c1); pop.push_back(c1);
} }
for(int i = 0; i < pb.coursesCatalogue().size(); i++)
{
std::cout << pb.coursesCatalogue().at(i) << std::endl;
}
std::cout << "===== CURRENT POP =====" << std::endl; std::cout << "===== CURRENT POP =====" << std::endl;
pop.printOn(std::cout); pop.printOn(std::cout);
std::cout << "===== =====" << std::endl; std::cout << "===== =====" << std::endl;
......
...@@ -5,6 +5,7 @@ SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) ...@@ -5,6 +5,7 @@ SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
SET (EXERCICE_SOURCES SET (EXERCICE_SOURCES
ectsConstraints.cpp ectsConstraints.cpp
repetitionConstraints.cpp
) )
ADD_LIBRARY(lCstr STATIC ${EXERCICE_SOURCES}) ADD_LIBRARY(lCstr STATIC ${EXERCICE_SOURCES})
\ No newline at end of file
...@@ -6,18 +6,18 @@ std::pair<bool, double> ConstraintsECTS::integrityCheck(Cursus indiv) ...@@ -6,18 +6,18 @@ std::pair<bool, double> ConstraintsECTS::integrityCheck(Cursus indiv)
{ {
std::vector<Course> courses = this->_pb.coursesCatalogue(); std::vector<Course> courses = this->_pb.coursesCatalogue();
int tmpECTS = 0; int tmpECTS = 0;
std::cout << "courses size : " << std::to_string(courses.size()) << std::endl; //std::cout << "courses size : " << std::to_string(courses.size()) << std::endl;
std::cout << "courses catl : " << std::to_string(this->_pb.cfg_quantityCourses()) << std::endl; //std::cout << "courses catl : " << std::to_string(this->_pb.cfg_quantityCourses()) << std::endl;
for(int i = 0; i < indiv.size(); i++) for(int i = 0; i < indiv.size(); i++)
{ {
tmpECTS += courses.at(indiv[i]).ects(); tmpECTS += courses.at(indiv[i]).ects();
std::cout << std::to_string(courses.at(indiv[i]).ects()) << " + "; //std::cout << std::to_string(courses.at(indiv[i]).ects()) << " + ";
} }
std::cout << " = " << std::to_string(tmpECTS) << std::endl; //std::cout << " = " << std::to_string(tmpECTS) << std::endl;
bool isCheckOK = false; bool isCheckOK = false;
if(tmpECTS >= this->_job.requiredECTS()) if(tmpECTS >= this->_job.requiredECTS())
isCheckOK = true; isCheckOK = true;
std::cout << "Required: " << std::to_string(this->_job.requiredECTS()); //std::cout << "Required: " << std::to_string(this->_job.requiredECTS());
double metric = (double)tmpECTS / this->_job.requiredECTS(); double metric = (double)tmpECTS / this->_job.requiredECTS();
return std::pair<bool, double>(isCheckOK, metric); return std::pair<bool, double>(isCheckOK, metric);
......
#include "repetitionConstraints.h"
#include "model/course.h"
std::pair<bool, double> ConstraintsRepetition::integrityCheck(Cursus indiv)
{
int nbOfRepetition = 0;
for(int i = 0; i < indiv.size(); i++)
{
for(int j = i+1; j < indiv.size(); j++)
{
if(indiv.at(i) == indiv.at(j))
nbOfRepetition++;
}
}
bool isOK = nbOfRepetition == 0;
double metric = 1 - ( ( (double) nbOfRepetition * 2) / (double)indiv.size() );
return std::pair<bool, double>(isOK, metric);
}
\ No newline at end of file
#ifndef SRC_MODEL_CONSTRAINTS_REPETITION_CONSTRAINTS_H_
#define SRC_MODEL_CONSTRAINTS_REPETITION_CONSTRAINTS_H_
#include <eo>
#include <utility>
#include "model/problem.h"
#include "model/profession.h"
#include "model/ea/cursus.h"
/** This class is used to verify the integrity of an individu regarding repetition of courses in the sol.
*/
class ConstraintsRepetition
{
private:
CSDVP _pb;
Profession _job;
public:
ConstraintsRepetition(const CSDVP & csdvp, const Profession & job)
: _pb(csdvp), _job(job) {}
/** Integrity check is used to investigate wheteher or not one indiv respects the constraints represented by THIS.
* Returns a std::pair. First is a boolean set to true when the indiv passes the test and therefore is compilant with the constraint, false otherwise. Second is the associated metric, mostly usable during fitness calcul.
*/
std::pair<bool, double> integrityCheck(Cursus indiv);
};
#endif //SRC_MODEL_CONSTRAINTS_REPETITION_CONSTRAINTS_H_
\ No newline at end of file
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <utility> #include <utility>
#include "competency.h" #include "competency.h"
#include "model/exception/notImplementedException.h"
/** /**
* Represents a course in an academic structure. * Represents a course in an academic structure.
......
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