Commit 3b5f6555 authored by Alexis Lebis's avatar Alexis Lebis

pb distrib for comp + prereq + job

parent bcc70b52
......@@ -466,6 +466,8 @@ int main(int argc, char* argv[]){
std::cout << "===============" << std::endl;
ctrPrq._displayDecayedArrays(pop.best_element());
std::cout << job ;
}
// ================================= END RUN ZONE ===============================
......
......@@ -79,8 +79,9 @@ void CompetencyDistribution::linearDistribution(CSDVP &pb)
// === STATIC
int CompetencyDistribution::HLevelRange(CSDVP & pb)
{
int interval = pb.cfg_competencyByCourseMax() - pb.cfg_competencyByCourseMin();
return interval;
assert(CompetencyDistribution::sanitizeHLEVEL);
// int interval = pb.cfg_competencyByCourseMax() - pb.cfg_competencyByCourseMin();
return CompetencyDistribution::HLEVEL.size();
}
std::vector<Competency> CompetencyDistribution::getHLevel(CSDVP & pb, int level)
......@@ -116,6 +117,38 @@ void CompetencyDistribution::linearDistribution(CSDVP &pb)
return res;
}
std::vector<Competency> CompetencyDistribution::unassignedUpToHLevel(CSDVP & pb, int level)
{
std::vector<Competency> res;
std::vector<Competency> tmp;
//assert(level < HLEVEL.size());
for(int i = 0; i <= level; i++)
{
tmp = CompetencyDistribution::unassignedAtHLevel(pb, i);
for(int j = 0; j < tmp.size(); j++)
res.push_back(tmp[j]);
}
return res;
}
std::vector<Competency> CompetencyDistribution::unassignedAtHLevel(CSDVP &pb, int hlevel)
{
assert(hlevel >= 0);
std::vector<Competency> res;
for(int i = 0; i < pb.competencyCatalogue().size(); i++)
{
if(pb.competencyCatalogue().at(i).hLevel() == hlevel && pb.unlocked_distributedCompetencies().at(i) == -1)
res.push_back(pb.competencyCatalogue().at(i));
}
return res;
}
void CompetencyDistribution::sanitizeHLEVEL()
{
int sum = 0;
......
......@@ -34,6 +34,8 @@ class CompetencyDistribution
static int HLevelRange(CSDVP &); //return the range max (starting from 0) of the HL
static std::vector<Competency> getHLevel(CSDVP &, int); // returns all the competency of a given HL
static std::vector<Competency> upToHLevel(CSDVP &, int); // retrieves all the comp comprised between [0;int] (and NOT [0;int[)
static std::vector<Competency> unassignedAtHLevel(CSDVP &, int hlevel);
static std::vector<Competency> unassignedUpToHLevel(CSDVP &, int);
/*
* sanitizeHLEVEL performs two task:
* * it verifies that the sum of all HLEVEL is equal to 100
......
......@@ -398,10 +398,13 @@ int CSDVP::CSDVP_COUNTER = 0;
x = _randomizeIn(pb.cfg_competencyByCourseMin(), pb.cfg_competencyByCourseMax());
lastTF = pb.coursesCatalogue().at(i).lastTimeFrame();
maxLevel = lastTF * hLevelR / nbTF;
HLComp = CompetencyDistribution::upToHLevel(pb, maxLevel);
HLComp = CompetencyDistribution::unassignedUpToHLevel(pb, maxLevel);
if(HLComp.size() == 0) //if there is no more HL unassigned, it doesnot matter which one we take
HLComp = CompetencyDistribution::upToHLevel(pb, maxLevel);
std::random_shuffle(HLComp.begin(), HLComp.end());
std::cout << "SIZE OF HLCOMP : " << HLComp.size() << std::endl;
// std::cout << "SIZE OF HLCOMP : " << HLComp.size() << std::endl;
for(int j = 0; j < x && HLComp.size() > 0 && j < HLComp.size(); j++)
{
......@@ -442,25 +445,24 @@ int CSDVP::CSDVP_COUNTER = 0;
x = _randomizeIn(pb.cfg_prerequisiteByCourseMin(), pb.cfg_prerequisiteByCourseMax());
lastTF = pb.coursesCatalogue().at(i).lastTimeFrame();
maxLevel = lastTF * hLevelR / nbTF;
HLComp = CompetencyDistribution::upToHLevel(pb, maxLevel-1);
std::random_shuffle(HLComp.begin(), HLComp.end());
maxLevel--; // Logically, prerequisite can only be according to comp of lower HL
if(maxLevel > 0) // then this means we are dealing with at least a HL 1, so only HL below can serve as prereq
{
HLComp = CompetencyDistribution::upToHLevel(pb, maxLevel);
if(x == 0)
std::cout << "X is 0! for " << pb.coursesCatalogue().at(i).name() << std::endl;
if(HLComp.size() == 0)
std::cout << "HLComp size is 0! for " << pb.coursesCatalogue().at(i).name() << std::endl;
std::random_shuffle(HLComp.begin(), HLComp.end());
for(int j = 0; j < x && HLComp.size() > 0 && j < HLComp.size(); j++)
{
tmpComp = HLComp.at(j);
//we change mag value for prereq
magVal = pb.cfg_magnitudeMin().value() + ( (double)rand()/RAND_MAX) * ( pb.cfg_magnitudeMax().value() - pb.cfg_magnitudeMin().value()) ;
Competency cpt = Competency::build(magVal,tmpComp.c_name());
pb.unlocked_coursesCatalogue().at(i).addPrerequisite(cpt);
queue.push(tmpComp);
for(int j = 0; j < x && HLComp.size() > 0 && j < HLComp.size(); j++)
{
tmpComp = HLComp.at(j);
//we change mag value for prereq
magVal = pb.cfg_magnitudeMin().value() + ( (double)rand()/RAND_MAX) * ( pb.cfg_magnitudeMax().value() - pb.cfg_magnitudeMin().value()) ;
Competency cpt = Competency::build(magVal,tmpComp.c_name());
pb.unlocked_coursesCatalogue().at(i).addPrerequisite(cpt);
queue.push(tmpComp);
}
}
}
}
void CSDVP::_sourceCourseTeachedComp(CSDVP & pb, unsigned int idx, Competency & c)
......@@ -488,6 +490,7 @@ int CSDVP::CSDVP_COUNTER = 0;
}
// --------- END GENERATION RELATED FUNCTIONS ---------
// === END STATIC
void const CSDVP::displayDistribution(){
......
......@@ -139,7 +139,8 @@ class CSDVP
std::vector<int> & unlocked_timeFrames(){return this->_timeFrames;}
std::vector<Course> & unlocked_coursesCatalogue(){return this->_availableCourses;}
std::vector<Competency> & unlocked_competenciesCatalogue(){return this->_availableCompentecies;}
std::vector<double> & unlocked_distributedCompetencies(){return this->_distributedCompetencies;}
int getQuantityCoursesToPick() const{
if(this->_isConfig)
return this->_timeFrames.size() * this->_pickedCoursesByTimeFrame;
......
......@@ -173,12 +173,12 @@ void Profession::_randomlyGenerate(Profession & job, CSDVP & pb)
int i;
std::vector<Competency> compHigherHL;
switch (Profession::JOB_SELECTION_TYPE)
{
case 1: //at least one comp in the higher HL
compHigherHL = CompetencyDistribution::getHLevel(pb, CompetencyDistribution::HLevelRange(pb));
std::cout << "compHigherHL size :" << compHigherHL.size() << std::endl;
compHigherHL = CompetencyDistribution::getHLevel(pb, CompetencyDistribution::HLevelRange(pb)-1);
// std::cout << "compHigherHL size :" << compHigherHL.size() << std::endl;
std::random_shuffle(compHigherHL.begin(), compHigherHL.end());
assert(compHigherHL.size() > 0); //if no comp retrieved in the higher hlevel (hhl), there is a pb here !
......@@ -254,9 +254,11 @@ void Profession::_pickWithHLWeighting(int nbToPick, Profession & job, CSDVP & pb
const int hLRange = CompetencyDistribution::HLevelRange(pb);
std::vector<Competency> hlComp;
for(int i = 0; i <= hLRange ; i++)
for(int i = 0; i < hLRange ; i++)
{
sumInterval+=i;
// sumInterval+=i;
// sumInterval = i * 2;
sumInterval = i * i;
range.push_back(sumInterval);
}
......@@ -267,13 +269,13 @@ void Profession::_pickWithHLWeighting(int nbToPick, Profession & job, CSDVP & pb
currentHL = 0;
std::cout << "sumInterval: " << sumInterval << " & x: " << x << std::endl;
// std::cout << "sumInterval: " << sumInterval << " & x: " << x << std::endl;
while(x > range[currentHL] && currentHL < range.size())
{
currentHL++;
}
std::cout << "I pick the prereq in the HL: " << currentHL << std::endl;
hlComp = CompetencyDistribution::getHLevel(pb, currentHL);//we get the correspond hl level
assert(hlComp.size() > 0);
std::random_shuffle(hlComp.begin(), hlComp.end());
......
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