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

New implementation of DM_Windows_list now we use IntervalSet

parent e44d51c2
Branches
Tags
1 merge request!16Merge request multibehavior
......@@ -316,7 +316,7 @@ DMWindow_list* Broker::parse_dm_windows(const std::string attr_name,
std::string error_message_sorted_disjoint = "Invalid user_description file : the field ";
error_message_sorted_disjoint += attr_name;
error_message_sorted_disjoint += " should be sorted and contains disjoint interval";
std::vector<DMWindow> windows_collect;
IntervalSet windows_set;
int last_bound = -1;
for (SizeType i = 0 ; i < windows_param.GetArray().Size(); i++) {
const Value &window =
......@@ -331,11 +331,10 @@ DMWindow_list* Broker::parse_dm_windows(const std::string attr_name,
PPK_ASSERT_ERROR(begin_window > last_bound,
"%s",error_message_sorted_disjoint.c_str());
last_bound = end_window;
DMWindow* to_add =
new DMWindow(begin_window,end_window);
windows_collect.push_back(*to_add);
IntervalSet to_add = IntervalSet::ClosedInterval (begin_window,end_window);
windows_set+= to_add;
}
return new DMWindow_list(windows_collect);
return new DMWindow_list(windows_set);
}
void Broker::update_status_if_dyn_job(
const string &job_id, JobStatus status)
......
......@@ -3,29 +3,16 @@
#include "../pempek_assert.hpp"
DMWindow_list::DMWindow_list(std::vector<DMWindow> window_array){
content= std::move(window_array);
DMWindow_list::DMWindow_list(const IntervalSet & interval){
this->interval= interval;
}
bool DMWindow_list::date_in_dm_window(double date){
bool DMWindow_list::date_in_dm_window(double date) const{
/* Returns true if the date is in one of the dm_window of the DMWindow_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.inf > date){
return content.size();
}
if(dm_window.date_in_dm_window(date)){
return i;
}
}
return content.size();
return interval.contains((int) date);
}
void DMUserMultiBehavior::init_prob(const rapidjson::Value &param,std::vector<double> & red_prob_array, std::vector<double> & yellow_prob_array){
......@@ -97,8 +84,6 @@ DMUserMultiBehavior::DMUserMultiBehavior(
yellow_windows = y_windows;
red_windows = r_windows;
this->logger = logger;
red_window_buffer = nullptr;
yellow_window_buffer = nullptr;
random_gen = std::mt19937(random_seed);
red_prob= vector<double> (R_TOTAL,0.0);
yellow_prob = vector<double> (Y_TOTAL,0.0);
......@@ -242,34 +227,11 @@ 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
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;
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
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;
return yellow_windows && yellow_windows->date_in_dm_window(date);
}
bool DMUserMultiBehavior::handle_job(double date, shared_ptr<Job> job, Profile *profile)
{
......
......@@ -17,10 +17,9 @@
struct DMWindow_list
{
std::vector<DMWindow> content;
explicit 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);
IntervalSet interval;
explicit DMWindow_list(const IntervalSet& interval);
bool date_in_dm_window(double date) const;
};
......@@ -53,8 +52,6 @@ protected:
enum yellow_behavior {Y_DEGRAD,Y_RECONFIG,Y_RIGID,Y_TOTAL};
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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment