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

distribution ok with HLEVEL in args

LinearDistrib has been deprecated
New displayers infos (nb comp by hlevelÃ)
parent 557f6071
#include <iostream> #include <iostream>
#include <assert.h> #include <assert.h>
#include <algorithm>
#include "competencyDistribution.h" #include "competencyDistribution.h"
std::vector<int> CompetencyDistribution::HLEVEL(10); std::vector<int> CompetencyDistribution::HLEVEL(10);
bool CompetencyDistribution::hlevelSanitized = false;
void CompetencyDistribution::distribute(CSDVP &pb)
{
if(!hlevelSanitized)
{
std::cout << "WARNING! HLevel has not been progammatically sanitized; automatically doing it" << std::endl;
CompetencyDistribution::sanitizeHLEVEL();
}
std::vector<int> idxComp;
for(int i = 0 ; i < pb.cfg_quantityCompetencies(); i++)
{
idxComp.push_back(i);
}
std::random_shuffle(idxComp.begin(), idxComp.end());
int nbAffected=0;
for(int i = 0; i < CompetencyDistribution::HLEVEL.size(); i++)
{
for(int j = 0; j < idxComp.size() && (j < (CompetencyDistribution::HLEVEL.at(i) * pb.cfg_quantityCompetencies()) / 100) ; j++)
{
pb.unlocked_competenciesCatalogue().at(idxComp.at(nbAffected)).setHL(i);
nbAffected++;
}
}
int notAffected = pb.cfg_quantityCompetencies() - nbAffected;
if(notAffected <= 0 )
return;
int hl = 0;
for(int i = 0; i < notAffected; i++)
{
assert(nbAffected+i <= pb.cfg_quantityCompetencies());
pb.unlocked_competenciesCatalogue().at(nbAffected+i).setHL(hl%CompetencyDistribution::HLEVEL.size());
hl++;
}
}
void CompetencyDistribution::linearDistribution(CSDVP &pb) void CompetencyDistribution::linearDistribution(CSDVP &pb)
{ {
std::cout << "Linear distribution of competency is deprecated" << std::endl;
assert(false);
int interval = CompetencyDistribution::HLevelRange(pb); int interval = CompetencyDistribution::HLevelRange(pb);
if(pb.cfg_competencyByCourseMin() != 0) //if the min borne is not 0, we add another interval for comp with no prereq if(pb.cfg_competencyByCourseMin() != 0) //if the min borne is not 0, we add another interval for comp with no prereq
interval++; interval++;
...@@ -88,6 +133,7 @@ void CompetencyDistribution::linearDistribution(CSDVP &pb) ...@@ -88,6 +133,7 @@ void CompetencyDistribution::linearDistribution(CSDVP &pb)
assert(sum==100); assert(sum==100);
CompetencyDistribution::HLEVEL = tmp; CompetencyDistribution::HLEVEL = tmp;
CompetencyDistribution::hlevelSanitized = true;
} }
void CompetencyDistribution::displayHLevel() void CompetencyDistribution::displayHLevel()
...@@ -99,3 +145,16 @@ void CompetencyDistribution::linearDistribution(CSDVP &pb) ...@@ -99,3 +145,16 @@ void CompetencyDistribution::linearDistribution(CSDVP &pb)
} }
std::cout << CompetencyDistribution::HLEVEL.at(CompetencyDistribution::HLEVEL.size()-1) << "]" << std::endl << std::endl; std::cout << CompetencyDistribution::HLEVEL.at(CompetencyDistribution::HLEVEL.size()-1) << "]" << std::endl << std::endl;
} }
std::vector<Competency> CompetencyDistribution::compsAtHLevel(CSDVP & pb, int level)
{
std::vector<Competency> res;
for(int i = 0; i < pb.cfg_quantityCompetencies(); i++)
{
if(pb.competencyCatalogue().at(i).hLevel() == level)
res.push_back(pb.competencyCatalogue().at(i));
}
return res;
}
\ No newline at end of file
...@@ -18,10 +18,17 @@ ...@@ -18,10 +18,17 @@
*/ */
class CompetencyDistribution class CompetencyDistribution
{ {
private:
static bool hlevelSanitized;
public: public:
static std::vector<int> HLEVEL; static std::vector<int> HLEVEL;
void linearDistribution(CSDVP &); void linearDistribution(CSDVP &);
/**
* distribute realises the competency distribution according to the HLEVEL
*/
void distribute(CSDVP &);
// === STATIC // === STATIC
static int HLevelRange(CSDVP &); //return the range max (starting from 0) of the HL static int HLevelRange(CSDVP &); //return the range max (starting from 0) of the HL
...@@ -34,6 +41,7 @@ class CompetencyDistribution ...@@ -34,6 +41,7 @@ class CompetencyDistribution
*/ */
static void sanitizeHLEVEL(); static void sanitizeHLEVEL();
static void displayHLevel(); static void displayHLevel();
static std::vector<Competency> compsAtHLevel(CSDVP &, int level);
}; };
......
...@@ -365,7 +365,8 @@ int CSDVP::CSDVP_COUNTER = 0; ...@@ -365,7 +365,8 @@ int CSDVP::CSDVP_COUNTER = 0;
* HL is used to improve the average quality of the course catalogue compared to random * HL is used to improve the average quality of the course catalogue compared to random
*/ */
CompetencyDistribution distr = CompetencyDistribution(); CompetencyDistribution distr = CompetencyDistribution();
distr.linearDistribution(pb); //distr.linearDistribution(pb);
distr.distribute(pb);
/* COMPETENCY ASSIGNATION FOR TEACHED /* COMPETENCY ASSIGNATION FOR TEACHED
* For each course c, we roll x, the nb of competencies associated to c. * For each course c, we roll x, the nb of competencies associated to c.
...@@ -499,7 +500,11 @@ void const CSDVP::displayDistribution(){ ...@@ -499,7 +500,11 @@ void const CSDVP::displayDistribution(){
std::cout << "\n\t# of above 0.5: " << std::get<1>(stats); std::cout << "\n\t# of above 0.5: " << std::get<1>(stats);
std::cout << "\n\tDistrib mean: " << std::get<2>(stats); std::cout << "\n\tDistrib mean: " << std::get<2>(stats);
std::cout << "\n\tDistrib median: " << std::get<3>(stats) << std::endl; std::cout << "\n\tDistrib median: " << std::get<3>(stats) << std::endl;
std::cout << "\n\tUnassigned in HL#" << -1 << std::endl;
for(int i = 0; i < CompetencyDistribution::HLEVEL.size(); i++)
{
std::cout << "\tAssigned in HL#" << i <<": " << CompetencyDistribution::compsAtHLevel(*this, i).size() << std::endl;
}
std::cout << "Distrib:" << std::endl; std::cout << "Distrib:" << std::endl;
std::cout << "["; std::cout << "[";
......
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