Commit e1f68a3a authored by Alexis Lebis's avatar Alexis Lebis

New Profession constraints checking requirement

parent ce024b1e
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <model/constraints/ectsConstraints.h> #include <model/constraints/ectsConstraints.h>
#include <model/constraints/repetitionConstraints.h> #include <model/constraints/repetitionConstraints.h>
#include <model/constraints/professionConstraints.h>
#include <model/exception/magnitudeException.h> #include <model/exception/magnitudeException.h>
#include <model/exception/competencyEvolvingException.h> #include <model/exception/competencyEvolvingException.h>
...@@ -85,6 +86,14 @@ int main(int argc, char* argv[]){ ...@@ -85,6 +86,14 @@ int main(int argc, char* argv[]){
assert(pb.checkConfig()); assert(pb.checkConfig());
job.setRequiredECTS(4 * 6); job.setRequiredECTS(4 * 6);
Competency tmpC = pb.competencyCatalogue().at(0);
job.addPrerequisite(tmpC);
tmpC = pb.competencyCatalogue().at(1);
job.addPrerequisite(tmpC);
tmpC = Competency::build(0.5,"Wesh");
job.addPrerequisite(tmpC);
tmpC = pb.competencyCatalogue().at(8);
job.addPrerequisite(tmpC);
// ===== END PB CONFIG ===== // ===== END PB CONFIG =====
Cursus c1; Cursus c1;
...@@ -110,14 +119,16 @@ int main(int argc, char* argv[]){ ...@@ -110,14 +119,16 @@ int main(int argc, char* argv[]){
ConstraintsECTS ctrECTS(pb, job); ConstraintsECTS ctrECTS(pb, job);
ConstraintsRepetition ctrRep(pb, job); ConstraintsRepetition ctrRep(pb, job);
ConstraintsProfession ctrJob(pb, job);
std::pair<bool,double> res; 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 = ctrECTS.integrityCheck(c1);
res = ctrRep.integrityCheck(c1); //res = ctrRep.integrityCheck(c1);
res = ctrJob.integrityCheck(c1);
std::cout << "IND#" << std::to_string(i) << "\nFirst: " << res.first << "\nSecond: " << std::to_string(res.second) << std::endl; 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);
} }
......
...@@ -6,6 +6,7 @@ SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) ...@@ -6,6 +6,7 @@ SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
SET (EXERCICE_SOURCES SET (EXERCICE_SOURCES
ectsConstraints.cpp ectsConstraints.cpp
repetitionConstraints.cpp repetitionConstraints.cpp
professionConstraints.cpp
) )
ADD_LIBRARY(lCstr STATIC ${EXERCICE_SOURCES}) ADD_LIBRARY(lCstr STATIC ${EXERCICE_SOURCES})
\ No newline at end of file
#include "professionConstraints.h"
#include <string>
#include <utility>
#include "model/course.h"
#include "model/competency.h"
#include "model/tools.h"
#include "model/exception/competencyEvolvingException.h"
std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv)
{
std::vector<Competency> compToAnswer;
for(int i = 0 ; i < this->_job.prerequisites().size(); i++)
{
std::string name = this->_job.prerequisites().at(i).c_name();
compToAnswer.push_back(Competency::build(0, name)); //same name to exploit the Competency::operator== on name equality
}
Course current;
Competency currentComp;
std::pair<int, Competency> posFound;
for(int i = 0 ; i < indiv.size(); i++)
{
current = this->_pb.coursesCatalogue().at(indiv.at(i));
for(int j = 0 ; j < current.teachedCompetenciesWeighted().size() ; j++)
{
currentComp = current.teachedCompetenciesWeighted().at(j).first;
posFound = findInVector(compToAnswer, currentComp);
if(posFound.first != -1)
{
try
{
compToAnswer.at(posFound.first).evolveTowards(currentComp.magnitude());
}
catch(CompetencyEvolvingException & e) //if CEE is thrown, then magnitude has been auto rebased
{
//Should has NTD here
//compToAnswer.at(posFound.first) = e.getCompetency();
std::cout << "INFO:\n(during ConstraintsProfession)\n\n Compentecy evolution throw an exception. Auto rebase. New value is " << e.getCompetency() << std::endl;
}
}
}
}
//Now that we have evolve all the tmp competency, we compate their mag to the requirement. We count how many is not met to define the metric
int score = 0;
for(int i = 0; i < this->_job.prerequisites().size(); i++)
{
if(compToAnswer.at(i).magnitude().value() < this->_job.prerequisites().at(i).c_magnitude().value())
score++;
}
std::cout << "Score: " << std::to_string(score) << std::endl;
std::cout << "Size: " << std::to_string(compToAnswer.size()) << std::endl;
bool res = score == 0;
return std::pair<bool, double>(res, 1 - ( (double)score / (double)compToAnswer.size()));
}
\ No newline at end of file
#ifndef SRC_MODEL_CONSTRAINTS_PROFESSION_CONSTRAINTS_H_
#define SRC_MODEL_CONSTRAINTS_PROFESSION_CONSTRAINTS_H_
#include <vector>
#include <utility>
#include <eo>
#include "model/problem.h"
#include "model/profession.h"
#include "model/ea/cursus.h"
/**
* This class is used to verify the constraints regarding the profession expected by the student
* It mostly consist in *version 1* to check if all the prerequisites have been answered.
*/
class ConstraintsProfession
{
private:
CSDVP _pb;
Profession _job;
public:
ConstraintsProfession(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.
* @todo Decay competency magnitude
*/
std::pair<bool, double> integrityCheck(Cursus indiv);
};
#endif // SRC_MODEL_CONSTRAINTS_PROFESSION_CONSTRAINTS_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