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

refactor DMUserMultibehavior in a new_file user_windows

parent fc6d5ff4
Branches
Tags
1 merge request!12Merge Request multibehavior
Pipeline #5461 passed with warnings
......@@ -44,6 +44,8 @@ src = [
'src/users/user_model.hpp',
'src/users/user_replay.cpp',
'src/users/user_replay.hpp',
'src/users/user_windows.cpp',
'src/users/user_windows.hpp',
'src/users/user_feedback.cpp',
'src/users/user_feedback.hpp',
'src/users/dynscheduler.cpp',
......
......@@ -233,24 +233,7 @@ bool DMWindow::date_in_dm_window(double date)
return date >= inf && date < sup;
}
DMWindow_list::DMWindow_list(std::vector<DMWindow> window_array){
content= window_array;
}
bool DMWindow_list::date_in_dm_window(double date){
// Return if the date belong in one of the dm_window of the list
std::vector<DMWindow_list>::size_type index = index_in_dm_window(date);
return index!=content.size();
}
std::vector<DMWindow_list>::size_type DMWindow_list::index_in_dm_window(double date){
for ( std::vector<DMWindow>::size_type i=0; i < content.size();i++){
DMWindow dm_window = content[i];
if(dm_window.date_in_dm_window(date)){
return i;
}
}
return content.size();
}
DMUserReconfig::DMUserReconfig(
std::string name, const rapidjson::Value &param, DMWindow *window)
......@@ -351,118 +334,6 @@ void DMUserDelay::jobs_to_submit(double date, std::list<shared_ptr<Job>> &jobs,
ReplayUser::jobs_to_submit(date, jobs, profiles);
}
void DMUserMultiBehavior::init_prob(const rapidjson::Value &param,uint_fast32_t random_seed){
random_gen = std::mt19937(random_seed);
//Red window probability initialization
std::vector<double> red_prob (5,-1.0);
std::vector<bool> red_set_prob (5,false);
std::string red_config[] = {"red_prob_degrad","red_prob_delay",
"red_prob_reconfig","red_prob_renonce","red_prob_rigid"};
double total_unset_probability = 1.0;
double total_random_set_prob = 0.0;
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.size();i++){
std::string current_prob = red_config[i];
if(param.HasMember(current_prob.c_str())){
/*PPK_ASSERT(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_set_prob[i] = true;
red_prob[i] = param[current_prob.c_str()].GetDouble();
total_unset_probability -= red_prob[i];
}
else
{
red_prob[i] = distribution(random_gen);
total_random_set_prob += red_prob[i];
}
}
// We normalize the probability that wasn't set by user such that the total
// probability is 1.0
double random_set_coeff = total_unset_probability/total_random_set_prob;
for (std::vector<double>::size_type i= 0 ; i < red_prob.size();i++){
if(not red_set_prob[i]){
red_prob[i]=red_prob[i]* random_set_coeff;
}
red_prob_total+= red_prob[i];
}
//we save the result in the used probability variable
red_prob_degrad = red_prob[0];
red_prob_delay = red_prob[1] ;
red_prob_reconfig = red_prob[2];
red_prob_renonce = red_prob[3];
// Yellow probability Initialization
std::vector<double> yellow_prob (3,-1.0);
std::vector<bool> yellow_set_prob (3,false);
std::string yellow_config[] = {"yellow_prob_degrad",
"yellow_prob_reconfig","yellow_prob_rigid"};
total_unset_probability = 1.0;
total_random_set_prob = 0.0;
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.size();i++){
std::string current_prob = yellow_config[i];
if(param.HasMember(current_prob.c_str())){
/*PPK_ASSERT(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_set_prob[i] = true;
yellow_prob[i] = param[current_prob.c_str()].GetDouble();
total_unset_probability -= yellow_prob[i];
}
else
{
yellow_prob[i] = distribution(random_gen);
total_random_set_prob += yellow_prob[i];
}
}
// We normalize the probability that wasn't set by user such that the total
// probability is 1.0
random_set_coeff = total_unset_probability/total_random_set_prob;
for (std::vector<double>::size_type i= 0 ; i < yellow_prob.size();i++){
if(not yellow_set_prob[i]){
yellow_prob[i]=yellow_prob[i]* random_set_coeff;
}
yellow_prob_total+= yellow_prob[i];
}
yellow_prob_degrad= yellow_prob[0];
yellow_prob_reconfig = yellow_prob[1];
}
DMUserMultiBehavior::DMUserMultiBehavior(
std::string name, const rapidjson::Value &param, DMWindow *window,
uint_fast32_t random_seed,DMWindow_list *y_windows,
DMWindow_list *r_windows, LoggerUserStat* logger)
: DMUserRenonce(name,param,window), DMUserDelay(name,param,window),
DMUserReconfig(name,param,window), DMUserDegrad(name,param,window)
{
yellow_windows = y_windows;
red_windows = r_windows;
this->logger = logger;
red_window_buffer = nullptr;
yellow_window_buffer = nullptr;
init_prob(param,random_seed);
}
DMUserMultiBehavior::~DMUserMultiBehavior()
{
if(original_trace)
{
delete original_trace;
original_trace = NULL;
}
}
void DMUserMultiBehavior::jobs_to_submit(
double date, std::list<shared_ptr<Job>> &jobs, std::list< const Profile *> &profiles)
{
DMUserRenonce::jobs_to_submit(date, jobs, profiles);
}
bool DMUserReconfig::reconfig_job(shared_ptr<Job> job, Profile *profile)
{
int orig_nb_core = job->nb_requested_resources;
......@@ -618,180 +489,4 @@ bool DMUserDelay::handle_job(double date, shared_ptr<Job> job, Profile *profile)
}
}
bool DMUserMultiBehavior::C_you_later_job(double date, double next_time,shared_ptr<Job> job)
{
/* Log... */
log_behavior(job,"C_you_later",next_time);
dm_stat[2 * DELAYED]++;
dm_stat[2*DELAYED+1]+= job->nb_requested_resources * std::stol(job->profile);
/* Delete original job from queue and update date */
original_trace->remove_job(original_trace->first_job());
job->submission_time = date + next_time;
/* Put job back in the queue and sort */
SortableJobOrder::UpdateInformation update_info(0);
Job *j = new Job();
*j = *job;
original_trace->insert_job(j);
original_trace->sort_queue(&update_info);
/* Return "Do not execute now" */
return false;
}
bool DMUserMultiBehavior::red_window_behavior(double date,shared_ptr<Job> job,Profile *profile)
{
/*
* We decide at random the behavior
* (renounce, C_you_later, degrad, reconfig,rigid)
* that will be done on this job
*/
double behavior = distribution(random_gen)*red_prob_total;
if (behavior < red_prob_renonce){
log_behavior(job,"renonce",0.);
return renonce_job(job);
}
else if (behavior < red_prob_renonce+red_prob_delay){
return C_you_later_job(date,3600.0,job);
}
else if (behavior < red_prob_degrad + red_prob_delay + red_prob_renonce){
if (job->nb_requested_resources== 1){
log_behavior(job,"rigid",0.);
}
else{
log_behavior(job, "degrad", 0.);
}
return degrad_job(job,profile);
}
else if (behavior <
red_prob_degrad + red_prob_delay + red_prob_renonce + red_prob_reconfig){
if (job->nb_requested_resources == 1){
log_behavior(job,"rigid",0.);
}
else{
log_behavior(job, "reconfig", 0.);
}
return reconfig_job(job,profile);
}
else{
// if none of the above we launch the job without changing anything
// i.e. rigid strategy
log_behavior(job,"rigid",0.);
Parser::profile_from_duration(
profile, job->profile, user_name, platform_computing_speed);
dm_stat[2 * RIGID]++;
dm_stat[2 * RIGID + 1]
+= job->nb_requested_resources * std::stol(job->profile);
return true;
}
}
bool DMUserMultiBehavior::yellow_window_behavior(shared_ptr<Job> job,Profile *profile){
/*
* We decide at random the behavior (rigid, degrad, reconfig)
* that will be done on this job
*/
double behavior = distribution(random_gen)*yellow_prob_total;
if (behavior < yellow_prob_reconfig){
if (job->nb_requested_resources == 1){
log_behavior(job,"rigid",0.);
}
else{
log_behavior(job, "reconfig", 0.);
}
return reconfig_job(job,profile);
}
else if (behavior < yellow_prob_reconfig+yellow_prob_degrad){
if (job->nb_requested_resources== 1){
log_behavior(job,"rigid",0.);
}
else{
log_behavior(job, "degrad", 0.);
}
return degrad_job(job,profile);
}
else{
// if none of the above we launch the job without i.e. rigid strategy
log_behavior(job,"rigid",0.);
Parser::profile_from_duration(
profile, job->profile, user_name, platform_computing_speed);
dm_stat[2 * RIGID]++;
dm_stat[2 * RIGID + 1]
+= job->nb_requested_resources * std::stol(job->profile);
return true;
}
}
void DMUserMultiBehavior::log_behavior(shared_ptr<Job> job, std::string behavior_name, double delay_time)
{
if(logger){
logger->add_stat(job,behavior_name,delay_time);
}
}
bool DMUserMultiBehavior::is_in_red_window(double date){
// Check whether the date is in a red_window
if ((dm_window && dm_window->date_in_dm_window(date))
|| (red_window_buffer && red_window_buffer->date_in_dm_window(date))){
return true;
}
if (red_windows == nullptr){
return false;
}
std::vector<DMWindow_list>::size_type index_red = red_windows->index_in_dm_window(date);
if( index_red != red_windows->content.size()) {
red_window_buffer = &red_windows->content[index_red];
return true;
}
return false;
}
bool DMUserMultiBehavior::is_in_yellow_window(double date){
// Check whether the date is in yellow_window
if (yellow_windows == nullptr){
return false;
}
if (yellow_window_buffer && yellow_window_buffer->date_in_dm_window(date)){
return true;
}
std::vector<DMWindow_list>::size_type index_yellow = yellow_windows->index_in_dm_window(date);
if( index_yellow != yellow_windows->content.size()) {
yellow_window_buffer = &yellow_windows->content[index_yellow];
return true;
}
return false;
}
bool DMUserMultiBehavior::handle_job(double date, shared_ptr<Job> job, Profile *profile)
{
/*
* function called each time the user want to submit a job it does the following :
* - if the user is in a red window
* the user adopt the behavior define in red_window_behavior
* - if the user is in a yellow window AND not in a red one
* the user adopt the behavior define in yellow_windows_behavior
* - else the user submit it job without any change
*/
if(is_in_red_window(date)) {
return red_window_behavior(date, job,profile);
}
// yellow_windows check
if (is_in_yellow_window(date)){
/*
* We decide at random the behavior (rigid,degrad, reconfig)
* that will be done on this job
*/
return yellow_window_behavior(job,profile);
}
else
{
log_behavior(job,"rigid",0.);
Parser::profile_from_duration(
profile, job->profile, user_name, platform_computing_speed);
dm_stat[2 * RIGID]++;
dm_stat[2 * RIGID + 1]
+= job->nb_requested_resources * std::stol(job->profile);
return true;
}
}
/**
* Users simulated by replaying an input trace.
*/
#pragma once
#include "users/user.hpp"
#include <random>
#include "queue.hpp"
......@@ -16,13 +17,7 @@ struct DMWindow
DMWindow(int a, int b);
bool date_in_dm_window(double date);
};
struct DMWindow_list
{
std::vector<DMWindow> content;
DMWindow_list(std::vector<DMWindow> window_array);
std::vector<DMWindow>::size_type index_in_dm_window(double date);
bool date_in_dm_window(double date);
};
class ReplayUser : public User
{
......@@ -200,50 +195,3 @@ protected:
bool delay_job(shared_ptr<Job> job);
bool handle_job(double date, shared_ptr<Job> job, Profile *profile);
};
/**
* @brief User class that combines all the behavior class above
* @details this User act as Replay_user_rigid when it is in no window contained
* in the fields 'red_windows', 'yellow_windows', 'dm_window'
* When in these windows it change behavior as detailed in red_window_behavior
* for 'red_windows' and 'dm_windows' that uses randomness.
* And for 'yellow_windows', it is detailed in yellow_window_behavior.
*/
class DMUserMultiBehavior : public DMUserRenonce, public DMUserDelay,
public DMUserReconfig, public DMUserDegrad
{
public:
DMUserMultiBehavior(
std::string name, const rapidjson::Value &param, DMWindow *window,
uint_fast32_t random_seed, DMWindow_list *yellow_windows,
DMWindow_list *red_windows, LoggerUserStat* logger);
~DMUserMultiBehavior();
void init_prob(const rapidjson::Value &param, uint_fast32_t random_seed);
double red_prob_delay;
double red_prob_renonce;
double red_prob_reconfig;
double red_prob_degrad;
double red_prob_total;
double yellow_prob_degrad;
double yellow_prob_reconfig;
double yellow_prob_total;
double next_submission();
void jobs_to_submit(
double date, std::list<shared_ptr<Job> > &jobs, std::list< const Profile *> &profiles);
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, double delay_time);
protected:
DMWindow_list *yellow_windows;
DMWindow_list * red_windows;
DMWindow *red_window_buffer;
DMWindow *yellow_window_buffer;
std::mt19937 random_gen;
std::uniform_real_distribution<double> distribution
= std::uniform_real_distribution<double>(0.0, 1.0);
LoggerUserStat *logger = nullptr ;
bool C_you_later_job(double date, double next_time,shared_ptr<Job> job);
bool handle_job(double date,shared_ptr<Job> job,Profile *profile);
bool red_window_behavior(double date,shared_ptr<Job> job, Profile *profile);
bool yellow_window_behavior(shared_ptr<Job> job, Profile *profile);
};
\ No newline at end of file
#include "user_windows.hpp"
#include "../pempek_assert.hpp"
DMWindow_list::DMWindow_list(std::vector<DMWindow> window_array){
content= window_array;
}
bool DMWindow_list::date_in_dm_window(double date){
// Return if the date belong in one of the dm_window of the list
std::vector<DMWindow_list>::size_type index = index_in_dm_window(date);
return index!=content.size();
}
std::vector<DMWindow_list>::size_type DMWindow_list::index_in_dm_window(double date){
for ( std::vector<DMWindow>::size_type i=0; i < content.size();i++){
DMWindow dm_window = content[i];
if(dm_window.date_in_dm_window(date)){
return i;
}
}
return content.size();
}
void DMUserMultiBehavior::init_prob(const rapidjson::Value &param,uint_fast32_t random_seed){
random_gen = std::mt19937(random_seed);
//Red window probability initialization
std::vector<double> red_prob (5,-1.0);
std::vector<bool> red_set_prob (5,false);
std::string red_config[] = {"red_prob_degrad","red_prob_delay",
"red_prob_reconfig","red_prob_renonce","red_prob_rigid"};
double total_unset_probability = 1.0;
double total_random_set_prob = 0.0;
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.size();i++){
std::string current_prob = red_config[i];
if(param.HasMember(current_prob.c_str())){
/*PPK_ASSERT(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_set_prob[i] = true;
red_prob[i] = param[current_prob.c_str()].GetDouble();
total_unset_probability -= red_prob[i];
}
else
{
red_prob[i] = distribution(random_gen);
total_random_set_prob += red_prob[i];
}
}
// We normalize the probability that wasn't set by user such that the total
// probability is 1.0
double random_set_coeff = total_unset_probability/total_random_set_prob;
for (std::vector<double>::size_type i= 0 ; i < red_prob.size();i++){
if(not red_set_prob[i]){
red_prob[i]=red_prob[i]* random_set_coeff;
}
red_prob_total+= red_prob[i];
}
//we save the result in the used probability variable
red_prob_degrad = red_prob[0];
red_prob_delay = red_prob[1] ;
red_prob_reconfig = red_prob[2];
red_prob_renonce = red_prob[3];
// Yellow probability Initialization
std::vector<double> yellow_prob (3,-1.0);
std::vector<bool> yellow_set_prob (3,false);
std::string yellow_config[] = {"yellow_prob_degrad",
"yellow_prob_reconfig","yellow_prob_rigid"};
total_unset_probability = 1.0;
total_random_set_prob = 0.0;
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.size();i++){
std::string current_prob = yellow_config[i];
if(param.HasMember(current_prob.c_str())){
/*PPK_ASSERT(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_set_prob[i] = true;
yellow_prob[i] = param[current_prob.c_str()].GetDouble();
total_unset_probability -= yellow_prob[i];
}
else
{
yellow_prob[i] = distribution(random_gen);
total_random_set_prob += yellow_prob[i];
}
}
// We normalize the probability that wasn't set by user such that the total
// probability is 1.0
random_set_coeff = total_unset_probability/total_random_set_prob;
for (std::vector<double>::size_type i= 0 ; i < yellow_prob.size();i++){
if(not yellow_set_prob[i]){
yellow_prob[i]=yellow_prob[i]* random_set_coeff;
}
yellow_prob_total+= yellow_prob[i];
}
yellow_prob_degrad= yellow_prob[0];
yellow_prob_reconfig = yellow_prob[1];
}
DMUserMultiBehavior::DMUserMultiBehavior(
std::string name, const rapidjson::Value &param, DMWindow *window,
uint_fast32_t random_seed,DMWindow_list *y_windows,
DMWindow_list *r_windows, LoggerUserStat* logger)
: DMUserRenonce(name,param,window), DMUserDelay(name,param,window),
DMUserReconfig(name,param,window), DMUserDegrad(name,param,window)
{
yellow_windows = y_windows;
red_windows = r_windows;
this->logger = logger;
red_window_buffer = nullptr;
yellow_window_buffer = nullptr;
init_prob(param,random_seed);
}
DMUserMultiBehavior::~DMUserMultiBehavior()
{
if(original_trace)
{
delete original_trace;
original_trace = NULL;
}
}
void DMUserMultiBehavior::jobs_to_submit(
double date, std::list<shared_ptr<Job>> &jobs, std::list< const Profile *> &profiles)
{
DMUserRenonce::jobs_to_submit(date, jobs, profiles);
}
bool DMUserMultiBehavior::C_you_later_job(double date, double next_time,shared_ptr<Job> job)
{
/* Log... */
log_behavior(job,"C_you_later",next_time);
dm_stat[2 * DELAYED]++;
dm_stat[2*DELAYED+1]+= job->nb_requested_resources * std::stol(job->profile);
/* Delete original job from queue and update date */
original_trace->remove_job(original_trace->first_job());
job->submission_time = date + next_time;
/* Put job back in the queue and sort */
SortableJobOrder::UpdateInformation update_info(0);
Job *j = new Job();
*j = *job;
original_trace->insert_job(j);
original_trace->sort_queue(&update_info);
/* Return "Do not execute now" */
return false;
}
bool DMUserMultiBehavior::red_window_behavior(double date,shared_ptr<Job> job,Profile *profile)
{
/*
* We decide at random the behavior
* (renounce, C_you_later, degrad, reconfig,rigid)
* that will be done on this job
*/
double behavior = distribution(random_gen)*red_prob_total;
if (behavior < red_prob_renonce){
log_behavior(job,"renonce",0.);
return renonce_job(job);
}
else if (behavior < red_prob_renonce+red_prob_delay){
return C_you_later_job(date,3600.0,job);
}
else if (behavior < red_prob_degrad + red_prob_delay + red_prob_renonce){
if (job->nb_requested_resources== 1){
log_behavior(job,"rigid",0.);
}
else{
log_behavior(job, "degrad", 0.);
}
return degrad_job(job,profile);
}
else if (behavior <
red_prob_degrad + red_prob_delay + red_prob_renonce + red_prob_reconfig){
if (job->nb_requested_resources == 1){
log_behavior(job,"rigid",0.);
}
else{
log_behavior(job, "reconfig", 0.);
}
return reconfig_job(job,profile);
}
else{
// if none of the above we launch the job without changing anything
// i.e. rigid strategy
log_behavior(job,"rigid",0.);
Parser::profile_from_duration(
profile, job->profile, user_name, platform_computing_speed);
dm_stat[2 * RIGID]++;
dm_stat[2 * RIGID + 1]
+= job->nb_requested_resources * std::stol(job->profile);
return true;
}
}
bool DMUserMultiBehavior::yellow_window_behavior(shared_ptr<Job> job,Profile *profile){
/*
* We decide at random the behavior (rigid, degrad, reconfig)
* that will be done on this job
*/
double behavior = distribution(random_gen)*yellow_prob_total;
if (behavior < yellow_prob_reconfig){
if (job->nb_requested_resources == 1){
log_behavior(job,"rigid",0.);
}
else{
log_behavior(job, "reconfig", 0.);
}
return reconfig_job(job,profile);
}
else if (behavior < yellow_prob_reconfig+yellow_prob_degrad){
if (job->nb_requested_resources== 1){
log_behavior(job,"rigid",0.);
}
else{
log_behavior(job, "degrad", 0.);
}
return degrad_job(job,profile);
}
else{
// if none of the above we launch the job without i.e. rigid strategy
log_behavior(job,"rigid",0.);
Parser::profile_from_duration(
profile, job->profile, user_name, platform_computing_speed);
dm_stat[2 * RIGID]++;
dm_stat[2 * RIGID + 1]
+= job->nb_requested_resources * std::stol(job->profile);
return true;
}
}
void DMUserMultiBehavior::log_behavior(shared_ptr<Job> job, std::string behavior_name, double delay_time)
{
if(logger){
logger->add_stat(job,behavior_name,delay_time);
}
}
bool DMUserMultiBehavior::is_in_red_window(double date){
// Check whether the date is in a red_window
if ((dm_window && dm_window->date_in_dm_window(date))
|| (red_window_buffer && red_window_buffer->date_in_dm_window(date))){
return true;
}
if (red_windows == nullptr){
return false;
}
std::vector<DMWindow_list>::size_type index_red = red_windows->index_in_dm_window(date);
if( index_red != red_windows->content.size()) {
red_window_buffer = &red_windows->content[index_red];
return true;
}
return false;
}
bool DMUserMultiBehavior::is_in_yellow_window(double date){
// Check whether the date is in yellow_window
if (yellow_windows == nullptr){
return false;
}
if (yellow_window_buffer && yellow_window_buffer->date_in_dm_window(date)){
return true;
}
std::vector<DMWindow_list>::size_type index_yellow = yellow_windows->index_in_dm_window(date);
if( index_yellow != yellow_windows->content.size()) {
yellow_window_buffer = &yellow_windows->content[index_yellow];
return true;
}
return false;
}
bool DMUserMultiBehavior::handle_job(double date, shared_ptr<Job> job, Profile *profile)
{
/*
* function called each time the user want to submit a job it does the following :
* - if the user is in a red window
* the user adopt the behavior define in red_window_behavior
* - if the user is in a yellow window AND not in a red one
* the user adopt the behavior define in yellow_windows_behavior
* - else the user submit it job without any change
*/
if(is_in_red_window(date)) {
return red_window_behavior(date, job,profile);
}
// yellow_windows check
if (is_in_yellow_window(date)){
/*
* We decide at random the behavior (rigid,degrad, reconfig)
* that will be done on this job
*/
return yellow_window_behavior(job,profile);
}
else
{
log_behavior(job,"rigid",0.);
Parser::profile_from_duration(
profile, job->profile, user_name, platform_computing_speed);
dm_stat[2 * RIGID]++;
dm_stat[2 * RIGID + 1]
+= job->nb_requested_resources * std::stol(job->profile);
return true;
}
}
\ No newline at end of file
#pragma once
#include "users/user.hpp"
#include <random>
#include "queue.hpp"
#include "users/user_replay.hpp"
#include "users/log_user_stat.hpp"
struct DMWindow_list
{
std::vector<DMWindow> content;
DMWindow_list(std::vector<DMWindow> window_array);
std::vector<DMWindow>::size_type index_in_dm_window(double date);
bool date_in_dm_window(double date);
};
class DMUserMultiBehavior : public DMUserRenonce, public DMUserDelay,
public DMUserReconfig, public DMUserDegrad
{
public:
DMUserMultiBehavior(
std::string name, const rapidjson::Value &param, DMWindow *window,
uint_fast32_t random_seed, DMWindow_list *yellow_windows,
DMWindow_list *red_windows, LoggerUserStat* logger);
~DMUserMultiBehavior();
void init_prob(const rapidjson::Value &param, uint_fast32_t random_seed);
double red_prob_delay;
double red_prob_renonce;
double red_prob_reconfig;
double red_prob_degrad;
double red_prob_total;
double yellow_prob_degrad;
double yellow_prob_reconfig;
double yellow_prob_total;
double next_submission();
void jobs_to_submit(
double date, std::list<shared_ptr<Job> > &jobs, std::list< const Profile *> &profiles);
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, double delay_time);
protected:
DMWindow_list *yellow_windows;
DMWindow_list * red_windows;
DMWindow *red_window_buffer;
DMWindow *yellow_window_buffer;
std::mt19937 random_gen;
std::uniform_real_distribution<double> distribution
= std::uniform_real_distribution<double>(0.0, 1.0);
LoggerUserStat *logger = nullptr ;
bool C_you_later_job(double date, double next_time,shared_ptr<Job> job);
bool handle_job(double date,shared_ptr<Job> job,Profile *profile);
bool red_window_behavior(double date,shared_ptr<Job> job, Profile *profile);
bool yellow_window_behavior(shared_ptr<Job> job, Profile *profile);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment