89 #include <unordered_map>
91 #include "../submodules/CoreLibrary/CoreLibrary/utils.h"
92 #include "controller.h"
111 uint32 sln_thr_changes_;
112 float32 acc_sln_thr_;
113 uint32 act_thr_changes_;
114 float32 acc_act_thr_;
115 uint32 vis_thr_changes_;
116 float32 acc_vis_thr_;
117 uint32 c_sln_changes_;
119 uint32 c_act_changes_;
121 uint32 c_sln_thr_changes_;
122 float32 acc_c_sln_thr_;
123 uint32 c_act_thr_changes_;
124 float32 acc_c_act_thr_;
125 void reset_ctrl_values();
139 float32 sln_thr_decay_;
140 int32 decay_periods_to_go_;
141 float32 decay_percentage_per_period_;
142 float32 decay_target_;
143 void reset_decay_values();
146 int32 sln_change_monitoring_periods_to_go_;
147 int32 act_change_monitoring_periods_to_go_;
149 void _mod_0_positive(uint16 member_index, float32 value);
150 void _mod_0_plus1(uint16 member_index, float32 value);
151 void _mod_minus1_plus1(uint16 member_index, float32 value);
152 void _set_0_positive(uint16 member_index, float32 value);
153 void _set_0_plus1(uint16 member_index, float32 value);
154 void _set_minus1_plus1(uint16 member_index, float32 value);
155 void _set_0_1(uint16 member_index, float32 value);
157 bool is_active_pgm(
View *view);
158 bool is_eligible_input(
View *view);
160 void inject(
View *view);
162 void notifyNew(
View *view);
163 void cov(
View *view);
167 float32 former_sln_thr;
172 GroupState(float32 former_sln_thr,
176 bool is_c_salient) : former_sln_thr(former_sln_thr), was_c_active(was_c_active), is_c_active(is_c_active), was_c_salient(was_c_salient), is_c_salient(is_c_salient) {}
179 void _update_saliency(GroupState *state,
View *view);
180 void _update_activation(GroupState *state,
View *view);
181 void _update_visibility(GroupState *state,
View *view);
183 void _initiate_sln_propagation(Code *
object, float32 change, float32 source_sln_thr)
const;
184 void _initiate_sln_propagation(Code *
object, float32 change, float32 source_sln_thr, std::vector<Code *> &path)
const;
185 void _propagate_sln(Code *
object, float32 change, float32 source_sln_thr, std::vector<Code *> &path)
const;
189 std::unordered_map<uint32, P<View> > ipgm_views_;
190 std::unordered_map<uint32, P<View> > anti_ipgm_views_;
191 std::unordered_map<uint32, P<View> > input_less_ipgm_views_;
192 std::unordered_map<uint32, P<View> > notification_views_;
193 std::unordered_map<uint32, P<View> > group_views_;
194 std::unordered_map<uint32, P<View> > other_views_;
200 std::unordered_map<Group *, bool> viewing_groups_;
206 std::vector<Controller *> new_controllers_;
213 virtual void execute(
Group *g)
const = 0;
219 ModSet(uint32 oid, uint16 member_index, float32 value) :
Operation(oid), member_index_(member_index), value_(value) {}
220 const uint16 member_index_;
221 const float32 value_;
227 Mod(uint32 oid, uint16 member_index, float32 value) :
ModSet(oid, member_index, value) {}
228 void execute(
Group *g)
const override {
230 View *v = g->get_view(oid_);
232 v->mod(member_index_, value_);
239 Set(uint32 oid, uint16 member_index, float32 value) :
ModSet(oid, member_index, value) {}
240 void execute(
Group *g)
const override {
242 View *v = g->get_view(oid_);
244 v->set(member_index_, value_);
249 std::vector<Operation *> pending_operations_;
255 bool invalidate()
override;
257 bool all_views_cond(uint8 &selector, std::unordered_map<uint32,
P<View> >::const_iterator &it, std::unordered_map<uint32,
P<View> >::const_iterator &end) {
259 switch (selector++) {
261 it = anti_ipgm_views_.begin();
262 end = anti_ipgm_views_.end();
265 it = input_less_ipgm_views_.begin();
266 end = input_less_ipgm_views_.end();
269 it = notification_views_.begin();
270 end = notification_views_.end();
273 it = group_views_.begin();
274 end = group_views_.end();
277 it = other_views_.begin();
278 end = other_views_.end();
288 #define FOR_ALL_VIEWS_BEGIN(g,it) { \
290 std::unordered_map<uint32,P<View> >::const_iterator it=g->ipgm_views_.begin(); \
291 std::unordered_map<uint32,P<View> >::const_iterator end=g->ipgm_views_.end(); \
292 for(selector=0;g->all_views_cond(selector,it,end);++it){
294 #define FOR_ALL_VIEWS_BEGIN_NO_INC(g,it) { \
296 std::unordered_map<uint32,P<View> >::const_iterator it=g->ipgm_views_.begin(); \
297 std::unordered_map<uint32,P<View> >::const_iterator end=g->ipgm_views_.end(); \
298 for(selector=0;g->all_views_cond(selector,it,end);){
300 #define FOR_ALL_VIEWS_END } \
303 bool views_with_inputs_cond(uint8 &selector, std::unordered_map<uint32,
P<View> >::const_iterator &it, std::unordered_map<uint32,
P<View> >::const_iterator &end) {
305 switch (selector++) {
307 it = anti_ipgm_views_.begin();
308 end = anti_ipgm_views_.end();
318 #define FOR_ALL_VIEWS_WITH_INPUTS_BEGIN(g,it) { \
320 std::unordered_map<uint32,P<View> >::const_iterator it=g->ipgm_views_.begin(); \
321 std::unordered_map<uint32,P<View> >::const_iterator end=g->ipgm_views_.end(); \
322 for(selector=0;g->views_with_inputs_cond(selector,it,end);++it){
324 #define FOR_ALL_VIEWS_WITH_INPUTS_END } \
327 bool non_ntf_views_cond(uint8 &selector, std::unordered_map<uint32,
P<View> >::const_iterator &it, std::unordered_map<uint32,
P<View> >::const_iterator &end) {
329 switch (selector++) {
331 it = anti_ipgm_views_.begin();
332 end = anti_ipgm_views_.end();
335 it = input_less_ipgm_views_.begin();
336 end = input_less_ipgm_views_.end();
339 it = group_views_.begin();
340 end = group_views_.end();
343 it = other_views_.begin();
344 end = other_views_.end();
354 #define FOR_ALL_NON_NTF_VIEWS_BEGIN(g,it) { \
356 std::unordered_map<uint32,P<View> >::const_iterator it=g->ipgm_views_.begin(); \
357 std::unordered_map<uint32,P<View> >::const_iterator end=g->ipgm_views_.end(); \
358 for(selector=0;g->non_ntf_views_cond(selector,it,end);++it){
360 #define FOR_ALL_NON_NTF_VIEWS_END } \
363 View *get_view(uint32 OID);
365 uint32 get_upr()
const;
367 float32 get_sln_thr()
const;
368 float32 get_act_thr()
const;
369 float32 get_vis_thr()
const;
371 float32 get_c_sln()
const;
372 float32 get_c_act()
const;
374 float32 get_c_sln_thr()
const;
375 float32 get_c_act_thr()
const;
377 void mod_sln_thr(float32 value);
378 void set_sln_thr(float32 value);
379 void mod_act_thr(float32 value);
380 void set_act_thr(float32 value);
381 void mod_vis_thr(float32 value);
382 void set_vis_thr(float32 value);
383 void mod_c_sln(float32 value);
384 void set_c_sln(float32 value);
385 void mod_c_act(float32 value);
386 void set_c_act(float32 value);
387 void mod_c_sln_thr(float32 value);
388 void set_c_sln_thr(float32 value);
389 void mod_c_act_thr(float32 value);
390 void set_c_act_thr(float32 value);
392 float32 update_sln_thr();
393 float32 update_act_thr();
394 float32 update_vis_thr();
395 float32 update_c_sln();
396 float32 update_c_act();
397 float32 update_c_sln_thr();
398 float32 update_c_act_thr();
400 float32 get_sln_chg_thr();
401 float32 get_sln_chg_prd();
402 float32 get_act_chg_thr();
403 float32 get_act_chg_prd();
405 float32 get_avg_sln();
406 float32 get_high_sln();
407 float32 get_low_sln();
408 float32 get_avg_act();
409 float32 get_high_act();
410 float32 get_low_act();
412 float32 get_high_sln_thr();
413 float32 get_low_sln_thr();
414 float32 get_sln_ntf_prd();
415 float32 get_high_act_thr();
416 float32 get_low_act_thr();
417 float32 get_act_ntf_prd();
418 float32 get_low_res_thr();
420 float32 get_ntf_new();
422 uint16 get_ntf_grp_count();
423 Group *get_ntf_grp(uint16 i);
426 float32 update_res(View *v);
427 float32 update_sln(View *v);
428 float32 update_act(View *v);
433 void mod(uint16 member_index, float32 value)
override;
434 void set(uint16 member_index, float32 value)
override;
439 bool load(View *view, Code *
object);
450 void update(Timestamp planned_time);
452 void inject_new_object(View *view);
453 void inject_existing_object(View *view);
454 void inject_group(View *view);
455 void inject_notification(View *view,
bool lock);
456 void inject_hlps(std::vector<View *> &views);
457 void inject_reduction_jobs(View *view);
463 size_t operator ()(
Group *g)
const {
470 bool operator ()(
const Group *lhs,
const Group *rhs)
const {
475 void delete_view(
View *v);
476 void delete_view(std::unordered_map<uint32,
P<View> >::const_iterator &v);
478 Group *get_secondary_group();
479 void load_secondary_mdl_controller(
View *view);
480 void inject_secondary_mdl_controller(
View *view);
482 Timestamp get_next_upr_time(Timestamp now)
const;
483 Timestamp get_prev_upr_time(Timestamp now)
const;
488 #include "object.tpl.cpp"
489 #include "group.inline.cpp"