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,6 +76,7 @@ int main(int argc, char* argv[]){
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 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 =====
CSDVP pb;
......@@ -264,6 +265,7 @@ int main(int argc, char* argv[]){
std::cout << pb.coursesCatalogue().at(i) << std::endl;
}
*/
std::cout << job << std::endl;
// ======================== TEST ZONE END========================
......
......@@ -61,7 +61,7 @@ Competency Competency::buildTMP(double d, std::string name)
// === CONSTRUCTOR
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)
{
}
......@@ -125,16 +125,21 @@ double Competency::decay()
if(!this->_isDecaying)
return this->_m.value();
try
{
this->evolveTowards((-1) * DecayEngine::defaultDecay(this->_howLongDecaying));
}
catch(CompetencyEvolvingException & e)
{
//NTD
}
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);
return this->_m.value();
}
// === OPERATOR
......
......@@ -79,8 +79,13 @@ class Competency
void resetDecay(){this->_isDecaying = false; this->_howLongDecaying = 0;}
void setTimeDecay(unsigned int time){this->_howLongDecaying = time;}
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 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
/// 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)
{
// HERE, VARIABLE DECAY CAN BE APPLIED!!!!!!!!
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
......@@ -83,6 +84,7 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
//std::cout << currentCompetency.c_name() << " already exists" <<std::endl;
try
{
compByTF.at(currentTF).at(alreadyExists.first).saveDecay();
compByTF.at(currentTF).at(alreadyExists.first).evolveTowards(currentCompetency.magnitude());
}
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)
}
}
//std::cout << "==EXPLORING COMP BY TF" << std::endl;
for(int i = 0; i < compByTF.size(); i++)
{
//std::cout << "TF#" << std::to_string(i) << std::endl;
for(int j = 0; j < compByTF.at(i).size() ; j++)
{
//std::cout << compByTF.at(i).at(j) << std::endl;
}
}
// //std::cout << "==EXPLORING COMP BY TF" << std::endl;
// for(int i = 0; i < compByTF.size(); i++)
// {
// //std::cout << "TF#" << std::to_string(i) << std::endl;
// for(int j = 0; j < compByTF.at(i).size() ; j++)
// {
// //std::cout << compByTF.at(i).at(j) << std::endl;
// }
// }
bool isOK = ((notFound == 0) && (notRespected == 0));
/*
......@@ -156,7 +158,7 @@ std::pair<int, int> ConstraintsPrerequisites::_prereqsInPreviousTF(std::vector<C
if(prereqs.at(i)==cInTF.at(j))
{
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++;
}
}
......
......@@ -23,10 +23,24 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv)
Competency currentComp;
std::pair<int, Competency> posFound;
bool changedTF = false;
int currentTF = 0;
for(int i = 0 ; i < indiv.size(); 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++)
{
currentComp = current.teachedCompetenciesWeighted().at(j).first;
......@@ -36,6 +50,7 @@ std::pair<bool, double> ConstraintsProfession::integrityCheck(Cursus indiv)
{
try
{
compToAnswer.at(posFound.first).saveDecay();
compToAnswer.at(posFound.first).evolveTowards(currentComp.magnitude());
}
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)
}
}
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
int score = 0;
......
......@@ -20,7 +20,6 @@ template <class EOT>
class mutCSDVP: public eoMonOp<EOT>
{
public:
mutCSDVP(CSDVP& _pb, ConstraintsRepetition& _ctr):pb(_pb),ctr(_ctr){}
//_CourseID subastraction from _chrom
......@@ -178,9 +177,9 @@ class mutCSDVP: public eoMonOp<EOT>
std::random_shuffle(gfiCourse.begin(), gfiCourse.end());
_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);
for(i = 1; i < coursesOfTF.size(); i++)
......@@ -228,10 +227,27 @@ class mutCSDVP: public eoMonOp<EOT>
bool addStatus = false;
int pos=0;
bool changedTF = false;
int currentTF = 0;
for(int i = 0; i < _chrom.size() && (i / nbCbyTF < TF); 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++)
{
tmpComp = currentCourse.teachedCompetenciesWeighted().at(j).first;
......@@ -246,7 +262,7 @@ class mutCSDVP: public eoMonOp<EOT>
try
{
Magnitude mag = currentCourse.teachedCompetenciesWeighted().at(j).first.c_magnitude();
//tmpCourse.unlocked_prerequisites().at(pos).saveDecay();
tmpCourse.unlocked_prerequisites().at(pos).evolveTowards(mag);
}
catch(CompetencyEvolvingException & e)
......@@ -259,6 +275,9 @@ class mutCSDVP: public eoMonOp<EOT>
}
compStatus = tmpCourse.prerequisites();
for(int i = 0; i < compStatus.size(); i++)
compStatus.at(i).saveDecay();
return compStatus;
}
......@@ -287,7 +306,7 @@ class mutCSDVP: public eoMonOp<EOT>
{
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; }
else
{ stop = true; found = true; }
......
......@@ -10,6 +10,7 @@
static const int ID_RANGE_FOR_OBJECT = 10000;
static const int ID_RANGE_FOR_TEMPORARY_OBJECT = std::numeric_limits<int>::max();
static unsigned int RATIO_RANDOM_VS_BEST;
template<typename T>
/** 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