replicode
mdl_controller.h
Go to the documentation of this file.
1 // mdl_controller.h
2 //
3 // Author: Eric Nivel
4 //
5 // BSD license:
6 // Copyright (c) 2010, Eric Nivel
7 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // - Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // - Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 // - Neither the name of Eric Nivel nor the
17 // names of their contributors may be used to endorse or promote products
18 // derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
24 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef mdl_controller_h
32 #define mdl_controller_h
33 
34 #include "hlp_overlay.h"
35 #include "hlp_controller.h"
36 #include "p_monitor.h"
37 #include "factory.h"
38 #include "reduction_job.h"
39 #include "mem.h"
40 
41 
42 namespace r_exec {
43 
44 class MDLOverlay:
45  public HLPOverlay {
46 protected:
47  MDLOverlay(Controller *c, const HLPBindingMap *bindngs);
48 public:
49  ~MDLOverlay();
50 
51  void load_patterns();
52 
53  virtual Overlay *reduce(_Fact *input, Fact *f_p_f_imdl, MDLController *req_controller) = 0;
54 };
55 
57  public MDLOverlay {
58 protected:
59  bool check_simulated_chaining(HLPBindingMap *bm, Fact *f_imdl, Pred *prediction);
60 public:
61  PrimaryMDLOverlay(Controller *c, const HLPBindingMap *bindngs);
63 
64  Overlay *reduce(_Fact *input, Fact *f_p_f_imdl, MDLController *req_controller);
65 };
66 
68  public MDLOverlay {
69 public:
70  SecondaryMDLOverlay(Controller *c, const HLPBindingMap *bindngs);
72 
73  Overlay *reduce(_Fact *input, Fact *f_p_f_imdl, MDLController *req_controller);
74 };
75 
76 class MDLController;
77 class Requirements {
78 public:
79  std::vector<P<MDLController> > controllers;
80  P<_Fact> f_imdl; // f1 as in f0->pred->f1->imdl.
82 };
83 typedef std::pair<Requirements, Requirements> RequirementsPair; // first: wr, second: sr.
84 
85 // Requirements don't monitor their predictions: they don't inject any; instead, they store a f->imdl in the controlled model controllers (both primary and secondary), thus, no success injected for the productions of requirements.
86 // Models controlled by requirements maintain for each prediction they make, a list of all the controllers of the requirements having allowed/inhibited said prediction.
87 // P-monitors (associated to non-requirement models) propagate the outcome to the controllers associated with the prediction they monitor.
88 //
89 // Predictions and goals are injected in the primary group only.
90 // Simulations are injected in the primary group only; no mk.rdx.
91 //
92 // Each time a prediction is made by a non-req model, a f->imdl is injected in both primary and secondary groups. If the input was a prediction, f->pred->f->imdl is injected instead.
93 // f->imdl can also be tagged as simulations.
94 //
95 // Successes and failures are injected only in output groups.
96 //
97 // If forward chaining is inhibited (by strong reqs with better cfd than weak reqs), predictions are still produced, but not injected (no mk.rdx): this is to allow the rating of the requirements.
99  public HLPController {
100 protected:
101  class REntry: // use for requirements.
102  public PEEntry {
103  public:
104  P<MDLController> controller; // of the requirement.
106 
107  REntry();
108  REntry(_Fact *f_p_f_imdl, MDLController *c, bool chaining_was_allowed); // f_imdl is f0 as in f0->pred->f1->imdl.
109 
111  return (before < now || after > now);
112  }
113  };
114 
115  class RCache {
116  public:
117  std::mutex mutex;
120  };
121 
124 
126 
127  std::mutex m_monitorMutex;
129 
132 
133  static const uint64_t LHSController = 0;
134  static const uint64_t RHSController = 1;
135 
136  typedef enum {
137  NaR = 0,
138  WR = 1,
139  SR = 2
140  } RType;
141 
143  bool _is_reuse;
144  bool _is_cmd;
145 
146  float get_cfd() const;
147 
149  std::unordered_map<P<_Fact>, RequirementsPair, PHash<_Fact> > active_requirements; // P<_Fact>: f1 as in f0->pred->f1->imdl; requirements having allowed the production of prediction; first: wr, second: sr.
150 
151  template<class C> void reduce_cache(Fact *f_p_f_imdl, MDLController *controller) { // fwd; controller is the controller of the requirement which produced f_p_f_imdl.
152 
155  }
156 
157  template<class E> void reduce_cache(Cache<E> *cache, Fact *f_p_f_imdl, MDLController *controller) {
158  std::lock_guard<std::mutex> guard(cache->mutex);
159  uint64_t now = Now();
161  for (_e = cache->evidences.begin(); _e != cache->evidences.end();) {
162 
163  if ((*_e).is_too_old(now)) // garbage collection.
164  _e = cache->evidences.erase(_e);
165  else {
166 
167  PrimaryMDLOverlay o(this, bindings);
168  o.reduce((*_e).evidence, f_p_f_imdl, controller);
169  ++_e;
170  }
171  }
172  }
173 
175  bool monitor_predictions(_Fact *input);
176 
178 public:
179  static MDLController *New(View *view, bool &inject_in_secondary_group);
180 
181  void add_monitor(PMonitor *m);
182  void remove_monitor(PMonitor *m);
183 
184  _Fact *get_lhs() const;
185  _Fact *get_rhs() const;
186  Fact *get_f_ihlp(HLPBindingMap *bindings, bool wr_enabled) const;
187 
188  virtual void store_requirement(_Fact *f_p_f_imdl, MDLController *controller, bool chaining_was_allowed, bool simulation) = 0;
189  ChainingStatus retrieve_imdl_fwd(HLPBindingMap *bm, Fact *f_imdl, RequirementsPair &r_p, Fact *&ground, MDLController *req_controller, bool &wr_enabled); // checks the requirement instances during fwd; r_p: all wrs in first, all srs in second.
190  ChainingStatus retrieve_imdl_bwd(HLPBindingMap *bm, Fact *f_imdl, Fact *&ground); // checks the requirement instances during bwd; ground is set to the best weak requirement if chaining allowed, NULL otherwise.
193 
194  virtual void predict(HLPBindingMap *bm, _Fact *input, Fact *f_imdl, bool chaining_was_allowed, RequirementsPair &r_p, Fact *ground) = 0;
195  virtual void register_pred_outcome(Fact *f_pred, bool success, _Fact *evidence, double confidence, bool rate_failures) = 0;
196  virtual void register_req_outcome(Fact *f_pred, bool success, bool rate_failures) = 0;
197 
198  void add_requirement_to_rhs();
200 
201  bool is_requirement() const {
202  return (_is_requirement != NaR);
203  }
204  bool is_reuse() const {
205  return _is_reuse;
206  }
207  bool is_cmd() const {
208  return _is_cmd;
209  }
210 
211  void register_requirement(_Fact *f_pred, RequirementsPair &r_p);
212 };
213 
215  public MDLController {
216 protected:
217  std::mutex m_gMonitorsMutex;
220 
222  return get_out_group_count();
223  }
224  void inject_goal(HLPBindingMap *bm, Fact *goal, Fact *f_imdl) const;
225  void inject_simulation(Fact *simulation) const;
226 
227  bool monitor_goals(_Fact *input);
228 
229  uint64_t get_sim_thz(uint64_t now, uint64_t deadline) const;
230 
232 public:
233  void add_g_monitor(_GMonitor *m);
234  void remove_g_monitor(_GMonitor *m);
235  void add_r_monitor(_GMonitor *m);
236  void remove_r_monitor(_GMonitor *m);
237 
238  virtual void register_goal_outcome(Fact *goal, bool success, _Fact *evidence) const = 0;
239  void register_predicted_goal_outcome(Fact *goal, HLPBindingMap *bm, Fact *f_imdl, bool success, bool injected_goal);
240  virtual void register_simulated_goal_outcome(Fact *goal, bool success, _Fact *evidence) const = 0;
241 };
242 
243 // See g_monitor.h: controllers and monitors work closely together.
244 //
245 // Min sthz is the time allowed for simulated predictions to flow upward.
246 // Max sthz sets the responsiveness of the model, i.e. limits the time waiting for simulation results, i.e. limits the latency of decision making.
247 // Simulation is synchronous, i.e. is performed within the enveloppe of sthz, recursively.
248 
249 // Drives are not monitored (since they are not produced by models): they are injected periodically by user-defined pgms.
250 // Drives are not observable: they cannot be predicted to succeed or fail.
251 // Rhs is a drive; the model is an axiom: no rating and lives in the primary group only.
252 // The model does not predict.
253 // There is exactly one top-level model for each drive: hence no simulation during backward chaining.
254 // Top-level models cannot have requirements.
255 //
256 // Backward chaining: inputs are drives.
257 // if lhs is in the fact cache, stop.
258 // if lhs is in the prediction cache, spawn a g-monitor (will be ready to catch a counter-prediction, invalidate the goal and trigger the re-issuing of a new goal).
259 // else commit to the sub-goal; this will trigger the simulation of sub-sub-goals; N.B.: commands are not simulated, commands with unbound values are not injected.
261  public PMDLController {
262 private:
264  return get_out_group_count() - 1; // so that rdx are not injected in the drives host.
265  }
266 
267  void abduce(HLPBindingMap *bm, Fact *super_goal, double confidence);
268  void abduce_lhs(HLPBindingMap *bm, Fact *super_goal, _Fact *sub_goal_target, Fact *f_imdl, _Fact *evidence);
269 
270  void register_drive_outcome(Fact *goal, bool success) const;
271 
273 public:
275 
276  void take_input(r_exec::View *input);
277  void reduce(r_exec::View *input);
278 
279  void store_requirement(_Fact *f_imdl, MDLController *controller, bool chaining_was_allowed, bool simulation); // never called.
280 
281  void predict(HLPBindingMap *bm, _Fact *input, Fact *f_imdl, bool chaining_was_allowed, RequirementsPair &r_p, Fact *ground);
282  void register_pred_outcome(Fact *f_pred, bool success, _Fact *evidence, double confidence, bool rate_failures);
283  void register_goal_outcome(Fact *goal, bool success, _Fact *evidence) const;
284  void register_simulated_goal_outcome(Fact *goal, bool success, _Fact *evidence) const;
285  void register_req_outcome(Fact *f_pred, bool success, bool rate_failures);
286 };
287 
288 class SecondaryMDLController;
289 
290 // Backward chaining: inputs are goals, actual or simulated.
291 // Actual goals:
292 // if lhs is in the fact cache, stop.
293 // if lhs is in the prediction cache, spawn a g-monitor (will be ready to catch a counter-prediction, invalidate the goal and re-issue a new goal).
294 // else
295 // if (before-now)*percentage<min sthz, commit sub-goal on lhs.
296 // else
297 // if chaining is allowed, simulate the lhs and spawn a g-monitor with sthz=min((before-now)*percentage,max sthz)-min sthz.
298 // else, simulate f->imdl and spawn a g-monitor with sthz=min((before-now)*percentage,max sthz)/2-min sthz.
299 // Simulated goals:
300 // if lhs is in the fact cache, .
301 // if lhs is in the prediction cache,
302 // else:
303 // if sthz/2>min thz, simulate the lhs and spawn a g-monitor with sthz/2-min sthz.
304 // else predict rhs (cfd=1) and stop.
305 // Commands with unbound values are not injected.
307  public PMDLController {
308 private:
310 
311  std::mutex m_codeMutex;
313 
314  std::mutex m_assumptionsMutex;
315  r_code::list<P<Code> > assumptions; // produced by the model; garbage collection at reduce(9 time..
316 
317  void rate_model(bool success);
318  void kill_views(); // force res in both primary/secondary to 0.
319  void check_last_match_time(bool match); // activate secondary controller if no match after primary_thz;
320 
321  void abduce_lhs(HLPBindingMap *bm, Fact *super_goal, Fact *f_imdl, bool opposite, double confidence, Sim *sim, Fact *ground, bool set_before);
322  void abduce_imdl(HLPBindingMap *bm, Fact *super_goal, Fact *f_imdl, bool opposite, double confidence, Sim *sim);
323  void abduce_simulated_lhs(HLPBindingMap *bm, Fact *super_goal, Fact *f_imdl, bool opposite, double confidence, Sim *sim);
324  void abduce_simulated_imdl(HLPBindingMap *bm, Fact *super_goal, Fact *f_imdl, bool opposite, double confidence, Sim *sim);
325  void predict_simulated_lhs(HLPBindingMap *bm, bool opposite, double confidence, Sim *sim);
326  void predict_simulated_evidence(_Fact *evidence, Sim *sim);
327  void assume(_Fact *input);
328  void assume_lhs(HLPBindingMap *bm, bool opposite, _Fact *input, double confidence);
329 
331 public:
333 
334  void set_secondary(SecondaryMDLController *secondary);
335 
336  void take_input(r_exec::View *input);
337  void reduce(r_exec::View *input);
338  void reduce_batch(Fact *f_p_f_imdl, MDLController *controller);
339 
340  void store_requirement(_Fact *f_imdl, MDLController *controller, bool chaining_was_allowed, bool simulation);
341 
342  void predict(HLPBindingMap *bm, _Fact *input, Fact *f_imdl, bool chaining_was_allowed, RequirementsPair &r_p, Fact *ground);
343  bool inject_prediction(Fact *prediction, Fact *f_imdl, double confidence, uint64_t time_to_live, Code *mk_rdx) const; // here, resilience=time to live, in us; returns true if the prediction has actually been injected.
344 
345  void register_pred_outcome(Fact *f_pred, bool success, _Fact *evidence, double confidence, bool rate_failures);
346  void register_req_outcome(Fact *f_pred, bool success, bool rate_failures);
347 
348  void register_goal_outcome(Fact *goal, bool success, _Fact *evidence) const;
349  void register_simulated_goal_outcome(Fact *goal, bool success, _Fact *evidence) const;
350 
351  bool check_imdl(Fact *goal, HLPBindingMap *bm);
352  bool check_simulated_imdl(Fact *goal, HLPBindingMap *bm, Controller *root);
353  void abduce(HLPBindingMap *bm, Fact *super_goal, bool opposite, double confidence);
354 
355  void debug(View *input);
356 };
357 
358 // No backward chaining.
359 // Rating happens only upon the success of predictions.
360 // Requirements are stroed whetwehr they come from a primary or a secondary controller.
361 // Positive requirements are stored into the rhs controller, both kinds (secondary or primary: the latter case is necessary for rating the model).
363  public MDLController {
364 private:
366 
367  std::mutex m_codeMutex;
369 
370 
371  void rate_model(); // record successes only.
372  void kill_views(); // force res in both primary/secondary to 0.
373  void check_last_match_time(bool match); // kill if no match after secondary_thz;
374 public:
376 
377  void set_primary(PrimaryMDLController *primary);
378 
379  void take_input(r_exec::View *input);
380  void reduce(r_exec::View *input);
381  void reduce_batch(Fact *f_p_f_imdl, MDLController *controller);
382 
383  void store_requirement(_Fact *f_imdl, MDLController *controller, bool chaining_was_allowed, bool simulation);
384 
385  void predict(HLPBindingMap *bm, _Fact *input, Fact *f_imdl, bool chaining_was_allowed, RequirementsPair &r_p, Fact *ground);
386  void register_pred_outcome(Fact *f_pred, bool success, _Fact *evidence, double confidence, bool rate_failures);
387  void register_req_outcome(Fact *f_pred, bool success, bool rate_failures);
388 };
389 }
390 
391 
392 #endif
Definition: factory.h:208
Definition: g_monitor.h:42
const_iterator & end() const
Definition: list.h:288
virtual void register_goal_outcome(Fact *goal, bool success, _Fact *evidence) const =0
Definition: hlp_controller.h:51
Definition: factory.h:98
Definition: mdl_controller.h:139
P< Code > rhs
Definition: mdl_controller.h:131
void register_pred_outcome(Fact *f_pred, bool success, _Fact *evidence, double confidence, bool rate_failures)
Definition: mdl_controller.cpp:1739
void remove_g_monitor(_GMonitor *m)
Definition: mdl_controller.cpp:896
ChainingStatus
Definition: hlp_controller.h:43
void abduce_imdl(HLPBindingMap *bm, Fact *super_goal, Fact *f_imdl, bool opposite, double confidence, Sim *sim)
Definition: mdl_controller.cpp:1594
void _store_requirement(r_code::list< REntry > *cache, REntry &e)
Definition: mdl_controller.cpp:363
Definition: factory.h:145
r_code::list< E > evidences
Definition: hlp_controller.h:86
MDLController(r_code::View *view)
Definition: mdl_controller.cpp:248
_Fact * get_rhs() const
Definition: mdl_controller.cpp:335
void assume_lhs(HLPBindingMap *bm, bool opposite, _Fact *input, double confidence)
Definition: mdl_controller.cpp:1956
r_code::list< REntry > positive_evidences
Definition: mdl_controller.h:118
Definition: mdl_controller.h:137
void store_requirement(_Fact *f_imdl, MDLController *controller, bool chaining_was_allowed, bool simulation)
Definition: mdl_controller.cpp:1229
Fact * get_f_ihlp(HLPBindingMap *bindings, bool wr_enabled) const
Definition: mdl_controller.cpp:340
void rate_model()
Definition: mdl_controller.cpp:2108
Definition: hlp_overlay.h:43
void predict_simulated_evidence(_Fact *evidence, Sim *sim)
Definition: mdl_controller.cpp:1730
void add_g_monitor(_GMonitor *m)
Definition: mdl_controller.cpp:891
bool now(const Context &context, uint16_t &index)
Definition: operator.cpp:55
void abduce_lhs(HLPBindingMap *bm, Fact *super_goal, _Fact *sub_goal_target, Fact *f_imdl, _Fact *evidence)
Definition: mdl_controller.cpp:1093
void register_req_outcome(Fact *f_pred, bool success, bool rate_failures)
Definition: mdl_controller.cpp:1783
r_code::list< P< Code > > assumptions
Definition: mdl_controller.h:315
void register_pred_outcome(Fact *f_pred, bool success, _Fact *evidence, double confidence, bool rate_failures)
Definition: mdl_controller.cpp:1118
std::mutex mutex
Definition: mdl_controller.h:117
Definition: overlay.h:116
void register_drive_outcome(Fact *goal, bool success) const
Definition: mdl_controller.cpp:1169
bool chaining_was_allowed
Definition: mdl_controller.h:81
ChainingStatus retrieve_simulated_imdl_fwd(HLPBindingMap *bm, Fact *f_imdl, Controller *root)
Definition: mdl_controller.cpp:378
void check_last_match_time(bool match)
Definition: mdl_controller.h:272
PMDLController(r_code::View *view)
Definition: mdl_controller.cpp:888
Definition: mdl_controller.h:98
void predict(HLPBindingMap *bm, _Fact *input, Fact *f_imdl, bool chaining_was_allowed, RequirementsPair &r_p, Fact *ground)
Definition: mdl_controller.cpp:2077
void store_requirement(_Fact *f_imdl, MDLController *controller, bool chaining_was_allowed, bool simulation)
Definition: mdl_controller.cpp:2097
bool inject_prediction(Fact *prediction, Fact *f_imdl, double confidence, uint64_t time_to_live, Code *mk_rdx) const
Definition: mdl_controller.cpp:1354
bool check_simulated_chaining(HLPBindingMap *bm, Fact *f_imdl, Pred *prediction)
Definition: mdl_controller.cpp:153
PrimaryMDLController * primary
Definition: mdl_controller.h:365
static const uint64_t RHSController
Definition: mdl_controller.h:134
r_code::list< P< _GMonitor > > g_monitors
Definition: mdl_controller.h:218
Definition: _context.cpp:34
Definition: mdl_controller.h:56
RCache requirements
Definition: mdl_controller.h:122
void take_input(r_exec::View *input)
Definition: mdl_controller.cpp:2041
virtual void register_pred_outcome(Fact *f_pred, bool success, _Fact *evidence, double confidence, bool rate_failures)=0
bool chaining_was_allowed
Definition: mdl_controller.h:105
void reduce_cache(Fact *f_p_f_imdl, MDLController *controller)
Definition: mdl_controller.h:151
bool is_reuse() const
Definition: mdl_controller.h:204
r_code::list< P< _GMonitor > > r_monitors
Definition: mdl_controller.h:219
std::mutex m_activeRequirementsMutex
Definition: mdl_controller.h:148
Definition: mdl_controller.h:115
void rate_model(bool success)
Definition: mdl_controller.cpp:1875
_Fact * get_lhs() const
Definition: mdl_controller.cpp:330
void reduce(r_exec::View *input)
Definition: mdl_controller.cpp:1023
void add_requirement_to_rhs()
Definition: mdl_controller.cpp:345
void take_input(r_exec::View *input)
Definition: mdl_controller.cpp:1262
ChainingStatus retrieve_imdl_fwd(HLPBindingMap *bm, Fact *f_imdl, RequirementsPair &r_p, Fact *&ground, MDLController *req_controller, bool &wr_enabled)
Definition: mdl_controller.cpp:593
~SecondaryMDLOverlay()
Definition: mdl_controller.cpp:174
void abduce(HLPBindingMap *bm, Fact *super_goal, double confidence)
Definition: mdl_controller.cpp:1060
bool abduction_allowed(HLPBindingMap *bm)
Definition: mdl_controller.cpp:2022
uint16_t get_out_group_count() const
Definition: hlp_controller.cpp:97
bool _is_cmd
Definition: mdl_controller.h:144
bool monitor_predictions(_Fact *input)
predictions are admissible inputs (for checking predicted counter-evidences).
Definition: mdl_controller.cpp:300
void predict(HLPBindingMap *bm, _Fact *input, Fact *f_imdl, bool chaining_was_allowed, RequirementsPair &r_p, Fact *ground)
Definition: mdl_controller.cpp:1272
void abduce_simulated_imdl(HLPBindingMap *bm, Fact *super_goal, Fact *f_imdl, bool opposite, double confidence, Sim *sim)
Definition: mdl_controller.cpp:1654
void load_patterns()
Definition: mdl_controller.cpp:48
void reduce_batch(Fact *f_p_f_imdl, MDLController *controller)
Definition: mdl_controller.cpp:2068
static _Mem * Get()
Definition: mem.h:187
bool monitor_goals(_Fact *input)
Definition: mdl_controller.cpp:946
void add_monitor(PMonitor *m)
Definition: mdl_controller.cpp:319
void predict(HLPBindingMap *bm, _Fact *input, Fact *f_imdl, bool chaining_was_allowed, RequirementsPair &r_p, Fact *ground)
Definition: mdl_controller.cpp:1115
Definition: base.h:47
void reduce_batch(Fact *f_p_f_imdl, MDLController *controller)
Definition: mdl_controller.cpp:1450
void abduce_simulated_lhs(HLPBindingMap *bm, Fact *super_goal, Fact *f_imdl, bool opposite, double confidence, Sim *sim)
Definition: mdl_controller.cpp:1608
Definition: binding_map.h:252
static MDLController * New(View *view, bool &inject_in_secondary_group)
Definition: mdl_controller.cpp:232
void assume(_Fact *input)
Definition: mdl_controller.cpp:1924
bool check_simulated_imdl(Fact *goal, HLPBindingMap *bm, Controller *root)
Definition: mdl_controller.cpp:1690
void register_simulated_goal_outcome(Fact *goal, bool success, _Fact *evidence) const
Definition: mdl_controller.cpp:1856
std::vector< P< MDLController > > controllers
Definition: mdl_controller.h:79
void register_simulated_goal_outcome(Fact *goal, bool success, _Fact *evidence) const
Definition: mdl_controller.cpp:1190
std::mutex m_gMonitorsMutex
Definition: mdl_controller.h:217
void inject_simulation(Fact *simulation) const
Definition: mdl_controller.cpp:935
void abduce(HLPBindingMap *bm, Fact *super_goal, bool opposite, double confidence)
Definition: mdl_controller.cpp:1459
bool match(const IPGMContext &input, const IPGMContext &pattern)
Definition: context.cpp:452
iterator begin()
Definition: list.h:282
Definition: mdl_controller.h:77
Definition: mdl_controller.h:101
uint64_t get_sim_thz(uint64_t now, uint64_t deadline) const
Definition: mdl_controller.cpp:993
void remove_monitor(PMonitor *m)
Definition: mdl_controller.cpp:324
void add_r_monitor(_GMonitor *m)
Definition: mdl_controller.cpp:902
Definition: utils.h:43
SecondaryMDLController * secondary
Definition: mdl_controller.h:309
std::mutex m_monitorMutex
Definition: mdl_controller.h:127
RCache simulated_requirements
Definition: mdl_controller.h:123
Definition: view.h:47
void remove_requirement_from_rhs()
Definition: mdl_controller.cpp:354
void set_primary(PrimaryMDLController *primary)
Definition: mdl_controller.cpp:2036
void set_secondary(SecondaryMDLController *secondary)
Definition: mdl_controller.cpp:1222
bool is_cmd() const
Definition: mdl_controller.h:207
P< MDLController > controller
Definition: mdl_controller.h:104
std::pair< Requirements, Requirements > RequirementsPair
Definition: mdl_controller.h:83
void predict_simulated_lhs(HLPBindingMap *bm, bool opposite, double confidence, Sim *sim)
Definition: mdl_controller.cpp:1720
SecondaryMDLController(r_code::View *view)
Definition: mdl_controller.cpp:2033
void reduce(r_exec::View *input)
Definition: mdl_controller.cpp:2051
~PrimaryMDLOverlay()
Definition: mdl_controller.cpp:58
RType _is_requirement
Definition: mdl_controller.h:142
P< Code > lhs
Definition: mdl_controller.h:130
RType
Definition: mdl_controller.h:136
ChainingStatus retrieve_imdl_bwd(HLPBindingMap *bm, Fact *f_imdl, Fact *&ground)
Definition: mdl_controller.cpp:765
void reduce_cache(Cache< E > *cache, Fact *f_p_f_imdl, MDLController *controller)
Definition: mdl_controller.h:157
r_code::View * view
Definition: overlay.h:58
float get_cfd() const
Definition: mdl_controller.cpp:295
void reduce(r_exec::View *input)
Definition: mdl_controller.cpp:1383
virtual Overlay * reduce(_Fact *input, Fact *f_p_f_imdl, MDLController *req_controller)=0
void register_goal_outcome(Fact *goal, bool success, _Fact *evidence) const
Definition: mdl_controller.cpp:1121
std::mutex m_lastMatchTimeMutex
Definition: mdl_controller.h:312
Definition: mdl_controller.h:260
Definition: list.h:216
dll_export uint64_t(* Now)()
Definition: init.cpp:49
std::mutex m_assumptionsMutex
Definition: mdl_controller.h:314
virtual uint64_t get_rdx_out_group_count() const
Definition: mdl_controller.h:221
Definition: mdl_controller.h:44
Definition: mdl_controller.h:306
bool _is_reuse
Definition: mdl_controller.h:143
ChainingStatus retrieve_simulated_imdl_bwd(HLPBindingMap *bm, Fact *f_imdl, Controller *root)
Definition: mdl_controller.cpp:487
Definition: object.h:100
iterator erase(iterator &i)
Definition: list.h:291
Definition: reduction_job.h:63
~MDLOverlay()
Definition: mdl_controller.cpp:45
Definition: list.h:42
r_code::list< REntry > negative_evidences
Definition: mdl_controller.h:119
Definition: object.h:172
Definition: overlay.h:50
Definition: mdl_controller.h:214
std::mutex m_codeMutex
Definition: mdl_controller.h:311
bool is_out_of_range(uint64_t now) const
Definition: mdl_controller.h:110
void remove_r_monitor(_GMonitor *m)
Definition: mdl_controller.cpp:908
void check_last_match_time(bool match)
Definition: mdl_controller.cpp:2171
Definition: mdl_controller.h:138
Definition: mdl_controller.h:362
void store_requirement(_Fact *f_imdl, MDLController *controller, bool chaining_was_allowed, bool simulation)
Definition: mdl_controller.cpp:1013
std::mutex m_lastMatchTimeMutex
Definition: mdl_controller.h:368
Definition: hlp_controller.h:83
void check_last_match_time(bool match)
Definition: mdl_controller.cpp:2007
P< HLPBindingMap > bindings
Definition: hlp_controller.h:108
virtual void register_req_outcome(Fact *f_pred, bool success, bool rate_failures)=0
Overlay * reduce(_Fact *input, Fact *f_p_f_imdl, MDLController *req_controller)
Definition: mdl_controller.cpp:177
void register_goal_outcome(Fact *goal, bool success, _Fact *evidence) const
Definition: mdl_controller.cpp:1807
void debug(View *input)
Definition: mdl_controller.cpp:1447
PrimaryMDLController(r_code::View *view)
Definition: mdl_controller.cpp:1219
PrimaryMDLOverlay(Controller *c, const HLPBindingMap *bindngs)
Definition: mdl_controller.cpp:55
virtual void register_simulated_goal_outcome(Fact *goal, bool success, _Fact *evidence) const =0
Definition: factory.h:174
void pushReductionJob(_ReductionJob *j)
Definition: mem.cpp:379
void abduce_lhs(HLPBindingMap *bm, Fact *super_goal, Fact *f_imdl, bool opposite, double confidence, Sim *sim, Fact *ground, bool set_before)
Definition: mdl_controller.cpp:1544
void register_req_outcome(Fact *f_pred, bool success, bool rate_failures)
Definition: mdl_controller.cpp:1214
bool check_imdl(Fact *goal, HLPBindingMap *bm)
Definition: mdl_controller.cpp:1667
P< _Fact > f_imdl
Definition: mdl_controller.h:80
Overlay * reduce(_Fact *input, Fact *f_p_f_imdl, MDLController *req_controller)
Definition: mdl_controller.cpp:61
void register_req_outcome(Fact *f_pred, bool success, bool rate_failures)
Definition: mdl_controller.cpp:2143
std::mutex m_codeMutex
Definition: mdl_controller.h:367
REntry()
Definition: mdl_controller.cpp:880
TopLevelMDLController(r_code::View *view)
Definition: mdl_controller.cpp:1010
void register_predicted_goal_outcome(Fact *goal, HLPBindingMap *bm, Fact *f_imdl, bool success, bool injected_goal)
Definition: mdl_controller.cpp:963
bool is_requirement() const
Definition: mdl_controller.h:201
static const uint64_t LHSController
Definition: mdl_controller.h:133
virtual void predict(HLPBindingMap *bm, _Fact *input, Fact *f_imdl, bool chaining_was_allowed, RequirementsPair &r_p, Fact *ground)=0
uint64_t get_rdx_out_group_count() const
Definition: mdl_controller.h:263
void register_requirement(_Fact *f_pred, RequirementsPair &r_p)
Definition: mdl_controller.cpp:873
r_code::list< P< PMonitor > > p_monitors
Definition: mdl_controller.h:128
void kill_views()
Definition: mdl_controller.cpp:1993
void take_input(r_exec::View *input)
Definition: mdl_controller.cpp:1016
Definition: mdl_controller.h:67
virtual void store_requirement(_Fact *f_p_f_imdl, MDLController *controller, bool chaining_was_allowed, bool simulation)=0
void register_pred_outcome(Fact *f_pred, bool success, _Fact *evidence, double confidence, bool rate_failures)
Definition: mdl_controller.cpp:2138
void kill_views()
Definition: mdl_controller.cpp:2162
Definition: p_monitor.h:41
std::unordered_map< P< _Fact >, RequirementsPair, PHash< _Fact > > active_requirements
Definition: mdl_controller.h:149
void inject_goal(HLPBindingMap *bm, Fact *goal, Fact *f_imdl) const
Definition: mdl_controller.cpp:914
MDLOverlay(Controller *c, const HLPBindingMap *bindngs)
Definition: mdl_controller.cpp:40
std::mutex mutex
Definition: hlp_controller.h:85
SecondaryMDLOverlay(Controller *c, const HLPBindingMap *bindngs)
Definition: mdl_controller.cpp:171