-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaera-event.hpp
854 lines (730 loc) · 28.3 KB
/
aera-event.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/
//_/_/ AERA Visualizer
//_/_/
//_/_/ Copyright (c) 2018-2025 Jeff Thompson
//_/_/ Copyright (c) 2018-2025 Kristinn R. Thorisson
//_/_/ Copyright (c) 2018-2025 Icelandic Institute for Intelligent Machines
//_/_/ http://www.iiim.is
//_/_/
//_/_/ --- Open-Source BSD License, with CADIA Clause v 1.0 ---
//_/_/
//_/_/ Redistribution and use in source and binary forms, with or without
//_/_/ modification, is permitted provided that the following conditions
//_/_/ are met:
//_/_/ - Redistributions of source code must retain the above copyright
//_/_/ and collaboration notice, this list of conditions and the
//_/_/ following disclaimer.
//_/_/ - Redistributions in binary form must reproduce the above copyright
//_/_/ notice, this list of conditions and the following disclaimer
//_/_/ in the documentation and/or other materials provided with
//_/_/ the distribution.
//_/_/
//_/_/ - Neither the name of its copyright holders nor the names of its
//_/_/ contributors may be used to endorse or promote products
//_/_/ derived from this software without specific prior
//_/_/ written permission.
//_/_/
//_/_/ - CADIA Clause: The license granted in and to the software
//_/_/ under this agreement is a limited-use license.
//_/_/ The software may not be used in furtherance of:
//_/_/ (i) intentionally causing bodily injury or severe emotional
//_/_/ distress to any person;
//_/_/ (ii) invading the personal privacy or violating the human
//_/_/ rights of any person; or
//_/_/ (iii) committing or preparing for any act of war.
//_/_/
//_/_/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
//_/_/ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
//_/_/ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
//_/_/ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
//_/_/ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
//_/_/ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
//_/_/ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//_/_/ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//_/_/ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
//_/_/ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
//_/_/ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//_/_/ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
//_/_/ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
//_/_/ OF SUCH DAMAGE.
//_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#ifndef AERA_EVENT_HPP
#define AERA_EVENT_HPP
#include <vector>
#include <QPointF>
#include <QString>
#include "submodules/AERA/r_code/object.h"
#include "submodules/AERA/r_exec/opcodes.h"
#include "submodules/AERA/r_exec/factory.h"
namespace aera_visualizer {
class AeraEvent {
public:
AeraEvent(int eventType, core::Timestamp time, r_code::Code* object)
: eventType_(eventType),
time_(time),
object_(object),
itemInitialTopLeftPosition_(qQNaN(), qQNaN()),
itemTopLeftPosition_(qQNaN(), qQNaN())
{}
virtual AeraEvent::~AeraEvent() {}
/**
* A class can override this to specify the primary input of a reduction.
* \return The primary input, or null if not specified.
*/
virtual r_code::Code* getInput() { return 0; }
std::vector<r_code::Code*> otherInputs_;
/**
* A helper method to get the first item in the reduction's set of productions.
* \param reduction The mk.rdx reduction.
* \return The first production.
*/
static r_code::Code* getFirstProduction(r_code::Code* reduction)
{
return reduction->get_reference(
reduction->code(reduction->code(MK_RDX_PRODS).asIndex() + 1).asIndex());
}
/**
* A helper method to get the second item in the reduction's set of inputs.
* \param reduction The mk.rdx reduction.
* \return The second input, or NULL if the set of inputs size is less than two.
*/
static r_code::Code* getSecondInput(r_code::Code* reduction)
{
uint16 input_set_index = reduction->code(MK_RDX_INPUTS).asIndex();
if (reduction->code(input_set_index).getAtomCount() < 2)
return NULL;
if (reduction->code(input_set_index + 2).getDescriptor() != r_code::Atom::R_PTR)
return NULL;
return reduction->get_reference(reduction->code(input_set_index + 2).asIndex());
}
int eventType_;
core::Timestamp time_;
r_code::Code* object_;
// itemOriginalTopLeftPosition_ is used by "Reset Position" to restore the initial placement.
QPointF itemInitialTopLeftPosition_;
// itemTopLeftPosition_ is used by "New" events to remember the screen position after undoing.
QPointF itemTopLeftPosition_;
protected:
void addOtherInput(r_code::Code* input) {
if (input)
otherInputs_.push_back(input);
}
};
class NewModelEvent : public AeraEvent {
public:
NewModelEvent(core::Timestamp time, r_code::Code* model, core::float32 strength,
core::float32 evidenceCount, core::float32 successRate, uint64 controllerDegugOid)
: AeraEvent(EVENT_TYPE, time, model),
strength_(strength),
evidenceCount_(evidenceCount),
successRate_(successRate),
controllerDegugOid_(controllerDegugOid)
{}
static const int EVENT_TYPE = 1;
core::float32 strength_;
core::float32 evidenceCount_;
core::float32 successRate_;
// TODO: Should the model's controller be recorded globally?
uint64 controllerDegugOid_;
};
class SetModelEvidenceCountAndSuccessRateEvent : public AeraEvent {
public:
SetModelEvidenceCountAndSuccessRateEvent
(core::Timestamp time, r_code::Code* model, core::float32 evidenceCount, core::float32 successRate)
: AeraEvent(EVENT_TYPE, time, model),
evidenceCount_(evidenceCount),
successRate_(successRate),
oldEvidenceCount_(qQNaN()),
oldSuccessRate_(qQNaN())
{}
static const int EVENT_TYPE = 2;
core::float32 evidenceCount_;
core::float32 successRate_;
core::float32 oldEvidenceCount_;
core::float32 oldSuccessRate_;
};
class SetModelStrengthEvent : public AeraEvent {
public:
SetModelStrengthEvent
(core::Timestamp time, r_code::Code* model, core::float32 strength)
: AeraEvent(EVENT_TYPE, time, model),
strength_(strength),
oldStrength_(qQNaN())
{}
static const int EVENT_TYPE = 3;
core::float32 strength_;
core::float32 oldStrength_;
};
class PhaseOutModelEvent : public AeraEvent {
public:
PhaseOutModelEvent(core::Timestamp time, r_code::Code* model)
: AeraEvent(EVENT_TYPE, time, model)
{}
static const int EVENT_TYPE = 4;
};
class PhaseInModelEvent : public AeraEvent {
public:
PhaseInModelEvent(core::Timestamp time, r_code::Code* model)
: AeraEvent(EVENT_TYPE, time, model)
{}
static const int EVENT_TYPE = 5;
};
// TODO: Record whether it was phased out before deletion so that this can be restored during unstep.
class DeleteModelEvent : public AeraEvent {
public:
DeleteModelEvent(core::Timestamp time, r_code::Code* model)
: AeraEvent(EVENT_TYPE, time, model)
{}
static const int EVENT_TYPE = 6;
};
class NewCompositeStateEvent : public AeraEvent {
public:
NewCompositeStateEvent(core::Timestamp time, r_code::Code* compositeState,
uint64 controllerDegugOid)
: AeraEvent(EVENT_TYPE, time, compositeState),
controllerDegugOid_(controllerDegugOid)
{}
static const int EVENT_TYPE = 7;
// TODO: Should the composite state's controller be recorded globally?
uint64 controllerDegugOid_;
};
class ProgramReductionEvent : public AeraEvent {
public:
// TODO: Get the reduction time from the mk.rdx view's injection time?
ProgramReductionEvent(core::Timestamp time, r_code::Code* programReduction,
uint64 controllerDegugOid)
: AeraEvent(EVENT_TYPE, time, programReduction),
controllerDegugOid_(controllerDegugOid)
{}
static const int EVENT_TYPE = 8;
// TODO: Should the program's controller be recorded globally?
uint64 controllerDegugOid_;
};
class ProgramReductionNewObjectEvent : public AeraEvent {
public:
ProgramReductionNewObjectEvent(core::Timestamp time, r_code::Code* outputObject,
r_code::Code* programReduction)
: AeraEvent(EVENT_TYPE, time, outputObject),
programReduction_(programReduction)
{}
static const int EVENT_TYPE = 9;
r_code::Code* programReduction_;
};
class AutoFocusNewObjectEvent : public AeraEvent {
public:
AutoFocusNewObjectEvent(core::Timestamp time, r_code::Code* fromObject,
r_code::Code* toObject, const std::string& syncMode)
: AeraEvent(EVENT_TYPE, time, toObject),
fromObject_(fromObject), syncMode_(syncMode)
{}
static const int EVENT_TYPE = 10;
r_code::Code* fromObject_;
std::string syncMode_;
};
/**
* ModelImdlPredictionEvent is a reduction event specific to a prediction of an imdl,
* which doesn't have an associated requirement (as opposed to a mk.val prediction which does).
*/
class ModelImdlPredictionEvent : public AeraEvent {
public:
/**
* Create a ModelImdlPredictionEvent.
* \param time The reduction time.
* \param factPred The (fact (pred (fact (imdl ...)))).
* \param predictingModel The model which made the prediction.
* \param cause The input cause for the prediction.
*/
ModelImdlPredictionEvent(core::Timestamp time, r_code::Code* factPred,
r_code::Code* predictingModel, r_code::Code* cause)
: AeraEvent(EVENT_TYPE, time, factPred),
predictingModel_(predictingModel), cause_(cause)
{}
static const int EVENT_TYPE = 11;
r_code::Code* predictingModel_;
r_code::Code* cause_;
};
/**
* ModelMkValPredictionReduction is a reduction event specific to a prediction of a mk.val,
* which has an associated requirement (as opposed to a prediction of an imdl which doesn't).
*/
class ModelMkValPredictionReduction : public AeraEvent {
public:
/**
* Create a ModelMkValPredictionReduction, but set object_ to the (fact (pred ...)).
* (mk.rdx fact_imdl [fact_cause fact_requirement] [fact_pred]) .
* \param time The reduction time.
* \param reduction The model reduction which points to the (fact (pred ...)) and the cause.
*/
ModelMkValPredictionReduction(core::Timestamp time, r_exec::MkRdx* reduction)
// The prediction is the first item in the set of productions.
: AeraEvent(EVENT_TYPE, time, getFirstProduction(reduction)),
reduction_(reduction)
{}
static const int EVENT_TYPE = 12;
r_code::Code* getFactImdl() { return reduction_->get_reference(MK_RDX_IHLP_REF); }
/**
* Get the cause from the reduction_, which is the first item in the set of inputs.
* \return The cause.
*/
r_code::Code* getCause() { return reduction_->get_first_input(); }
/**
* Get the requirement from the reduction_, where the second item in the set of inputs is
* the mk.rdx for the requirement (so we get the mk.rdx production).
* \return The requirement, or NULL if the set of inputs has less than two items.
*/
r_code::Code* getRequirement() {
r_code::Code* req_mk_rdx = getSecondInput(reduction_);
if (!req_mk_rdx || req_mk_rdx->code(0).asOpcode() != r_exec::Opcodes::MkRdx)
return NULL;
return ((r_exec::MkRdx*)req_mk_rdx)->get_first_production();
}
r_code::Code* getFactPred() { return object_; }
r_exec::MkRdx* reduction_;
int imdlPredictionEventIndex_;
};
/**
* ModelGoalReduction is a reduction event of a model abduction to a goal.
*/
class ModelGoalReduction : public AeraEvent {
public:
/**
* Create a ModelGoalReduction, but set object_ to the (fact (goal...)).
* \param time The reduction time.
* \param model The model which did the reduction.
* \param factGoal The (fact (goal...)) (production).
* \param factSuperGoal The (fact (goal...)) super goal (input).
*/
ModelGoalReduction(core::Timestamp time, r_code::Code* model,
r_code::Code* factGoal, r_code::Code* factSuperGoal)
: AeraEvent(EVENT_TYPE, time, factGoal),
model_(model), factGoal_((r_exec::_Fact*)factGoal),
factSuperGoal_((r_exec::_Fact*)factSuperGoal)
{}
r_code::Code* getInput() override { return factSuperGoal_; }
static const int EVENT_TYPE = 13;
r_code::Code* model_;
r_exec::_Fact* factGoal_;
r_exec::_Fact* factSuperGoal_;
};
/**
* CompositeStateGoalReduction is a reduction event of a composite statue abduction to a goal.
*/
class CompositeStateGoalReduction : public AeraEvent {
public:
/**
* Create a CompositeStateGoalReduction, but set object_ to the (fact (goal...)).
* \param time The reduction time.
* \param compositeState The composite state which did the reduction.
* \param factGoal The (fact (goal...)) (production).
* \param factSuperGoal The (fact (goal...)) super goal (input).
*/
CompositeStateGoalReduction(core::Timestamp time, r_code::Code* compositeState,
r_code::Code* factGoal, r_code::Code* factSuperGoal)
: AeraEvent(EVENT_TYPE, time, factGoal),
compositeState_(compositeState), factGoal_((r_exec::_Fact*)factGoal),
factSuperGoal_((r_exec::_Fact*)factSuperGoal)
{}
r_code::Code* getInput() override { return factSuperGoal_; }
static const int EVENT_TYPE = 14;
r_code::Code* compositeState_;
r_exec::_Fact* factGoal_;
r_exec::_Fact* factSuperGoal_;
};
/**
* ModelSimulatedPredictionReduction is a reduction event of a model to a simulated prediction.
*/
class ModelSimulatedPredictionReduction : public AeraEvent {
public:
/**
* Create a ModelSimulatedPredictionReduction.
* \param time The reduction time.
* \param model The model which did the reduction.
* \param factPred The (fact (pred...)) (production).
* \param input The input fact triggering the reduction.
* \param requirement The requirement used by the reduction (may be NULL).
* \param inputIsSuperGoal True if the input is a super goal, meaning that this event
* is the last step of simulated backward chaining to start forward chaining.
* \param factPredIsImdl True if the prediction is of the imdl, not of the RHS.
*/
ModelSimulatedPredictionReduction(core::Timestamp time, r_code::Code* model,
r_code::Code* factPred, r_code::Code* input, r_code::Code* requirement, bool inputIsSuperGoal,
bool factPredIsImdl)
: AeraEvent(EVENT_TYPE, time, factPred),
model_(model), factPred_((r_exec::_Fact*)factPred),
input_((r_exec::_Fact*)input), requirement_((r_exec::_Fact*)requirement),
inputIsSuperGoal_(inputIsSuperGoal), factPredIsImdl_(factPredIsImdl)
{
addOtherInput(requirement);
}
r_code::Code* getInput() override { return input_; }
static const int EVENT_TYPE = 15;
r_code::Code* model_;
r_exec::_Fact* factPred_;
r_exec::_Fact* input_;
r_exec::_Fact* requirement_;
bool inputIsSuperGoal_;
bool factPredIsImdl_;
};
/**
* CompositeStateSimulatedPredictionReduction is a reduction event of a composite state to a simulated prediction.
*/
class CompositeStateSimulatedPredictionReduction : public AeraEvent {
public:
/**
* Create a CompositeStateSimulatedPredictionReduction.
* \param time The reduction time.
* \param compositeState The composite state which did the reduction.
* \param factPred The (fact (pred...)) (production).
* \param input The input fact triggering the reduction.
* \param inputs The set of inputs which made the icst (one of which is input).
*/
CompositeStateSimulatedPredictionReduction(core::Timestamp time, r_code::Code* compositeState,
r_code::Code* factPred, r_code::Code* input, const std::vector<r_code::Code*>& inputs)
: AeraEvent(EVENT_TYPE, time, factPred),
compositeState_(compositeState), factPred_((r_exec::_Fact*)factPred),
input_((r_exec::_Fact*)input), inputs_(inputs)
{
for (auto i = inputs.begin(); i != inputs.end(); ++i) {
if (*i != input)
addOtherInput(*i);
}
}
r_code::Code* getInput() override { return input_; }
static const int EVENT_TYPE = 16;
r_code::Code* compositeState_;
r_exec::_Fact* factPred_;
r_exec::_Fact* input_;
std::vector<r_code::Code*> inputs_;
};
class NewInstantiatedCompositeStateEvent : public AeraEvent {
public:
NewInstantiatedCompositeStateEvent(
core::Timestamp time, r_code::Code* instantiatedCompositeState,
const std::vector<r_code::Code*>& inputs)
: AeraEvent(EVENT_TYPE, time, instantiatedCompositeState),
inputs_(inputs)
{}
static const int EVENT_TYPE = 17;
std::vector<r_code::Code*> inputs_;
};
/* Use NewPredictedInstantiatedCompositeStateEvent for a new predicted (non-simulated) icst.
*/
class NewPredictedInstantiatedCompositeStateEvent : public AeraEvent {
public:
/**
* Create a NewPredictedInstantiatedCompositeStateEvent.
* \param time The reduction time.
* \param f_p_f_icst The new (fact (pred (fact (icst ...))))
* \param inputs The list of inputs. Note that some may be predictions.
*/
NewPredictedInstantiatedCompositeStateEvent(
core::Timestamp time, r_code::Code* f_p_f_icst,
const std::vector<r_code::Code*>& inputs)
: AeraEvent(EVENT_TYPE, time, f_p_f_icst),
inputs_(inputs)
{}
static const int EVENT_TYPE = 18;
std::vector<r_code::Code*> inputs_;
};
/**
* Use PredictionResultEvent for both success and failure. Use the method isSuccess to distinguish.
*/
class PredictionResultEvent : public AeraEvent {
public:
PredictionResultEvent(core::Timestamp time, r_code::Code* factSuccessFactPred)
: AeraEvent(EVENT_TYPE, time, factSuccessFactPred)
{}
/**
* Check if this is for a prediction success.
* \return True for prediction success (fact) or false for prediction failure (anti-fact).
*/
bool isSuccess() { return object_->code(0).asOpcode() == r_exec::Opcodes::Fact; }
static const int EVENT_TYPE = 19;
};
class IoDeviceInjectEvent : public AeraEvent {
public:
IoDeviceInjectEvent(
core::Timestamp time, r_code::Code* object, core::Timestamp injectionTime)
: AeraEvent(EVENT_TYPE, time, object),
injectionTime_(injectionTime)
{}
static const int EVENT_TYPE = 20;
core::Timestamp injectionTime_;
};
class IoDeviceEjectEvent : public AeraEvent {
public:
IoDeviceEjectEvent(core::Timestamp time, r_code::Code* object, r_code::Code* reduction)
: AeraEvent(EVENT_TYPE, time, object),
reduction_(reduction)
{}
static const int EVENT_TYPE = 21;
r_code::Code* reduction_;
};
class DriveInjectEvent : public AeraEvent {
public:
DriveInjectEvent(
core::Timestamp time, r_code::Code* object, core::Timestamp injectionTime)
: AeraEvent(EVENT_TYPE, time, object),
injectionTime_(injectionTime)
{}
static const int EVENT_TYPE = 22;
core::Timestamp injectionTime_;
};
/**
* The input of a SimulationCommitEvent is a simulated (fact (pred (fact (success...)))),
* and the output is a commited non-simulated (fact (goal...)) which is the RHS of a
* model whose LHS is the committed action.
*/
class SimulationCommitEvent : public AeraEvent {
public:
/**
* Create a SimulationCommitEvent
* \param time The event time.
* \param factGoal The (fact (goal...)) (committed RHS).
* \param factPredFactSuccess The (fact (pred (fact (success...)))).
*/
SimulationCommitEvent(core::Timestamp time,
r_code::Code* factGoal, r_code::Code* factPredFactSuccess)
: AeraEvent(EVENT_TYPE, time, factGoal),
factPredFactSuccess_((r_exec::_Fact*)factPredFactSuccess)
{}
r_code::Code* getInput() override { return factPredFactSuccess_; }
static const int EVENT_TYPE = 23;
r_exec::_Fact* factPredFactSuccess_;
};
/**
* ModelSimulatedPredictionReductionFromGoalRequirement is a reduction event of a model from a goal requirement
* to a simulated prediction of the LHS.
*/
class ModelSimulatedPredictionReductionFromGoalRequirement : public AeraEvent {
public:
/**
* Create a ModelSimulatedPredictionReductionFromGoalRequirement.
* \param time The reduction time.
* \param model The model which did the reduction.
* \param factPred The (fact (pred...)) (production).
* \param input The input fact triggering the reduction.
* \param goal_requirement The original goal requirement (the target of the signalled SRMonitor).
*/
ModelSimulatedPredictionReductionFromGoalRequirement(core::Timestamp time, r_code::Code* model,
r_code::Code* factPred, r_code::Code* input, r_code::Code* goal_requirement)
: AeraEvent(EVENT_TYPE, time, factPred),
model_(model), factPred_((r_exec::_Fact*)factPred),
input_((r_exec::_Fact*)input), goal_requirement_((r_exec::_Fact*)goal_requirement)
{
addOtherInput(goal_requirement);
}
r_code::Code* getInput() override { return input_; }
static const int EVENT_TYPE = 24;
r_code::Code* model_;
r_exec::_Fact* factPred_;
r_exec::_Fact* input_;
r_exec::_Fact* goal_requirement_;
};
/**
* ModelPredictionFromRequirementDisabledEvent is the event when a weak requirement is disabled by
* a strong requirement.
*/
class ModelPredictionFromRequirementDisabledEvent : public AeraEvent {
public:
/**
* Create a ModelPredictionFromRequirementDisabledEvent. This sets object_ to NULL, since this is
* an event for disabling the production of an output.
* \param time The time of the disable event.
* \param model The model which did the reduction.
* \param input The input fact (weak requirement) triggering the event.
* \param goal_requirement The original goal requirement (the target of the signalled SRMonitor), or null
* if not from SRMonitor.
* \param strong_requirement The strong requirement which disabled the input (weak requirement).
*/
ModelPredictionFromRequirementDisabledEvent(core::Timestamp time, r_code::Code* model,
r_code::Code* input, r_code::Code* goal_requirement, r_code::Code* strong_requirement)
: AeraEvent(EVENT_TYPE, time, NULL),
model_(model), input_((r_exec::_Fact*)input),
goal_requirement_((r_exec::_Fact*)goal_requirement),
strong_requirement_((r_exec::_Fact*)strong_requirement)
{}
r_code::Code* getInput() override { return input_; }
static const int EVENT_TYPE = 25;
r_code::Code* model_;
r_exec::_Fact* input_;
r_exec::_Fact* goal_requirement_;
r_exec::_Fact* strong_requirement_;
};
class PromotedSimulatedPredictionEvent : public AeraEvent {
public:
/**
* Create a PromotedSimulatedPredictionEvent
* \param time The event time.
* \param promotedFact The promoted fact.
* \param promotedFromFact The fact from which the promoted fact was made.
* \param timingsFact The fact whose timings are used for the promoted fact (treated as the input).
*/
PromotedSimulatedPredictionEvent(core::Timestamp time,
r_code::Code* promotedFact, r_code::Code* promotedFromFact, r_code::Code* timingsFact)
: AeraEvent(EVENT_TYPE, time, promotedFact),
promotedFromFact_((r_exec::_Fact*)promotedFromFact),
timingsFact_((r_exec::_Fact*)timingsFact)
{
addOtherInput(promotedFromFact);
}
r_code::Code* getInput() override { return timingsFact_; }
static const int EVENT_TYPE = 26;
r_exec::_Fact* promotedFromFact_;
r_exec::_Fact* timingsFact_;
};
/**
* A PromotedSimulatedPredictionDefeatEvent is the event when an actual simulated prediction defeats a
* promoted simulated prediction.
*/
class PromotedSimulatedPredictionDefeatEvent : public AeraEvent {
public:
/**
* Create a PromotedSimulatedPredictionDefeatEvent. This sets object_ to NULL, since this is
* an event for invalidating the production of an output.
* \param time The time of the defeat event.
* \param input The input fact (non-promoted) triggering the event.
* \param promoted_fact The promoted fact which is defeated.
*/
PromotedSimulatedPredictionDefeatEvent(core::Timestamp time, r_code::Code* input, r_code::Code* promotedFact)
: AeraEvent(EVENT_TYPE, time, NULL),
input_((r_exec::_Fact*)input),
promotedFact_((r_exec::_Fact*)promotedFact)
{}
r_code::Code* getInput() override { return input_; }
static const int EVENT_TYPE = 27;
r_code::Code* model_;
r_exec::_Fact* input_;
r_exec::_Fact* promotedFact_;
};
/* Use NewInstantiatedModelEvent to display imdls separately from the items
* that produce them
*/
class NewInstantiatedModelEvent : public AeraEvent {
public:
NewInstantiatedModelEvent(
core::Timestamp time, r_exec::MkRdx* reduction, r_code::Code* factPred)
: AeraEvent(EVENT_TYPE, time, reduction->get_reference(MK_RDX_IHLP_REF)),
factPred_(factPred),
factImdl_(reduction->get_reference(MK_RDX_IHLP_REF)),
imdl_(factImdl_->get_reference(0)),
baseModel_(factImdl_->get_reference(0)->get_reference(0)),
reduction_(reduction)
{}
static const int EVENT_TYPE = 28;
r_code::Code* factPred_; // The fact from 'fact imdl ...'
r_code::Code* factImdl_; // The fact from 'fact imdl ...'
r_code::Code* imdl_; // The imdl from 'fact imdl ...'
r_code::Code* baseModel_; // The mdl that's instantiated
r_exec::MkRdx* reduction_; // The reduction that produces everything
/**
* Get the cause from the reduction_, which is the first item in the set of inputs.
* \return The cause.
*/
r_code::Code* getCause() { return reduction_->get_first_input(); }
};
/* NewReductionMarkerEvent is the event when a mk.rdx is produced.
* \param time The time of the reduction event.
* \param mk_rdx The mk.rdx object.
*/
class NewReductionMarkerEvent : public AeraEvent {
public:
NewReductionMarkerEvent(core::Timestamp time, r_exec::MkRdx* mk_rdx)
: AeraEvent(EVENT_TYPE, time, mk_rdx), mk_rdx_(mk_rdx)
{}
static const int EVENT_TYPE = 29;
r_exec::MkRdx* mk_rdx_;
};
class AbaAddSentence : public AeraEvent {
public:
/**
* Create an AbaAddSentence event for a new (unmarked) sentence.
* \param time The reduction time.
* \param fact The fact produced by the step.
* \param isAssumption True if fact is an assumption.
* \param isClaim True if fact is the claim of the graph.
* \param graphId S*100 + ID, where S is the solution number and ID is 0 for proponent graph,
* otherwise the opponent graph ID (within the solution).
* \param parent The fact which produced the step, or NULL if the first.
* \param abaCase The derivation case which produced the sentence.
* \param step (optional) The step number to print, if greater than zero.
*/
AbaAddSentence(core::Timestamp time, r_code::Code* fact, bool isAssumption, bool isClaim,
int graphId, r_code::Code* parent, const std::string& abaCase, int step = 0)
: AeraEvent(EVENT_TYPE, time, fact),
fact_((r_exec::_Fact*)fact),
isAssumption_(isAssumption),
isClaim_(isClaim),
graphId_(graphId),
parent_((r_exec::_Fact*)parent),
abaCase_(abaCase),
step_(step)
{}
r_code::Code* getInput() override { return parent_; }
static const int EVENT_TYPE = 30;
r_exec::_Fact* fact_;
bool isAssumption_;
bool isClaim_;
int graphId_;
r_exec::_Fact* parent_;
std::string abaCase_;
int step_;
};
class AbaMarkSentence : public AeraEvent {
public:
/**
* Create an AbaMarkSentence event to mark an existing sentence.
* \param time The reduction time.
* \param fact The fact to be marked.
* \param alsoMarkGraph (optional) If true, also mark the graph that the fact is in.
*/
AbaMarkSentence(core::Timestamp time, r_code::Code* fact, bool alsoMarkGraph = false)
// Set the object_ NULL since there is already an AeraEvent for it.
: AeraEvent(EVENT_TYPE, time, NULL),
fact_((r_exec::_Fact*)fact),
alsoMarkGraph_(alsoMarkGraph)
{}
static const int EVENT_TYPE = 31;
r_exec::_Fact* fact_;
bool alsoMarkGraph_;
};
class AbaMarkedSentenceToParent : public AeraEvent {
public:
/**
* Create an AbaMarkedSentenceToParent event for a link from a marked sentence to a parent.
* \param time The reduction time.
* \param markedFact The fact which is already marked.
* \param parent The parent fact which is justified by the markedFact.
*/
AbaMarkedSentenceToParent(core::Timestamp time, r_code::Code* markedFact, r_code::Code* parent)
// Set the object_ NULL since there is already an AeraEvent for it.
: AeraEvent(EVENT_TYPE, time, NULL),
markedFact_((r_exec::_Fact*)markedFact),
parent_((r_exec::_Fact*)parent)
{}
static const int EVENT_TYPE = 32;
r_exec::_Fact* markedFact_;
r_exec::_Fact* parent_;
};
class AbaBindVariable : public AeraEvent {
public:
/**
* Create an AbaBindVariable event for binding a variable.
* \param time The reduction time.
* \param varNumber The variable number.
* \param value The bound value.
*/
AbaBindVariable(core::Timestamp time, int varNumber, const QString& value)
// Set the object_ NULL since there is already an AeraEvent for it.
: AeraEvent(EVENT_TYPE, time, NULL),
varNumber_(varNumber),
value_(value)
{}
static const int EVENT_TYPE = 33;
int varNumber_;
QString value_;
};
}
#endif