← Documentation
ADS-IDAC Engine 5.0.0
MRComponentStateUnit.cpp
Go to the documentation of this file.
1// MRComponentState.cpp: implementation of the MRComponentState class.
2//
4
5#include <string>
6#include <sstream>
7#include <iostream>
8#include <fstream>
9
11#include "SentenceUnit.h"
12#include "../Crew/OperatorDM.h"
13#include "../Crew/OperatorAT.h"
14#include "ReasonMachine.h"
15#include "Statement.h"
16#include "../Global/SimulationContext.h"
17
18using namespace std;
19
20
21
23// Construction/Destruction
25
27{
28 this->m_ID_Type = 202;
29 this->m_Concept_ID_pt = NULL;
30 this->m_recent_state_statement = NULL;
31 this->m_recent_action_statement = NULL;
32 this->m_concept_ID = "";
35 this->m_change_threshold = 0;
38
39 //201--MRParameterUnit
40 //202--MRComponentStateUnit
41 //203--MRAlarmUnit
42}
43
45{
46 this->m_history_state.clear();
47 this->m_history_position_value.clear();
48}
49
50void MRComponentStateUnit::AddNewState(int _state, int _operator, bool _expecting)
51{
52 string ID_name;
53 string prompt, str;
54 stringstream conv;
55
56
57 if(r5pars_.timesno > 969)
58 {this->PrintMessage("check");}
59
60 bool state_bl;
61 SentenceUnit * found_sent_pt;
62 ReasonMachine * RM_pt;
63 Investigator * invest_pt;
64 Statement * statement_pt;
65 bool NewStatement_bl = false;
66
67 if (_operator == sim::Operator::ODM)
68 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
69 else if (_operator == sim::Operator::OAT)
70 {RM_pt = g_sim.Action_Taker.m_RM.get();}
71 else
72 {}//add error message
73 //convert the key words into 0/1
74 if (_state == sim::State::On || _state == sim::State::Open)
75 {
76 state_bl = true;
77 str = "ON";
78 }
79 else if(_state == sim::State::Off || _state == sim::State::Close)
80 {
81 state_bl = false;
82 str = "OFF";
83 }
84
85 prompt = "Received new reading of ";
86 prompt += this->Component_State_Indicator_ID;
87 prompt += ": ";
88 prompt += str;
89 this->PrintMessage(prompt);
90
91 RM_pt->AddDeltaToCognitiveLoad(0.024);
92 //check whether this is consistant with what is observed before
93 if((this->m_recent_state != NULL) && (this->m_recent_state->m_perceived_state != state_bl))
94 {
95 //state changed
96 NewStatement_bl = true;
97 if(state_bl == true)
98 {
99 //add one statement: "xxx turn_on"
100 SentenceUnit turn_on_sent;
101 turn_on_sent.m_sentence_type = 1;
102 turn_on_sent.m_subject_pt = this->m_Concept_ID_pt;
103 turn_on_sent.m_process_pt = RM_pt->m_Concept_Base->getTurnOnPt();
104 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&turn_on_sent);
105 }
106 else
107 {
108 //add one statement to say it is turned off
109 SentenceUnit turn_off_sent;
110 turn_off_sent.m_sentence_type = 1;
111 turn_off_sent.m_subject_pt = this->m_Concept_ID_pt;
112 turn_off_sent.m_process_pt = RM_pt->m_Concept_Base->getTurnOffPt();
113 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&turn_off_sent);
114 }
115 if(found_sent_pt != 0)
116 {
117 auto stmt = make_unique<Statement>();
118 stmt->m_factual_type = 1;
119 stmt->m_confidence =1;
120 stmt->m_sent_pt = found_sent_pt;
121 stmt->m_state = true;
122 stmt->m_time_range.m_time_after = this->m_recent_state->m_time_perceived;
123 stmt->m_time_range.m_time_before = r5pars_.timesno;
124 statement_pt = stmt.get();
125 RM_pt->AddANewStatement(stmt.release());
126 this->m_recent_action_statement = statement_pt;
127 RM_pt->AddDeltaToSystemDynamics(0.12);
128
129 if(_expecting == true)
130 {
132 if(sent_pt->m_sentence_type == statement_pt->m_sent_pt->m_sentence_type)
133 {
134 RM_pt->m_working_on_invest_pt->m_Statement_pt = statement_pt;
135 RM_pt->AddDeltaToCognitiveLoad(0.024);
136 statement_pt->m_investigator_ID_pt = (IDElement*)(RM_pt->m_working_on_invest_pt);
137 }
138 }
139
140 //Add an investigator for this statement
141 if(statement_pt->m_investigator_ID_pt == NULL)
142 {
143 auto inv = make_unique<Investigator>();
144 inv->m_note = "by a statement";
145 inv->m_motivation = 1;
146 inv->m_Statement_pt = statement_pt;
147 RM_pt->AddDeltaToCognitiveLoad(0.024);
148 inv->m_Happen = 3;
149 inv->m_operator = this->m_operator;
150 inv->m_root_of_a_thought_line = true;
151 invest_pt = inv.get();
152 RM_pt->AddNewInvestigator(inv.release());
153 //link the statement to the statement pointer
154 statement_pt->m_investigator_ID_pt = (IDElement*)invest_pt;
155 }
156 }
157 }
158 else if(this->m_recent_state == NULL)
159 {
160 NewStatement_bl = true;
161 }
162 else
163 {
164 NewStatement_bl = false;
165 //the state has not changed
166 if(this->m_recent_state_statement != NULL)
167 {
170 }
171 else
172 {}//error message
173 }
174 if(NewStatement_bl == true)
175 {
176 if(state_bl == true)
177 {
178 //add one statement to say "xxx is on"
179 SentenceUnit is_on_sent;
180 is_on_sent.m_sentence_type = 2;
181 is_on_sent.m_subject_pt = this->m_Concept_ID_pt;
182 is_on_sent.m_state_pt = RM_pt->m_Concept_Base->getONpt();
183 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&is_on_sent);
184 }
185 else
186 {
187 //add one statement to say "xxx is OFF"
188 SentenceUnit is_off_sent;
189 is_off_sent.m_sentence_type = 2;
190 is_off_sent.m_subject_pt = this->m_Concept_ID_pt;
191 is_off_sent.m_state_pt = RM_pt->m_Concept_Base->getOFFpt();
192 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&is_off_sent);
193 }
194 if(found_sent_pt != 0)
195 {
196 auto stmt = make_unique<Statement>();
197 stmt->m_factual_type = 1;
198 stmt->m_confidence =1;
199 stmt->m_sent_pt = found_sent_pt;
200 stmt->m_state = true;
201 stmt->m_time_generated = r5pars_.timesno;
202 stmt->m_time_range.m_start_time = r5pars_.timesno;
203 if(this->m_recent_state)
204 {stmt->m_time_range.m_time_after = this->m_recent_state->m_time_perceived;}
205 stmt->m_time_range.m_end_time = r5pars_.timesno;
206 statement_pt = stmt.get();
207 RM_pt->AddANewStatement(stmt.release());
208 this->m_recent_state_statement = statement_pt;
209 statement_pt->m_tbi_bl = false;
210
211 if(_expecting == true)
212 {
214 if(sent_pt->m_sentence_type == statement_pt->m_sent_pt->m_sentence_type)
215 {
216 RM_pt->m_working_on_invest_pt->m_Statement_pt = statement_pt;
217 RM_pt->AddDeltaToCognitiveLoad(0.024);
218 statement_pt->m_investigator_ID_pt = (IDElement*)(RM_pt->m_working_on_invest_pt);
219 }
220 }
221 }
222 else
223 {}//warning message/error message
224 }
225
226 if(this->m_recent_state)
227 {
228 this->m_history_state.push_back(std::move(this->m_recent_state));
229 }
230 this->m_recent_state = make_unique<MRStateSchema>();
231 this->m_recent_state->m_perceived_state = state_bl;
232 this->m_recent_state->m_time_perceived = r5pars_.timesno;
233 //To be added, compare the current state with the expectation
234
235 this->UpdateTheRelevantInvestigator(_operator);
236}
237
238void MRComponentStateUnit::AddNewPositionValue(float _position, int _operator, bool _expecting)
239{
240 SentenceUnit * found_sent_pt;
241 ReasonMachine * RM_pt;
242 Investigator * invest_pt;
243 Statement * statement_pt;
244 IDElement * ID_pt;
245 bool NewStatement_bl = false;
246 bool update_action_bl = false;
247
248 string ID_name;
249 stringstream conv;
250 string prompt;
251
252 prompt = "Received new reading of ";
253 prompt += this->Control_Value_Indicator_ID;
254 prompt += ": ";
255 conv.str("");
256 conv << _position;
257 prompt += conv.str();
258 this->PrintMessage(prompt);
259
260 if (_operator == sim::Operator::ODM)
261 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
262 else if (_operator == sim::Operator::OAT)
263 {RM_pt = g_sim.Action_Taker.m_RM.get();}
264 else
265 {}//add error message
266
267 RM_pt->AddDeltaToCognitiveLoad(0.024);
268 if(this->m_recent_position_value != 0)
269 {//compare with the last received value
270 if(_position - this->m_recent_position_value->m_perceived_value > this->m_change_threshold)
271 {
272 ID_pt = RM_pt->m_Concept_Base->getOpenBiggerPt();
273 NewStatement_bl = true;
274 }
275 //only use one change threshold
276 else if (_position - this->m_recent_position_value->m_perceived_value < 0 - this->m_change_threshold)
277 {
278 ID_pt = RM_pt->m_Concept_Base->getCloseSmallerPt();
279 NewStatement_bl = true;
280 }
281
282 if(NewStatement_bl == true && this->m_recent_action_statement != NULL)
283 {
285 {
286 NewStatement_bl = false;
287 update_action_bl = true;
288 }
289 }
290 if(update_action_bl == true)
291 {
292 //only need to update the statement effective time
293
294 this->m_recent_action_statement->RefreshStatementEndTimeToCurrentTime(0); //needs to improve with the boundary; like the valve position is 0 for a long while, it should be type 0 instead of type 1
296 }
297 if(NewStatement_bl == true)
298 {
299 SentenceUnit sent;
300 sent.m_sentence_type = 1;
301 sent.m_subject_pt = this->m_Concept_ID_pt;
302 sent.m_process_pt = ID_pt;
303 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&sent);
304 if(found_sent_pt != 0)
305 {
306 //new phenomenon, need to add a new statement
307 auto stmt = make_unique<Statement>();
308 stmt->m_factual_type = 1;
309 stmt->m_confidence =1;
310 stmt->m_sent_pt = found_sent_pt;
311 stmt->m_state = true;
312 stmt->m_time_generated = r5pars_.timesno;
313 stmt->m_time_range.m_time_before =r5pars_.timesno;
314 stmt->m_time_range.m_time_after = this->m_recent_position_value->m_time_perceived;
315 statement_pt = stmt.get();
316 RM_pt->AddANewStatement(stmt.release());
317 this->m_recent_action_statement = statement_pt;
318 RM_pt->AddDeltaToSystemDynamics(0.12);
319
320 if(_expecting == true)
321 {
323 if(sent_pt->m_sentence_type == statement_pt->m_sent_pt->m_sentence_type)
324 {
325 RM_pt->m_working_on_invest_pt->m_Statement_pt = statement_pt;
326 RM_pt->AddDeltaToCognitiveLoad(0.024);
327 statement_pt->m_investigator_ID_pt = (IDElement*)(RM_pt->m_working_on_invest_pt);
328 }
329 }
330
331 //Add an investigator for this statement
332 if(statement_pt->m_investigator_ID_pt == NULL)
333 {
334 auto inv = make_unique<Investigator>();
335 inv->m_note = "by a statement";
336 inv->m_motivation = 1;
337 inv->m_Statement_pt = statement_pt;
338 RM_pt->AddDeltaToCognitiveLoad(0.024);
339 inv->m_Happen = 3;
340 inv->m_operator = this->m_operator;
341 invest_pt = inv.get();
342 RM_pt->AddNewInvestigator(inv.release());
343 invest_pt->m_root_of_a_thought_line = true;
344 //link the statement to the statement pointer
345 statement_pt->m_investigator_ID_pt = (IDElement*)invest_pt;
346 }
347 }
348 }
349 this->m_history_position_value.push_back(std::move(this->m_recent_position_value));
350 }
351 //save the newly received position value
352 this->m_recent_position_value = make_unique<MRValueSchema>();
353 this->m_recent_position_value->m_perceived_value = _position;
354 this->m_recent_position_value->m_time_perceived = r5pars_.timesno;
355
356 //update the relevant investigation
357 this->UpdateTheRelevantInvestigator(_operator);
358}
359
361{
362
363
364 // this function is to find a position reading in the history which is within the required time range
365 MRValueSchema * value_schema_pt = NULL;
366 bool found = false;
367 if(!this->m_recent_position_value)
368 {
369 return NULL; //question: could use return 0 instead??
370 }
371 else if(this->m_recent_position_value->m_time_perceived >= _start && this->m_recent_position_value->m_time_perceived <= _end)
372 {
373 value_schema_pt = this->m_recent_position_value.get();
374 found = true;
375 }
376 else
377 {// To be added, the memory decay effect, only the active value could be retrieved from the memory
378 for(auto &e : this->m_history_position_value)
379 {
380 if(found) break;
381 if(e->m_time_perceived >= _start && e->m_time_perceived <= _end)
382 {
383 value_schema_pt = e.get();
384 found = true;
385 }
386 }
387 }
388 return value_schema_pt;
389
390}
391
393{
394 float timer = 0.5;
395 Operator * operator_pt;
396 switch (this->m_operator)
397 {
399 operator_pt = &g_sim.Action_Taker;
400 break;
402 operator_pt = &g_sim.Decision_Maker;
403 break;
404 default:
405 break;
406 //error message
407 }
408 //be careful, verify an uninitiated string varible is ""
409 if(this->m_CS_type == 0)
410 {operator_pt->ActiveFetchComponentStateInfo(this->Component_State_Indicator_ID, _timer); }
411 if(this->m_CS_type == 1)
412 {operator_pt->ActiveFetchParameterValueInfo(this->Control_Value_Indicator_ID, _timer);}
413}
414
416{
417 bool found = false;
418 MRValueSchema * value_schema_pt = NULL;
419 if(this->m_CS_type != 1)
420 {
421 return NULL;//error message
422 }
423 if(this->m_recent_position_value == NULL)
424 {
425 return NULL;
426 }
427 else
428 {
429 if(this->m_recent_position_value->m_time_perceived >= _start && this->m_recent_position_value->m_time_perceived <= _end)
430 {
431 return this->m_recent_position_value.get();
432 }
433 }
434
435 for(auto ritr = this->m_history_position_value.rbegin(); ritr != this->m_history_position_value.rend() && found == false; ritr++)
436 {
437 if((*ritr)->m_time_perceived <= _end)
438 {
439 if((*ritr)->m_time_perceived >= _start)
440 {
441 found = true;
442 value_schema_pt = ritr->get();
443 }
444 else
445 {
446 //need to verify "break" jumps out of the for loop
447 break;
448 }
449 }
450 }
451 return value_schema_pt;
452}
453
455{
456 SentenceUnit * found_sent_pt;
457 ReasonMachine * RM_pt;
458 Statement * statement_pt;
459 IDElement * ID_pt;
460 bool NewStatement_bl = false;
461 bool update_action_bl = false;
462
463 string ID_name;
464 stringstream conv;
465 string prompt;
466
467 prompt = "Received new reading of ";
468 prompt += this->Control_Value_Indicator_ID;
469 prompt += ": ";
470 conv.str("");
471 conv << _position;
472 prompt += conv.str();
473 this->PrintMessage(prompt);
474
475 if (_operator == sim::Operator::ODM)
476 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
477 else if (_operator == sim::Operator::OAT)
478 {RM_pt = g_sim.Action_Taker.m_RM.get();}
479 else
480 {}//add error message
481
483 {//compare with the last received value
484 if(_position - this->m_recent_position_value->m_perceived_value > this->m_change_threshold)
485 {
486 ID_pt = RM_pt->m_Concept_Base->getOpenBiggerPt();
487 NewStatement_bl = true;
488 }
489 //only use one change threshold
490 else if (_position - this->m_recent_position_value->m_perceived_value > 0 - this->m_change_threshold)
491 {
492 ID_pt = RM_pt->m_Concept_Base->getCloseSmallerPt();
493 NewStatement_bl = true;
494 }
495
496 if(NewStatement_bl == true)
497 {
499 {
500 NewStatement_bl = false;
501 update_action_bl = true;
502 }
503 }
504 if(update_action_bl == true)
505 {
506 //only need to update the statement effective time
507 this->m_recent_action_statement->RefreshStatementEndTimeToCurrentTime(0);//needs to improve with the boundary; like the valve position is 0 for a long while, it should be type 0 instead of type 1
509 }
510 if(NewStatement_bl == true)
511 {
512 SentenceUnit sent;
513 sent.m_sentence_type = 1;
514 sent.m_subject_pt = this->m_Concept_ID_pt;
515 sent.m_process_pt = ID_pt;
516 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&sent);
517 if(found_sent_pt != 0)
518 {
519 //new phenomenon, need to add a new statement
520 auto stmt = make_unique<Statement>();
521 stmt->m_factual_type = 1;
522 stmt->m_confidence =1;
523 stmt->m_sent_pt = found_sent_pt;
524 stmt->m_state = true;
525 stmt->m_time_generated = r5pars_.timesno;
526 stmt->m_time_range.m_time_before =r5pars_.timesno;
527 stmt->m_time_range.m_time_after = this->m_recent_position_value->m_time_perceived;
528 statement_pt = stmt.get();
529 RM_pt->AddANewStatement(stmt.release());
530 this->m_recent_action_statement = statement_pt;
531 }
532 }
533 this->m_history_position_value.push_back(std::move(this->m_recent_position_value));
534 }
535 //save the newly received position value
536 this->m_recent_position_value = make_unique<MRValueSchema>();
537 this->m_recent_position_value->m_perceived_value = _position;
538 this->m_recent_position_value->m_time_perceived = r5pars_.timesno;
539}
540
541
543{
544 string ID_name;
545 stringstream conv;
546 string prompt, str;
547
548 bool state_bl;
549 SentenceUnit * found_sent_pt;
550 ReasonMachine * RM_pt;
551 Statement * statement_pt;
552 bool NewStatement_bl = false;
553
554 if (_operator == sim::Operator::ODM)
555 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
556 else if (_operator == sim::Operator::OAT)
557 {RM_pt = g_sim.Action_Taker.m_RM.get();}
558 else
559 {}//add error message
560 //convert the key words into 0/1
561 if (_state == sim::State::On || _state == sim::State::Open)
562 {
563 state_bl = true;
564 str = "ON";
565 }
566 else if(_state == sim::State::Off || _state == sim::State::Close)
567 {
568 state_bl = false;
569 str = "OFF";
570 }
571
572 prompt = "Received new reading of ";
573 prompt += this->Component_State_Indicator_ID;
574 prompt += ": ";
575 prompt += str;
576 this->PrintMessage(prompt);
577
578 //check whether this is consistant with what is observed before
579 if((this->m_recent_state != NULL) && (this->m_recent_state->m_perceived_state != state_bl))
580 {
581 //state changed
582 NewStatement_bl = true;
583 if(state_bl == true)
584 {
585 //add one statement: "xxx turn_on"
586 SentenceUnit turn_on_sent;
587 turn_on_sent.m_sentence_type = 1;
588 turn_on_sent.m_subject_pt = this->m_Concept_ID_pt;
589 turn_on_sent.m_process_pt = RM_pt->m_Concept_Base->getTurnOnPt();
590 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&turn_on_sent);
591 }
592 else
593 {
594 //add one statement to say it is turned off
595 SentenceUnit turn_off_sent;
596 turn_off_sent.m_sentence_type = 1;
597 turn_off_sent.m_subject_pt = this->m_Concept_ID_pt;
598 turn_off_sent.m_process_pt = RM_pt->m_Concept_Base->getTurnOffPt();
599 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&turn_off_sent);
600 }
601 if(found_sent_pt != 0)
602 {
603 auto stmt = make_unique<Statement>();
604 stmt->m_factual_type = 1;
605 stmt->m_confidence =1;
606 stmt->m_sent_pt = found_sent_pt;
607 stmt->m_state = true;
608 stmt->m_time_range.m_time_after = this->m_recent_state->m_time_perceived;
609 stmt->m_time_range.m_time_before = r5pars_.timesno;
610 statement_pt = stmt.get();
611 RM_pt->AddANewStatement(stmt.release());
612 this->m_recent_action_statement = statement_pt;
613 }
614 }
615 else if(this->m_recent_state == NULL)
616 {
617 NewStatement_bl = true;
618 }
619 else
620 {
621 NewStatement_bl = false;
622 //the state has not changed
623 if(this->m_recent_state_statement != NULL)
624 {
627 }
628 else
629 {}//error message
630 }
631 if(NewStatement_bl == true)
632 {
633 if(state_bl == true)
634 {
635 //add one statement to say "xxx is on"
636 SentenceUnit is_on_sent;
637 is_on_sent.m_sentence_type = 2;
638 is_on_sent.m_subject_pt = this->m_Concept_ID_pt;
639 is_on_sent.m_state_pt = RM_pt->m_Concept_Base->getONpt();
640 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&is_on_sent);
641 }
642 else
643 {
644 //add one statement to say "xxx is OFF"
645 SentenceUnit is_off_sent;
646 is_off_sent.m_sentence_type = 2;
647 is_off_sent.m_subject_pt = this->m_Concept_ID_pt;
648 is_off_sent.m_state_pt = RM_pt->m_Concept_Base->getOFFpt();
649 found_sent_pt = RM_pt->CheckExistInSemanticPoolBySentence(&is_off_sent);
650 }
651 if(found_sent_pt != 0)
652 {
653 auto stmt = make_unique<Statement>();
654 stmt->m_factual_type = 1;
655 stmt->m_confidence =1;
656 stmt->m_sent_pt = found_sent_pt;
657 stmt->m_state = true;
658 stmt->m_time_generated = r5pars_.timesno;
659 stmt->m_time_range.m_start_time = r5pars_.timesno;
660 if(this->m_recent_state)
661 {stmt->m_time_range.m_time_after = this->m_recent_state->m_time_perceived;}
662 stmt->m_time_range.m_end_time = r5pars_.timesno;
663 statement_pt = stmt.get();
664 RM_pt->AddANewStatement(stmt.release());
665 this->m_recent_state_statement = statement_pt;
666 statement_pt->m_tbi_bl = false;
667 }
668 else
669 {}//warning message/error message
670 }
671
672 if(this->m_recent_state)
673 {
674 this->m_history_state.push_back(std::move(this->m_recent_state));
675 }
676 this->m_recent_state = make_unique<MRStateSchema>();
677 this->m_recent_state->m_perceived_state = state_bl;
678 this->m_recent_state->m_time_perceived = r5pars_.timesno;
679 //To be added, compare the current state with the expectation
680}
681
683{
684 cout << "Time: " << r5pars_.timesno << ": " << str << '\n';
685
686 //test
687 ofstream fout("RMI.txt", ios::app);
688 fout << "Time: " << r5pars_.timesno << ": " << str << '\n';
689 fout.close();
690}
691
693{
694 MRStateSchema * found_state_schema_pt = NULL;
695 if(this->m_recent_state->m_time_perceived >= _start && this->m_recent_state->m_time_perceived <= _end)
696 {
697 found_state_schema_pt = this->m_recent_state.get();
698 return found_state_schema_pt;
699 }
700 else if(this->m_recent_state->m_time_perceived > _end)
701 {
702 for(auto &e : this->m_history_state)
703 {
704 if(e->m_time_perceived >= _start && e->m_time_perceived <= _end)
705 {
706 found_state_schema_pt = e.get();
707 }
708 }
709 }
710 return found_state_schema_pt;
711}
712
714{
715 MRStateSchema * found_state_schema_pt = NULL;
716
717 if(this->m_recent_state == NULL)
718 {return NULL;}
719
720 if(this->m_recent_state->m_time_perceived < _start)
721 {
722 found_state_schema_pt = this->m_recent_state.get();
723 return found_state_schema_pt;
724 }
725 else
726 {
727 for(auto ritr = this->m_history_state.rbegin(); ritr != this->m_history_state.rend(); ritr++)
728 {
729 if((*ritr)->m_time_perceived < _start)
730 {
731 found_state_schema_pt = ritr->get();
732 return found_state_schema_pt;
733 }
734 }
735 }
736 return found_state_schema_pt;
737}
738
740{
741 MRStateSchema * found_state_schema_pt = NULL;
742
743 for(auto &e : this->m_history_state)
744 {
745 if(e->m_time_perceived > _end)
746 {
747 found_state_schema_pt = e.get();
748 return found_state_schema_pt;
749 }
750 }
751
752 if(this->m_recent_state->m_time_perceived > _end)
753 {
754 found_state_schema_pt = this->m_recent_state.get();
755 }
756 return found_state_schema_pt;
757}
758
759
761{
762 MRValueSchema * found_schema_pt = NULL;
763 MRValueSchema * value_schema_pt;
764 float value, delta;
765
766 ReasonMachine * RM_pt;
767 if (this->m_operator == sim::Operator::ODM)
768 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
769 else if (this->m_operator == sim::Operator::OAT)
770 {RM_pt = g_sim.Action_Taker.m_RM.get();}
771 else
772 {}//add error message
773 int comparison_type;
774
775 if(_sent_pt->m_sentence_type != 3)
776 {
777 //error message
778 this->ErrorMessage("Error!");
779 }
780
781 if(_sent_pt->m_comparison_pt == (IDElement *)RM_pt->m_Concept_Base->getBiggerPt())
782 {comparison_type = 1;}
783 else if(_sent_pt->m_comparison_pt == (IDElement *)RM_pt->m_Concept_Base->getSmallerPt())
784 {comparison_type = 2;}
785 else if(_sent_pt->m_comparison_pt == (IDElement *)RM_pt->m_Concept_Base->getEqualPt())
786 {comparison_type = 3;}
787 else
788 {
789 this->ErrorMessage("Error!");
790 }
791
792 value = _sent_pt->m_value;
793 delta = _sent_pt->m_delta_value;
794
795
796 value_schema_pt = this->m_recent_position_value.get();
797 if(value_schema_pt != NULL)
798 {
799 if(value_schema_pt->m_time_perceived >= _start
800 && value_schema_pt->m_time_perceived <= _end)
801 {
802 switch (comparison_type)
803 {//1->; 2-<; 3-=;
804 case 1:
805 if(value_schema_pt->m_perceived_value - value > delta)
806 {
807 found_schema_pt = value_schema_pt;
808 }
809 break;
810 case 2:
811 if(value - value_schema_pt->m_perceived_value > delta)
812 {
813 found_schema_pt = value_schema_pt;
814 }
815 break;
816 case 3:
817 if(value - value_schema_pt->m_perceived_value < delta
818 && value_schema_pt->m_perceived_value - value < delta)
819 {
820 found_schema_pt = value_schema_pt;
821 }
822 break;
823 default:
824 break;
825 }
826 }
827 else
828 {
829 if(value_schema_pt->m_time_perceived < _start)
830 {
831 return NULL;
832 }
833 }
834 }
835
836 auto VS_ritr = this->m_history_position_value.rbegin();
837
838 while(VS_ritr != this->m_history_position_value.rend() && found_schema_pt == NULL)
839 {
840 value_schema_pt = VS_ritr->get();
841 if(value_schema_pt->m_time_perceived >= _start
842 && value_schema_pt->m_time_perceived <= _end)
843 {
844 switch (comparison_type)
845 {//1->; 2-<; 3-=;
846 case 1:
847 if(value_schema_pt->m_perceived_value - value > delta)
848 {
849 found_schema_pt = value_schema_pt;
850 }
851 break;
852 case 2:
853 if(value - value_schema_pt->m_perceived_value > delta)
854 {
855 found_schema_pt = value_schema_pt;
856 }
857 break;
858 case 3:
859 if(value - value_schema_pt->m_perceived_value < delta
860 && value_schema_pt->m_perceived_value - value < delta)
861 {
862 found_schema_pt = value_schema_pt;
863 }
864 break;
865 default:
866 break;
867 }
868 }
869 else
870 {
871 if(value_schema_pt->m_time_perceived < _start)
872 {
873 return NULL;
874 }
875 }
876 VS_ritr++;
877 }
878 return found_schema_pt;
879}
880
882{
883 cout << r5pars_.timesno << " " << str << " in MRComponentStateUnit.cpp" << '\n';
884 ofstream fout("err messages.txt", ios::app);
885 fout << r5pars_.timesno << " " << str << '\n';
886 fout.close();
887 //r5pars_.terminateall = true;
888}
889
891{
892 MRValueSchema * found_schema_pt = NULL;
893 MRValueSchema * value_schema_pt;
894 float value, delta;
895
896 ReasonMachine * RM_pt;
897 if (this->m_operator == sim::Operator::ODM)
898 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
899 else if (this->m_operator == sim::Operator::OAT)
900 {RM_pt = g_sim.Action_Taker.m_RM.get();}
901 else
902 {}//add error message
903 int comparison_type;
904
905 if(_sent_pt->m_sentence_type != 3)
906 {
907 //error message
908 this->ErrorMessage("Error!");
909 }
910
911 if(_sent_pt->m_comparison_pt == (IDElement *)RM_pt->m_Concept_Base->getBiggerPt())
912 {comparison_type = 1;}
913 else if(_sent_pt->m_comparison_pt == (IDElement *)RM_pt->m_Concept_Base->getSmallerPt())
914 {comparison_type = 2;}
915 else if(_sent_pt->m_comparison_pt == (IDElement *)RM_pt->m_Concept_Base->getEqualPt())
916 {comparison_type = 3;}
917 else
918 {
919 this->ErrorMessage("Error!");
920 }
921
922 value = _sent_pt->m_value;
923 delta = _sent_pt->m_delta_value;
924
925
926 value_schema_pt = this->m_recent_position_value.get();
927 if(value_schema_pt != NULL)
928 {
929 if(value_schema_pt->m_time_perceived >= _start
930 && value_schema_pt->m_time_perceived <= _end)
931 {
932 switch (comparison_type)
933 {//1->; 2-<; 3-=;
934 case 1:
935 if(!(value_schema_pt->m_perceived_value - value > delta))
936 {
937 found_schema_pt = value_schema_pt;
938 }
939 break;
940 case 2:
941 if(!(value - value_schema_pt->m_perceived_value > delta))
942 {
943 found_schema_pt = value_schema_pt;
944 }
945 break;
946 case 3:
947 if(!(value - value_schema_pt->m_perceived_value < delta
948 && value_schema_pt->m_perceived_value - value < delta))
949 {
950 found_schema_pt = value_schema_pt;
951 }
952 break;
953 default:
954 break;
955 }
956 }
957 else
958 {
959 if(value_schema_pt->m_time_perceived < _start)
960 {
961 return NULL;
962 }
963 }
964 }
965
966 auto VS_ritr = this->m_history_position_value.rbegin();
967
968 while(VS_ritr != this->m_history_position_value.rend() && found_schema_pt == NULL)
969 {
970 value_schema_pt = VS_ritr->get();
971 if(value_schema_pt->m_time_perceived >= _start
972 && value_schema_pt->m_time_perceived <= _end)
973 {
974 switch (comparison_type)
975 {//1->; 2-<; 3-=;
976 case 1:
977 if(!(value_schema_pt->m_perceived_value - value > delta))
978 {
979 found_schema_pt = value_schema_pt;
980 }
981 break;
982 case 2:
983 if(!(value - value_schema_pt->m_perceived_value > delta))
984 {
985 found_schema_pt = value_schema_pt;
986 }
987 break;
988 case 3:
989 if(!(value - value_schema_pt->m_perceived_value < delta
990 && value_schema_pt->m_perceived_value - value < delta))
991 {
992 found_schema_pt = value_schema_pt;
993 }
994 break;
995 default:
996 break;
997 }
998 }
999 else
1000 {
1001 if(value_schema_pt->m_time_perceived < _start)
1002 {
1003 return NULL;
1004 }
1005 }
1006 VS_ritr++;
1007 }
1008 return found_schema_pt;
1009}
1010
1012{
1013 MRValueSchema * found_VS_pt = NULL;
1014 MRValueSchema * VS_pt = NULL;
1015
1016 if(this->m_recent_position_value)
1017 {
1018 if(this->m_recent_position_value->m_time_perceived < _start)
1019 {
1020 found_VS_pt = this->m_recent_position_value.get();
1021 return found_VS_pt;
1022 }
1023 }
1024 else
1025 {
1026 return NULL;
1027 }
1028
1029 for(auto ritr = this->m_history_position_value.rbegin(); ritr != this->m_history_position_value.rend(); ritr++)
1030 {
1031 VS_pt = ritr->get();
1032 if(VS_pt->m_time_perceived < _start)
1033 {
1034 found_VS_pt = VS_pt;
1035 return found_VS_pt;
1036 }
1037 }
1038 return found_VS_pt;
1039
1040}
1041
1043{
1044 MRValueSchema * found_VS_pt = NULL;
1045 MRValueSchema * VS_pt = NULL;
1046
1047 if(this->m_recent_position_value == NULL)
1048 {
1049 return NULL;
1050 }
1051
1052 for(auto &e : this->m_history_position_value)
1053 {
1054 VS_pt = e.get();
1055 if(VS_pt->m_time_perceived > _end)
1056 {
1057 found_VS_pt = VS_pt;
1058 return found_VS_pt;
1059 }
1060 }
1061
1062 if(this->m_recent_position_value->m_time_perceived > _end)
1063 {
1064 found_VS_pt = this->m_recent_position_value.get();
1065 }
1066 return found_VS_pt;
1067}
1068
1070{
1072 this->m_operator = _s_pt->m_operator;
1073 this->m_CS_type = _s_pt->m_CS_type;
1077
1078 if(_s_pt->m_Concept_ID_pt != NULL)
1079 {this->m_concept_ID = _s_pt->m_Concept_ID_pt->m_ID;}
1080 else
1081 {this->m_concept_ID = _s_pt->m_concept_ID;}
1082
1083 //statement
1084 if(_s_pt->m_recent_action_statement != NULL)
1086 else
1088
1089 if(_s_pt->m_recent_state_statement != NULL)
1091 else
1093
1094 //recent reading
1095 if(_s_pt->m_recent_state)
1096 {
1097 this->m_recent_state = make_unique<MRStateSchema>();
1098 this->m_recent_state->CopyStateSchemaFromAnother(_s_pt->m_recent_state.get());
1099 }
1100 if(_s_pt->m_recent_position_value)
1101 {
1102 this->m_recent_position_value = make_unique<MRValueSchema>();
1103 this->m_recent_position_value->CopyMRValueSchemaFromAnother(_s_pt->m_recent_position_value.get());
1104 }
1105 for(auto &e : _s_pt->m_history_state)
1106 {
1107 auto state_pt = make_unique<MRStateSchema>();
1108 state_pt->CopyStateSchemaFromAnother(e.get());
1109 this->m_history_state.push_back(std::move(state_pt));
1110 }
1111 for(auto &e : _s_pt->m_history_position_value)
1112 {
1113 auto value_pt = make_unique<MRValueSchema>();
1114 value_pt->CopyMRValueSchemaFromAnother(e.get());
1115 this->m_history_position_value.push_back(std::move(value_pt));
1116 }
1117
1118
1119}
1120
1122{
1123 ReasonMachine * RM_pt;
1124 RM_pt = (ReasonMachine *)_pt;
1125/*
1126 IDElement * m_Concept_ID_pt;
1127 Statement * m_recent_action_statement;
1128 Statement * m_recent_state_statement;
1129
1130 string m_concept_ID;
1131 string m_ID_recent_action_statement;
1132 string m_ID_recent_state_statement;
1133*/
1134 if(this->m_concept_ID.compare("") != 0)
1135 {
1136 this->m_Concept_ID_pt = RM_pt->m_Concept_Base->FindConceptByID(this->m_concept_ID);
1137 if(this->m_Concept_ID_pt == NULL)
1138 {this->ErrorMessage("could not find the concept " + this->m_concept_ID); return;}
1139 }
1140 if(this->m_ID_recent_action_statement.compare("") != 0)
1141 {
1143 if(this->m_recent_action_statement == NULL)
1144 {this->ErrorMessage("could not find the concept " + this->m_ID_recent_action_statement); return;}
1145 }
1147
1148 if(this->m_ID_recent_state_statement.compare("") != 0)
1149 {
1151 if(this->m_recent_state_statement == NULL)
1152 {this->ErrorMessage("could not find the concept " + this->m_ID_recent_state_statement); return;}
1153 }
1154 this->m_ID_recent_state_statement = "";
1155}
1156
1158{
1159
1160 ReasonMachine * RM_pt;
1161 Investigator * invest_pt;
1162 if (_operator == sim::Operator::ODM)
1163 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
1164 else if (_operator == sim::Operator::OAT)
1165 {RM_pt = g_sim.Action_Taker.m_RM.get();}
1166 else
1167 {}//add error message
1168 //update the relevant investigation
1169 if(this->m_recent_action_statement != NULL)
1170 {
1171 if(this->m_recent_action_statement->m_ID_investigator.compare("") != 0)
1172 {
1174 if(invest_pt != NULL)
1175 {
1176 if(invest_pt->m_investigator_token < 3029)
1177 {
1178 invest_pt->m_last_active_time = r5pars_.timesno;
1179 if(invest_pt->m_investigation_closed == true)
1180 {
1181 invest_pt->ReopenThisInvestigator();
1182 }
1183 }
1184 }
1185 }
1186 }
1187
1188 if(this->m_recent_state_statement != NULL)
1189 {
1190 if(this->m_recent_state_statement->m_ID_investigator.compare("") != 0)
1191 {
1193 if(invest_pt != NULL)
1194 {
1195 if(invest_pt->m_investigator_token < 3029)
1196 {
1197 invest_pt->m_last_active_time = r5pars_.timesno;
1198 if(invest_pt->m_investigation_closed == true)
1199 {
1200 invest_pt->ReopenThisInvestigator();
1201 }
1202 }
1203 }
1204 }
1205 }
1206}
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
document e
void CopyIDElementToRestartInfo(IDElement *)
Definition: IDElement.cpp:23
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
float m_last_active_time
Definition: Investigator.h:87
bool m_investigation_closed
Definition: Investigator.h:88
SentenceUnit * GetSemanticSentenceOfThisInvestigator()
void ReopenThisInvestigator()
bool m_root_of_a_thought_line
Definition: Investigator.h:85
int m_investigator_token
Definition: Investigator.h:99
Statement * m_Statement_pt
Definition: Investigator.h:130
MRValueSchema * FindAPositionReadingConsistantWithASentenceWithinTimeRange(float _start, float _end, SentenceUnit *_sent_pt)
std::unique_ptr< MRStateSchema > m_recent_state
MRValueSchema * FindTheFirstPositionReadingAfterATime(float _end)
void AddNewState(int, int, bool)
void AddNewStateForFirstRoundCheck(int, int)
std::string m_ID_recent_state_statement
MRValueSchema * FindTheLastPositionReadingBeforeATime(float _start)
MRValueSchema * CheckPositionReadingWithinTimeRange(double, double)
MRStateSchema * CheckTheFirstComponentStateReadingAfterATime(float _end)
MRValueSchema * FindAPositionReadingInconsitantWithASentenceWithinTimeRange(float _start, float _end, SentenceUnit *_sent_pt)
MRStateSchema * CheckComponentStateWithinTimeRange(float _start, float _end)
Statement * m_recent_state_statement
std::string Control_Value_Indicator_ID
void ReadComponentStateIndication(double)
MRStateSchema * CheckLastComponentStateReadingBeforeATime(float _start)
std::string Component_State_Indicator_ID
void AddNewPositionValue(float, int, bool)
void CopyMRComponentStateInfoFromAnother(MRComponentStateUnit *)
std::vector< std::unique_ptr< MRValueSchema > > m_history_position_value
MRValueSchema * FoundAPositionReadingWithinTimeRange(float, float)
Statement * m_recent_action_statement
std::unique_ptr< MRValueSchema > m_recent_position_value
std::vector< std::unique_ptr< MRStateSchema > > m_history_state
void AddNewPositionValueForFirstRoundCheck(float, int)
void ErrorMessage(std::string str)
void PrintMessage(std::string)
void BuildConnectionsForThisMRComponentState(void *)
std::string m_ID_recent_action_statement
float m_time_perceived
Definition: MRValueSchema.h:11
float m_perceived_value
Definition: MRValueSchema.h:14
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
void ActiveFetchParameterValueInfo(std::string, int)
Definition: Operator.cpp:1451
void ActiveFetchComponentStateInfo(std::string, int)
Definition: Operator.cpp:1466
std::unique_ptr< KBConcept > m_Concept_Base
void ActivationUpdateByRefreshAStatement(Statement *)
Investigator * m_working_on_invest_pt
void AddDeltaToCognitiveLoad(float)
void AddANewStatement(Statement *)
Statement * FindStatementByID(std::string)
Investigator * FindInvestigatorByID(std::string)
SentenceUnit * CheckExistInSemanticPoolBySentence(SentenceUnit *)
void AddDeltaToSystemDynamics(float)
void AddNewInvestigator(Investigator *)
IDElement * m_process_pt
Definition: SentenceUnit.h:38
int m_sentence_type
Definition: SentenceUnit.h:34
double m_value
Definition: SentenceUnit.h:31
IDElement * m_state_pt
Definition: SentenceUnit.h:36
float m_delta_value
Definition: SentenceUnit.h:33
IDElement * m_comparison_pt
Definition: SentenceUnit.h:37
IDElement * m_subject_pt
Definition: SentenceUnit.h:40
bool m_tbi_bl
Definition: Statement.h:39
SentenceUnit * m_sent_pt
Definition: Statement.h:43
void RefreshStatementEndTimeToCurrentTime(int)
Definition: Statement.cpp:73
IDElement * m_investigator_ID_pt
Definition: Statement.h:42
std::string m_ID_investigator
Definition: Statement.h:48
struct @0 r5pars_
Definition: RMTokens.h:21
constexpr int ODM
Definition: SimConstants.h:145
constexpr int OAT
Definition: SimConstants.h:144
constexpr int On
Definition: SimConstants.h:105
constexpr int Off
Definition: SimConstants.h:106
constexpr int Open
Definition: SimConstants.h:116
constexpr int Close
Definition: SimConstants.h:117
OperatorAT Action_Taker
Crew action execution model.
OperatorDM Decision_Maker
Crew decision-making model.