← Documentation
ADS-IDAC Engine 5.0.0
EventSchemaBase.cpp
Go to the documentation of this file.
1// EventSchemaBase.cpp: implementation of the EventSchemaBase class.
2//
4
5#include <string>
6#include <sstream>
7#include <iostream>
8#include <fstream>
9
10#include "EventSchemaBase.h"
11#include "InstantiationBase.h"
12#include "RMTokens.h"
13#include "../Crew/OperatorDM.h"
14#include "../Crew/OperatorAT.h"
15#include "ReasonMachine.h"
16#include "KnowledgeUnit.h"
17#include "Label.h"
18#include "../Procedure/Procedures.h"
19#include "../Branch/BranchProbability.h"
20#include "../Global/SimulationContext.h"
21using namespace std;
22
23
25// Construction/Destruction
27
29{
30 this->m_ID_Type = 500;
31 this->m_timing = 0;
32 this->m_timed_DI = NULL;
33 this->m_diagnose_claim_threshold = 0.85;
35 this->m_ID_timed_DI = "";
36}
37
39{
40 this->m_event_schema_list.clear();
41 this->m_diagnose_invest_list.clear();
42
44 this->m_ID_interested_invest_list.clear();
46 this->m_interested_invest_list.clear();
47 this->m_debug_info.clear();
48}
49
51{
52 ReasonMachine * RM_pt;
53 if (this->m_operator == sim::Operator::ODM)
54 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
55 else if (this->m_operator == sim::Operator::OAT)
56 {RM_pt = g_sim.Action_Taker.m_RM.get();}
57 else
58 {}//add error message
59
60 string dir_path, str, str_ID, err_mes;
61 ifstream fin;
62 int n_event, n_symptom, n_KU, i, j, k;
63 EventSchemaUnit * schema_pt;
64 EventSymptomUnit * symptom_pt;
65 KnowledgeUnit * KU_pt;
66 map<string, ProcedureStep *>::iterator procedure_map_itr;
67
68
69 //initialize some variables
72
73 //get the file directory
74 if (this->m_operator == sim::Operator::ODM)
75 {
76 dir_path = g_sim.SScheduler.getODMDirectory();
77 }
78 else if(this->m_operator == sim::Operator::OAT)
79 {
80 dir_path = g_sim.SScheduler.getOATDirectory();
81 }
82 dir_path += "RM//";
83 dir_path += "KB_ODM_Event_Schema_Base.txt";
84
85 fin.open(dir_path.c_str(), ios::in);
86 if(!fin.is_open()){
87 err_mes = "can not find file: " + dir_path;
88 this->ErrorMessage(err_mes);
89 return; //has to return and close this program if there is an error
90 }
91 else
92 {
93 fin >> str >> n_event;
94 if(str.compare("No_of_Event_Schemas:") != 0)
95 {
96 err_mes = str + " is incorrectly in the position of Number_of_Instantiation_Label_Groups:";
97 this->ErrorMessage(err_mes);
98 return;
99 }
100
101 fin >> str >> this->m_diagnose_claim_threshold;
102 if(str.compare("Diagnose_Claim_Threshold:") != 0)
103 {
104 err_mes = str + " is incorrectly in the position of Diagnose_Claim_Threshold:";
105 this->ErrorMessage(err_mes);
106 return;
107 }
108
109 string ID_name;
110 stringstream conv;
111
112 for(i=0; i < n_event; i++)
113 {
114 auto schema_owned = std::make_unique<EventSchemaUnit>();
115 schema_pt = schema_owned.get();
116 this->m_event_schema_list.push_back(std::move(schema_owned));
117
118 conv.str(""); // clean the conv
119 conv << this->m_event_schema_list.size();
120 ID_name = "Event_Schema_" + conv.str();
121 schema_pt->m_ID = ID_name;
122
124
125 fin >> str >> str_ID;
126 if(str.compare("Event_KE_ID:") != 0)
127 {
128 err_mes = str + " is incorrectly in the position of Event_KE_ID:";
129 this->ErrorMessage(err_mes);
130 return;
131 }
132 schema_pt->m_event_KE_pt = RM_pt->FindKnowledgeElementByID(str_ID);
133 if(schema_pt->m_event_KE_pt == NULL)
134 {
135 this->ErrorMessage("Could not find the KE" + str_ID +" for a schema");
136 return;
137 }
138
139 fin >> str >> n_symptom;
140 if(str.compare("No_of_Symptoms:") != 0)
141 {
142 err_mes = str + " is incorrectly in the position of No_of_Symptoms:";
143 this->ErrorMessage(err_mes);
144 return;
145 }
146
147 for(j = 0; j < n_symptom; j++)
148 {
149 auto symptom_owned = std::make_unique<EventSymptomUnit>();
150 symptom_pt = symptom_owned.get();
151 schema_pt->m_symptom_list.push_back(std::move(symptom_owned));
152 ID_name = schema_pt->m_ID + "_symptom_" ;
153 conv.str("");
154 conv << schema_pt->m_symptom_list.size();
155 ID_name += conv.str();
156 symptom_pt->m_ID = ID_name;
157
158 fin >> str >> str_ID;
159 if(str.compare("Symptom_KE_ID:") != 0)
160 {
161 err_mes = str + " is incorrectly in the position of Symptom_KE_ID:";
162 this->ErrorMessage(err_mes);
163 return;
164 }
165 symptom_pt->m_symptom_KE_pt = RM_pt->FindKnowledgeElementByID(str_ID);
166 if(symptom_pt->m_symptom_KE_pt == NULL)
167 {
168 this->ErrorMessage("Could not find the KE" + str_ID +" for a symptom");
169 return;
170 }
171
172 fin >> str >> n_KU;
173 if(str.compare("No_of_causal_chains:") != 0)
174 {
175 err_mes = str + " is incorrectly in the position of No_of_causal_chains:";
176 this->ErrorMessage(err_mes);
177 return;
178 }
179
180 for(k = 0; k < n_KU; k++)
181 {
182
183 KU_pt = NULL;
184 fin >> str >> str_ID;
185 if(str.compare("KU_ID:") != 0)
186 {
187 err_mes = str + " is incorrectly in the position of KU_ID:";
188 this->ErrorMessage(err_mes);
189 return;
190 }
191 KU_pt = RM_pt->FindKnowledgeUnitByID(str_ID);
192 if(KU_pt == NULL)
193 {
194 this->ErrorMessage("Could not find the KU" + str_ID +" for a symptom");
195 return;
196 }
197 symptom_pt->m_KU_list.push_back(KU_pt);
198 }
199
200 }
201
202 fin >> str >> schema_pt->m_procedure_name;
203 if(str.compare("Response_Procedure_Name:") != 0)
204 {
205 err_mes = str + " is incorrectly in the position of Response_Procedure_Name:";
206 this->ErrorMessage(err_mes);
207 return;
208 }
209
210 fin >> str >> schema_pt->m_procedure_step_name;
211 if(str.compare("Response_Procedure_Step:") != 0)
212 {
213 err_mes = str + " is incorrectly in the position of Response_Procedure_Step:";
214 this->ErrorMessage(err_mes);
215 return;
216 }
217 if(schema_pt->m_procedure_step_name.compare("NONE") == 0 || schema_pt->m_procedure_step_name.compare("NONE") == 0)
218 {
219 schema_pt->m_procedure_step_pt = NULL;
220 }
221 else
222 {
223 procedure_map_itr = g_sim.All_procedure.procedure_map.find(schema_pt->m_procedure_name + schema_pt->m_procedure_step_name);
224 if(procedure_map_itr != g_sim.All_procedure.procedure_map.end())
225 {
226 schema_pt->m_procedure_step_pt = procedure_map_itr->second;
227 }
228 else
229 {
230 this->ErrorMessage("Could not find this procedure step: " + schema_pt->m_procedure_name + schema_pt->m_procedure_step_name);
231 return;
232 }
233 }
234 }
235
236 }
237}
238
240{
241 cout << r5pars_.timesno << " " << str << " in EventSchemaBase.cpp" << '\n';
242 ofstream fout("err messages.txt", ios::app);
243 fout << r5pars_.timesno << " " << str << '\n';
244 fout.close();
245}
246
248{
249 stringstream conv;
250 string str_ID;
251 string str;
252
253 this->m_diagnose_invest_list.push_back(std::unique_ptr<DiagnoseInvestigator>(_diagnose_invest_pt));
254 str_ID = "Diagnose_Investigator_";
255 conv.str("");
256 conv << this->m_diagnose_invest_list.size();
257 str_ID += conv.str();
258 _diagnose_invest_pt->m_ID = str_ID;
259 _diagnose_invest_pt->m_operator = this->m_operator;
260 _diagnose_invest_pt->m_ES_base_ID_pt = (IDElement *)this;
261
262 conv.str("");
263 conv << r5pars_.timesno;
264 str = conv.str() + ", a DiagnoseInvestigator is added: " + _diagnose_invest_pt->m_event_statement_pt->m_ID;
265
266}
267
269{
270 DiagnoseInvestigator * found_DI_pt = NULL;
271
272 for(auto &e : this->m_diagnose_invest_list)
273 {
274 if(e->m_event_KE_pt == _KE_pt)
275 {
276 found_DI_pt = e.get();
277 }
278 }
279 return found_DI_pt;
280}
281
283{
284 EventSchemaUnit * found_ES_pt = NULL;
285 Label *label_group_pt;
286
287 ReasonMachine * RM_pt;
288 if (this->m_operator == sim::Operator::ODM)
289 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
290 else if (this->m_operator == sim::Operator::OAT)
291 {RM_pt = g_sim.Action_Taker.m_RM.get();}
292 else
293 {}//add error message
294
295 for(auto &e : this->m_event_schema_list)
296 {
297 if(found_ES_pt != NULL) break;
298 //caution here: the input _KE_pt should be instantiated. It can not have any indefinite concept.
299 if(e->m_event_KE_pt->m_negation != _KE_pt->m_negation)
300 {continue;}
301
302 label_group_pt = RM_pt->m_IB->CheckWhetherASentenceContainIndefiniteItem(e->m_event_KE_pt->m_SentenceUnit_pt);
303 if(label_group_pt != NULL)
304 {
305 if(RM_pt->FindAnIndefiniteSentenceMatchTheInputSentence(_KE_pt->m_SentenceUnit_pt) == e->m_event_KE_pt->m_SentenceUnit_pt)
306 {
307 found_ES_pt = e.get();
308 }
309 }
310 else
311 {
312 if(e->m_event_KE_pt == _KE_pt)
313 {
314 found_ES_pt = e.get();
315 }
316 }
317 }
318 return found_ES_pt;
319}
320
322{
323 bool new_SI_case_bl;
324 SymptomCase * case_pt;
325
326 for(auto &DI_e : this->m_diagnose_invest_list)
327 {
328 for(auto &SI_e : DI_e->m_symptom_invest_list)
329 {
330 new_SI_case_bl = false;
331
332 if(_invest_pt->m_motivation == 0)
333 {
334 if(_invest_pt->m_KElement_ID_pt == (IDElement*)SI_e->m_symptom_KE_pt)
335 {
336 new_SI_case_bl = true;
337 }
338 }
339 else if(_invest_pt->m_motivation == 1)
340 {
341 if(_invest_pt->m_Statement_pt->m_sent_pt == SI_e->m_symptom_KE_pt->m_SentenceUnit_pt
342 && _invest_pt->m_Statement_pt->m_state == !SI_e->m_symptom_KE_pt->m_negation)
343 {
344 new_SI_case_bl = true;
345 }
346 }
347 else
348 {this->ErrorMessage("error!");}
349
350 //add a new SymptomCase if required
351 if(new_SI_case_bl == true)
352 {
353 auto case_owned = std::make_unique<SymptomCase>();
354 case_owned->m_invest_pt = _invest_pt;
355 case_owned->m_finished_bl = false;
356 SI_e->m_candidate_case_list.push_back(std::move(case_owned));
357 }
358 }
359 }
360
361}
362
364{
365 for(auto &e : this->m_diagnose_invest_list)
366 {
367 e->DITrackTheOngoingInvestigation();
368 }
369}
370
372{
374
375}
376
378{
379 Investigator * invest_pt;
380 //vector<SymptomInvestigator *>::iterator SI_itr;
381 float highest_score = 0;
382 float score;
383 bool ongoing_bl = false;
384 bool generated_bl = false;
385 SymptomInvestigator * ongoing_SI_pt = NULL;
386 SymptomCase * case_pt = NULL;
387 string str;
388 stringstream conv;
389
390 ReasonMachine * RM_pt;
391 if (this->m_operator == sim::Operator::ODM)
392 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
393 else if (this->m_operator == sim::Operator::OAT)
394 {RM_pt = g_sim.Action_Taker.m_RM.get();}
395 else
396 {}//add error message
397
398 if(r5pars_.timesno > 2002)
399 {this->PrintMessage("");}
400
401 //check point
402// if(r5pars_.timesno > 900)
403// {
404// this->ErrorMessage("Check point!");
405// }
406 //
407// ----ongoing----pick a SI--(time delay)--generate investigator--
408
409 bool create_bl;
410
411 if(this->m_timed_DI != NULL)
412 {
413 create_bl = true;
414 if(this->m_timed_DI->m_tbi_SI->m_candidate_case_list.size() > 0)
415 {
416 for(auto &case_e : this->m_timed_DI->m_tbi_SI->m_candidate_case_list)
417 {
418 if(this->m_timed_DI->m_tbi_SI->m_need_to_invest_opposite_bl == false && case_e->m_invest_pt->m_KElement_ID_pt == (IDElement *)(this->m_timed_DI->m_tbi_SI->m_symptom_KE_pt))
419 {create_bl = false;}
420 }
421 }
422 if(this->m_timing < r5pars_.timesno && create_bl == true)
423 {
424 //create a new investigator
425 invest_pt = new Investigator();
426 invest_pt->m_note = "by event schema";
427 invest_pt->m_motivation = 0;
428 invest_pt->m_effective_start = r5pars_.timesno - 10;
429 invest_pt->m_effective_end = r5pars_.timesno + 100;
430
431 if(this->m_timed_DI->m_tbi_SI->m_need_to_invest_opposite_bl == true && this->m_timed_DI->m_tbi_SI->m_opposite_KE_pt != NULL && this->m_timed_DI->m_tbi_SI->m_can_not_explain_opposite_bl == false)
432 {
435 invest_pt->m_Happen = 3;
436 /*
437 case_pt = new SymptomCase();
438 case_pt->m_invest_pt = invest_pt;
439 case_pt->m_invest_opposite_bl = true;
440 this->m_timed_DI->m_tbi_SI->m_candidate_case_list.push_back(case_pt);
441 */
442 }
443 else
444 {
447 invest_pt->m_Happen = 1;
448 }
449 invest_pt->m_invest_dormant = false;
451 invest_pt->m_operator = this->m_operator;
453 {invest_pt->m_SI_ID_pt = (IDElement *)this->m_timed_DI->m_tbi_SI;}
454 invest_pt->m_root_of_a_thought_line = true;
455 invest_pt->m_active_investigation = true;
456 RM_pt->AddNewInvestigator(invest_pt);
457 //activate the relevant sentence
458 invest_pt->CrankTheActivationToOne();
459 generated_bl = true;
460
461 //create a new SymptomCase for this
462 //case_pt = new SymptomCase();
463 //case_pt->m_invest_pt = invest_pt;
464 //case_pt->m_finished_bl = false;
465 //this->m_timed_DI->m_tbi_SI->m_candidate_case_list.push_back(case_pt);
466 //
467 cout << this->m_timed_DI->m_tbi_SI->m_candidate_case_list.size();
468 // conv.str("");
469 conv << r5pars_.timesno;
470 str = "Created " + invest_pt->m_ID + " for " + this->m_timed_DI->m_tbi_SI->m_symptom_KE_pt->m_ID + " at time: ";
471 str += conv.str();
472 this->m_debug_info.push_back(str);
473 if(invest_pt->m_ID == "Investigator_308")
474 {this->PrintMessage("");}
475 //clear the m_timed_DI
476 this->m_timed_DI->m_tbi_SI = NULL;
477 this->m_timed_DI = NULL;
478 this->m_timing = 0;
479 return generated_bl;
480 }
481
482 if(create_bl == false)
483 {
484 this->m_timed_DI->m_tbi_SI = NULL;
485 this->m_timed_DI = NULL;
486 this->m_timing = 0;
487 }
488 else
489 {return generated_bl;}
490 }
491
492 //search and initiate for generating the next one to be investigated
493 highest_score = 0;
494 for(auto &DI_e : this->m_diagnose_invest_list)
495 {
496 if(ongoing_bl) break;
497 DI_e->SearchForTheToBeInvestigatedSI();
498 if(DI_e->m_ongoing_SI != NULL)
499 {
500 if(DI_e->m_ongoing_SI->m_confirmed_case_list.size() == 0 || DI_e->m_ongoing_SI->m_independent_symptom_probability < 0.02)
501 {
502 ongoing_bl = true;
503 ongoing_SI_pt = DI_e->m_ongoing_SI;
504 break;
505 }
506 }
507 else if(DI_e->m_tbi_SI != NULL)
508 {
509 score = DI_e->m_confidence;
510 //if(DI_e->m_tbi_SI->m_rejected_case_list.size() > 0 || DI_e->m_tbi_SI->m_confirmed_case_list.size() > 0)
511 //{score *= 0.5;}
512 //score *= 1 - exp(-0.01 * (r5pars_.timesno - DI_e->m_tbi_SI->m_last_case_end_time));
513 if(r5pars_.timesno >2046)
514 {this->PrintMessage("");}
515 //score *= 1 - exp(-0.01 * (r5pars_.timesno - DI_e->m_tbi_SI->m_last_case_end_time));
516 if(score > highest_score && DI_e->m_confidence > this->m_active_investigation_threshold && DI_e->m_confidence < 0.92)
517 {
518 highest_score = score;
519 this->m_timed_DI = DI_e.get();
520 //caution: adjust the sclae of m_timing to model active investigation and passive investigation
521 //this->m_timing = r5pars_.timesno + max(min(200, 80/pow(score,2)), 5);
522 //this->m_timing = r5pars_.timesno + 2*(260 * pow(DI_e->m_confidence,2) - 530 * DI_e->m_confidence + 300);
523 this->m_timing = r5pars_.timesno + 672.96 * exp(-2.5*DI_e->m_confidence) * 1.5;
524 }
525 }
526 }
527
528
529 if(ongoing_bl == true)
530 {
531 this->m_timed_DI = NULL;
532 this->m_timing = 0;
533 invest_pt = (* ongoing_SI_pt->m_candidate_case_list.begin())->m_invest_pt;
534
535 //
536 if(invest_pt->m_ID == "Investigator_229")
537 {this->PrintMessage("Check");}
538 //
539 if(invest_pt->m_invest_dormant == true)
540 {invest_pt->m_invest_dormant = false;}
542 conv.str("");
543 conv << r5pars_.timesno;
544 str = conv.str();
545 str += ", working on ";
546 str += invest_pt->m_ID;
547 this->m_debug_info.push_back(str);
548 if(r5pars_.timesno > 1433)
549 {this->PrintMessage("Check point!");}
550 //
551 }
552 else
553 {
554 if(this->m_timed_DI != NULL)
555 {
556 if(r5pars_.timesno > 2590)
557 {this->PrintMessage("");}
558 conv.str("");
559 conv << r5pars_.timesno;
560 str = conv.str();
561 str += ", Plan to investigate ";
562 str += this->m_timed_DI->m_event_KE_pt->m_ID;
563 str += " at ";
564 conv.str("");
565 conv << this->m_timing;
566 str += conv.str();
567 this->m_debug_info.push_back(str);
568 }
569 }
570 return generated_bl;
571}
572
574{
575 vector<float>::iterator confidence_itr, timeline_itr;
576 vector<string>::iterator str_itr;
577 vector<float>::iterator Integrated_prob_itr;
578 vector<float>::iterator coverage_itr;
579 vector<int>::iterator N_setback_itr;
580 vector<int>::iterator N_disabled_itr;
581 vector<int>::iterator N_voided_itr;
582 vector<string>::iterator symp_confidence_itr;
583 string str;
584 //vector<SymptomCase *>::iterator case_itr;
585 DiagnoseInvestigator * DI_pt;
586 SymptomInvestigator * SI_pt;
587 ofstream fout(_path.c_str(), ios::out);
588 for(auto &DI_e : this->m_diagnose_invest_list)
589 {
590 DI_pt = DI_e.get();
591 fout << '\n' << "***Accident Diagnosis:" << DI_pt->m_event_KE_pt->m_ID << '\n';
592 fout << "Diagnose Confidence: " << DI_pt->m_confidence;
593 for(auto &SI_e : DI_pt->m_symptom_invest_list)
594 {
595 SI_pt = SI_e.get();
596 fout << '\n' << "---Symptom: " << SI_pt->m_symptom_KE_pt->m_ID;
597 fout << "; Symptom confidence: " << SI_pt->m_independent_symptom_probability;
598 fout << "; Status: ";
599 if(SI_pt->m_confirmed_case_list.size() > 0)
600 {
601 fout << "Confirmed by: ";
602 auto &last_confirmed = SI_pt->m_confirmed_case_list.back();
603 fout << last_confirmed->m_invest_pt->m_ID << " " << last_confirmed->m_confirmed_time;
604 }
605 else if(SI_pt->m_voided_case_list.size() > 0)
606 {
607 fout << "Voided by: ";
608 auto &last_voided = SI_pt->m_voided_case_list.back();
609 fout << last_voided->m_invest_pt->m_ID;
610 }
611 else if(SI_pt->m_exception_case_list.size() > 0)
612 {
613 fout << "Exception found: ";
614 auto &last_exception = SI_pt->m_exception_case_list.back();
615 fout << last_exception->m_invest_pt->m_ID << " " << last_exception->m_exception_time;
616 }
617 else if(SI_pt->m_rejected_case_list.size() > 0)
618 {
619 fout << "Rejected by: ";
620 auto &last_rejected = SI_pt->m_rejected_case_list.back();
621 fout << last_rejected->m_invest_pt->m_ID << " " << last_rejected->m_rejection_time;
622 }
623 else if(SI_pt->m_candidate_case_list.size() > 0)
624 {
625 fout << "Unfinished: ";
626 }
627 else
628 {
629 fout << "miscellaneous";
630 }
631 fout << " N_confirmation " << SI_pt->m_confirmed_case_list.size();
632 for(auto &ce : SI_pt->m_confirmed_case_list)
633 {
634 fout << ce->m_invest_pt->m_ID << "||";
635 }
636 fout << " N_voided " << SI_pt->m_voided_case_list.size();
637 for(auto &ce : SI_pt->m_voided_case_list)
638 {
639 fout << ce->m_invest_pt->m_ID << "||";
640 }
641
642 fout << " N_exception " << SI_pt->m_exception_case_list.size();
643 for(auto &ce : SI_pt->m_exception_case_list)
644 {
645 fout << ce->m_invest_pt->m_ID << "||";
646 }
647 fout << " N_rejection " << SI_pt->m_rejected_case_list.size();
648 for(auto &ce : SI_pt->m_rejected_case_list)
649 {
650 fout << ce->m_invest_pt->m_ID << "||";
651 }
652 fout << " N_inconsist " << SI_pt->m_inconsistant_case_list.size();
653 for(auto &ce : SI_pt->m_inconsistant_case_list)
654 {
655 fout << ce->m_invest_pt->m_ID << "||";
656 }
657 fout << " N_candidate " << SI_pt->m_candidate_case_list.size();
658 for(auto &ce : SI_pt->m_candidate_case_list)
659 {
660 fout << ce->m_invest_pt->m_ID << "||";
661 }
662
663 }
664 fout << '\n' << "Timeline of the confidence level";
665 /*
666 vector<float>::iterator Integrated_prob_itr;
667 vector<float>::iterator coverage_itr;
668 vector<int>::iterator N_setback_itr;
669 vector<int>::iterator N_disabled_itr;
670 vector<string>::iterator symp_confidence_itr;
671 */
672 confidence_itr = DI_pt->m_confidence_history.begin();
673 timeline_itr = DI_pt->m_confidence_timeline.begin();
674 Integrated_prob_itr = DI_pt->m_Integrated_prob_list.begin();
675 coverage_itr = DI_pt->m_coverage_list.begin();
676 N_setback_itr = DI_pt->m_N_setback_list.begin();
677 N_disabled_itr = DI_pt->m_N_disabled_list.begin();
678 N_voided_itr = DI_pt->m_N_voided_list.begin();
679 symp_confidence_itr = DI_pt->m_symp_confidence_list.begin();
680
681 fout << '\n';
682 fout << "time" << '\t' << '\t'
683 << "confidence" << '\t' << '\t'
684 << "Integrated_confidence" << '\t' << '\t'
685 << "Coverage" << '\t' << '\t'
686 << "N_setback" << '\t' << '\t'
687 << "N_blocked" << '\t' << '\t'
688 << "N_voided" << '\t' << '\t'
689 << "symptom_confidence";
690
691 while(confidence_itr != DI_pt->m_confidence_history.end())
692 {
693 fout << '\n'
694 << *timeline_itr << '\t' << '\t'
695 << *confidence_itr << '\t' << '\t'
696 << *Integrated_prob_itr << '\t' << '\t'
697 << *coverage_itr << '\t' << '\t'
698 << *N_setback_itr << '\t' << '\t'
699 << *N_disabled_itr << '\t' << '\t'
700 << *N_voided_itr << '\t' << '\t'
701 << *symp_confidence_itr << '\t' << '\t';
702
703 confidence_itr++;
704 timeline_itr++;
705 Integrated_prob_itr++;
706 coverage_itr++;
707 N_setback_itr++;
708 N_disabled_itr++;
709 N_voided_itr++;
710 symp_confidence_itr++;
711 }
712 fout << '\n';
713
714 if(DI_pt->m_other_evidence_list.size() > 0)
715 {
716 fout << "Other evidence information: " << '\n';
717 for(auto &tvn_e : DI_pt->m_other_evidence_list)
718 {
719 fout << tvn_e->m_string << '\t'
720 << tvn_e->m_value << '\t'
721 << tvn_e->m_note <<'\t'
722 << tvn_e->m_time << '\n';
723 }
724 }
725 }
726
727 for(str_itr = this->m_debug_info.begin(); str_itr != this->m_debug_info.end(); str_itr++)
728 {
729 str = *str_itr;
730 fout << '\n';
731 //fout << *str_itr << '\n';
732 fout << str ;
733
734 }
735
736 fout.close();
737}
738
739
741{
742 DiagnoseInvestigator * DI_pt;
743 SymptomInvestigator * SI_pt;
744 bool match_bl = false;
745 bool exist_bl = false;
746 bool opposite_bl;
747 SymptomCase * case_pt;
748
749 for(auto &DI_e : this->m_diagnose_invest_list)
750 {
751 DI_pt = DI_e.get();
752 for(auto &SI_e : DI_pt->m_symptom_invest_list)
753 {
754 match_bl = false;
755 exist_bl = false;
756 SI_pt = SI_e.get();
757 match_bl = false;
758 opposite_bl = false;
759 if(_invest_pt->m_KElement_ID_pt != NULL)
760 {
761 if((IDElement *)SI_pt->m_symptom_KE_pt == _invest_pt->m_KElement_ID_pt)
762 {
763 match_bl = true;
764 }
765 else if((IDElement *)SI_pt->m_opposite_KE_pt == _invest_pt->m_KElement_ID_pt )
766 {
767 match_bl = true;
768 opposite_bl = true;
769 }
770 }
771 else if(_invest_pt->m_Statement_pt != NULL)
772 {
774 {
775 if(_invest_pt->m_Statement_pt->m_state == !SI_pt->m_symptom_KE_pt->m_negation)
776 {
777 match_bl = true;
778 }
779 }
780 else if(SI_pt->m_opposite_KE_pt != NULL)
781 {
783 && _invest_pt->m_Statement_pt->m_state == !SI_pt->m_opposite_KE_pt->m_negation)
784 {
785 match_bl = true;
786 opposite_bl = true;
787 }
788 }
789 }
790
791 if(match_bl == true)
792 {
793 for(auto &case_e : SI_pt->m_candidate_case_list)
794 {
795 if(case_e->m_invest_pt == _invest_pt)
796 {
797 exist_bl = true;
798 }
799 }
800 if(exist_bl == false)
801 {
802 auto case_owned = std::make_unique<SymptomCase>();
803 case_owned->m_invest_pt = _invest_pt;
804 case_owned->m_finished_bl = false;
805 case_owned->m_invest_opposite_bl = opposite_bl;
806 SI_pt->m_candidate_case_list.push_back(std::move(case_owned));
807 }
808 }
809 }//end of SI_itr
810 }//end of DI_itr
811}
812
813
814
816{
817 // << "\n";
818 //cout << "Time: " << r5pars_.timesno << ":\n" << str << '\n';
819 cout << ":\n" << str << '\n';
820
821 //test
822 ofstream fout("RMI.txt", ios::app);
823 fout <<"\n" << "Time: " << r5pars_.timesno << ":\n" << str << '\n';
824 fout.close();
825}
826
828{
829 if(this->m_operator != sim::Operator::ODM)
830 {return;}
831
832 //Concern: if there are more than one accident diagnosises active and they all link to procedures
833 //The situation covered by the current codes: only one diagnosis is active and links to a procedure;
834 for(auto &e : this->m_diagnose_invest_list)
835 {
836 if(e->m_procedure_step_pt != NULL && e->m_procedure_entered_bl == false)
837 {
838 e->CheckforPotentialProcedureBranching();
839 }
840 }
841
842}
843
845{
846 for(auto &e : this->m_event_schema_list)
847 {
848 e->ConvertESUinfoToString();
849 }
850}
851
853{
854/*
855 int m_operator;
856 float m_diagnose_claim_threshold;
857 float m_timing; // this timer is used for generating a new investigator
858*/
859 this->CopyIDElementToRestartInfo((IDElement*)_ESB_pt);
861 this->m_operator = _ESB_pt->m_operator;
862 this->m_timing = _ESB_pt->m_timing;
864/*
865 DiagnoseInvestigator * m_timed_DI;
866 string m_ID_timed_DI;
867*/
868 if(_ESB_pt->m_timed_DI != NULL)
869 {this->m_ID_timed_DI = _ESB_pt->m_timed_DI->m_ID;}
870 else
871 {this->m_ID_timed_DI = _ESB_pt->m_ID_timed_DI;}
872
873 if(this->m_event_schema_list.size() != 0)
874 {this->ErrorMessage("this->m_event_schema_list.size() != 0");return;}
875 if(this->m_diagnose_invest_list.size() != 0)
876 {this->ErrorMessage("this->m_diagnose_invest_list.size() != 0"); return;}
877 if(this->m_interested_invest_list.size() != 0)
878 {this->ErrorMessage("this->m_interested_invest_list.size() != 0"); return;}
879 if(this->m_interested_invest_link_list.size() != 0)
880 {this->ErrorMessage("this->m_interested_invest_link_list.size() != 0"); return;}
881 if(this->m_debug_info.size() != 0)
882 {this->ErrorMessage("this->m_debug_info.size() != 0"); return;}
883/*
884 vector<EventSchemaUnit *> m_event_schema_list;
885 vector<DiagnoseInvestigator *> m_diagnose_invest_list;
886 vector<string> m_debug_info;
887*/
888 for(auto &e : _ESB_pt->m_event_schema_list)
889 {
890 auto es_pt = std::make_unique<EventSchemaUnit>();
891 es_pt->CopyESUInfoWithoutPointerFromAnother(e.get());
892 this->m_event_schema_list.push_back(std::move(es_pt));
893 }
894
895 for(auto &e : _ESB_pt->m_diagnose_invest_list)
896 {
897 auto di_pt = std::make_unique<DiagnoseInvestigator>();
898 di_pt->CopyDiagnoseInvestigatorInfoFromAnother(e.get());
899 this->m_diagnose_invest_list.push_back(std::move(di_pt));
900 }
901
902 vector<string>::iterator str_itr;
903 string str;
904 for(str_itr = _ESB_pt->m_debug_info.begin(); str_itr != _ESB_pt->m_debug_info.end(); str_itr++)
905 {
906 str = *str_itr;
907 this->m_debug_info.push_back(str);
908 }
909
910/*
911 vector<Investigator *> m_interested_invest_list;
912 vector<InvestigatorLink *> m_interested_invest_link_list;
913
914 vector<string> m_ID_interested_invest_list;
915 vector<string> m_ID_interested_invest_link_list;
916*/
917
918 vector<Investigator *>::iterator invest_itr;
919 string ID;
920 if(_ESB_pt->m_interested_invest_list.size() != 0)
921 {
922 for(invest_itr = _ESB_pt->m_interested_invest_list.begin(); invest_itr != _ESB_pt->m_interested_invest_list.end(); invest_itr++)
923 {
924 ID = (*invest_itr)->m_ID;
925 this->m_ID_interested_invest_list.push_back(ID);
926 }
927 }
928 else
929 {
930 for(str_itr = _ESB_pt->m_ID_interested_invest_list.begin(); str_itr != _ESB_pt->m_ID_interested_invest_list.end(); str_itr++)
931 {
932 ID = *str_itr;
933 this->m_ID_interested_invest_list.push_back(ID);
934 }
935 }
936
937 vector<InvestigatorLink *>::iterator link_itr;
938 if(_ESB_pt->m_interested_invest_link_list.size() != 0)
939 {
940 for(link_itr = _ESB_pt->m_interested_invest_link_list.begin(); link_itr != _ESB_pt->m_interested_invest_link_list.end(); link_itr++)
941 {
942 ID = (*link_itr)->m_ID;
943 this->m_ID_interested_invest_link_list.push_back(ID);
944 }
945 }
946 else
947 {
948 for(str_itr = _ESB_pt->m_ID_interested_invest_link_list.begin(); str_itr != _ESB_pt->m_ID_interested_invest_link_list.end(); str_itr++)
949 {
950 ID = *str_itr;
951 this->m_ID_interested_invest_link_list.push_back(ID);
952 }
953 }
954}
955
957{
958 DiagnoseInvestigator * found_di = NULL;
959
960 for(auto &e : this->m_diagnose_invest_list)
961 {
962 if(found_di != NULL) break;
963 if(e->m_ID == _ID)
964 {
965 found_di = e.get();
966 }
967 }
968 return found_di;
969}
970
972{
973 SymptomInvestigator * found_SI = NULL;
974
975 for(auto &DI_e : this->m_diagnose_invest_list)
976 {
977 if(found_SI != NULL) break;
978 for(auto &SI_e : DI_e->m_symptom_invest_list)
979 {
980 if(found_SI != NULL) break;
981 if(SI_e->m_ID == _ID)
982 {found_SI = SI_e.get();}
983 }
984 }
985 return found_SI;
986}
987
989{
990 ReasonMachine * RM_pt;
991 RM_pt = (ReasonMachine*)_pt;
992/*
993 DiagnoseInvestigator * m_timed_DI;
994 string m_ID_timed_DI;
995*/
996 if(this->m_ID_timed_DI.compare("") != 0)
997 {
999 if(this->m_timed_DI == NULL)
1000 {this->ErrorMessage("this->m_timed_DI == NULL"); return;}
1001 }
1002 this->m_ID_timed_DI = "";
1003/*
1004 vector<Investigator *> m_interested_invest_list;
1005 vector<InvestigatorLink *> m_interested_invest_link_list;
1006
1007 vector<string> m_ID_interested_invest_list;
1008 vector<string> m_ID_interested_invest_link_list;
1009*/
1010 Investigator * invest_pt;
1011 InvestigatorLink * link_pt;
1012
1013 vector<string >::iterator str_itr;
1014 for(str_itr = this->m_ID_interested_invest_list.begin(); str_itr != this->m_ID_interested_invest_list.end(); str_itr++)
1015 {
1016 invest_pt = RM_pt->FindInvestigatorByID(*str_itr);
1017 if(invest_pt == NULL)
1018 {this->ErrorMessage("invest_pt == NULL ESB"); return;}
1019 this->m_interested_invest_list.push_back(invest_pt);
1020 }
1021 this->m_ID_interested_invest_list.clear();
1022
1023 for(str_itr = this->m_ID_interested_invest_link_list.begin(); str_itr != this->m_ID_interested_invest_link_list.end(); str_itr++)
1024 {
1025 link_pt = RM_pt->FindInvestigatorLinkByID(*str_itr);
1026 if(link_pt == NULL)
1027 {this->ErrorMessage("link_pt == NULL ESB"); return;}
1028 this->m_interested_invest_link_list.push_back(link_pt);
1029 }
1031
1032 //vector<unique_ptr<EventSchemaUnit>> m_event_schema_list;
1033 for(auto &esu_e : this->m_event_schema_list)
1034 {esu_e->BuildConnectionsForThisESU(_pt);}
1035
1036 //vector<unique_ptr<DiagnoseInvestigator>> m_diagnose_invest_list;
1037 for(auto &di_e : this->m_diagnose_invest_list)
1038 {di_e->BuildConnectionsForThisDiagnoseInvestigator(_pt);}
1039
1040}
1041
1043{
1044 EventSchemaUnit * found_esu = NULL;
1045 for(auto &e : this->m_event_schema_list)
1046 {
1047 if(found_esu != NULL) break;
1048 if(e->m_ID == _ID)
1049 {found_esu = e.get();}
1050 }
1051 return found_esu;
1052}
1053
1055{
1056 EventSymptomUnit * found_symp = NULL;
1057 for(auto &schema_e : this->m_event_schema_list)
1058 {
1059 if(found_symp != NULL) break;
1060 for(auto &symp_e : schema_e->m_symptom_list)
1061 {
1062 if(found_symp != NULL) break;
1063 if(symp_e->m_ID == _ID)
1064 {found_symp = symp_e.get();}
1065 }
1066 }
1067 return found_symp;
1068}
1069
1071{
1072 for(auto &e : this->m_diagnose_invest_list)
1073 {
1074 e->UpdateDiagnoseInvestigatorBranchingInfo(_pt);
1075 }
1076}
1077
1078//DEL void EventSchemaBase::test()
1079//DEL {
1080//DEL }
1081
1082//DEL float EventSchemaBase::m_active_investigation_threshold()
1083//DEL {
1084//DEL
1085//DEL }
1086
1088{
1089 Investigator * invest_pt = (Investigator*) _ID_pt;
1090 SymptomInvestigator * SI_pt;
1091 SymptomCase * case_pt;
1092 int i;
1093
1094 if(invest_pt->m_KElement_ID_pt != NULL)
1095 {
1096 if(invest_pt->m_KElement_ID_pt->m_ID == "KE_SG_A_level_increase" && r5pars_.timesno > 1868)
1097 {this->PrintMessage("");}
1098 }
1099
1100 for(auto &DI_e : this->m_diagnose_invest_list)
1101 {
1102 for(auto &SI_e : DI_e->m_symptom_invest_list)
1103 {
1104 SI_pt = SI_e.get();
1105 i = 0;
1106 while(i < (int)SI_pt->m_candidate_case_list.size())
1107 {
1108 case_pt = SI_pt->m_candidate_case_list[i].get();
1109 if(case_pt->m_invest_pt->m_ID == _ID_pt->m_ID)
1110 {
1111 //this symptom case will be removed into three places:
1112 //1--discarded list
1113 //2--rejection list
1114 //3--vioded list, which means the symptom is observed but there is one or more stronger competing explanation to account for it.
1115
1116 case_pt->m_finished_bl = true;
1117 if(case_pt->m_invest_pt->m_Happen == 4)
1118 {
1119 case_pt->m_rejection_time = r5pars_.timesno;
1120 SI_pt->m_last_case_end_time = r5pars_.timesno;
1121 SI_pt->MoveCaseFromCandidateTo(case_pt, SI_pt->m_rejected_case_list);
1122 }
1123 else if(case_pt->m_invest_pt->m_Happen == 2)
1124 {
1125 SI_pt->MoveCaseFromCandidateTo(case_pt, SI_pt->m_discarded_case_list);
1126 }
1127 else if(case_pt->m_invest_pt->m_Happen == 3)
1128 {//need to create a list of voided symptom cases
1129 if(case_pt->m_invest_pt->m_ID == "Investigator_3")
1130 {case_pt = case_pt;}//check point
1131 SI_pt->m_last_case_end_time = r5pars_.timesno;
1132 //
1133 if(case_pt->m_invest_pt == NULL)
1134 {
1135 this->PrintMessage("");
1136 }
1137 else if(case_pt->m_ID_invest == "Investigator_278" || case_pt->m_invest_pt->m_ID == "Investigator_278")
1138 {
1139 this->PrintMessage("");
1140 }
1141 //
1142 SI_pt->MoveCaseFromCandidateTo(case_pt, SI_pt->m_voided_case_list);
1143 }
1144 else
1145 {
1147 }
1148 }
1149 else
1150 {i++;}
1151 }
1152 }
1153 }
1154}
1155
1157{
1158 bool normal_bl = true;
1159
1160 //if(this->m_operator != sim::Operator::ODM)
1161 //{return ;}
1162
1163 //Concern: if there are more than one accident diagnosises active and they all link to procedures
1164 //The situation covered by the current codes: only one diagnosis is active and links to a procedure;
1165 for(auto &e : this->m_diagnose_invest_list)
1166 {
1167 //if(e->m_confidence > 0.2)
1168 if(e->m_claim_bl == true)
1169 {normal_bl = false;}
1170 }
1171 return normal_bl;
1172}
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
document e
std::vector< float > m_confidence_timeline
std::vector< std::unique_ptr< SymptomInvestigator > > m_symptom_invest_list
std::vector< float > m_coverage_list
std::vector< int > m_N_setback_list
SymptomInvestigator * m_tbi_SI
KnowledgeElement * m_event_KE_pt
std::vector< int > m_N_voided_list
std::vector< std::unique_ptr< TimeValueNoteUnit > > m_other_evidence_list
std::vector< float > m_confidence_history
std::vector< int > m_N_disabled_list
std::vector< std::string > m_symp_confidence_list
std::vector< float > m_Integrated_prob_list
EventSchemaUnit * FindACorrespondingEventSchemaUnitByKE(KnowledgeElement *_KE_pt)
float m_active_investigation_threshold
std::vector< InvestigatorLink * > m_interested_invest_link_list
std::vector< std::unique_ptr< EventSchemaUnit > > m_event_schema_list
DiagnoseInvestigator * m_timed_DI
void TrackTheOngoingInvestigation()
void UpdateTheBranchingHistory(void *_pt)
void RemoveAllTheCaseAssociatedWithAnInvestigator(IDElement *)
DiagnoseInvestigator * FindACorrespondingDiagnoseInvestigatorByKE(KnowledgeElement *_KE_pt)
SymptomInvestigator * FindSymtomInvestigatorByID(std::string)
std::vector< std::string > m_ID_interested_invest_list
DiagnoseInvestigator * FindDiagnoseInvestigatorByID(std::string)
virtual ~EventSchemaBase()
void ErrorMessage(std::string)
void BuildTheConnectionsForThisEventSchemaBase(void *)
void AddNewSymptomCaseWithNewInvestigatorIfNecessary(Investigator *_invest_pt)
void ConvertStaticESBinfoToString()
void PrintMessage(std::string str)
std::vector< std::string > m_ID_interested_invest_link_list
bool WhetherItIsNormalOperating()
bool GenerateANewInvestigatorOrNot()
std::string m_ID_timed_DI
void ReadEventSchemaBaseFromInputFile()
std::vector< std::unique_ptr< DiagnoseInvestigator > > m_diagnose_invest_list
std::vector< Investigator * > m_interested_invest_list
void AddANewDiagnoseInvestigator(DiagnoseInvestigator *_diagnose_invest_pt)
float m_diagnose_claim_threshold
void SaveAllDiagnoseInvestigatorInforToFile(std::string _path)
void CopyESBinfoFromAnother(EventSchemaBase *)
void UpdateTheInterestForInvestigatorOrInvestigatorLink()
EventSchemaUnit * FindEventSchemaUnitByID(std::string)
EventSymptomUnit * FindEventSymptomUnitByID(std::string)
std::vector< std::string > m_debug_info
void LinkNewInvestigatorToDiagnoseInvestigatorIfNecessary(Investigator *_invest_pt)
std::vector< std::unique_ptr< EventSymptomUnit > > m_symptom_list
std::string m_procedure_step_name
ProcedureStep * m_procedure_step_pt
KnowledgeElement * m_event_KE_pt
float m_diagnose_claim_threshold
std::string m_procedure_name
std::vector< KnowledgeUnit * > m_KU_list
KnowledgeElement * m_symptom_KE_pt
void CopyIDElementToRestartInfo(IDElement *)
Definition: IDElement.cpp:23
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
std::string m_note
Definition: Investigator.h:124
bool m_motivation
Definition: Investigator.h:92
bool m_invest_dormant
Definition: Investigator.h:94
double m_effective_end
Definition: Investigator.h:118
double m_effective_start
Definition: Investigator.h:119
IDElement * m_KElement_ID_pt
Definition: Investigator.h:129
bool m_active_investigation
Definition: Investigator.h:22
bool m_root_of_a_thought_line
Definition: Investigator.h:85
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
Statement * m_Statement_pt
Definition: Investigator.h:130
SentenceUnit * m_SentenceUnit_pt
Definition: Label.h:13
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
std::map< std::string, ProcedureStep * > procedure_map
Definition: Procedures.h:72
InvestigatorLink * FindInvestigatorLinkByID(std::string)
KnowledgeUnit * FindKnowledgeUnitByID(std::string)
KnowledgeElement * FindKnowledgeElementByID(std::string)
SentenceUnit * FindAnIndefiniteSentenceMatchTheInputSentence(SentenceUnit *)
ProblemSolvingStyle m_problem_solving_style
std::unique_ptr< InstantiationBase > m_IB
Investigator * FindInvestigatorByID(std::string)
void AddNewInvestigator(Investigator *)
std::string getOATDirectory()
Definition: Scheduler.cpp:622
std::string getODMDirectory()
Definition: Scheduler.cpp:619
SentenceUnit * m_sent_pt
Definition: Statement.h:43
bool m_state
Definition: Statement.h:35
Investigator * m_invest_pt
Definition: SymptomCase.h:30
std::string m_ID_invest
Definition: SymptomCase.h:37
float m_rejection_time
Definition: SymptomCase.h:24
bool m_finished_bl
Definition: SymptomCase.h:21
void RemoveADeterminedCaseFromCandiateList(SymptomCase *_case_pt)
std::vector< std::unique_ptr< SymptomCase > > m_voided_case_list
KnowledgeElement * m_symptom_KE_pt
std::vector< std::unique_ptr< SymptomCase > > m_candidate_case_list
std::vector< std::unique_ptr< SymptomCase > > m_exception_case_list
std::vector< std::unique_ptr< SymptomCase > > m_inconsistant_case_list
void MoveCaseFromCandidateTo(SymptomCase *_case_pt, std::vector< std::unique_ptr< SymptomCase > > &_target)
KnowledgeElement * m_opposite_KE_pt
std::vector< std::unique_ptr< SymptomCase > > m_rejected_case_list
std::vector< std::unique_ptr< SymptomCase > > m_confirmed_case_list
std::vector< std::unique_ptr< SymptomCase > > m_discarded_case_list
struct @0 r5pars_
constexpr int FindMatchingStatement
Definition: RMTokens.h:24
constexpr int SearchPossibleCauses
Definition: RMTokens.h:32
constexpr int ODM
Definition: SimConstants.h:145
constexpr int OAT
Definition: SimConstants.h:144
Scheduler SScheduler
Simulation scheduling, parses CLI options.
Procedures All_procedure
Emergency operating procedures.
OperatorAT Action_Taker
Crew action execution model.
OperatorDM Decision_Maker
Crew decision-making model.