Commit 8706ae03 authored by Alexis Lebis's avatar Alexis Lebis

Adding decay for competency.

The competency's decay here is somewhat more stronger than the previous implementation in JAVA and Prolog, since a compentecy always decays.
parent 1ad04219
...@@ -76,7 +76,8 @@ int main(int argc, char* argv[]){ ...@@ -76,7 +76,8 @@ int main(int argc, char* argv[]){
double PCROSS = parser.createParam((double)(0.5), "pCross", "crossover 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 NBGEN = parser.createParam((unsigned int)(100), "nbGen", "Number of generation",'G',"Param").value();
unsigned int SIZET = parser.createParam((unsigned int)(7), "sizeT", "Tournament Size",'F',"Param").value(); unsigned int SIZET = parser.createParam((unsigned int)(7), "sizeT", "Tournament Size",'F',"Param").value();
RATIO_RANDOM_VS_BEST = parser.createParam((unsigned int)(75), "ratioBest", "Ratio between full random and best while prereq check fails in mutation",'B',"Param").value();
// ===== PB CONFIG ZONE ===== // ===== PB CONFIG ZONE =====
CSDVP pb; CSDVP pb;
Profession job; Profession job;
...@@ -264,6 +265,7 @@ int main(int argc, char* argv[]){ ...@@ -264,6 +265,7 @@ int main(int argc, char* argv[]){
std::cout << pb.coursesCatalogue().at(i) << std::endl; std::cout << pb.coursesCatalogue().at(i) << std::endl;
} }
*/ */
std::cout << job << std::endl;
// ======================== TEST ZONE END======================== // ======================== TEST ZONE END========================
......
...@@ -61,7 +61,7 @@ Competency Competency::buildTMP(double d, std::string name) ...@@ -61,7 +61,7 @@ Competency Competency::buildTMP(double d, std::string name)
// === CONSTRUCTOR // === CONSTRUCTOR
Competency::Competency(int id, Magnitude m, std::string s) Competency::Competency(int id, Magnitude m, std::string s)
: _id(id), _m(m), _undecayedMag(m), _name(s) : _id(id), _m(m), _undecayedMag(m), _name(s), _howLongDecaying(0), _isDecaying(false)
{ {
} }
...@@ -124,17 +124,22 @@ double Competency::decay() ...@@ -124,17 +124,22 @@ double Competency::decay()
{ {
if(!this->_isDecaying) if(!this->_isDecaying)
return this->_m.value(); return this->_m.value();
try
{
this->evolveTowards((-1) * DecayEngine::defaultDecay(this->_howLongDecaying));
}
catch(CompetencyEvolvingException & e)
{
//NTD
}
return this->_m.value(); double val = this->_m.value();
val -= DecayEngine::defaultDecay(this->_howLongDecaying);
//std::cout << "before:" << this->_m.value() << " vs. after: " << val << std::endl;
return val < 0 ? 0 : val > 1 ? 1 : val;
}
void Competency::saveDecay()
{
double val = this->decay();
//std::cout << "inS&D:" << val << std::endl;
this->_howLongDecaying = 0;
this->_isDecaying = false;
this->_m.set(val);
} }
// === OPERATOR // === OPERATOR
......
...@@ -79,8 +79,13 @@ class Competency ...@@ -79,8 +79,13 @@ class Competency
void resetDecay(){this->_isDecaying = false; this->_howLongDecaying = 0;} void resetDecay(){this->_isDecaying = false; this->_howLongDecaying = 0;}
void setTimeDecay(unsigned int time){this->_howLongDecaying = time;} void setTimeDecay(unsigned int time){this->_howLongDecaying = time;}
Magnitude getUndecayedMagnitude(){return this->_undecayedMag;} Magnitude getUndecayedMagnitude(){return this->_undecayedMag;}
/**Returns the new magnitude of this affected by the current competency's decay.
* Note that the decay **IS NOT** saved in the magnitude. Use saveDecay instead.
*/
double decay(); double decay();
double decayAndReset(){this->decay(); this->resetDecay(); return this->_m.value();} /** Save the new magnitude value according to the decay of this. The function reset the decay of this by setting it to FALSE. Therefore, the decay restart to 0.
*/
void saveDecay();
// === OPERATOR // === OPERATOR
/// A competency is equal to another iff their id are the same, or their name /// A competency is equal to another iff their id are the same, or their name
......
...@@ -46,6 +46,7 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -46,6 +46,7 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
{ {
// HERE, VARIABLE DECAY CAN BE APPLIED!!!!!!!! // HERE, VARIABLE DECAY CAN BE APPLIED!!!!!!!!
compByTF.at(currentTF).push_back(compByTF.at(currentTF-1).at(j)); compByTF.at(currentTF).push_back(compByTF.at(currentTF-1).at(j));
compByTF.at(currentTF).at(compByTF.at(currentTF).size()-1).increaseDecay();
} }
// Then, we explore the current TF for new Comp // Then, we explore the current TF for new Comp
...@@ -83,6 +84,7 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -83,6 +84,7 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
//std::cout << currentCompetency.c_name() << " already exists" <<std::endl; //std::cout << currentCompetency.c_name() << " already exists" <<std::endl;
try try
{ {
compByTF.at(currentTF).at(alreadyExists.first).saveDecay();
compByTF.at(currentTF).at(alreadyExists.first).evolveTowards(currentCompetency.magnitude()); compByTF.at(currentTF).at(alreadyExists.first).evolveTowards(currentCompetency.magnitude());
} }
catch(CompetencyEvolvingException & e) //if CEE is thrown, then magnitude has been auto rebased catch(CompetencyEvolvingException & e) //if CEE is thrown, then magnitude has been auto rebased
...@@ -101,15 +103,15 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -101,15 +103,15 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
} }
} }
//std::cout << "==EXPLORING COMP BY TF" << std::endl; // //std::cout << "==EXPLORING COMP BY TF" << std::endl;
for(int i = 0; i < compByTF.size(); i++) // for(int i = 0; i < compByTF.size(); i++)
{ // {
//std::cout << "TF#" << std::to_string(i) << std::endl; // //std::cout << "TF#" << std::to_string(i) << std::endl;
for(int j = 0; j < compByTF.at(i).size() ; j++) // for(int j = 0; j < compByTF.at(i).size() ; j++)
{ // {
//std::cout << compByTF.at(i).at(j) << std::endl; // //std::cout << compByTF.at(i).at(j) << std::endl;
} // }
} // }
bool isOK = ((notFound == 0) && (notRespected == 0)); bool isOK = ((notFound == 0) && (notRespected == 0));
/* /*
...@@ -156,7 +158,7 @@ std::pair<int, int> ConstraintsPrerequisites::_prereqsInPreviousTF(std::vector<C ...@@ -156,7 +158,7 @@ std::pair<int, int> ConstraintsPrerequisites::_prereqsInPreviousTF(std::vector<C
if(prereqs.at(i)==cInTF.at(j)) if(prereqs.at(i)==cInTF.at(j))
{ {
found = true; found = true;
if(prereqs.at(i).c_magnitude().value() > cInTF.at(j).c_magnitude().value()) if(prereqs.at(i).c_magnitude().value() > cInTF.at(j).decay())
notRespected++; notRespected++;
} }
} }
......
...@@ -23,10 +23,24 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv) ...@@ -23,10 +23,24 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv)
Competency currentComp; Competency currentComp;
std::pair<int, Competency> posFound; std::pair<int, Competency> posFound;
bool changedTF = false;
int currentTF = 0;
for(int i = 0 ; i < indiv.size(); i++) for(int i = 0 ; i < indiv.size(); i++)
{ {
current = this->_pb.coursesCatalogue().at(indiv.at(i)); current = this->_pb.coursesCatalogue().at(indiv.at(i));
if(currentTF != i / this->_pb.cfg_pickedCoursesByTimeFrame())
changedTF = true;
else
changedTF = false;
currentTF = i / this->_pb.cfg_pickedCoursesByTimeFrame();
for(int j = 0; j < compToAnswer.size(); j++)
{
compToAnswer.at(j).increaseDecay();
}
for(int j = 0 ; j < current.teachedCompetenciesWeighted().size() ; j++) for(int j = 0 ; j < current.teachedCompetenciesWeighted().size() ; j++)
{ {
currentComp = current.teachedCompetenciesWeighted().at(j).first; currentComp = current.teachedCompetenciesWeighted().at(j).first;
...@@ -36,6 +50,7 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv) ...@@ -36,6 +50,7 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv)
{ {
try try
{ {
compToAnswer.at(posFound.first).saveDecay();
compToAnswer.at(posFound.first).evolveTowards(currentComp.magnitude()); compToAnswer.at(posFound.first).evolveTowards(currentComp.magnitude());
} }
catch(CompetencyEvolvingException & e) //if CEE is thrown, then magnitude has been auto rebased catch(CompetencyEvolvingException & e) //if CEE is thrown, then magnitude has been auto rebased
...@@ -48,6 +63,12 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv) ...@@ -48,6 +63,12 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv)
} }
} }
for(int i = 0; i < compToAnswer.size(); i++)
{
compToAnswer.at(i).saveDecay();
//std::cout << compToAnswer.at(i) << 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 //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; int score = 0;
......
...@@ -20,7 +20,6 @@ template <class EOT> ...@@ -20,7 +20,6 @@ template <class EOT>
class mutCSDVP: public eoMonOp<EOT> class mutCSDVP: public eoMonOp<EOT>
{ {
public: public:
mutCSDVP(CSDVP& _pb, ConstraintsRepetition& _ctr):pb(_pb),ctr(_ctr){} mutCSDVP(CSDVP& _pb, ConstraintsRepetition& _ctr):pb(_pb),ctr(_ctr){}
//_CourseID subastraction from _chrom //_CourseID subastraction from _chrom
...@@ -178,9 +177,9 @@ class mutCSDVP: public eoMonOp<EOT> ...@@ -178,9 +177,9 @@ class mutCSDVP: public eoMonOp<EOT>
std::random_shuffle(gfiCourse.begin(), gfiCourse.end()); std::random_shuffle(gfiCourse.begin(), gfiCourse.end());
_chrom[rngCourseToSwap] = pb.mapCourseToPosition(gfiCourse.at(0)); _chrom[rngCourseToSwap] = pb.mapCourseToPosition(gfiCourse.at(0));
} }
else //least constraint courses in 60% of the cases, otherwise full rand else //least constraint courses in 25% of the cases, otherwise full rand
{ {
if(eo::rng.random(100) > 60) if(eo::rng.random(100) > RATIO_RANDOM_VS_BEST)
{ {
fbBestCourse = coursesOfTF.at(0); fbBestCourse = coursesOfTF.at(0);
for(i = 1; i < coursesOfTF.size(); i++) for(i = 1; i < coursesOfTF.size(); i++)
...@@ -228,9 +227,26 @@ class mutCSDVP: public eoMonOp<EOT> ...@@ -228,9 +227,26 @@ class mutCSDVP: public eoMonOp<EOT>
bool addStatus = false; bool addStatus = false;
int pos=0; int pos=0;
bool changedTF = false;
int currentTF = 0;
for(int i = 0; i < _chrom.size() && (i / nbCbyTF < TF); i++) for(int i = 0; i < _chrom.size() && (i / nbCbyTF < TF); i++)
{ {
currentCourse = catalogue.at(_chrom.at(i)); currentCourse = catalogue.at(_chrom.at(i));
if(currentTF != i / nbCbyTF)
changedTF = true;
else
changedTF = false;
currentTF = i / nbCbyTF;
if(changedTF) //if we have changed of tf, lets improve decay for all comp
{
for(int j = 0; j < tmpCourse.prerequisites().size(); j++)
{
tmpCourse.unlocked_prerequisites().at(j).increaseDecay();
}
}
for(int j = 0; j < currentCourse.teachedCompetenciesWeighted().size(); j++) for(int j = 0; j < currentCourse.teachedCompetenciesWeighted().size(); j++)
{ {
...@@ -246,7 +262,7 @@ class mutCSDVP: public eoMonOp<EOT> ...@@ -246,7 +262,7 @@ class mutCSDVP: public eoMonOp<EOT>
try try
{ {
Magnitude mag = currentCourse.teachedCompetenciesWeighted().at(j).first.c_magnitude(); Magnitude mag = currentCourse.teachedCompetenciesWeighted().at(j).first.c_magnitude();
//tmpCourse.unlocked_prerequisites().at(pos).saveDecay();
tmpCourse.unlocked_prerequisites().at(pos).evolveTowards(mag); tmpCourse.unlocked_prerequisites().at(pos).evolveTowards(mag);
} }
catch(CompetencyEvolvingException & e) catch(CompetencyEvolvingException & e)
...@@ -259,6 +275,9 @@ class mutCSDVP: public eoMonOp<EOT> ...@@ -259,6 +275,9 @@ class mutCSDVP: public eoMonOp<EOT>
} }
compStatus = tmpCourse.prerequisites(); compStatus = tmpCourse.prerequisites();
for(int i = 0; i < compStatus.size(); i++)
compStatus.at(i).saveDecay();
return compStatus; return compStatus;
} }
...@@ -287,7 +306,7 @@ class mutCSDVP: public eoMonOp<EOT> ...@@ -287,7 +306,7 @@ class mutCSDVP: public eoMonOp<EOT>
{ {
if(checkCmp == state.at(itState)) if(checkCmp == state.at(itState))
{ {
if(checkCmp.c_magnitude().value() > state.at(itState).c_magnitude().value()) if(checkCmp.c_magnitude().value() > state.at(itState).decay())
{ stop = true; found = false; } { stop = true; found = false; }
else else
{ stop = true; found = true; } { stop = true; found = true; }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
static const int ID_RANGE_FOR_OBJECT = 10000; static const int ID_RANGE_FOR_OBJECT = 10000;
static const int ID_RANGE_FOR_TEMPORARY_OBJECT = std::numeric_limits<int>::max(); static const int ID_RANGE_FOR_TEMPORARY_OBJECT = std::numeric_limits<int>::max();
static unsigned int RATIO_RANDOM_VS_BEST;
template<typename T> template<typename T>
/** Searches into vec the element findMe. The class T must have T() defined ( T()=default; is OK) */ /** Searches into vec the element findMe. The class T must have T() defined ( T()=default; is OK) */
......
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