Skip to content
Snippets Groups Projects
Commit 61b76c53 authored by jgatt's avatar jgatt
Browse files

factorization of code + separated enum for mono_core and multi_core on red_window

parent 2599feb4
No related branches found
No related tags found
1 merge request!20merge requested multibehavor_mono_multi_core
......@@ -22,35 +22,42 @@ bool DMWindow_list::have_no_common_element( DMWindow_list* compare_list) const
return intersect.is_empty();
}
double DMUserMultiBehavior::parse_proba_param(const rapidjson::Value &param, const std::vector<string> &config_param, std::vector<double> &probability_array)
{
//fill the config_param fields to probability_array
double prob_total = 0.0;
for (std::vector<double>::size_type i =0 ; i < probability_array.size();i++)
{
std::string current_param = config_param[i];
if (param.HasMember(current_param.c_str()))
{
PPK_ASSERT_ERROR(param[current_param.c_str()].IsDouble()
&& param[current_param.c_str()].GetDouble() >= 0.0,
"Error every specified probability should be a non-negative Double");
probability_array[i] = param[current_param.c_str()].GetDouble();
prob_total += probability_array[i];
}
}
return prob_total;
}
void DMUserMultiBehavior::init_prob_mono_core(const rapidjson::Value &param,std::vector<double> & red_prob_array, std::vector<double> & yellow_prob_array){
//Red window probability initialization
std::vector<string> red_config (R_TOTAL,"");
red_config[R_DEGRAD] = "red_prob_degrad_mono_core";
red_config[R_C_YOU_LATER] = "red_prob_see_you_later_mono_core";
red_config[R_RECONFIG] = "red_prob_reconfig_mono_core";
red_config[R_RENONCE] = "red_prob_renonce_mono_core";
red_config[R_RIGID] = "red_prob_rigid_mono_core";
red_prob_total=0.0;
//We set the probability either by reading json data or by drawing it randomly
for (std::vector<double>::size_type i =0 ; i < red_prob_array.size();i++){
std::string current_prob = red_config[i];
if(param.HasMember(current_prob.c_str())){
PPK_ASSERT_ERROR(param[current_prob.c_str()].IsDouble()
&& param[current_prob.c_str()].GetDouble()>=0.0,
"Error every specified red probability should be a non-negative Double");
red_prob_array[i] = param[current_prob.c_str()].GetDouble();
red_prob_total += red_prob_array[i];
}
}
/* If we need red_probabilities and
std::vector<string> red_config (R_TOTAL_MONO,"");
red_config[R_DEGRAD_MONO] = "red_prob_degrad_mono_core";
red_config[R_C_YOU_LATER_MONO] = "red_prob_see_you_later_mono_core";
red_config[R_RECONFIG_MONO] = "red_prob_reconfig_mono_core";
red_config[R_RENONCE_MONO] = "red_prob_renonce_mono_core";
red_config[R_RIGID_MONO] = "red_prob_rigid_mono_core";
red_prob_total_mono_core= parse_proba_param(param,red_config,red_prob_array);
/* If we need red_probabilities, and
* they are none that are defined and non-zero we raise an error */
std::string error_message = "Error in parameter defined for user ";
error_message += user_name;
error_message += ". The sum of the probability given in parameter sum to 0.0 for red_windows"
"Check that you gave red_prob_behavior parameter to user and at least "
"one non-zero probability";
PPK_ASSERT_ERROR( red_prob_total != 0.0 || !(dm_window || red_windows), "%s", error_message.c_str());
PPK_ASSERT_ERROR( red_prob_total_mono_core != 0.0 || !(dm_window || red_windows), "%s", error_message.c_str());
//we save the result in the used probability variable
// Yellow probability Initialization
......@@ -60,18 +67,7 @@ void DMUserMultiBehavior::init_prob_mono_core(const rapidjson::Value &param,std:
yellow_config[Y_DEGRAD] = "yellow_prob_degrad_mono_core";
yellow_config[Y_RECONFIG] = "yellow_prob_reconfig_mono_core";
yellow_config[Y_RIGID] = "yellow_prob_rigid_mono_core";
yellow_prob_total=0.0;
//We set the probability either by reading json data or by drawing it randomly
for (std::vector<double>::size_type i =0 ; i < yellow_prob_array.size();i++){
std::string current_prob = yellow_config[i];
if(param.HasMember(current_prob.c_str())){
PPK_ASSERT_ERROR(param[current_prob.c_str()].IsDouble()
&& param[current_prob.c_str()].GetDouble()>=0.0,
"Error every specified yellow probability should be a non-negative Double");
yellow_prob_array[i] = param[current_prob.c_str()].GetDouble();
yellow_prob_total += yellow_prob_array[i];
}
}
yellow_prob_total= parse_proba_param(param,yellow_config,yellow_prob_array);
error_message = "Error in parameter defined for user ";
error_message += user_name;
error_message += ". The sum of the probability given in parameter sum to 0.0 for yellow_windows"
......@@ -81,27 +77,17 @@ void DMUserMultiBehavior::init_prob_mono_core(const rapidjson::Value &param,std:
PPK_ASSERT_ERROR( yellow_prob_total != 0.0 || !(yellow_windows), "%s", error_message.c_str());
//we save the result in the used probability variable
}
void DMUserMultiBehavior::init_prob_multi_core(const rapidjson::Value &param,std::vector<double> & red_prob_array, std::vector<double> & yellow_prob_array){
//Red window probability initialization
std::vector<string> red_config (R_TOTAL,"");
red_config[R_DEGRAD] = "red_prob_degrad_multi_core";
red_config[R_C_YOU_LATER] = "red_prob_see_you_later_multi_core";
red_config[R_RECONFIG] = "red_prob_reconfig_multi_core";
red_config[R_RENONCE] = "red_prob_renonce_multi_core";
red_config[R_RIGID] = "red_prob_rigid_multi_core";
red_prob_total=0.0;
//We set the probability either by reading json data or by drawing it randomly
for (std::vector<double>::size_type i =0 ; i < red_prob_array.size();i++){
std::string current_prob = red_config[i];
if(param.HasMember(current_prob.c_str())){
PPK_ASSERT_ERROR(param[current_prob.c_str()].IsDouble()
&& param[current_prob.c_str()].GetDouble()>=0.0,
"Error every specified red probability should be a non-negative Double");
red_prob_array[i] = param[current_prob.c_str()].GetDouble();
red_prob_total += red_prob_array[i];
}
}
std::vector<string> red_config (R_TOTAL_MULTI,"");
red_config[R_DEGRAD_MULTI] = "red_prob_degrad_multi_core";
red_config[R_C_YOU_LATER_MULTI] = "red_prob_see_you_later_multi_core";
red_config[R_RECONFIG_MULTI] = "red_prob_reconfig_multi_core";
red_config[R_RENONCE_MULTI] = "red_prob_renonce_multi_core";
red_config[R_RIGID_MULTI] = "red_prob_rigid_multi_core";
red_prob_total_multi_core= parse_proba_param(param,red_config,red_prob_array);
/* If we need red_probabilities and
* they are none that are defined and non-zero we raise an error */
std::string error_message = "Error in parameter defined for user ";
......@@ -109,7 +95,7 @@ void DMUserMultiBehavior::init_prob_multi_core(const rapidjson::Value &param,std
error_message += ". The sum of the probability given in parameter sum to 0.0 for red_windows"
"Check that you gave red_prob_behavior parameter to user and at least "
"one non-zero probability";
PPK_ASSERT_ERROR( red_prob_total != 0.0 || !(dm_window || red_windows), "%s", error_message.c_str());
PPK_ASSERT_ERROR( red_prob_total_multi_core != 0.0 || !(dm_window || red_windows), "%s", error_message.c_str());
//we save the result in the used probability variable
// Yellow probability Initialization
......@@ -119,18 +105,8 @@ void DMUserMultiBehavior::init_prob_multi_core(const rapidjson::Value &param,std
yellow_config[Y_DEGRAD] = "yellow_prob_degrad_multi_core";
yellow_config[Y_RECONFIG] = "yellow_prob_reconfig_multi_core";
yellow_config[Y_RIGID] = "yellow_prob_rigid_multi_core";
yellow_prob_total=0.0;
yellow_prob_total= parse_proba_param(param,yellow_config,yellow_prob_array);
//We set the probability either by reading json data or by drawing it randomly
for (std::vector<double>::size_type i =0 ; i < yellow_prob_array.size();i++){
std::string current_prob = yellow_config[i];
if(param.HasMember(current_prob.c_str())){
PPK_ASSERT_ERROR(param[current_prob.c_str()].IsDouble()
&& param[current_prob.c_str()].GetDouble()>=0.0,
"Error every specified yellow probability should be a non-negative Double");
yellow_prob_array[i] = param[current_prob.c_str()].GetDouble();
yellow_prob_total += yellow_prob_array[i];
}
}
error_message = "Error in parameter defined for user ";
error_message += user_name;
error_message += ". The sum of the probability given in parameter sum to 0.0 for yellow_windows"
......@@ -151,8 +127,8 @@ DMUserMultiBehavior::DMUserMultiBehavior(
red_windows = r_windows;
this->logger = logger;
random_gen = std::mt19937(random_seed);
red_prob_multi_core= vector<double> (R_TOTAL,0.0);
red_prob_mono_core = vector<double> (R_TOTAL,0.0);
red_prob_multi_core= vector<double> (R_TOTAL_MULTI,0.0);
red_prob_mono_core = vector<double> (R_TOTAL_MONO,0.0);
yellow_prob_mono_core = vector<double> (Y_TOTAL,0.0);
yellow_prob_multi_core = vector<double> (Y_TOTAL,0.0);
init_prob_mono_core(param,red_prob_mono_core,yellow_prob_mono_core);
......@@ -221,72 +197,75 @@ bool DMUserMultiBehavior::degrad_time_job(shared_ptr<Job> & job, Profile *profil
job->profile = profile->name = std::to_string(original_time);
return true;
}
bool DMUserMultiBehavior::red_window_behavior_mono_core(double date, shared_ptr<Job> job, Profile *profile)
{
double behavior = distribution(random_gen)*red_prob_total;
double total_probability = 0.0;
/* Renonce*/
total_probability += red_prob_mono_core[R_RENONCE];
if (behavior < total_probability){
bool DMUserMultiBehavior::exec_red_behavior_mono(std::vector<double>::size_type behavior_number,double date,shared_ptr<Job> job,Profile *profile){
if(behavior_number==R_RENONCE_MONO){
log_behavior(job,"renonce",0);
return renonce_job(job);
}
/* See you later */
total_probability += red_prob_mono_core[R_C_YOU_LATER];
if (behavior < total_probability){
if(behavior_number==R_C_YOU_LATER_MONO){
return C_you_later_job(date,3600,job);
}
/* Degrad */
total_probability += red_prob_mono_core[R_DEGRAD];
if (behavior < total_probability){
if(behavior_number == R_DEGRAD_MONO){
return degrad_time_job(job,profile);
}
/* Reconfig */
total_probability += red_prob_mono_core[R_RECONFIG];
if (behavior < total_probability){
if(behavior_number == R_RECONFIG_MONO){
log_behavior(job,"consider_reconfig",0);
log_behavior(job,"rigid",0);
return reconfig_job(job,profile);
}
if(behavior_number == R_RIGID_MONO){
return rigid_job(job,profile);
}
}
bool DMUserMultiBehavior::red_window_behavior_mono_core(double date, shared_ptr<Job> job, Profile *profile)
{
double behavior = distribution(random_gen)*red_prob_total_mono_core;
double total_probability = 0.0;
/* Renonce*/
for (std::vector<double>::size_type i =0 ; i < red_prob_mono_core.size();i++){
total_probability+=red_prob_mono_core[i];
if (behavior < total_probability){
return exec_red_behavior_mono(i,date,job,profile);
}
}
/* if none of the above we launch the job without changing anything
Rigid strategy*/
return rigid_job(job,profile);
}
bool DMUserMultiBehavior::red_window_behavior_multi_core(double date, shared_ptr<Job> job, Profile *profile)
bool DMUserMultiBehavior::exec_red_behavior_multi(std::vector<double>::size_type behavior_number,double date,shared_ptr<Job> job,Profile *profile)
{
double behavior = distribution(random_gen)*red_prob_total;
double total_probability = 0.0;
/* Renonce*/
total_probability += red_prob_multi_core[R_RENONCE];
if (behavior < total_probability){
if(behavior_number==R_RENONCE_MULTI){
log_behavior(job,"renonce",0);
return renonce_job(job);
}
/* See you later */
total_probability += red_prob_multi_core[R_C_YOU_LATER];
if (behavior < total_probability){
if(behavior_number==R_C_YOU_LATER_MULTI){
return C_you_later_job(date,3600,job);
}
/* Degrad */
total_probability += red_prob_multi_core[R_DEGRAD];
if (behavior < total_probability){
if(behavior_number == R_DEGRAD_MULTI){
log_behavior(job,"consider_degrad",0);
log_behavior(job, "degrad", 0);
log_behavior(job,"degrad",0);
return degrad_space_job(job,profile);
}
/* Reconfig */
total_probability += red_prob_multi_core[R_RECONFIG];
if (behavior < total_probability){
if(behavior_number == R_RECONFIG_MULTI){
log_behavior(job,"consider_reconfig",0);
log_behavior(job, "reconfig", 0);
log_behavior(job,"reconfig",0);
return reconfig_job(job,profile);
}
/* if none of the above we launch the job without changing anything
Rigid strategy*/
if(behavior_number == R_RIGID_MULTI){
return rigid_job(job,profile);
}
}
bool DMUserMultiBehavior::red_window_behavior_multi_core(double date, shared_ptr<Job> job, Profile *profile)
{
double behavior = distribution(random_gen)*red_prob_total_multi_core;
double total_probability = 0.0;
/* Renonce*/
for (std::vector<double>::size_type i =0 ; i < red_prob_multi_core.size();i++){
total_probability+=red_prob_multi_core[i];
if (behavior < total_probability){
return exec_red_behavior_multi(i,date,job,profile);
}
}
return rigid_job(job,profile);
}
......@@ -391,4 +370,3 @@ bool DMUserMultiBehavior::handle_job(double date, shared_ptr<Job> job, Profile *
return rigid_job(job,profile);
}
}
......@@ -50,7 +50,10 @@ public:
protected:
enum red_behavior {R_DEGRAD,R_RECONFIG,R_RENONCE,R_RIGID,R_C_YOU_LATER,R_TOTAL};
enum red_behavior_multi {R_RENONCE_MULTI,R_C_YOU_LATER_MULTI,R_DEGRAD_MULTI,
R_RECONFIG_MULTI,R_RIGID_MULTI,R_TOTAL_MULTI};
enum red_behavior_mono {R_RENONCE_MONO,R_C_YOU_LATER_MONO,R_DEGRAD_MONO,
R_RECONFIG_MONO,R_RIGID_MONO,R_TOTAL_MONO};
enum yellow_behavior {Y_DEGRAD,Y_RECONFIG,Y_RIGID,Y_TOTAL};
DMWindow_list *yellow_windows;
DMWindow_list * red_windows;
......@@ -59,6 +62,7 @@ protected:
= std::uniform_real_distribution<double>(0.0, 1.0);
LoggerUserStat *logger = nullptr ;
double parse_proba_param(const rapidjson::Value & param, const std::vector<string> & config_param,std::vector<double> & probability_array);
void init_prob_mono_core(const rapidjson::Value &param, vector<double> &red_prob_array, vector<double> & yellow_prob_array);
void init_prob_multi_core(const rapidjson::Value &param, vector<double> &red_prob_array, vector<double> & yellow_prob_array);
bool is_in_yellow_window(double date);
......@@ -89,6 +93,9 @@ protected:
bool red_window_behavior(double date,shared_ptr<Job> & job, Profile *profile);
bool red_window_behavior_mono_core(double date,shared_ptr<Job> job,Profile *profile);
bool red_window_behavior_multi_core(double date,shared_ptr<Job> job, Profile *profile);
bool exec_red_behavior_multi(unsigned long behavior_number, double date,
shared_ptr<Job> job, Profile *profile);
bool exec_red_behavior_mono(std::vector<double>::size_type behavior_number,double date,shared_ptr<Job> job,Profile *profile);
/**
* @brief function called when the user submit a job in yellow state
* @details This function do the 3 behaviors for yellow windows (degrad,reconfig, rigid)
......@@ -99,8 +106,10 @@ protected:
bool yellow_window_behavior_multi_core(shared_ptr<Job> job,Profile *profile);
std::vector<double> red_prob_multi_core;
std::vector<double> red_prob_mono_core;
double red_prob_total;
double red_prob_total_multi_core;
double red_prob_total_mono_core;
std::vector<double> yellow_prob_multi_core;
std::vector<double> yellow_prob_mono_core;
double yellow_prob_total;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment