Skip to content
Snippets Groups Projects
Commit 9c12d698 authored by jgatt's avatar jgatt
Browse files

factorisation of error_message in code

parent 21442983
No related branches found
No related tags found
1 merge request!20merge requested multibehavor_mono_multi_core
Pipeline #5897 passed
......@@ -22,7 +22,9 @@ 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)
double DMUserMultiBehavior::parse_proba_param(const rapidjson::Value &param,
const std::vector<string> &config_param, std::vector<double> &probability_array,
const std::string & window_name, const std::string & type_prob_name)
{
//fill the config_param fields to probability_array
double prob_total = 0.0;
......@@ -38,83 +40,77 @@ double DMUserMultiBehavior::parse_proba_param(const rapidjson::Value &param, con
prob_total += probability_array[i];
}
}
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 ";
error_message += window_name;
error_message += ". Check that you gave";
error_message += type_prob_name;
error_message +=" parameter to user and at least one non-zero probability";
PPK_ASSERT_ERROR(prob_total != 0.0, "%s", error_message.c_str());
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_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_mono_core != 0.0 || !(dm_window || red_windows), "%s", error_message.c_str());
if(dm_window || red_windows)
{
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,
"red_windows","red_windows_prob_mono_core");
}
//we save the result in the used probability variable
// Yellow probability Initialization
std::vector<string> yellow_config (Y_TOTAL_MONO,"");
yellow_config[Y_DEGRAD_MONO] = "yellow_prob_degrad_mono_core";
yellow_config[Y_RECONFIG_MONO] = "yellow_prob_reconfig_mono_core";
yellow_config[Y_RIGID_MONO] = "yellow_prob_rigid_mono_core";
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"
" Check that you gave at least one non-zero yellow_prob_behavior parameter to user ";
/* If we need yellow_probabilities,
* and they are none that are defined and non-zero we raise an error */
PPK_ASSERT_ERROR( yellow_prob_total != 0.0 || !(yellow_windows), "%s", error_message.c_str());
//we save the result in the used probability variable
if(yellow_windows)
{
std::vector<string> yellow_config(Y_TOTAL_MONO, "");
yellow_config[Y_DEGRAD_MONO] = "yellow_prob_degrad_mono_core";
yellow_config[Y_RECONFIG_MONO] = "yellow_prob_reconfig_mono_core";
yellow_config[Y_RIGID_MONO] = "yellow_prob_rigid_mono_core";
yellow_prob_total
= parse_proba_param(param, yellow_config, yellow_prob_array,
"yellow_windows","yellow_windows_prob_mono_core");
}
}
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_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 ";
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_multi_core != 0.0 || !(dm_window || red_windows), "%s", error_message.c_str());
if (dm_window || red_windows)
{
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,
"red_windows","red_windows_prob_multi_core");
}
//we save the result in the used probability variable
// Yellow probability Initialization
std::vector<string> yellow_config (Y_TOTAL_MULTI,"");
yellow_config[Y_DEGRAD_MULTI] = "yellow_prob_degrad_multi_core";
yellow_config[Y_RECONFIG_MULTI] = "yellow_prob_reconfig_multi_core";
yellow_config[Y_RIGID_MULTI] = "yellow_prob_rigid_multi_core";
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
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"
" Check that you gave at least one non-zero yellow_prob_behavior parameter to user ";
/* If we need yellow_probabilities,
* and they are none that are defined and non-zero we raise an error */
PPK_ASSERT_ERROR( yellow_prob_total != 0.0 || !(yellow_windows), "%s", error_message.c_str());
//we save the result in the used probability variable
if (yellow_windows)
{
std::vector<string> yellow_config(Y_TOTAL_MULTI, "");
yellow_config[Y_DEGRAD_MULTI] = "yellow_prob_degrad_multi_core";
yellow_config[Y_RECONFIG_MULTI] = "yellow_prob_reconfig_multi_core";
yellow_config[Y_RIGID_MULTI] = "yellow_prob_rigid_multi_core";
yellow_prob_total
= parse_proba_param(param, yellow_config, yellow_prob_array,
"yellow_windows","yellow_windows_prob_multi_core");
}
}
DMUserMultiBehavior::DMUserMultiBehavior(
const std::string & name, const rapidjson::Value &param, DMWindow *window,
......
......@@ -63,7 +63,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);
double parse_proba_param(const rapidjson::Value & param, const std::vector<string> & config_param,std::vector<double> & probability_array, const std::string & window_name, const std::string & type_prob_name);
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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment