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

state computation has been move to its own class

parent f748ee8a
Branches multibehavior_mono_multi_core
Tags
1 merge request!20merge requested multibehavor_mono_multi_core
Pipeline #6018 passed
...@@ -54,6 +54,7 @@ Broker::Broker(rapidjson::Document *user_description_file) ...@@ -54,6 +54,7 @@ Broker::Broker(rapidjson::Document *user_description_file)
PPK_ASSERT_ERROR(red_windows_list->have_no_common_element(yellow_windows_list), PPK_ASSERT_ERROR(red_windows_list->have_no_common_element(yellow_windows_list),
"Error red_windows field and yellow_windows field have at least one common element in their interval"); "Error red_windows field and yellow_windows field have at least one common element in their interval");
} }
state_automata = new DMWindowAutomata(dm_window,red_windows_list,yellow_windows_list);
//seed parameter parsing //seed parameter parsing
bool seed_defined = false; bool seed_defined = false;
...@@ -163,8 +164,8 @@ Broker::Broker(rapidjson::Document *user_description_file) ...@@ -163,8 +164,8 @@ Broker::Broker(rapidjson::Document *user_description_file)
seed_defined, seed_defined,
"No field 'seed' defined although dm_user_multi_behavior " "No field 'seed' defined although dm_user_multi_behavior "
"needs it"); "needs it");
user = new DMUserMultiBehavior(name, param, dm_window, user = new DMUserMultiBehavior(name, param,
seed_generator(), yellow_windows_list, red_windows_list, seed_generator(), state_automata,
logger_user_stat); logger_user_stat);
} }
/* Feedback user */ /* Feedback user */
......
...@@ -66,4 +66,5 @@ private: ...@@ -66,4 +66,5 @@ private:
/* (Optional) Red and Yellow windows for MultiBehavior DM users */ /* (Optional) Red and Yellow windows for MultiBehavior DM users */
DMWindow_list* red_windows_list=nullptr; DMWindow_list* red_windows_list=nullptr;
DMWindow_list* yellow_windows_list = nullptr; DMWindow_list* yellow_windows_list = nullptr;
DMWindowAutomata* state_automata = nullptr;
}; };
\ No newline at end of file
...@@ -22,15 +22,44 @@ bool DMWindow_list::have_no_common_element( DMWindow_list* compare_list) const ...@@ -22,15 +22,44 @@ bool DMWindow_list::have_no_common_element( DMWindow_list* compare_list) const
return intersect.is_empty(); return intersect.is_empty();
} }
DMWindowAutomata::DMWindowAutomata(DMWindow* dm_window,DMWindow_list* red_windows,
DMWindow_list* yellow_windows)
{
this->dm_window = dm_window;
this->red_windows = red_windows;
this->yellow_windows = yellow_windows;
}
bool DMWindowAutomata::is_in_red_state(double date){
// Check whether the date is in a red window
return (dm_window && dm_window->date_in_dm_window(date)) || (red_windows && red_windows->date_in_dm_window(date));
}
bool DMWindowAutomata::is_in_yellow_state(double date){
// Check whether the date is in yellow window
return yellow_windows && yellow_windows->date_in_dm_window(date);
}
bool DMWindowAutomata::has_red_state()
{
return dm_window || red_windows;
}
bool DMWindowAutomata::has_yellow_state()
{
return yellow_windows;
}
DMWindowAutomata::~DMWindowAutomata()
{
}
StateAutomata::~StateAutomata()
{
}
DMUserMultiBehavior::DMUserMultiBehavior( DMUserMultiBehavior::DMUserMultiBehavior(
const std::string & name, const rapidjson::Value &param, DMWindow *window, const std::string & name, const rapidjson::Value &param,
uint_fast32_t random_seed,DMWindow_list *y_windows, uint_fast32_t random_seed,StateAutomata* state_automata, LoggerUserStat* logger)
DMWindow_list *r_windows, LoggerUserStat* logger) : DMUserRenonce(name,param,nullptr),DMUserReconfig(name,param,nullptr),
: DMUserRenonce(name,param,window),DMUserReconfig(name,param,window), DMUserDegrad(name,param,nullptr)
DMUserDegrad(name,param,window)
{ {
yellow_windows = y_windows; this->state_automata = state_automata;
red_windows = r_windows;
this->logger = logger; this->logger = logger;
random_gen = std::mt19937(random_seed); random_gen = std::mt19937(random_seed);
red_prob_multi_core= vector<double> (R_TOTAL_MULTI,0.0); red_prob_multi_core= vector<double> (R_TOTAL_MULTI,0.0);
...@@ -73,7 +102,7 @@ double DMUserMultiBehavior::parse_proba_param(const rapidjson::Value &param, ...@@ -73,7 +102,7 @@ double DMUserMultiBehavior::parse_proba_param(const rapidjson::Value &param,
} }
void DMUserMultiBehavior::init_prob_mono_core(const rapidjson::Value &param,std::vector<double> & red_prob_array, std::vector<double> & yellow_prob_array){ 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 //Red window probability initialization
if(dm_window || red_windows) if(state_automata->has_red_state())
{ {
std::vector<string> red_config(R_TOTAL_MONO, ""); std::vector<string> red_config(R_TOTAL_MONO, "");
red_config[R_DEGRAD_MONO] = "red_prob_degrad_mono_core"; red_config[R_DEGRAD_MONO] = "red_prob_degrad_mono_core";
...@@ -86,7 +115,7 @@ void DMUserMultiBehavior::init_prob_mono_core(const rapidjson::Value &param,std: ...@@ -86,7 +115,7 @@ void DMUserMultiBehavior::init_prob_mono_core(const rapidjson::Value &param,std:
} }
// Yellow probability Initialization // Yellow probability Initialization
if(yellow_windows) if(state_automata->has_yellow_state())
{ {
std::vector<string> yellow_config(Y_TOTAL_MONO, ""); std::vector<string> yellow_config(Y_TOTAL_MONO, "");
yellow_config[Y_DEGRAD_MONO] = "yellow_prob_degrad_mono_core"; yellow_config[Y_DEGRAD_MONO] = "yellow_prob_degrad_mono_core";
...@@ -99,7 +128,7 @@ void DMUserMultiBehavior::init_prob_mono_core(const rapidjson::Value &param,std: ...@@ -99,7 +128,7 @@ void DMUserMultiBehavior::init_prob_mono_core(const rapidjson::Value &param,std:
void DMUserMultiBehavior::init_prob_multi_core(const rapidjson::Value &param,std::vector<double> & red_prob_array, std::vector<double> & yellow_prob_array){ 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 //Red window probability initialization
if (dm_window || red_windows) if (state_automata->has_red_state())
{ {
std::vector<string> red_config(R_TOTAL_MULTI, ""); std::vector<string> red_config(R_TOTAL_MULTI, "");
red_config[R_DEGRAD_MULTI] = "red_prob_degrad_multi_core"; red_config[R_DEGRAD_MULTI] = "red_prob_degrad_multi_core";
...@@ -114,7 +143,7 @@ void DMUserMultiBehavior::init_prob_multi_core(const rapidjson::Value &param,std ...@@ -114,7 +143,7 @@ void DMUserMultiBehavior::init_prob_multi_core(const rapidjson::Value &param,std
} }
// Yellow probability Initialization // Yellow probability Initialization
if (yellow_windows) if (state_automata->has_yellow_state())
{ {
std::vector<string> yellow_config(Y_TOTAL_MULTI, ""); std::vector<string> yellow_config(Y_TOTAL_MULTI, "");
yellow_config[Y_DEGRAD_MULTI] = "yellow_prob_degrad_multi_core"; yellow_config[Y_DEGRAD_MULTI] = "yellow_prob_degrad_multi_core";
...@@ -337,23 +366,15 @@ void DMUserMultiBehavior::log_behavior(shared_ptr<Job> & job,std::string behavio ...@@ -337,23 +366,15 @@ void DMUserMultiBehavior::log_behavior(shared_ptr<Job> & job,std::string behavio
} }
} }
bool DMUserMultiBehavior::is_in_red_window(double date){
// Check whether the date is in a red_window
return (dm_window && dm_window->date_in_dm_window(date)) || (red_windows && red_windows->date_in_dm_window(date));
}
bool DMUserMultiBehavior::is_in_yellow_window(double date){
// Check whether the date is in yellow_window
return yellow_windows && yellow_windows->date_in_dm_window(date);
}
bool DMUserMultiBehavior::handle_job(double date, shared_ptr<Job> job, Profile *profile) bool DMUserMultiBehavior::handle_job(double date, shared_ptr<Job> job, Profile *profile)
{ {
//red_windows and dm_windows check //red_windows and dm_windows check
if(is_in_red_window(date)) { if(state_automata->is_in_red_state(date)) {
return red_window_behavior(date, job,profile); return red_window_behavior(date, job,profile);
} }
// yellow_windows check // yellow_windows check
if (is_in_yellow_window(date)){ if (state_automata->is_in_yellow_state(date)){
/* /*
* We decide at random the behavior (rigid,degrad, reconfig) * We decide at random the behavior (rigid,degrad, reconfig)
* that will be done on this job * that will be done on this job
...@@ -365,4 +386,3 @@ bool DMUserMultiBehavior::handle_job(double date, shared_ptr<Job> job, Profile * ...@@ -365,4 +386,3 @@ bool DMUserMultiBehavior::handle_job(double date, shared_ptr<Job> job, Profile *
return rigid_job(job,profile,1.0); return rigid_job(job,profile,1.0);
} }
} }
...@@ -25,6 +25,29 @@ struct DMWindow_list ...@@ -25,6 +25,29 @@ struct DMWindow_list
}; };
class StateAutomata {
public:
virtual bool is_in_red_state(double date) = 0;
virtual bool is_in_yellow_state(double date) =0;
virtual bool has_red_state()=0;
virtual bool has_yellow_state()=0;
virtual ~StateAutomata();
};
class DMWindowAutomata: public StateAutomata {
public:
DMWindowAutomata(DMWindow* dm_window,DMWindow_list* red_windows, DMWindow_list* yellow_windows);
bool is_in_yellow_state(double date);
bool is_in_red_state(double date);
bool has_yellow_state();
bool has_red_state();
~DMWindowAutomata();
private:
DMWindow* dm_window;
DMWindow_list* red_windows;
DMWindow_list* yellow_windows;
};
/** /**
* @brief User class that adopts a different set of submission behaviors depending * @brief User class that adopts a different set of submission behaviors depending
* on the energy state (red, yellow, green) * on the energy state (red, yellow, green)
...@@ -40,9 +63,8 @@ class DMUserMultiBehavior : public DMUserRenonce,public DMUserReconfig, ...@@ -40,9 +63,8 @@ class DMUserMultiBehavior : public DMUserRenonce,public DMUserReconfig,
{ {
public: public:
DMUserMultiBehavior( DMUserMultiBehavior(
const std::string & name, const rapidjson::Value &param, DMWindow *window, const std::string & name, const rapidjson::Value &param,
uint_fast32_t random_seed, DMWindow_list *yellow_windows, uint_fast32_t random_seed, StateAutomata* state_automata, LoggerUserStat* logger);
DMWindow_list *red_windows, LoggerUserStat* logger);
~DMUserMultiBehavior(); ~DMUserMultiBehavior();
double next_submission(); double next_submission();
void jobs_to_submit( void jobs_to_submit(
...@@ -56,8 +78,7 @@ protected: ...@@ -56,8 +78,7 @@ protected:
R_RIGID_MONO,R_TOTAL_MONO}; R_RIGID_MONO,R_TOTAL_MONO};
enum yellow_behavior_multi {Y_DEGRAD_MULTI,Y_RECONFIG_MULTI,Y_RIGID_MULTI,Y_TOTAL_MULTI}; enum yellow_behavior_multi {Y_DEGRAD_MULTI,Y_RECONFIG_MULTI,Y_RIGID_MULTI,Y_TOTAL_MULTI};
enum yellow_behavior_mono {Y_DEGRAD_MONO,Y_RIGID_MONO,Y_TOTAL_MONO}; enum yellow_behavior_mono {Y_DEGRAD_MONO,Y_RIGID_MONO,Y_TOTAL_MONO};
DMWindow_list *yellow_windows; StateAutomata* state_automata;
DMWindow_list * red_windows;
std::mt19937 random_gen; std::mt19937 random_gen;
std::uniform_real_distribution<double> distribution std::uniform_real_distribution<double> distribution
= std::uniform_real_distribution<double>(0.0, 1.0); = std::uniform_real_distribution<double>(0.0, 1.0);
...@@ -71,9 +92,6 @@ protected: ...@@ -71,9 +92,6 @@ protected:
void init_prob_multi_core(const rapidjson::Value &param, void init_prob_multi_core(const rapidjson::Value &param,
vector<double> &red_prob_array, vector<double> & yellow_prob_array); vector<double> &red_prob_array, vector<double> & yellow_prob_array);
void check_deprecated_param(const rapidjson::Value &param); void check_deprecated_param(const rapidjson::Value &param);
bool is_in_yellow_window(double date);
bool is_in_red_window(double date);
void log_behavior(shared_ptr<Job> & job, std::string behavior_name, void log_behavior(shared_ptr<Job> & job, std::string behavior_name,
long delay_time,double random_value); long delay_time,double random_value);
bool rigid_job(shared_ptr<Job> job,Profile* profile,double random_number); bool rigid_job(shared_ptr<Job> job,Profile* profile,double random_number);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment