Commit 01e1c03c authored by Alexis Lebis's avatar Alexis Lebis

Implemented continue metric. Weird behavior!

parent d14eaec3
...@@ -70,6 +70,9 @@ int main(int argc, char* argv[]){ ...@@ -70,6 +70,9 @@ int main(int argc, char* argv[]){
CursusEval::WEIGHT_PREREQ = parser.createParam((double)(1.0), "wPrereq", "Weight of prerequisites in the fitness value", 'W', "Param").value(); CursusEval::WEIGHT_PREREQ = parser.createParam((double)(1.0), "wPrereq", "Weight of prerequisites in the fitness value", 'W', "Param").value();
DecayEngine::IS_DECAY_DEACTIVATED = parser.createParam((int)(0), "decayDeactivated", "Wether or not the decay is deactivated", 'D', "Param").value(); DecayEngine::IS_DECAY_DEACTIVATED = parser.createParam((int)(0), "decayDeactivated", "Wether or not the decay is deactivated", 'D', "Param").value();
ConstraintsProfession::DISCRETE_METRIC = parser.createParam((unsigned int)(1), "jobEvalDiscrete" , "What type of metric to use between discret and continue with mag", 'k', "Param").value();
ConstraintsPrerequisites::DISCRETE_METRIC = parser.createParam((unsigned int)(1), "prqEvalDiscrete" , "What type of metric to use between discret and continue with mag", 'K', "Param").value();
//PROFESSION PARAMETERS //PROFESSION PARAMETERS
unsigned int JOB_SEED = parser.createParam((unsigned int)(7777), "jobSeed", "Seed used for the Profession", 'g', "Param").value(); unsigned int JOB_SEED = parser.createParam((unsigned int)(7777), "jobSeed", "Seed used for the Profession", 'g', "Param").value();
unsigned int JOB_MINPRE = parser.createParam((unsigned int)(2), "jobMinPre" , "minimum competency prerequisite by a job", 'j', "Param").value(); unsigned int JOB_MINPRE = parser.createParam((unsigned int)(2), "jobMinPre" , "minimum competency prerequisite by a job", 'j', "Param").value();
...@@ -77,7 +80,7 @@ int main(int argc, char* argv[]){ ...@@ -77,7 +80,7 @@ int main(int argc, char* argv[]){
double JOB_MINMAG = parser.createParam((double)(0.5), "jobMinMag" , "miminal magnitude for a job" , 'h', "Param").value(); double JOB_MINMAG = parser.createParam((double)(0.5), "jobMinMag" , "miminal magnitude for a job" , 'h', "Param").value();
double JOB_MAXMAG = parser.createParam((double)(0.95), "jobMaxMag" , "maxima magnitude for a job" , 'H', "Param").value(); double JOB_MAXMAG = parser.createParam((double)(0.95), "jobMaxMag" , "maxima magnitude for a job" , 'H', "Param").value();
Profession::JOB_SELECTION_TYPE = parser.createParam((unsigned int)(0), "jobSelectType" , "Which type to use to select job", 'z', "Param").value(); Profession::JOB_SELECTION_TYPE = parser.createParam((unsigned int)(0), "jobSelectType" , "Which type to use to select job", 'z', "Param").value();
Profession::JOB_EVAL_DISCRETE = parser.createParam((unsigned int)(1), "jobEvalDiscrete" , "What type of metric to use between discret and continue with mag", 'Z', "Param").value();
//EVOLUTION ENGINE PARAMETERS //EVOLUTION ENGINE PARAMETERS
unsigned int POPSIZE = parser.createParam((unsigned int)(100), "popSize", "Population size", 'P', "Evolution Engine").value(); 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 PMUT = parser.createParam((double)(0.5), "pMut", "mutation rate", 'x', "Evolution Engine").value();
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <tuple>
#include "model/course.h" #include "model/course.h"
#include "model/competency.h" #include "model/competency.h"
...@@ -9,6 +10,8 @@ ...@@ -9,6 +10,8 @@
#include "model/exception/competencyEvolvingException.h" #include "model/exception/competencyEvolvingException.h"
int ConstraintsPrerequisites::DISCRETE_METRIC = 1;
std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
{ {
int currentTF = 0; int currentTF = 0;
...@@ -17,12 +20,17 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -17,12 +20,17 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
int score = 0; int score = 0;
int nbPrereq = 0; int nbPrereq = 0;
int magDivisor = 0;
double magDiff = 0;
//Each comp availble at a specific TF. Decay can be applied between i and i+1 //Each comp availble at a specific TF. Decay can be applied between i and i+1
std::vector<std::vector<Competency>> compByTF(this->_pb.timeFrames().size()); std::vector<std::vector<Competency>> compByTF(this->_pb.timeFrames().size());
Course currentCourse; Course currentCourse;
Competency currentCompetency; Competency currentCompetency;
std::pair<int, int> prereqFound; prereqFound.first = 0; prereqFound.second = 0; std::tuple<int, int, double, int> prereqFound;
std::get<0>(prereqFound) = 0; std::get<1>(prereqFound) = 0;
std::get<2>(prereqFound) = 0; std::get<3>(prereqFound) = 0;
std::pair<int, Competency> alreadyExists; std::pair<int, Competency> alreadyExists;
bool changedTF = false; bool changedTF = false;
...@@ -67,8 +75,10 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -67,8 +75,10 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
{ {
prereqFound = this->_prereqsInPreviousTF(std::vector<Competency>(0), currentCourse.prerequisites()); prereqFound = this->_prereqsInPreviousTF(std::vector<Competency>(0), currentCourse.prerequisites());
} }
notFound += prereqFound.first; notFound += std::get<0>(prereqFound);
notRespected += prereqFound.second; notRespected += std::get<1>(prereqFound);
magDiff += std::get<2>(prereqFound);
magDivisor += std::get<3>(prereqFound);
// Handling teached comp // Handling teached comp
...@@ -120,6 +130,13 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -120,6 +130,13 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
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;
*/ */
switch (ConstraintsPrerequisites::DISCRETE_METRIC)
{
case 0/* constant-expression */:
std::cout << "MagDiff: " << magDiff << " for " << (double)magDivisor << " prereqs. (1 - " << ( magDiff / (double)magDivisor ) << std::endl;
assert(magDivisor != 0);
return std::pair<bool, double>(isOK, 1 - ( magDiff / (double)magDivisor ) );
default:
double metric = 0; double metric = 0;
if(nbPrereq > 0) if(nbPrereq > 0)
{ {
...@@ -135,16 +152,20 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -135,16 +152,20 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
//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);
}
} }
std::pair<int, int> ConstraintsPrerequisites::_prereqsInPreviousTF(std::vector<Competency> cInTF, std::vector<Competency> prereqs) std::tuple<int, int, double, int> ConstraintsPrerequisites::_prereqsInPreviousTF(std::vector<Competency> cInTF, std::vector<Competency> prereqs)
{ {
int notFound = 0; int notFound = 0;
int notRespected = 0; int notRespected = 0;
int nbFound = 0;
bool found = false; bool found = false;
double magDiff = 0;
int divisor = 0;
if(cInTF.size() == 0) //if empty, we'll find nothing if(cInTF.size() == 0) //if empty, we'll find nothing
return std::pair<int, int>(prereqs.size(), 0); return std::tuple<int, int, double, int>(prereqs.size(), 0, magDiff, divisor);
for(int i = 0; i < prereqs.size(); i++) for(int i = 0; i < prereqs.size(); i++)
{ {
...@@ -157,15 +178,22 @@ std::pair<int, int> ConstraintsPrerequisites::_prereqsInPreviousTF(std::vector<C ...@@ -157,15 +178,22 @@ std::pair<int, int> ConstraintsPrerequisites::_prereqsInPreviousTF(std::vector<C
if(prereqs.at(i)==cInTF.at(j)) if(prereqs.at(i)==cInTF.at(j))
{ {
nbFound++;
found = true; found = true;
if(prereqs.at(i).c_magnitude().value() > cInTF.at(j).decay()) if(prereqs.at(i).c_magnitude().value() > cInTF.at(j).decay())
{
notRespected++; notRespected++;
magDiff += ( prereqs.at(i).c_magnitude().value() - cInTF.at(j).decay() ) / prereqs.at(i).c_magnitude().value();
std::cout << "\tMag diff: " << prereqs.at(i).c_magnitude().value() - cInTF.at(j).decay() << "\t Ratio:" << magDiff << std::endl;
}
} }
} }
if(!found) if(!found)
notFound++; notFound++;
} }
divisor = (notFound + nbFound);
//std::cout << "NF: " << std::to_string(notFound) << " | NR: " << std::to_string(notRespected) << std::endl; //std::cout << "NF: " << std::to_string(notFound) << " | NR: " << std::to_string(notRespected) << std::endl;
return std::pair<int, int>(notFound, notRespected); return std::tuple<int, int, double, int>(notFound, notRespected, magDiff, divisor);
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <vector> #include <vector>
#include <utility> #include <utility>
#include <tuple>
#include <eo> #include <eo>
...@@ -25,11 +26,15 @@ class ConstraintsPrerequisites ...@@ -25,11 +26,15 @@ class ConstraintsPrerequisites
/** /**
* Checks the prerequisites prereqs in the competencies cInTF (generally, the competencies from the previous TF). * Checks the prerequisites prereqs in the competencies cInTF (generally, the competencies from the previous TF).
* It returns a std::pair, where the first element indicates how many prerequisites HAS NOT BEEN FOUND. * It returns a std::tuple, where the first element indicates how many prerequisites HAS NOT BEEN FOUND.
* The second elements indicates how many prerequisites has not enought mastery (BUT EXISTS in cInTF!) * The second elements indicates how many prerequisites has not enought mastery (BUT EXISTS in cInTF!)
* The third element is the continous metric calculated accordingly the difference of mag between cours prereqs and comp mag
* The fourth element is to be used to divide the third one (how many elements contributed to establish the mag diff)
*/ */
std::pair<int,int> _prereqsInPreviousTF(std::vector<Competency> cInTF, std::vector<Competency> prereqs); std::tuple<int,int, double, int> _prereqsInPreviousTF(std::vector<Competency> cInTF, std::vector<Competency> prereqs);
public: public:
static int DISCRETE_METRIC;
ConstraintsPrerequisites(const CSDVP & csdvp, const Profession & job) ConstraintsPrerequisites(const CSDVP & csdvp, const Profession & job)
: _pb(csdvp), _job(job) {} : _pb(csdvp), _job(job) {}
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "model/exception/competencyEvolvingException.h" #include "model/exception/competencyEvolvingException.h"
int ConstraintsProfession::DISCRETE_METRIC = 1;
std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv) std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv)
{ {
std::vector<Competency> compToAnswer; std::vector<Competency> compToAnswer;
...@@ -87,7 +89,7 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv) ...@@ -87,7 +89,7 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv)
//std::cout << "Size: " << std::to_string(compToAnswer.size()) << std::endl; //std::cout << "Size: " << std::to_string(compToAnswer.size()) << std::endl;
bool res = score == 0; bool res = score == 0;
switch (Profession::JOB_EVAL_DISCRETE) //whether we use discrete or continue metrics switch (ConstraintsProfession::DISCRETE_METRIC) //whether we use discrete or continue metrics
{ {
case 0: case 0:
return std::pair<bool, double>(res, 1 - ( magDiff / (double)compToAnswer.size() ) ); return std::pair<bool, double>(res, 1 - ( magDiff / (double)compToAnswer.size() ) );
......
...@@ -22,6 +22,8 @@ class ConstraintsProfession ...@@ -22,6 +22,8 @@ class ConstraintsProfession
Profession _job; Profession _job;
public: public:
static int DISCRETE_METRIC;
ConstraintsProfession(const CSDVP & csdvp, const Profession & job) ConstraintsProfession(const CSDVP & csdvp, const Profession & job)
: _pb(csdvp), _job(job) {} : _pb(csdvp), _job(job) {}
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
int Profession::PROFESSION_COUNTER = 0; int Profession::PROFESSION_COUNTER = 0;
unsigned int Profession::JOB_SELECTION_TYPE = 0; unsigned int Profession::JOB_SELECTION_TYPE = 0;
unsigned int Profession::JOB_EVAL_DISCRETE = 1;
// === FACTORY // === FACTORY
// No factory needed // No factory needed
......
...@@ -49,7 +49,6 @@ class Profession ...@@ -49,7 +49,6 @@ class Profession
public: public:
static unsigned int JOB_SELECTION_TYPE; static unsigned int JOB_SELECTION_TYPE;
static unsigned int JOB_EVAL_DISCRETE;
enum GenerationType enum GenerationType
{ {
......
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