|
@@ -48,11 +48,11 @@ namespace artis {
|
|
|
: public artis::pdevs::Dynamics<Time, Quantifier<Time>, QuantifierParameters> {
|
|
|
public:
|
|
|
enum inputs {
|
|
|
- IN = 1
|
|
|
+ IN, RESET
|
|
|
};
|
|
|
|
|
|
enum outputs {
|
|
|
- OUT = 1
|
|
|
+ OUT
|
|
|
};
|
|
|
|
|
|
enum states {
|
|
@@ -72,7 +72,8 @@ namespace artis {
|
|
|
DECLARE_STATES(double,
|
|
|
((OFFSET, &Quantifier<Time>::_offset), (UP_THRESHOLD, &Quantifier<Time>::_up_threshold), (DOWN_THRESHOLD, &Quantifier<Time>::_down_threshold)));
|
|
|
|
|
|
- this->input_port({IN, "in"});
|
|
|
+ this->input_ports({{IN, "in"},
|
|
|
+ {RESET, "reset"}});
|
|
|
this->output_port({OUT, "out"});
|
|
|
this->observables({{UP, "up"},
|
|
|
{DOWN, "down"},
|
|
@@ -117,61 +118,66 @@ namespace artis {
|
|
|
{
|
|
|
std::for_each(bag.begin(), bag.end(),
|
|
|
[this, t, e](const common::ExternalEvent<Time>& event) {
|
|
|
- IntegratorData data;
|
|
|
- double shifting_factor;
|
|
|
- double value;
|
|
|
- int cnt;
|
|
|
-
|
|
|
- event.data()(data);
|
|
|
- value = data.value;
|
|
|
- if (_state == INIT) {
|
|
|
- init_step_number_and_offset(value);
|
|
|
- update_thresholds();
|
|
|
- _state = RESPONSE;
|
|
|
- } else {
|
|
|
- cnt = 0;
|
|
|
- while (value >= _up_threshold or value <= _down_threshold) {
|
|
|
- cnt++;
|
|
|
- if (value >= _up_threshold) {
|
|
|
- _step_number++;
|
|
|
- } else {
|
|
|
- _step_number--;
|
|
|
- }
|
|
|
- switch (_adaptive_state) {
|
|
|
- case IMPOSSIBLE:
|
|
|
- update_thresholds();
|
|
|
- break;
|
|
|
- case POSSIBLE:
|
|
|
+ if (event.on_port(IN)) {
|
|
|
+ IntegratorData data;
|
|
|
+ double shifting_factor;
|
|
|
+ double value;
|
|
|
+ int cnt;
|
|
|
+
|
|
|
+ event.data()(data);
|
|
|
+ value = data.value;
|
|
|
+ if (_state == INIT) {
|
|
|
+ init_step_number_and_offset(value);
|
|
|
+ update_thresholds();
|
|
|
+ _state = RESPONSE;
|
|
|
+ } else {
|
|
|
+ cnt = 0;
|
|
|
+ while (value >= _up_threshold or value <= _down_threshold) {
|
|
|
+ cnt++;
|
|
|
if (value >= _up_threshold) {
|
|
|
- store_change(_step_size, t);
|
|
|
+ _step_number++;
|
|
|
} else {
|
|
|
- store_change(-_step_size, t);
|
|
|
+ _step_number--;
|
|
|
}
|
|
|
- shifting_factor = shift_quanta();
|
|
|
-
|
|
|
- assert(shifting_factor >= 0
|
|
|
- and shifting_factor <= 1);
|
|
|
-
|
|
|
- if (shifting_factor != 0 and shifting_factor != 1) {
|
|
|
+ switch (_adaptive_state) {
|
|
|
+ case IMPOSSIBLE:
|
|
|
+ update_thresholds();
|
|
|
+ break;
|
|
|
+ case POSSIBLE:
|
|
|
if (value >= _up_threshold) {
|
|
|
- update_thresholds(shifting_factor,
|
|
|
- DIRECTION_DOWN);
|
|
|
+ store_change(_step_size, t);
|
|
|
} else {
|
|
|
- update_thresholds(shifting_factor,
|
|
|
- DIRECTION_UP);
|
|
|
+ store_change(-_step_size, t);
|
|
|
}
|
|
|
- _adaptive_state = DONE;
|
|
|
- } else {
|
|
|
+ shifting_factor = shift_quanta();
|
|
|
+
|
|
|
+ assert(shifting_factor >= 0
|
|
|
+ and shifting_factor <= 1);
|
|
|
+
|
|
|
+ if (shifting_factor != 0 and shifting_factor != 1) {
|
|
|
+ if (value >= _up_threshold) {
|
|
|
+ update_thresholds(shifting_factor,
|
|
|
+ DIRECTION_DOWN);
|
|
|
+ } else {
|
|
|
+ update_thresholds(shifting_factor,
|
|
|
+ DIRECTION_UP);
|
|
|
+ }
|
|
|
+ _adaptive_state = DONE;
|
|
|
+ } else {
|
|
|
+ update_thresholds();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case DONE:
|
|
|
+ init_step_number_and_offset(value);
|
|
|
+ _adaptive_state = POSSIBLE;
|
|
|
update_thresholds();
|
|
|
+ break;
|
|
|
}
|
|
|
- break;
|
|
|
- case DONE:
|
|
|
- init_step_number_and_offset(value);
|
|
|
- _adaptive_state = POSSIBLE;
|
|
|
- update_thresholds();
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
+ } else if (event.on_port(RESET)) {
|
|
|
+ _offset = 0;
|
|
|
+ _state = INIT;
|
|
|
}
|
|
|
});
|
|
|
_state = RESPONSE;
|