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

starting random gen pb

parent d9aac66f
......@@ -23,11 +23,11 @@ int main(int argc, char* argv[])
assert(pb.checkConfig() == false);
std::cout << "OK! CSDVP shoukd not be config yet here" << std::endl;
CSDVP::generateProblem(pb, 7777);
CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777);
assert(pb.seed() == 7777);
assert(pb.checkConfig() == false);
CSDVP::generateProblem(pb, -1);
CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, -1);
assert(pb.seed() == -1);
assert(pb.checkConfig() == false);
std::cout << "generateProblem does not trigger generation if pb is not config" << std::endl;
......@@ -40,8 +40,12 @@ int main(int argc, char* argv[])
assert(pb.cfg_quantityCourses() == 25);
assert(pb.checkConfig() == false);
pb.set_cfg_quantityTimeFrames(10);
assert(pb.cfg_quantityTimeFrames() == 10);
pb.set_cfg_minimalTimeFrames(5);
assert(pb.cfg_minimalTimeFrame() == 5);
assert(pb.checkConfig() == false);
pb.set_cfg_maximalTimeFrames(10);
assert(pb.cfg_maximalTimeFrame() == 10);
assert(pb.checkConfig() == false);
pb.set_cfg_ectsMin(3);
......@@ -59,13 +63,19 @@ int main(int argc, char* argv[])
pb.set_cfg_courseByTFMax(8);
assert(pb.cfg_courseByTFMax() == 8);
assert(pb.checkConfig() == false);
pb.set_cfg_minimalMagnitude(0.2);
pb.set_cfg_maximalMagnitude(0.5);
assert(pb.cfg_magnitudeMin().value() == 0.2);
assert(pb.cfg_magnitudeMax().value() == 0.5);
assert(pb.checkConfig() == false );
std::cout << "Config ok -- excepting seed" << std::endl;
pb.set_cfg_courseByTFMin(9);
try
{
CSDVP::generateProblem(pb, 7777);
CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777);
}
catch(CSDVPOverlapingBoundariesException & e)
{
......@@ -77,7 +87,7 @@ int main(int argc, char* argv[])
try
{
CSDVP::generateProblem(pb, 7777);
CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777);
}
catch(CSDVPOverlapingBoundariesException & e)
{
......@@ -86,9 +96,49 @@ int main(int argc, char* argv[])
pb.set_cfg_ectsMax(5);
CSDVP::generateProblem(pb, 7777);
pb.addTimeFrame(2);
pb.addTimeFrame(5);
assert(pb.timeFrames().size() == 2);
pb.addTimeFrame(5);
assert(pb.timeFrames().size() == 2);
std::cout << "duplicata protection TF ok" << std::endl;
Course c = Course::build();
Course c2 = Course::build();
assert( ! (c == c2) );
pb.addCourseToCatalogue(c);
pb.addCourseToCatalogue(c2);
assert(pb.coursesCatalogue().size() == 2);
pb.addCourseToCatalogue(c);
assert(pb.coursesCatalogue().size() == 2);
std::cout << "duplicata protection for course ok" << std::endl;
Competency comp1 = Competency::build(0.5);
Competency comp2 = Competency::build(0.7);
assert(!(comp1 == comp2));
pb.addCompetencyToCatalogue(comp1);
pb.addCompetencyToCatalogue(comp2);
assert(pb.competencyCatalogue().size() == 2);
pb.addCompetencyToCatalogue(comp1);
assert(pb.competencyCatalogue().size() == 2);
std::cout << "duplicata protection for competency ok" << std::endl;
std::cout << pb << std::endl;
CSDVP::generateProblem(pb, CSDVP::GenerationType::RANDOM, 7777);
assert(pb.checkConfig());
std::cout << "CSDVP has been correctly configurated" << std::endl;
assert(pb.timeFrames().at(0) == pb.cfg_minimalTimeFrame());
assert(pb.timeFrames().at(1) == pb.cfg_minimalTimeFrame()+1);
assert(pb.timeFrames().at(pb.timeFrames().size()-1) == pb.cfg_maximalTimeFrame());
std::cout << "TimeFrames vector correctly init" << std::endl;
return EXIT_SUCCESS;
}
\ No newline at end of file
......@@ -83,6 +83,11 @@ Magnitude operator+(const Magnitude & m, const double d)
return mag;
}
bool Magnitude::operator>(const Magnitude & m) const
{
return this->_value > m.value();
}
// === FUNCTION
/** Checks if the value v is in [0;1]. If yes, return 0. Else, if v < 0 return -1, 1 otherwise
*/
......
......@@ -27,6 +27,7 @@ class Magnitude
// Operator
Magnitude & operator+=(const Magnitude & m);
Magnitude & operator+=(double const d);
bool operator>(const Magnitude & m) const;
//GETTER
double value() const;
......
......@@ -2,11 +2,13 @@
#include <utility>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include "problem.h"
#include "tools.h"
#include "exception/csdvpOverlapingBoundaryException.h"
#include "exception/notImplementedException.h"
int CSDVP::CSDVP_COUNTER = 0;
......@@ -24,7 +26,8 @@ int CSDVP::CSDVP_COUNTER = 0;
this->_quantityAvailableCompetencies = -1;
this->_quantityAvailableCourses = -1;
this->_quantityOfTimeFrame = -1;
this->_minimalTimeFrame = -1;
this->_maximalTimeFrame = -1;
this->_minimalECTSValue = -1;
this->_maximalECTSValue = -1;
this->_minimalCoursesByTimeFrame = -1;
......@@ -38,17 +41,26 @@ int CSDVP::CSDVP_COUNTER = 0;
{this->_quantityAvailableCompetencies = nb;}
void CSDVP::set_cfg_quantityCourses(int nb)
{this->_quantityAvailableCourses = nb;}
void CSDVP::set_cfg_quantityTimeFrames(int nb)
{this->_quantityOfTimeFrame = nb;}
void CSDVP::set_cfg_minimalTimeFrames(int nb)
{this->_minimalTimeFrame = nb;}
void CSDVP::set_cfg_maximalTimeFrames(int nb)
{this->_maximalTimeFrame = nb;}
void CSDVP::set_cfg_ectsMin(int nb)
{
this->_minimalECTSValue = nb;}
{this->_minimalECTSValue = nb;}
void CSDVP::set_cfg_ectsMax(int nb)
{this->_maximalECTSValue = nb;}
void CSDVP::set_cfg_courseByTFMin(int nb)
{this->_minimalCoursesByTimeFrame = nb;}
void CSDVP::set_cfg_courseByTFMax(int nb)
{this->_maximalCoursesByTimeFrame = nb;}
void CSDVP::set_cfg_minimalMagnitude(double m)
{
this->_minimalMagnitude = Magnitude::build(m);
}
void CSDVP::set_cfg_maximalMagnitude(double m)
{
this->_maximalMagnitude = Magnitude::build(m);
}
void CSDVP::setTimeFrames(std::vector<int> & v)
{this->_timeFrames = v;}
......@@ -89,19 +101,24 @@ int CSDVP::CSDVP_COUNTER = 0;
if( this->_seed < 0 ||
this->_quantityAvailableCompetencies < 0||
this->_quantityAvailableCourses < 0 ||
this->_quantityOfTimeFrame < 0 ||
this->_minimalTimeFrame < 0 ||
this->_maximalTimeFrame < 0 ||
this->_minimalECTSValue < 0 ||
this->_maximalECTSValue < 0 ||
this->_minimalCoursesByTimeFrame < 0 ||
this->_maximalCoursesByTimeFrame < 0 )
this->_maximalCoursesByTimeFrame < 0 ||
this->_minimalMagnitude.value() < 0 ||
this->_maximalMagnitude.value() < 0 )
{
this->_isConfig = false;
return this->_isConfig;
}
// verify overlaping range
if( this->_minimalECTSValue > this->_maximalECTSValue ||
this->_minimalCoursesByTimeFrame > this->_maximalCoursesByTimeFrame)
if( this->_minimalTimeFrame > this->_maximalTimeFrame ||
this->_minimalECTSValue > this->_maximalECTSValue ||
this->_minimalCoursesByTimeFrame > this->_maximalCoursesByTimeFrame ||
this->_minimalMagnitude > this->_maximalMagnitude)
{
throw CSDVPOverlapingBoundariesException(this);
}
......@@ -112,7 +129,11 @@ int CSDVP::CSDVP_COUNTER = 0;
// === END FUNC
// === STATIC
void CSDVP::generateProblem(CSDVP & csdvp, int seed)
int CSDVP::assignID()
{ return ++CSDVP::CSDVP_COUNTER;}
// ---------- GENERATION RELATED FUNCTIONS ----------
void CSDVP::generateProblem(CSDVP & csdvp, CSDVP::GenerationType type, int seed)
{
csdvp._seed = seed;
......@@ -120,7 +141,65 @@ int CSDVP::CSDVP_COUNTER = 0;
return; //aborting pb generation
std::cout << "generateProblem TODO" << std::endl;
switch (type)
{
case CSDVP::GenerationType::RANDOM:
_randomlyGenerated(csdvp);
break;
default:
break;
}
}
int CSDVP::assignID()
{ return ++CSDVP::CSDVP_COUNTER;}
\ No newline at end of file
int CSDVP::_randomizeIn(const int min, const int max)
{
return min + ( rand() % (max - min + 1) );
}
double CSDVP::_randomizeIn(const double min, const double max)
{
throw NotImplementedException("CSDVP::_randomizeIn");
}
void CSDVP::randomizeProblem(CSDVP & pb, int seed)
{
pb._seed = seed;
srand(pb.seed());
pb.set_cfg_ectsMin(_randomizeIn(1, CSDVP::RANDOM_MAX_ECTS_VALUE));
pb.set_cfg_ectsMax(_randomizeIn(pb.cfg_ectsMin(), CSDVP::RANDOM_MAX_ECTS_VALUE));
throw NotImplementedException("_randomizeProblem");
//SKILL_MAX_VALUE
}
void CSDVP::_randomlyGenerated(CSDVP & pb)
{
srand(pb.seed());
pb.unlocked_timeFrames().clear();
pb.unlocked_competenciesCatalogue().clear();
pb.unlocked_coursesCatalogue().clear();
for(int i = 0; i < (pb.cfg_maximalTimeFrame() - pb.cfg_minimalTimeFrame()) + 1 ; i++)
{
pb.addTimeFrame(pb.cfg_minimalTimeFrame()+i);
}
}
// --------- END GENERATION RELATED FUNCTIONS ---------
// === END STATIC
// === OPERATOR
std::ostream & operator<<(std::ostream & Stream, const CSDVP & c)
{
std::string s = "--------------\n| Problem n°"+std::to_string(c.id())+"|\n---------------\n| Configuration:";
s+= "\n\tseed: "+std::to_string(c.seed())+"\n\tNb comp: "+std::to_string(c.cfg_quantityCompetencies())+"\n\tNb courses: "+std::to_string(c.cfg_quantityCourses())+"\n\tMin TimeF: "+std::to_string(c.cfg_minimalTimeFrame())+"\n\tMax TimeF: "+std::to_string(c.cfg_maximalTimeFrame());
s+= "\n\tECTS Min: "+std::to_string(c.cfg_ectsMin())+"\n\tECTS Max: "+std::to_string(c.cfg_ectsMax())+"\n\tCourse by TF min: "+std::to_string(c.cfg_courseByTFMin())+"\n\tCourse by TF max: "+std::to_string(c.cfg_courseByTFMax());
s+="\n\tMagnitude min: "+std::to_string(c.cfg_magnitudeMax().value())+"\n\tMagnitude max: "+std::to_string(c.cfg_magnitudeMax().value());
Stream << s;
return Stream;
}
// === END OPERATOR
\ No newline at end of file
......@@ -5,6 +5,7 @@
#include "course.h"
#include "competency.h"
#include "magnitude.h"
/**
* Model of the CSDVP (Constraint Satisfaction Decaying Variables Problem).
......@@ -28,13 +29,17 @@ class CSDVP
int _quantityAvailableCompetencies;
int _quantityAvailableCourses;
int _quantityOfTimeFrame;
int _minimalTimeFrame;
int _maximalTimeFrame;
/// ECTS values, defining the intervale [_minimal,_maximal] for random
int _minimalECTSValue;
int _maximalECTSValue;
int _minimalCoursesByTimeFrame;
int _maximalCoursesByTimeFrame;
Magnitude _minimalMagnitude;
Magnitude _maximalMagnitude;
// ---------- END CONFIGURATION ATTRIBUTES ----------
// ---------- PROBLEM SPECIFIC ATTRIBUTES ----------
......@@ -47,33 +52,61 @@ class CSDVP
//DecayPolitics
// --------- END PROBLEM SPECIFIC ATTRIBUTES ---------
// Static
// === STATIC
static int CSDVP_COUNTER;
static int assignID();
static const int RANDOM_MAX_ECTS_VALUE = 10;
static const int RANDOM_MAX_QTE_COMPETENCIES = 50;
static const int RANDOM_MAX_QTE_COURSES = 50;
static const int RANDOM_MAX_TIME_FRAMES = 15;
static const int RANDOM_MAX_COURSE_TIME_FRAMES = 10;
// --------- GENERATION RELATED FUNCTION ---------
static void _randomlyGenerated(CSDVP & pb);
static int _randomizeIn(const int min, const int max);
static double _randomizeIn(const double min, const double max);
// --------- END GENERATION RELATED FUNCTION ---------
public:
// --------- GENERATION RELATED FUNCTION ---------
/// allows a random attribution of pb's attributes
static void randomizeProblem(CSDVP & pb, int seed);
// --------- END GENERATION RELATED FUNCTION ---------
// === ENUM
enum GenerationType
{
RANDOM
//PRESET
};
// === CONSTRUCTOR
CSDVP();
/// Generate an instance of the CSDVP iff isConfig is true. Thus, seed != -1;
void static generateProblem(CSDVP & csdvp, int seed= -1 );
static void generateProblem(CSDVP & csdvp, CSDVP::GenerationType type, int seed= -1 );
// === GETTER
const int id() const{return this->_id;}
const int seed() const{return this->_seed;}
const int cfg_quantityCompetencies() const{return this->_quantityAvailableCompetencies;}
const int cfg_quantityCourses() const{return this->_quantityAvailableCourses;}
const int cfg_quantityTimeFrames() const{return this->_quantityOfTimeFrame;}
const int cfg_minimalTimeFrame() const{return this->_minimalTimeFrame;}
const int cfg_maximalTimeFrame() const{return this->_maximalTimeFrame;}
const int cfg_ectsMax() const{return this->_maximalECTSValue;}
const int cfg_ectsMin() const{return this->_minimalECTSValue;}
const int cfg_courseByTFMax() const{return this->_maximalCoursesByTimeFrame;}
const int cfg_courseByTFMin() const{return this->_minimalCoursesByTimeFrame;}
const std::vector<int> timeFrames() const{return this->_timeFrames;}
const std::vector<Course> coursesCatalogue() const{return this->_availableCourses;}
const std::vector<Competency> competencyCatalogue() const{return this->_availableCompentecies;}
std::vector<int> unlocked_timeFrames(){return this->_timeFrames;}
std::vector<Course> unlocked_coursesCatalogue(){return this->_availableCourses;}
std::vector<Competency> unlocked_competenciesCatalogue(){return this->_availableCompentecies;}
const Magnitude & cfg_magnitudeMin() const{return this->_minimalMagnitude;}
const Magnitude & cfg_magnitudeMax() const{return this->_maximalMagnitude;}
const std::vector<int> & timeFrames() const{return this->_timeFrames;}
const std::vector<Course> & coursesCatalogue() const{return this->_availableCourses;}
const std::vector<Competency> & competencyCatalogue() const{return this->_availableCompentecies;}
std::vector<int> & unlocked_timeFrames(){return this->_timeFrames;}
std::vector<Course> & unlocked_coursesCatalogue(){return this->_availableCourses;}
std::vector<Competency> & unlocked_competenciesCatalogue(){return this->_availableCompentecies;}
///@todo getDecayPolitic
// === MUTATOR
......@@ -82,11 +115,14 @@ class CSDVP
//void setSeed(int s);
void set_cfg_quantityCompetencies(int nb);
void set_cfg_quantityCourses(int nb);
void set_cfg_quantityTimeFrames(int nb);
void set_cfg_minimalTimeFrames(int nb);
void set_cfg_maximalTimeFrames(int nb);
void set_cfg_ectsMin(int nb);
void set_cfg_ectsMax(int nb);
void set_cfg_courseByTFMax(int nb);
void set_cfg_courseByTFMin(int nb);
void set_cfg_minimalMagnitude(double mag);
void set_cfg_maximalMagnitude(double mag);
void setTimeFrames(std::vector<int> & v);
void setCoursesCatalogue(std::vector<Course> &);
......@@ -101,6 +137,8 @@ class CSDVP
/// Checks all configuration attributes. If they have been all set, then isConfig is set to true
bool checkConfig();
};
std::ostream & operator<<(std::ostream & Stream, const CSDVP & c);
#endif // SRC_PROBLEM_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