← Documentation
ADS-IDAC Engine 5.0.0
InvestigatorLink.cpp
Go to the documentation of this file.
1// InvestigatorLink.cpp: implementation of the InvestigatorLink class.
2//
4
5#include <sstream>
6#include <iostream>
7#include <fstream>
8
9#include "InvestigatorLink.h"
10#include "Investigator.h"
11#include "RMTokens.h"
12#include "KnowledgeElement.h"
13#include "ReasonMachine.h"
14#include "../Crew/OperatorDM.h"
15#include "../Crew/OperatorAT.h"
16#include "../Global/SimulationContext.h"
17
18using namespace std;
19
20
22// Construction/Destruction
24
26{
27 this->m_Happen_incomplete = false;
28 // m_dummy_activation default-constructs to nullptr
29 this->m_has_moved_to_invest = NULL;
30 this->m_is_a_strong_inference = false;
31 this->m_ID_Type = 302;
32 //301--Investigator
33 //302--InvestigatorLink
34 this->m_path_status = 1; // set the default path status as "unknown".
35 this->m_invest_link_pause = false;
37 this->m_invest_link_dormant = true;
38 this->m_condition_ID_pt = NULL;
39 this->m_downstream_ID_pt = NULL;
40 this->m_K_unit_pt = NULL;
41 this->m_is_causal_path_bl = true;
42 this->m_is_inference_path_bl = false;
44 this->m_SI_ID_pt = NULL;
46 this->m_forgotten_bl = false;
47 this->m_link_last_activated_time = r5pars_.timesno;
48 this->m_has_feedback_to_downstream = false;
49
50 this->m_ID_KU = "";
51 this->m_ID_downstream = "";
52 this->m_ID_condition = "";
53 this->m_ID_SI = "";
54 this->m_ID_has_moved_to_invest = "";
55}
56
58{
59 this->m_invest_link_Token_history.clear();
60 this->m_link_token_endtime_history.clear();
61
62 this->m_upperstream_ID_list.clear();
63 this->m_explanation_ID_list.clear();
64 this->m_confirmed_invest_ID_list.clear();
65 this->m_rejected_invest_ID_list.clear();
66 this->m_possible_invest_ID_list.clear();
67
68 this->m_ID_upperstream_list.clear();
69 this->m_ID_explanation_list.clear();
70 this->m_ID_confirmed_invest_list.clear();
71 this->m_ID_rejected_invest_list.clear();
72 this->m_ID_possible_invest_list.clear();
73}
74
76{
77 string str;
78 stringstream conv;
79
80 ReasonMachine * RM_pt;
81 if (this->m_operator == sim::Operator::ODM)
82 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
83 else if (this->m_operator == sim::Operator::OAT)
84 {RM_pt = g_sim.Action_Taker.m_RM.get();}
85 else
86 {}//add error message
87 if(this->m_invest_link_dormant == true)
88 {
89 this->m_invest_link_dormant = false;
90 }
91
92 if(this->m_invest_link_pause == true)
93 {
94 this->m_invest_link_pause = false;
95 }
96
97 if(this->m_forgotten_bl == true)
98 {
99 this->m_forgotten_bl = false;
100 }
101
102 this->m_link_last_activated_time = r5pars_.timesno;
103
104 switch (this->m_invest_link_Token)
105 {
108 break;
111 break;
114 break;
117 break;
120 break;
122 /*RM_pt->ChangeRMTokenValue(rm::Prioritize);
123
124 conv.str("");
125 conv << r5pars_.timesno;
126 str = conv.str();
127 str += ": transfer out: to prioritization";
128 this->m_note_list.push_back(str);*/
130 //error message, this InvestigatorLink has already been closed, should not enter this any more
131 break;
132 default:
133 break;
134 }
135}
136
138{//to be modified
139 //this is a perfect process, the operator would do a complete exam of both the condition and the causes
140 Investigator * invest_pt;
141 Investigator * next_invest_pt = NULL;
142 vector<IDElement *>::iterator ID_itr;
143 KnowledgeElement * KE_pt;
144 bool want_to_exam_condition_now = false;
145 float highest_score = 0;
146 float score;
147 string prompt, err_mes, str;
148 stringstream conv;
149
150 ReasonMachine * RM_pt;
151 if (this->m_operator == sim::Operator::ODM)
152 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
153 else if (this->m_operator == sim::Operator::OAT)
154 {RM_pt = g_sim.Action_Taker.m_RM.get();}
155 else
156 {}//add error message
157
158 //to be modified, the current prioritization is only based on the activation level of each KE sentence
159 //also, if there is one cause examed and the condition has not been examed yet, the operator would want to exam the condition first
160 prompt = "\n";
161 prompt += "Retrieving the next Investigator from the InvestigatorLink:\n";
163 RM_pt->m_event_schema_base->UpdateTheInterestForInvestigatorOrInvestigatorLink();
164 //
165 //for debug use only
166 if(r5pars_.timesno > 134.114)
167 {
168 // this->ErrorMessage("pause");
169 }
170 //
171 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr ++)
172 {
173 invest_pt = (Investigator*)(*ID_itr);
174 prompt += invest_pt->GetASimpleDescriptionOfThisInvestigator();
175 prompt += "\nRetrieve Score: ";
176 if(invest_pt->m_Happen == 1)
177 {
178 KE_pt = (KnowledgeElement*)(invest_pt->m_KElement_ID_pt);
179 if(KE_pt == NULL)
180 {
181 this->ErrorMessage("Error!");
182 }
183 score = KE_pt->m_SentenceUnit_pt->m_activation * (1 + invest_pt->m_interest_from_SymptomInvestigator *2);
184 if(next_invest_pt == NULL)
185 {
186 next_invest_pt = invest_pt;
187 highest_score = score;
188 }
189 else if(score > highest_score)
190 {
191 next_invest_pt = invest_pt;
192 highest_score = score;
193 }
194 conv.str("");
195 conv << score;
196 prompt += conv.str();
197 prompt += "\n";
198 }
199 else if(invest_pt->m_Happen == 3)
200 {
201 if(this->m_link_type == 1 || this->m_link_type == 3)
202 {
203 want_to_exam_condition_now = true;
204 }
205 }
206 }
207
208 if(this->m_condition_ID_pt != NULL)
209 {
210 invest_pt = (Investigator*)(this->m_condition_ID_pt);
211 if(invest_pt->m_Happen == 1)
212 {
213 KE_pt = (KnowledgeElement*)(invest_pt->m_KElement_ID_pt);
214 score = KE_pt->m_SentenceUnit_pt->m_activation * (1 + invest_pt->m_interest_from_SymptomInvestigator *2);
215 if(want_to_exam_condition_now == true)
216 {
217 next_invest_pt = invest_pt;
218 prompt += "Condition KE needs to be investigated!\n";
219 highest_score = score;
220 }
221 else
222 {
223 prompt += invest_pt->GetASimpleDescriptionOfThisInvestigator();
224 prompt += "\nRetrieve Score: ";
225 if(score > highest_score)
226 {
227 next_invest_pt = invest_pt;
228 highest_score = KE_pt->m_SentenceUnit_pt->m_activation;
229 }
230 conv.str("");
231 conv << score;
232 prompt += conv.str();
233 prompt += "\n";
234 }
235 }
236 }
237 this->PrintMessage(prompt);
238
239 if(next_invest_pt != NULL)
240 {
241 //forced inverstigation
242 if(this->m_SI_ID_pt != NULL)
243 {
244 next_invest_pt->m_SI_ID_pt = this->m_SI_ID_pt;
245 }
246 next_invest_pt->m_invest_dormant = false;
247 next_invest_pt->CrankTheActivationToOne();
248 //
249 prompt = "\n";
250 prompt += "The retrieved one: ";
251 prompt += next_invest_pt->GetASimpleDescriptionOfThisInvestigator();
252 this->PrintMessage(prompt);
254 this->m_invest_link_pause = true;
255 this->m_has_moved_to_invest = (IDElement *)next_invest_pt;
256 RM_pt->m_investigation_trace.push_back((IDElement*)this);
257 RM_pt->m_working_on_invest_pt = next_invest_pt;
259
260 conv.str("");
261 conv << r5pars_.timesno;
262 str = conv.str();
263 str += ": transfer out: to ";
264 str += RM_pt->m_working_on_invest_pt->m_ID;
265 this->m_note_list.push_back(str);
266 }
267 else
268 {
270 }
271}
272
274{//3102
275 //need to go through the logic again to verify it is correct
276 //to be modified, the current codes only reflect the OR logic, not and logic
277 string prompt, err_mes;
278 Investigator * invest_pt;
279 vector<IDElement *>::iterator ID_itr;
280 if(this->m_path_status == 2 || this->m_path_status == 3 )
281 {}//error message, it's already known, should not enter this micro function
282 bool status_determined = false;
283 bool unknown_cause_exist = false;
284 bool all_cause_not_happen = true;
285 bool all_cause_happen = true;
286 int condition_status = 3;
287 int next_status = 1;
288 int next_token;
289 bool has_a_strong_inference = false;
290 bool has_a_determined_cause = false;
291
292 ReasonMachine * RM_pt;
293 if (this->m_operator == sim::Operator::ODM)
294 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
295 else if (this->m_operator == sim::Operator::OAT)
296 {RM_pt = g_sim.Action_Taker.m_RM.get();}
297 else
298 {}//add error message
299 //caution here: Should examine the time range again here?
300 //examine the condition first
301
302 if(this->m_ID == "InvestigatorLink_60")
303 {
304 this->PrintMessage("Check");
305 }
306
307 prompt = "\n\n";
308 if(this->m_condition_ID_pt != NULL)
309 {
310 invest_pt = (Investigator*)(this->m_condition_ID_pt);
311 condition_status = invest_pt->m_Happen;
312 prompt += "Condition: ";
313 prompt += invest_pt->GetASimpleDescriptionOfThisInvestigator();
314 prompt += ", ";
315 }
316
317 if(condition_status == 3 || condition_status == 2)
318 {//condition satisfied
319 if(this->m_condition_ID_pt != NULL)
320 {
321 prompt += "happend\n";
322 }
323 //examine the causes
324 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end() && status_determined == false; ID_itr ++)
325 {
326 invest_pt = (Investigator*)(*ID_itr);
327 prompt += "Cause: ";
328 prompt += invest_pt->GetASimpleDescriptionOfThisInvestigator();
329 prompt += ", ";
330 switch (invest_pt->m_Happen)
331 {
332 case 1://unknown
333 prompt += "unknown\n";
334 unknown_cause_exist = true;
335 all_cause_happen = false;
336 all_cause_not_happen = false;
337 if(this->m_link_type == 2 || this->m_link_type == 1)
338 {//have to know this investigator path in order to determine this path
339 next_status = 1;
340 status_determined = true;
341 }
342 break;
343 case 2://could not determine
344 prompt += "could not be determined\n";
345 all_cause_happen = false;
346 all_cause_not_happen = false;
347 if(this->m_link_type == 2 || this->m_link_type ==1)
348 {
349 next_status = 2;
350 status_determined = true;
351 }
352 if(this->CheckExistenceInThePossibleInvestList(*ID_itr) == NULL)
353 {this->m_possible_invest_ID_list.push_back(*ID_itr);}
354 break;
355 case 3://yes, it happens
356 prompt += "happened\n";
357 all_cause_not_happen = false;
358 if(this->m_link_type == 3 || this->m_link_type == 1)
359 {
360 next_status = 3;
361 status_determined = true;
362 }
363
364 if(invest_pt->m_Statement_pt->m_factual_type == 3)
365 {has_a_strong_inference = true;}
366 else
367 {has_a_determined_cause = true;}
368
369 if(this->CheckExistenceInTheConfirmedInvestList(*ID_itr) == NULL)
370 {this->m_confirmed_invest_ID_list.push_back(*ID_itr);}
371 break;
372
373 case 4://no, it doesn't go through
374 prompt += "did not happen\n";
375 all_cause_happen = false;
376 if(this->m_link_type == 2 || this->m_link_type ==1)
377 {
378 next_status = 4;
379 status_determined = true;
380 }
381 if(this->CheckExistenceInTheRejectedInvestList(*ID_itr) == NULL)
382 {this->m_rejected_invest_ID_list.push_back(*ID_itr);}
383 break;
384 }
385 }
386 if(next_status == 1)
387 {
388 if(all_cause_not_happen == true)
389 {
390 prompt += "All the causes did not happen\n";
391 next_status = 4;
392 }
393 else if(unknown_cause_exist == true)
394 {
395 prompt += "Still more to investigate\n";
396 next_status = 1;
397 }
398 else//some of them could not be determined
399 {
400 prompt += "One or more causes could not be determined\n";
401 next_status = 2;
402 }
403 }
404
405 if(condition_status == 2)
406 {
407 if(next_status == 1 || next_status == 3)
408 {next_status = 2;}
409 }
410 this->PrintMessage(prompt);
411 }
412 else if(condition_status == 4)
413 {//condition not satisfied
414 prompt += "The condition is not satisfied\n";
415 next_status = 4; //doesn't go through
416 }
417 else if(condition_status == 1)
418 {//unknown yet
419 prompt += "The condition is not known\n";
420 next_status = 1; //unknow
421 }
422
423 if(condition_status == 3 && this->m_link_type == 2 && all_cause_happen == true)
424 {
425 prompt += "This inference path goes through.\n";
426 next_status = 3;
427 }
428//bool has_a_strong_inference = false;
429 //bool has_a_determined_cause = false;
430
431 this->m_path_status = next_status;
432 if(next_status == 3)
433 {
434 if(has_a_strong_inference == true)
435 {
436 if(this->m_link_type ==1)//and gate
437 {this->m_is_a_strong_inference = true;}
438 else//or gate
439 {
440 if(has_a_determined_cause == false)
441 {this->m_is_a_strong_inference = true;}
442 }
443 }
444 }
445 switch (next_status)
446 {
447 case 1:
449 break;
450 case 2:
452 break;
453 case 3:
454 if(unknown_cause_exist == true )
456 else
457 {next_token = inv_link::FeedbackDetermined;}
458 break;
459 case 4:
460 next_token = inv_link::FeedbackPartial;
461 break;
462 default:
463 //error message, should not be here
464 break;
465 }
466 if(this->m_invest_link_dormant == true)
467 {
468 if(next_token == inv_link::FeedbackDetermined || next_token == inv_link::FeedbackPartial || next_token == inv_link::FeedbackUndetermined)
469 {
470 this->m_invest_link_dormant = false;
471 RM_pt->AddToRMFeedbackStack(this);
472 }
473 }
474 this->ChangeInvestigatorLinkToken(next_token);
476}
477
479{//3103/3104/3105
480 string str;
481 stringstream conv;
482 vector<IDElement *>::iterator ID_itr;
483 Investigator * invest_pt;
484
485 //Caution Assumption: Each InvestigatorLink connects only one downstream investigator
486 ReasonMachine * RM_pt;
487 string prompt;
488 if (this->m_operator == sim::Operator::ODM)
489 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
490 else if (this->m_operator == sim::Operator::OAT)
491 {RM_pt = g_sim.Action_Taker.m_RM.get();}
492 else
493 {}//add error message
494
495
496 if(this->m_has_feedback_to_downstream == true)
497 {
498 if(this->m_confirmed_invest_ID_list.size() != 0)
499 {
500 ID_itr = this->m_confirmed_invest_ID_list.begin();
501 while(ID_itr != this->m_confirmed_invest_ID_list.end())
502 {
503 invest_pt = (Investigator *)(*ID_itr);
505 {
506 invest_pt->CrankTheActivationToOne();
507 RM_pt->m_working_on_invest_pt = invest_pt;
509 return;
510 }
511 ID_itr++;
512 }
513 }
515 return;
516 }
517 prompt += "Feedback to the downstream investigator";
518 this->PrintMessage(prompt);
519
520 RM_pt->AddToRMFeedbackStack((IDElement*)this);
523 this->m_has_feedback_to_downstream = true;
524
525 conv.str("");
526 conv << r5pars_.timesno;
527 str = conv.str();
528 str += ": transfer out: to ";
529 str += RM_pt->m_working_on_invest_pt->m_ID;
530 this->m_note_list.push_back(str);
531}
532
534{//to be modified
535 //this is a simple version
536 //it finds the highest activation in the condition KE and the causal KE
537 //the score is the multiplication of the backward reasoning weight and the highest activation
538 double score;
539 double highest_activation = 0;
540 double activation;
541 vector<IDElement*>::iterator ID_itr;
542 Investigator * invest_pt;
543
544 //check point
545 if(this->m_upperstream_ID_list.size() == 0)
546 {
547 this->ErrorMessage("Error!");
548 }
549
550
551 if(this->m_condition_ID_pt != NULL)
552 {
553 invest_pt = (Investigator *)(this->m_condition_ID_pt);
554 highest_activation = invest_pt->GetActivation();
555 }
556
557 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr ++)
558 {
559 invest_pt = (Investigator *)(*ID_itr);
560 activation = invest_pt->GetActivation();
561 if(activation > highest_activation)
562 {
563 highest_activation = activation;
564 }
565 }
566 score = pow((this->m_K_unit_pt->m_backward_retrieve_weight),1.6) * pow(highest_activation,0.4);
567 score *= 1 + 2 * this->m_interest_from_SymptomInvestigator;
568 if(score == 0)
569 {}//error message
570 return score;
571}
572
574{
575 ReasonMachine * RM_pt;
576 if (this->m_operator == sim::Operator::ODM)
577 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
578 else if (this->m_operator == sim::Operator::OAT)
579 {RM_pt = g_sim.Action_Taker.m_RM.get();}
580 else
581 {}//add error message
582 RM_pt->AddConsumptedDeltaT(_delta);
583}
584
586{
587 float score = 0;
588 float highest_score = 0;
589 vector<IDElement *>::iterator ID_itr;
590 Investigator * invest_pt;
591
592 if(this->m_ID == "InvestigatorLink_64")
593 {
594 this->PrintMessage("");
595 }
596 if(this->m_invest_link_dormant == true || this->m_invest_link_pause == true || this->m_invest_link_Token == inv_link::TransferOut)
597 {
598 return 0;
599 }
600 if(this->m_condition_ID_pt != NULL)
601 {
602 invest_pt = (Investigator*)this->m_condition_ID_pt;
603 highest_score = invest_pt->CalculatePriorityScoreEvenDormantOrPaused();
604 }
606 {
607 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr++)
608 {
609 invest_pt = (Investigator *)(*ID_itr);
611 }
612 }
613
614 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr++)
615 {
616 invest_pt = (Investigator *)(*ID_itr);
618 if(score > highest_score)
619 {
620 highest_score = score;
621 }
622 }
623
624 return highest_score + 20 * this->m_interest_from_SymptomInvestigator;
625}
626
628{
629 string str;
630 stringstream conv;
631
632 ReasonMachine * RM_pt;
633 if (this->m_operator == sim::Operator::ODM)
634 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
635 else if (this->m_operator == sim::Operator::OAT)
636 {RM_pt = g_sim.Action_Taker.m_RM.get();}
637 else
638 {}//add error message
639
640
643 {
645 RM_pt->EraseFromOngoingItemStack(this->m_ID);
646 }
648
649
650 conv.str("");
651 conv << r5pars_.timesno;
652 str = conv.str();
653 str += ": transfer out: to prioritization";
654 this->m_note_list.push_back(str);
655
656}
657
659{
661 this->m_invest_link_Token = _token;
662 this->m_link_token_endtime_history.push_back(r5pars_.timesno);
663}
664
666{
667 string str;
668 Investigator* invest_pt;
669 vector<IDElement *>::iterator ID_itr;
670
671 str = "InvestigatorLink Information: \n";
672 //describe the upperstream
673 str += "Upperstream of this inference Path ";
674 if(this->m_link_type == 2)
675 {
676 str += ", OR GATE:\n";
677 }
678 else if(this->m_link_type == 3)
679 {
680 str += ", AND GATE: \n";
681 }
682 else
683 {
684 str += ":\n";
685 }
686 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr++)
687 {
688 invest_pt = (Investigator *)(*ID_itr);
689 str += invest_pt->GetASimpleDescriptionOfThisInvestigator();
690 str += "\n";
691 }
692
693 //describe the downstream
694 str += "Downstream of this inference path:\n";
695 invest_pt = (Investigator*)(this->m_downstream_ID_pt);
696 str += invest_pt->GetASimpleDescriptionOfThisInvestigator();
697 str += "\n";
698
699 //describe the condition
700 if(this->m_condition_ID_pt != NULL)
701 {
702 invest_pt = (Investigator *)(this->m_condition_ID_pt);
703 str+= "Condition of this inference path:\n";
704 str += invest_pt->GetASimpleDescriptionOfThisInvestigator();
705 }
706 //to be added
707 return str;
708}
709
711{
712 cout << "\n";
713 cout << "Time: " << r5pars_.timesno << ":\n" << str << '\n';
714
715 //test
716 ofstream fout("RMI.txt", ios::app);
717 fout <<"\n" << "Time: " << r5pars_.timesno << ":\n" << str << '\n';
718 fout.close();
719}
720
722{
723 cout << r5pars_.timesno << " " << str << " in InvestigatorLink.cpp" << '\n';
724 ofstream fout("err messages.txt", ios::app);
725 fout << r5pars_.timesno << " " << str << '\n';
726 fout.close();
727 //r5pars_.terminateall = true;
728}
729
731{
732 float confidence = 0;
733 vector<IDElement *>::iterator ID_itr;
734 Investigator * invest_pt;
735 int number_of_strong_reference = 0;
736 bool unexplored_cause = false;
737
738 ReasonMachine * RM_pt;
739 if (this->m_operator == sim::Operator::ODM)
740 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
741 else if (this->m_operator == sim::Operator::OAT)
742 {RM_pt = g_sim.Action_Taker.m_RM.get();}
743 else
744 {}//add error message
745
746 for(ID_itr = this->m_confirmed_invest_ID_list.begin(); ID_itr != this->m_confirmed_invest_ID_list.end(); ID_itr++)
747 {
748 invest_pt = (Investigator*)(*ID_itr);
749 if(invest_pt->m_Happen == 3 && invest_pt->m_Statement_pt->m_factual_type == 3)
750 {number_of_strong_reference++;}
751 }
752
753 if(this->m_path_status != 2)
754 {
755 if(this->m_path_status != 3 || this->m_is_a_strong_inference == false)
756 {this->ErrorMessage("Error!");}
757 }
758
759 if(this->m_link_type == 1) //only connect to one upperstream investigator
760 {
761 confidence = _p;
762 }
763 else if(this->m_link_type == 3) //Or gate
764 {
765 //confidence = _p/(this->m_possible_invest_ID_list.size()) + number_of_strong_reference;
766 confidence = _p;
767 }
768 else if(this->m_link_type == 2) //And gate
769 {
770 confidence = _p;
771 if(this->m_rejected_invest_ID_list.size() != 0)
772 {
773 this->ErrorMessage("Error!");
774 return;
775 }
776 }
777
778 unexplored_cause = false;
779 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr++)
780 {
781 invest_pt = (Investigator*)(*ID_itr);
782 if(invest_pt->m_Happen == 1)
783 {unexplored_cause = true; break;}
784 }
785
786 if(unexplored_cause == true)
787 {
789 this->m_paused_confidence_passing_list.push_back(_p);
790 return;
791 }
792
793 for(ID_itr = this->m_possible_invest_ID_list.begin(); ID_itr != this->m_possible_invest_ID_list.end(); ID_itr++)
794 {
795 invest_pt = (Investigator*)(*ID_itr);
796 if((*ID_itr) == this->m_condition_ID_pt)
797 {
799 }
800 else
801 {
802 invest_pt->BackwardPropagateConfidenceLevel(confidence);
803 }
804 }
805 for(ID_itr = this->m_confirmed_invest_ID_list.begin(); ID_itr != this->m_confirmed_invest_ID_list.end(); ID_itr++)
806 {
807 invest_pt = (Investigator*)(*ID_itr);
808 if(invest_pt->m_Happen == 3 && invest_pt->m_Statement_pt->m_factual_type == 3)
809 {invest_pt->BackwardPropagateConfidenceLevel(confidence);}
810 }
811
812}
813
815{
816 IDElement * found_ID_pt = NULL;
817 vector<IDElement *>::iterator ID_itr;
818
819 for(ID_itr = this->m_confirmed_invest_ID_list.begin(); ID_itr != this->m_confirmed_invest_ID_list.end() && found_ID_pt == NULL; ID_itr++)
820 {
821 if((*ID_itr) == _ID_pt)
822 {
823 found_ID_pt = (*ID_itr);
824 }
825 }
826 return found_ID_pt;
827}
828
830{
831 IDElement * found_ID_pt = NULL;
832 vector<IDElement *>::iterator ID_itr;
833
834 for(ID_itr = this->m_possible_invest_ID_list.begin(); ID_itr != this->m_possible_invest_ID_list.end() && found_ID_pt == NULL; ID_itr++)
835 {
836 if((*ID_itr) == _ID_pt)
837 {
838 found_ID_pt = (*ID_itr);
839 }
840 }
841 return found_ID_pt;
842}
843
845{
846 IDElement * found_ID_pt = NULL;
847 vector<IDElement *>::iterator ID_itr;
848
849 for(ID_itr = this->m_rejected_invest_ID_list.begin(); ID_itr != this->m_rejected_invest_ID_list.end() && found_ID_pt == NULL; ID_itr++)
850 {
851 if((*ID_itr) == _ID_pt)
852 {
853 found_ID_pt = (*ID_itr);
854 }
855 }
856 return found_ID_pt;
857}
858
860{
861 this->CopyIDElementToRestartInfo((IDElement *)_link_pt);
862
864 if(_link_pt->m_dummy_activation)
865 {
866 this->m_dummy_activation = make_unique<Activation>();
867 this->m_dummy_activation->CopyActivationToRestartInfo(_link_pt->m_dummy_activation.get());
868 }
869/* bool m_invest_link_dormant;
870 int m_operator;
871 int m_invest_link_Token;
872 bool m_invest_link_pause;
873 bool m_is_inference_path_bl;
874 bool m_is_causal_path_bl;
875 float m_interest_from_SymptomInvestigator;
876 int m_path_status; //1--unknown; 2--could not be determined; 3--connect through; 4--doesn't go through;
877 int m_link_type; //1--one to one knowledge link; 2--And gate link; 3--Or gate link
878*/
879 this->m_operator = _link_pt->m_operator;
886 this->m_path_status = _link_pt->m_path_status;
887 this->m_link_type = _link_pt->m_link_type;
889 this->m_forgotten_bl = _link_pt->m_forgotten_bl;
892/*
893 string m_ID_KU;
894 string m_ID_downstream;
895 string m_ID_condition;
896 string m_ID_SI;
897*/
898 if(_link_pt->m_K_unit_pt != NULL)
899 {this->m_ID_KU = _link_pt->m_K_unit_pt->m_ID;}
900 else
901 {this->m_ID_KU = _link_pt->m_ID_KU;}
902
903 if(_link_pt->m_downstream_ID_pt != NULL)
904 {this->m_ID_downstream = _link_pt->m_downstream_ID_pt->m_ID;}
905 else
906 {this->m_ID_downstream = _link_pt->m_ID_downstream;}
907
908 if(_link_pt->m_condition_ID_pt != NULL)
909 {this->m_ID_condition = _link_pt->m_condition_ID_pt->m_ID;}
910 else
911 {this->m_ID_condition = _link_pt->m_ID_condition;}
912
913 if(_link_pt->m_SI_ID_pt != NULL)
914 {this->m_ID_SI = _link_pt->m_SI_ID_pt->m_ID;}
915 else
916 {this->m_ID_SI = _link_pt->m_ID_SI;}
917
918 if(_link_pt->m_has_moved_to_invest != NULL)
920 else
922
923 if(this->m_invest_link_Token_history.size() != 0)
924 {this->ErrorMessage("this->m_invest_link_Token_history.size() != 0");return;}
925 if(this->m_link_token_endtime_history.size() != 0)
926 {this->ErrorMessage("this->m_link_token_endtime_history.size() != 0");return;}
927 if(this->m_upperstream_ID_list.size() != 0)
928 {this->ErrorMessage("this->m_upperstream_ID_list.size() != 0");return;}
929 if(this->m_explanation_ID_list.size() != 0)
930 {this->ErrorMessage("this->m_explanation_ID_list.size() != 0");return;}
931 if(this->m_confirmed_invest_ID_list.size() != 0)
932 {this->ErrorMessage("this->m_confirmed_invest_ID_list.size() != 0");return;}
933 if(this->m_rejected_invest_ID_list.size() != 0)
934 {this->ErrorMessage("this->m_rejected_invest_ID_list.size() != 0");return;}
935 if(this->m_possible_invest_ID_list.size() != 0)
936 {this->ErrorMessage("this->m_possible_invest_ID_list.size() != 0");return;}
937 if(this->m_thoughtline_roots_list.size() > 0)
938 {this->ErrorMessage("this->m_thoughtline_roots_list.size() > 0");}
939/*
940 vector<int> m_invest_link_Token_history;
941 vector<double> m_link_token_endtime_history;
942*/
943 vector<int>::iterator int_itr;
944 int i;
945 for(int_itr = _link_pt->m_invest_link_Token_history.begin(); int_itr != _link_pt->m_invest_link_Token_history.end(); int_itr++)
946 {
947 i = *int_itr;
948 this->m_invest_link_Token_history.push_back(i);
949 }
950
951 vector<float>::iterator fl_itr;
952 float fl;
953 for(fl_itr = _link_pt->m_link_token_endtime_history.begin(); fl_itr != _link_pt->m_link_token_endtime_history.end(); fl_itr++)
954 {
955 fl = * fl_itr;
956 this->m_link_token_endtime_history.push_back(fl);
957 }
958
959 for(fl_itr = _link_pt->m_paused_confidence_passing_list.begin(); fl_itr != _link_pt->m_paused_confidence_passing_list.end(); fl_itr++)
960 {
961 fl = *fl_itr;
962 this->m_paused_confidence_passing_list.push_back(fl);
963 }
964/*
965 vector<IDElement *> m_upperstream_ID_list;
966 vector<IDElement *> m_explanation_ID_list;
967 vector<IDElement *> m_confirmed_invest_ID_list;
968 vector<IDElement *> m_rejected_invest_ID_list;
969 vector<IDElement *> m_possible_invest_ID_list;
970*/
971 vector<IDElement *>::iterator ID_itr;
972 vector<string>::iterator str_itr;
973 string ID;
974
975 for(str_itr = _link_pt->m_pause_confidence_propagation_ID_list.begin(); str_itr != _link_pt->m_pause_confidence_propagation_ID_list.end(); str_itr++)
976 {
977 ID = *str_itr;
978 this->m_pause_confidence_propagation_ID_list.push_back(ID);
979 }
980
981 for(str_itr = _link_pt->m_thoughtline_roots_list.begin(); str_itr != _link_pt->m_thoughtline_roots_list.end(); str_itr++)
982 {
983 ID = *str_itr;
984 this->m_thoughtline_roots_list.push_back(ID);
985 }
986
987 if(_link_pt->m_upperstream_ID_list.size() != 0)
988 {
989 for(ID_itr = _link_pt->m_upperstream_ID_list.begin(); ID_itr != _link_pt->m_upperstream_ID_list.end(); ID_itr++)
990 {
991 ID = (*ID_itr)->m_ID;
992 this->m_ID_upperstream_list.push_back(ID);
993 }
994 }
995 else
996 {
997 for(str_itr = _link_pt->m_ID_upperstream_list.begin(); str_itr != _link_pt->m_ID_upperstream_list.end(); str_itr++)
998 {
999 ID = *str_itr;
1000 this->m_ID_upperstream_list.push_back(ID);
1001 }
1002 }
1003
1004 if(_link_pt->m_explanation_ID_list.size() != 0)
1005 {
1006 for(ID_itr = _link_pt->m_explanation_ID_list.begin(); ID_itr != _link_pt->m_explanation_ID_list.end(); ID_itr++)
1007 {
1008 ID = (*ID_itr)->m_ID;
1009 this->m_ID_explanation_list.push_back(ID);
1010 }
1011 }
1012 else
1013 {
1014 for(str_itr = _link_pt->m_ID_explanation_list.begin(); str_itr != _link_pt->m_ID_explanation_list.end(); str_itr++)
1015 {
1016 ID = *str_itr;
1017 this->m_ID_explanation_list.push_back(ID);
1018 }
1019 }
1020
1021 if(_link_pt->m_confirmed_invest_ID_list.size() != 0)
1022 {
1023 for(ID_itr = _link_pt->m_confirmed_invest_ID_list.begin(); ID_itr != _link_pt->m_confirmed_invest_ID_list.end(); ID_itr++)
1024 {
1025 ID = (*ID_itr)->m_ID;
1026 this->m_ID_confirmed_invest_list.push_back(ID);
1027 }
1028 }
1029 else
1030 {
1031 for(str_itr = _link_pt->m_ID_confirmed_invest_list.begin(); str_itr != _link_pt->m_ID_confirmed_invest_list.end(); str_itr++)
1032 {
1033 ID = *str_itr;
1034 this->m_ID_confirmed_invest_list.push_back(ID);
1035 }
1036 }
1037
1038 if(_link_pt->m_rejected_invest_ID_list.size() != 0)
1039 {
1040 for(ID_itr = _link_pt->m_rejected_invest_ID_list.begin(); ID_itr != _link_pt->m_rejected_invest_ID_list.end(); ID_itr++)
1041 {
1042 ID = (*ID_itr)->m_ID;
1043 this->m_ID_rejected_invest_list.push_back(ID);
1044 }
1045 }
1046 else
1047 {
1048 for(str_itr = _link_pt->m_ID_rejected_invest_list.begin(); str_itr != _link_pt->m_ID_rejected_invest_list.end(); str_itr++)
1049 {
1050 ID = *str_itr;
1051 this->m_ID_rejected_invest_list.push_back(ID);
1052 }
1053 }
1054
1055 if(_link_pt->m_possible_invest_ID_list.size() != 0)
1056 {
1057 for(ID_itr = _link_pt->m_possible_invest_ID_list.begin(); ID_itr != _link_pt->m_possible_invest_ID_list.end(); ID_itr++)
1058 {
1059 ID = (*ID_itr)->m_ID;
1060 this->m_ID_possible_invest_list.push_back(ID);
1061 }
1062 }
1063 else
1064 {
1065 for(str_itr = _link_pt->m_ID_possible_invest_list.begin(); str_itr != _link_pt->m_ID_possible_invest_list.end(); str_itr++)
1066 {
1067 ID = *str_itr;
1068 this->m_ID_possible_invest_list.push_back(ID);
1069 }
1070 }
1071
1072 if(this->m_note_list.size()>0)
1073 {this->ErrorMessage("this->m_note_list.size()>0");}
1074 for(str_itr = _link_pt->m_note_list.begin(); str_itr != _link_pt->m_note_list.end(); str_itr++)
1075 {
1076 this->m_note_list.push_back(*str_itr);
1077 }
1078}
1079
1081{
1082 ReasonMachine * RM_pt;
1083 RM_pt = (ReasonMachine *)_pt;
1084
1085 if(this->m_ID_has_moved_to_invest.compare("") != 0)
1086 {
1088 if(this->m_has_moved_to_invest == NULL)
1089 {this->ErrorMessage("this->m_has_moved_to_invest == NULL");return;}
1090 this->m_ID_has_moved_to_invest = "";
1091 }
1092
1093 //KnowledgeUnit * m_K_unit_pt;
1094 if(this->m_ID_KU.compare("") != 0)
1095 {
1096 this->m_K_unit_pt = RM_pt->FindKnowledgeUnitByID(this->m_ID_KU);
1097 if(this->m_K_unit_pt == NULL)
1098 {this->ErrorMessage("could not find the knowledge " + this->m_ID_KU); return;}
1099 }
1100 //IDElement * m_downstream_ID_pt;
1101 if(this->m_ID_downstream.compare("") != 0)
1102 {
1104 if(this->m_downstream_ID_pt == NULL)
1105 {this->ErrorMessage("could not find the downstream investigator" + this->m_ID_downstream); return;}
1106 }
1107 //IDElement * m_condition_ID_pt;
1108 if(this->m_ID_condition.compare("") != 0)
1109 {
1111 if(this->m_condition_ID_pt == NULL)
1112 {this->ErrorMessage("could not find the condition investigator " + this->m_ID_condition); return;}
1113 }
1114
1115 //IDElement * m_SI_ID_pt;
1116 if(this->m_ID_SI.compare("") != 0)
1117 {
1118 this->m_SI_ID_pt = RM_pt->m_event_schema_base->FindSymtomInvestigatorByID(this->m_ID_SI);
1119 if(this->m_SI_ID_pt == NULL)
1120 {this->ErrorMessage("could not find the SymptomInvestigator " + this->m_ID_SI); return;}
1121 }
1122
1123
1124/*
1125 vector<IDElement *> m_upperstream_ID_list;
1126 vector<IDElement *> m_explanation_ID_list;
1127 vector<IDElement *> m_confirmed_invest_ID_list;
1128 vector<IDElement *> m_rejected_invest_ID_list;
1129 vector<IDElement *> m_possible_invest_ID_list;
1130*/
1131 vector<string>::iterator str_itr;
1132 IDElement * ID_pt;
1133
1134 //vector<IDElement *> m_upperstream_ID_list;
1135 for(str_itr = this->m_ID_upperstream_list.begin(); str_itr != this->m_ID_upperstream_list.end(); str_itr++)
1136 {
1137 ID_pt = (IDElement *)(RM_pt->FindInvestigatorByID(*str_itr));
1138 if(ID_pt == NULL)
1139 {this->ErrorMessage("could not find the investigator " + *str_itr); return;}
1140 this->m_upperstream_ID_list.push_back(ID_pt);
1141 }
1142 //vector<IDElement *> m_explanation_ID_list;
1143 for(str_itr = this->m_ID_explanation_list.begin(); str_itr != this->m_ID_explanation_list.end(); str_itr++)
1144 {
1145 ID_pt = (IDElement *)(RM_pt->FindInvestigatorByID(*str_itr));
1146 if(ID_pt == NULL)
1147 {this->ErrorMessage("could not find the investigator " + *str_itr); return;}
1148 this->m_explanation_ID_list.push_back(ID_pt);
1149 }
1150 //vector<IDElement *> m_confirmed_invest_ID_list;
1151 for(str_itr = this->m_ID_confirmed_invest_list.begin(); str_itr != this->m_ID_confirmed_invest_list.end(); str_itr++)
1152 {
1153 ID_pt = (IDElement *)(RM_pt->FindInvestigatorByID(*str_itr));
1154 if(ID_pt == NULL)
1155 {this->ErrorMessage("could not find the investigator " + *str_itr); return;}
1156 this->m_confirmed_invest_ID_list.push_back(ID_pt);
1157 }
1158 //vector<IDElement *> m_rejected_invest_ID_list;
1159 for(str_itr = this->m_ID_rejected_invest_list.begin(); str_itr != this->m_ID_rejected_invest_list.end(); str_itr++)
1160 {
1161 ID_pt = (IDElement *)(RM_pt->FindInvestigatorByID(*str_itr));
1162 if(ID_pt == NULL)
1163 {this->ErrorMessage("could not find the investigator " + *str_itr); return;}
1164 this->m_rejected_invest_ID_list.push_back(ID_pt);
1165 }
1166 //vector<IDElement *> m_possible_invest_ID_list;
1167 for(str_itr = this->m_ID_possible_invest_list.begin(); str_itr != this->m_ID_possible_invest_list.end(); str_itr++)
1168 {
1169 ID_pt = (IDElement *)(RM_pt->FindInvestigatorByID(*str_itr));
1170 if(ID_pt == NULL)
1171 {this->ErrorMessage("could not find the investigator " + *str_itr); return;}
1172 this->m_possible_invest_ID_list.push_back(ID_pt);
1173 }
1174}
1175
1177{
1178 bool found = false;
1179 vector<string>::iterator str_itr;
1180 vector<IDElement *>::iterator ID_itr;
1181 Investigator * invest_pt;
1182
1183 if(this->m_ID.compare(_line_ID) == 0)
1184 {return;} //there is a loop
1185
1186 for(str_itr = this->m_thoughtline_roots_list.begin(); str_itr != this->m_thoughtline_roots_list.end(); str_itr++)
1187 {
1188 if(_line_ID.compare(*str_itr) == 0)
1189 {found = true;}
1190 }
1191
1192 if(found == true)
1193 {return;}
1194
1195 this->m_thoughtline_roots_list.push_back(_line_ID);
1196
1197 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr++)
1198 {
1199 invest_pt = (Investigator *)(*ID_itr);
1200 invest_pt->AttachThoughtLineToThisInvestigator(_line_ID);
1201 }
1202
1203 if(this->m_condition_ID_pt != NULL)
1204 {
1205 invest_pt = (Investigator*)(this->m_condition_ID_pt);
1206 invest_pt->AttachThoughtLineToThisInvestigator(_line_ID);
1207 }
1208 return;
1209}
1210
1212{
1213 bool within = false;
1214
1215 vector<string>::iterator str_itr;
1216 for(str_itr = this->m_thoughtline_roots_list.begin(); str_itr != this->m_thoughtline_roots_list.end(); str_itr++)
1217 {
1218 if(_line_ID.compare(*str_itr) == 0)
1219 {within = true;}
1220 }
1221 return within;
1222}
1223
1225{
1226 Investigator * invest_pt;
1227 invest_pt = (Investigator*)(this->m_downstream_ID_pt);
1229}
1230
1232{
1233 this->m_dummy_activation = make_unique<Activation>();
1234 this->m_dummy_activation->m_activation = 1;
1235}
1236
1238{
1239 Investigator * invest_pt;
1240 Investigator * next_invest_pt = NULL;
1241 vector<IDElement *>::iterator ID_itr;
1242 KnowledgeElement * KE_pt;
1243 bool want_to_exam_condition_now = false;
1244 float highest_score = 0;
1245 float score;
1246 string prompt, err_mes, str;
1247 stringstream conv;
1248
1249 ReasonMachine * RM_pt;
1250 if (this->m_operator == sim::Operator::ODM)
1251 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
1252 else if (this->m_operator == sim::Operator::OAT)
1253 {RM_pt = g_sim.Action_Taker.m_RM.get();}
1254 else
1255 {}//add error message
1256
1257 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr ++)
1258 {
1259 invest_pt = (Investigator*)(*ID_itr);
1260 if(invest_pt->m_Happen == 1)
1261 {
1262 KE_pt = (KnowledgeElement*)(invest_pt->m_KElement_ID_pt);
1263 if(KE_pt == NULL)
1264 {
1265 this->ErrorMessage("Error!");
1266 }
1267 score = KE_pt->m_SentenceUnit_pt->m_activation * (1 + invest_pt->m_interest_from_SymptomInvestigator *2);
1268 if(next_invest_pt == NULL)
1269 {
1270 next_invest_pt = invest_pt;
1271 highest_score = score;
1272 }
1273 else if(score > highest_score)
1274 {
1275 next_invest_pt = invest_pt;
1276 highest_score = score;
1277 }
1278 }
1279 }
1280
1281 if(this->m_condition_ID_pt != NULL)
1282 {
1283 invest_pt = (Investigator*)(this->m_condition_ID_pt);
1284 if(invest_pt->m_Happen == 1)
1285 {
1286 KE_pt = (KnowledgeElement*)(invest_pt->m_KElement_ID_pt);
1287 score = KE_pt->m_SentenceUnit_pt->m_activation * (1 + invest_pt->m_interest_from_SymptomInvestigator *2);
1288 if(score > highest_score)
1289 {
1290 next_invest_pt = invest_pt;
1291 highest_score = KE_pt->m_SentenceUnit_pt->m_activation;
1292 }
1293 }
1294 }
1295
1296 if(next_invest_pt != NULL)
1297 {
1298 next_invest_pt->CrankTheActivationToOne();
1299 }
1300}
1301
1303{
1304 Investigator * invest_pt;
1305 if(this->m_invest_link_pause == false)
1306 {
1308
1309 }
1310 else
1311 {
1312 invest_pt = (Investigator *)(this->m_has_moved_to_invest);
1313 if(invest_pt != NULL)
1315 }
1316}
1317
1319{
1320 Investigator * invest_pt;
1321 if(this->m_invest_link_pause == false)
1322 {
1324 this->m_forgotten_bl = false;
1325 }
1326 else
1327 {
1328 invest_pt = (Investigator *)(this->m_has_moved_to_invest);
1329 if(invest_pt != NULL)
1330 {invest_pt->BoostAttentionofThisByDiagnosisInvestigation(_i, _vagabond_reset);}
1331 }
1332}
1333
1335{
1336 Investigator * invest_pt;
1337 Investigator * next_invest_pt = NULL;
1338 vector<IDElement *>::iterator ID_itr;
1339 KnowledgeElement * KE_pt;
1340 bool want_to_exam_condition_now = false;
1341 float highest_score = 0;
1342 float score;
1343 string prompt, err_mes, str;
1344 stringstream conv;
1345
1346 ReasonMachine * RM_pt;
1347 if (this->m_operator == sim::Operator::ODM)
1348 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
1349 else if (this->m_operator == sim::Operator::OAT)
1350 {RM_pt = g_sim.Action_Taker.m_RM.get();}
1351 else
1352 {}//add error message
1353
1354 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr ++)
1355 {
1356 invest_pt = (Investigator*)(*ID_itr);
1357 if(invest_pt->m_Happen == 1)
1358 {
1359 KE_pt = (KnowledgeElement*)(invest_pt->m_KElement_ID_pt);
1360 if(KE_pt == NULL)
1361 {
1362 this->ErrorMessage("Error!");
1363 }
1364 score = KE_pt->m_SentenceUnit_pt->m_activation * (1 + invest_pt->m_interest_from_SymptomInvestigator *2);
1365 if(next_invest_pt == NULL)
1366 {
1367 next_invest_pt = invest_pt;
1368 highest_score = score;
1369 }
1370 else if(score > highest_score)
1371 {
1372 next_invest_pt = invest_pt;
1373 highest_score = score;
1374 }
1375 }
1376 }
1377
1378 if(this->m_condition_ID_pt != NULL)
1379 {
1380 invest_pt = (Investigator*)(this->m_condition_ID_pt);
1381 if(invest_pt->m_Happen == 1)
1382 {
1383 KE_pt = (KnowledgeElement*)(invest_pt->m_KElement_ID_pt);
1384 score = KE_pt->m_SentenceUnit_pt->m_activation * (1 + invest_pt->m_interest_from_SymptomInvestigator *2);
1385 if(score > highest_score)
1386 {
1387 next_invest_pt = invest_pt;
1388 highest_score = KE_pt->m_SentenceUnit_pt->m_activation;
1389 }
1390 }
1391 }
1392
1393 if(next_invest_pt != NULL)
1394 {
1395 next_invest_pt->m_last_active_time = r5pars_.timesno;
1396 }
1397}
1398
1400{
1401 Investigator * invest_pt;
1402 vector<IDElement *>::iterator ID_itr;
1403 bool mark_change = false;
1404
1405 if(this->m_Happen_incomplete == true)
1406 {return;}
1407
1408 if(this->m_condition_ID_pt != NULL)
1409 {
1410 invest_pt = (Investigator *)(this->m_condition_ID_pt);
1411 if(invest_pt->m_Happen_incomplete == true)
1412 {mark_change = true;}
1413 }
1414
1415 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr++)
1416 {
1417 invest_pt = (Investigator *)(*ID_itr);
1418 if(invest_pt->m_Happen_incomplete == true)
1419 {mark_change = true;}
1420 }
1421
1422 if(mark_change == true)
1423 {
1425 }
1426
1427}
1428
1430{
1431 Investigator * invest_pt;
1432 this->m_Happen_incomplete = true;
1433
1434 invest_pt = (Investigator*)(this->m_downstream_ID_pt);
1435 invest_pt->UpdateHappenExplainIncomeplete();
1436}
1437
1439{
1440 float confidence, _p;
1441 vector<IDElement *>::iterator ID_itr;
1442 Investigator * invest_pt;
1443 Investigator * buffer_invest_pt;
1444 int number_of_strong_reference = 0;
1445 bool unexplored_cause = false;
1446
1447 vector<string>::iterator str_itr;
1448 vector<float>::iterator fl_itr;
1449
1450 ReasonMachine * RM_pt;
1451 if (this->m_operator == sim::Operator::ODM)
1452 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
1453 else if (this->m_operator == sim::Operator::OAT)
1454 {RM_pt = g_sim.Action_Taker.m_RM.get();}
1455 else
1456 {}//add error message
1457
1458 if(this->m_pause_confidence_propagation_ID_list.size() == 0)
1459 {return;}
1460
1461 if(this->m_pause_confidence_propagation_ID_list.size() != this->m_paused_confidence_passing_list.size())
1462 {
1463 this->ErrorMessage("this->m_pause_confidence_propagation_ID_list.size() != this->m_paused_confidence_passing_list.size()");
1464 }
1465
1466 for(ID_itr = this->m_confirmed_invest_ID_list.begin(); ID_itr != this->m_confirmed_invest_ID_list.end(); ID_itr++)
1467 {
1468 invest_pt = (Investigator*)(*ID_itr);
1469 if(invest_pt->m_Happen == 3 && invest_pt->m_Statement_pt->m_factual_type == 3)
1470 {number_of_strong_reference++;}
1471 }
1472
1473 while(this->m_paused_confidence_passing_list.size() > 0)
1474 {
1475 str_itr = this->m_pause_confidence_propagation_ID_list.begin();
1476 fl_itr = this->m_paused_confidence_passing_list.begin();
1477
1478 _p = *fl_itr;
1479 buffer_invest_pt = RM_pt->FindInvestigatorByID(*str_itr);
1480 if(buffer_invest_pt == NULL)
1481 {this->ErrorMessage("buffer_invest_pt == NULL");}
1482
1483 if(this->m_link_type == 1) //only connect to one upperstream investigator
1484 {
1485 confidence = _p;
1486 }
1487 else if(this->m_link_type == 3) //Or gate
1488 {
1489 confidence = _p/(this->m_possible_invest_ID_list.size()) + number_of_strong_reference;
1490 }
1491 else if(this->m_link_type == 2) //And gate
1492 {
1493 confidence = _p;
1494 if(this->m_rejected_invest_ID_list.size() != 0)
1495 {
1496 this->ErrorMessage("Error!");
1497 return;
1498 }
1499 }
1500
1501 for(ID_itr = this->m_possible_invest_ID_list.begin(); ID_itr != this->m_possible_invest_ID_list.end(); ID_itr++)
1502 {
1503 RM_pt->m_buffer_invest_pt = buffer_invest_pt;
1504 invest_pt = (Investigator*)(*ID_itr);
1505 if((*ID_itr) == this->m_condition_ID_pt)
1506 {
1507 invest_pt->BackwardPropagateConfidenceLevel(_p);
1508 }
1509 else
1510 {
1511 invest_pt->BackwardPropagateConfidenceLevel(confidence);
1512 }
1513 RM_pt->m_buffer_invest_pt = NULL;
1514 }
1515
1516 for(ID_itr = this->m_confirmed_invest_ID_list.begin(); ID_itr != this->m_confirmed_invest_ID_list.end(); ID_itr++)
1517 {
1518 RM_pt->m_buffer_invest_pt = buffer_invest_pt;
1519 invest_pt = (Investigator*)(*ID_itr);
1520 if(invest_pt->m_Happen == 3 && invest_pt->m_Statement_pt->m_factual_type == 3)
1521 {invest_pt->BackwardPropagateConfidenceLevel(confidence);}
1522 RM_pt->m_buffer_invest_pt = NULL;
1523 }
1524
1525 this->m_pause_confidence_propagation_ID_list.erase(str_itr);
1526 this->m_paused_confidence_passing_list.erase(fl_itr);
1527 }
1528}
1529
1531{
1532 double highest_activation = 0;
1533 double activation;
1534 vector<IDElement*>::iterator ID_itr;
1535 Investigator * invest_pt;
1536
1537 //check point
1538 if(this->m_upperstream_ID_list.size() == 0)
1539 {
1540 this->ErrorMessage("Error!");
1541 }
1542
1543
1544 if(this->m_condition_ID_pt != NULL)
1545 {
1546 invest_pt = (Investigator *)(this->m_condition_ID_pt);
1547 highest_activation = invest_pt->GetActivation();
1548 }
1549
1550 for(ID_itr = this->m_upperstream_ID_list.begin(); ID_itr != this->m_upperstream_ID_list.end(); ID_itr ++)
1551 {
1552 invest_pt = (Investigator *)(*ID_itr);
1553 activation = invest_pt->GetActivation();
1554 if(activation > highest_activation)
1555 {
1556 highest_activation = activation;
1557 }
1558 }
1559
1560 return highest_activation;
1561}
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
double m_activation
Definition: Activation.h:22
void CopyIDElementToRestartInfo(IDElement *)
Definition: IDElement.cpp:23
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
void UpdateHappenExplainIncomeplete()
float m_last_active_time
Definition: Investigator.h:87
void AttachThoughtLineToThisInvestigator(std::string)
void BackwardPropagateConfidenceLevel(float _p)
bool m_invest_dormant
Definition: Investigator.h:94
void BoostAttentionofThisByDiagnosisInvestigation(float, bool)
std::string GetASimpleDescriptionOfThisInvestigator()
bool m_Happen_incomplete
Definition: Investigator.h:81
IDElement * m_KElement_ID_pt
Definition: Investigator.h:129
void CrankTheActivationToOne()
int m_investigator_token
Definition: Investigator.h:99
float m_interest_from_SymptomInvestigator
Definition: Investigator.h:122
IDElement * m_SI_ID_pt
Definition: Investigator.h:128
void BoostActivationOfThisByActiveDiagnosisInvestigation()
float CalculatePriorityScoreEvenDormantOrPaused()
float GetInitiationTimeOrStatementTimeOrLastActiveTime()
Statement * m_Statement_pt
Definition: Investigator.h:130
double GetActivation()
SentenceUnit * m_SentenceUnit_pt
double m_backward_retrieve_weight
Definition: KnowledgeUnit.h:30
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
KnowledgeUnit * FindKnowledgeUnitByID(std::string)
void EraseFromOngoingItemStack(std::string)
Investigator * m_working_on_invest_pt
void AddToRMFeedbackStack(IDElement *)
void ZeroAllTheInterestFromSymptomInvestigator()
void EraseItemFromFeedbackStack(IDElement *)
ProblemSolvingStyle m_problem_solving_style
void AddConsumptedDeltaT(double)
Investigator * FindInvestigatorByID(std::string)
std::vector< IDElement * > m_investigation_trace
std::unique_ptr< EventSchemaBase > m_event_schema_base
void ChangeRMTokenValue(int)
Investigator * m_buffer_invest_pt
int m_factual_type
Definition: Statement.h:33
struct @0 r5pars_
constexpr int GetCorrespondingKE
Definition: RMTokens.h:23
constexpr int WorkOnInvestigator
Definition: RMTokens.h:17
constexpr int Prioritize
Definition: RMTokens.h:16
constexpr int ODM
Definition: SimConstants.h:145
constexpr int OAT
Definition: SimConstants.h:144
OperatorAT Action_Taker
Crew action execution model.
OperatorDM Decision_Maker
Crew decision-making model.