Commit 4cc8a0e0 authored by Alexis Lebis's avatar Alexis Lebis

debugged integrityCheck

parent d2eb097f
...@@ -464,6 +464,8 @@ int main(int argc, char* argv[]){ ...@@ -464,6 +464,8 @@ int main(int argc, char* argv[]){
std::cout << " | value: " << resPrq.second << std::endl; std::cout << " | value: " << resPrq.second << std::endl;
std::cout << "===============" << std::endl; std::cout << "===============" << std::endl;
ctrPrq._displayDecayedArrays(pop.best_element());
} }
// ================================= END RUN ZONE =============================== // ================================= END RUN ZONE ===============================
......
#include "prerequisitesConstraints.h" #include "prerequisitesConstraints.h"
#include <iomanip>
#include <string> #include <string>
#include <utility> #include <utility>
#include <tuple> #include <tuple>
...@@ -243,17 +244,15 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -243,17 +244,15 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
// === sum for t of all t-i // === sum for t of all t-i
for(int i = 1; i < this->_pb.timeFrames().size() ; i++) for(int i = 1; i < this->_pb.timeFrames().size() ; i++)
{
for(int j = 0; j < i; j++)
{ {
for(int k = 0; k < this->_pb.competencyCatalogue().size() ; k++) for(int k = 0; k < this->_pb.competencyCatalogue().size() ; k++)
{ {
compDistribyTF.at(i).at(k) += compDistribyTF.at(j).at(k); compDistribyTF.at(i).at(k) += compDistribyTF.at(i-1).at(k);
// if(compDistribyTF.at(i).at(k) > 1) //commented because decay
// if(compDistribyTF.at(i).at(k) > 1) //commented because decay ! warning it will make subsequent delta equal !! need to create a new tmp array
// compDistribyTF.at(i).at(k) = 1; // compDistribyTF.at(i).at(k) = 1;
} }
} }
}
// === apply decay // === apply decay
std::vector<double> tmpDiff; std::vector<double> tmpDiff;
...@@ -263,25 +262,26 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -263,25 +262,26 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
for(int i = 1; i < compDistribyTF.size(); i++) //starts to 1 because 0 does not have decay for(int i = 1; i < compDistribyTF.size(); i++) //starts to 1 because 0 does not have decay
{ {
for(int j = 0; j < compDistribyTF.at(0).size(); j++) //0 because we do not care which, they all have the same size == this->_pb.competencyCatalogue().size() for(int j = 0; j < compDistribyTF.at(0).size(); j++) //cDTF[0] because we do not care which, they all have the same size == this->_pb.competencyCatalogue().size()
{ {
decayVal = 0; delta = 0; decayed = 0; decayVal = 0; delta = 0; decayed = 0;
tmpDiff.push_back(compDistribyTF.at(i).at(j) - compDistribyTF.at(i-1).at(j)); // storing the delta of the mag in i-1 ; i
delta = compDistribyTF.at(i).at(j) - compDistribyTF.at(i-1).at(j);
if(compDistribyTF.at(i).at(j) - compDistribyTF.at(i-1).at(j) == 0) //if 0->comp stagnation therefore decay if(delta == 0) //if 0 -->comp not mobilized here, thus stagnation therefore decay for the jth comp
{ {
decayClock.at(j)++; decayClock.at(j)++;
} }
else else
{ {
if(decayClock.at(j)>0) if(decayClock.at(j)>0) //if there is decay
{ {
decayVal = DecayEngine::defaultDecay(decayClock.at(j)); decayVal = DecayEngine::defaultDecay(decayClock.at(j));
decaynb++; decaynb++;
} }
// storing the delta of the mag in i-1 ; i
delta = compDistribyTF.at(i).at(j) - compDistribyTF.at(i-1).at(j); //delta = compDistribyTF.at(i).at(j) - compDistribyTF.at(i-1).at(j);
decayed = compDistribyTF.at(i-1).at(j) - decayVal; decayed = compDistribyTF.at(i-1).at(j) - decayVal;
...@@ -296,6 +296,9 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -296,6 +296,9 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
for(int k = i+1 ; k < compDistribyTF.size(); k++) for(int k = i+1 ; k < compDistribyTF.size(); k++)
{ {
compDistribyTF.at(k).at(j) -= decayVal; compDistribyTF.at(k).at(j) -= decayVal;
if(compDistribyTF.at(k).at(j) < 0)
compDistribyTF.at(k).at(j) = 0;
} }
} }
...@@ -371,3 +374,150 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv) ...@@ -371,3 +374,150 @@ std::pair<bool, double> ConstraintsPrerequisites::integrityCheck(Cursus indiv)
return std::pair<bool, double>(isOK, metric); return std::pair<bool, double>(isOK, metric);
} }
} }
void ConstraintsPrerequisites::_displayDecayedArrays(Cursus indiv)
{
std::pair<bool, double> res;
std::vector<std::vector<double>> compDistribyTF; //each i contains an vector representing the magnitique of each comp existing, according to the path followed. [0;1]
// === init
for(unsigned int i = 0; i < this->_pb.timeFrames().size(); i++)
{
std::vector<double> tmp;
for(unsigned int j = 0; j < this->_pb.competencyCatalogue().size(); j++)
{
tmp.push_back(0);
}
compDistribyTF.push_back(tmp);
}
// === fill each double vector of each tf according to comp seen
int currentTF = 0;
Course currentCourse;
std::vector<std::pair<Competency, double>> teachedComps;
unsigned int idx;
for(int i = 0; i < indiv.size(); i++)
{
currentTF = i / this->_pb.cfg_pickedCoursesByTimeFrame();
currentCourse = this->_pb.coursesCatalogue().at(indiv.at(i));
teachedComps = currentCourse.teachedCompetenciesWeighted();
for(int j = 0; j < teachedComps.size(); j++)
{
idx = this->_pb.mapCompToPosition(teachedComps.at(j).first);
assert(idx >= 0);
compDistribyTF.at(currentTF).at(idx) += teachedComps.at(j).first.magnitude().value();
if(compDistribyTF.at(currentTF).at(idx) > 1) //can't exceed 1 in a signle TF
compDistribyTF.at(currentTF).at(idx) = 1;
}
}
// === Comp by TF display section
std::cout << "\n* Competency value by TF" << std::endl;
for(int i = 0 ; i < compDistribyTF.size(); i++)
{
std::cout << "TF#" << i << ": [";
for(int j = 0; j < compDistribyTF.at(i).size()-1; j++)
{
std::cout << std::setprecision(3) << compDistribyTF.at(i).at(j) << ";\t";
}
std::cout << compDistribyTF.at(i).at(compDistribyTF.at(i).size()-1) << "]" << std::endl;
}
// === sum for t of all t-i
for(int i = 1; i < this->_pb.timeFrames().size() ; i++)
{
// for(int j = 0; j < i; j++)
// {
for(int k = 0; k < this->_pb.competencyCatalogue().size() ; k++)
{
compDistribyTF.at(i).at(k) += compDistribyTF.at(i-1).at(k);
// if(compDistribyTF.at(i).at(k) > 1) //commented because decay
// compDistribyTF.at(i).at(k) = 1;
}
// }
}
// === Summed display section
std::cout << "\n* Summed value by TF" << std::endl;
for(int i = 0 ; i < compDistribyTF.size(); i++)
{
std::cout << "TF#" << i << ": [";
for(int j = 0; j < compDistribyTF.at(i).size()-1; j++)
{
std::cout << std::setprecision(3) << compDistribyTF.at(i).at(j) << ";\t";
}
std::cout << compDistribyTF.at(i).at(compDistribyTF.at(i).size()-1) << "]" << std::endl;
}
// === apply decay
std::vector<double> tmpDiff;
std::vector<int> decayClock(this->_pb.competencyCatalogue().size());
double decayVal = 0; double delta = 0; double decayed = 0;
int decaynb = 0;
for(int i = 1; i < compDistribyTF.size(); i++) //starts to 1 because 0 does not have decay
{
for(int j = 0; j < compDistribyTF.at(0).size(); j++) //cDTF[0] because we do not care which, they all have the same size == this->_pb.competencyCatalogue().size()
{
decayVal = 0; delta = 0; decayed = 0;
// storing the delta of the mag in i-1 ; i
delta = compDistribyTF.at(i).at(j) - compDistribyTF.at(i-1).at(j);
if(delta == 0) //if 0 -->comp not mobilized here, thus stagnation therefore decay for the jth comp
{
decayClock.at(j)++;
}
else
{
if(decayClock.at(j)>0) //if there is decay
{
decayVal = DecayEngine::defaultDecay(decayClock.at(j));
decaynb++;
}
//delta = compDistribyTF.at(i).at(j) - compDistribyTF.at(i-1).at(j);
decayed = compDistribyTF.at(i-1).at(j) - decayVal;
if(decayed < 0)
decayed = 0;
compDistribyTF.at(i).at(j) = delta + decayed;
// affecting the decay to this comp in upper TFs
if(decayed > 0)
{
for(int k = i+1 ; k < compDistribyTF.size(); k++)
{
compDistribyTF.at(k).at(j) -= decayVal;
if(compDistribyTF.at(k).at(j) < 0)
compDistribyTF.at(k).at(j) = 0;
}
}
decayClock.at(j) = 0;
}
}
}
//=== Decay Display Section
std::cout << "\n* Decayed value by TF" << std::endl;
for(int i = 0 ; i < compDistribyTF.size(); i++)
{
std::cout << "TF#" << i << ": [";
for(int j = 0; j < compDistribyTF.at(i).size()-1; j++)
{
std::cout << std::setprecision(3) << compDistribyTF.at(i).at(j) << ";\t";
}
std::cout << compDistribyTF.at(i).at(compDistribyTF.at(i).size()-1) << "]" << std::endl;
}
}
...@@ -50,6 +50,12 @@ class ConstraintsPrerequisites ...@@ -50,6 +50,12 @@ class ConstraintsPrerequisites
* 2nd version of integrity check. Supposed to be more reliable and faster * 2nd version of integrity check. Supposed to be more reliable and faster
*/ */
std::pair<bool, double> integrityCheck(Cursus indiv); std::pair<bool, double> integrityCheck(Cursus indiv);
/**
* Displayer debug purpose. Display decayed array and non decayed array
* This is mostly a duplicata of integrityCheck without the prerequisite check and display
*/
void _displayDecayedArrays(Cursus indiv);
}; };
#endif // SRC_MODEL_CONSTRAINTS_PREREQUISITES_CONSTRAINTS_H_ #endif // SRC_MODEL_CONSTRAINTS_PREREQUISITES_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