85 #include "p_monitor.h"
87 #include "mdl_controller.h"
89 using namespace std::chrono;
90 using namespace r_code;
94 PMonitor::PMonitor(MDLController *controller,
98 bool rate_failures) : Monitor(controller, bindings, prediction, mk_rdx), rate_failures_(rate_failures) {
100 prediction_target_ = prediction->get_pred()->get_target();
103 bindings->reset_fwd_timings(prediction_target_);
105 MonitoringJob<PMonitor> *j =
new MonitoringJob<PMonitor>(
this, prediction_target_->get_before() + Utils::GetTimeTolerance());
106 _Mem::Get()->push_time_job(j);
109 PMonitor::~PMonitor() {
112 bool PMonitor::reduce(_Fact *input) {
114 if (target_->is_invalidated()) {
117 if (target_->get_pred()->grounds_invalidated(input)) {
119 target_->invalidate();
123 Pred *prediction = input->get_pred();
126 switch (prediction->get_target()->is_evidence(prediction_target_)) {
127 case MATCH_SUCCESS_POSITIVE:
129 case MATCH_SUCCESS_NEGATIVE:
130 if (prediction->get_target()->get_cfd() > prediction_target_->get_cfd()) {
132 target_->invalidate();
141 switch (((Fact *)input)->is_evidence(prediction_target_)) {
142 case MATCH_SUCCESS_POSITIVE:
143 controller_->register_pred_outcome(target_, mk_rdx_,
true, input, input->get_cfd(), rate_failures_);
145 case MATCH_SUCCESS_NEGATIVE:
147 controller_->register_pred_outcome(target_, mk_rdx_,
false, input, input->get_cfd(), rate_failures_);
157 void PMonitor::update(Timestamp &next_target) {
159 if (!target_->is_invalidated()) {
166 if (rate_failures_ && target_->get_pred()->get_target()->is_fact())
167 controller_->register_pred_outcome(target_, mk_rdx_,
false, NULL, 1, rate_failures_);
169 controller_->remove_monitor(
this);
170 next_target = Timestamp(seconds(0));