13#include "../Crew/OperatorDM.h"
14#include "../Crew/OperatorAT.h"
18#include "../Procedure/Procedures.h"
19#include "../Branch/BranchProbability.h"
20#include "../Global/SimulationContext.h"
60 string dir_path, str, str_ID, err_mes;
62 int n_event, n_symptom, n_KU, i, j, k;
66 map<string, ProcedureStep *>::iterator procedure_map_itr;
83 dir_path +=
"KB_ODM_Event_Schema_Base.txt";
85 fin.open(dir_path.c_str(), ios::in);
87 err_mes =
"can not find file: " + dir_path;
93 fin >> str >> n_event;
94 if(str.compare(
"No_of_Event_Schemas:") != 0)
96 err_mes = str +
" is incorrectly in the position of Number_of_Instantiation_Label_Groups:";
102 if(str.compare(
"Diagnose_Claim_Threshold:") != 0)
104 err_mes = str +
" is incorrectly in the position of Diagnose_Claim_Threshold:";
112 for(i=0; i < n_event; i++)
114 auto schema_owned = std::make_unique<EventSchemaUnit>();
115 schema_pt = schema_owned.get();
120 ID_name =
"Event_Schema_" + conv.str();
121 schema_pt->
m_ID = ID_name;
125 fin >> str >> str_ID;
126 if(str.compare(
"Event_KE_ID:") != 0)
128 err_mes = str +
" is incorrectly in the position of Event_KE_ID:";
135 this->
ErrorMessage(
"Could not find the KE" + str_ID +
" for a schema");
139 fin >> str >> n_symptom;
140 if(str.compare(
"No_of_Symptoms:") != 0)
142 err_mes = str +
" is incorrectly in the position of No_of_Symptoms:";
147 for(j = 0; j < n_symptom; j++)
149 auto symptom_owned = std::make_unique<EventSymptomUnit>();
150 symptom_pt = symptom_owned.get();
152 ID_name = schema_pt->
m_ID +
"_symptom_" ;
155 ID_name += conv.str();
156 symptom_pt->
m_ID = ID_name;
158 fin >> str >> str_ID;
159 if(str.compare(
"Symptom_KE_ID:") != 0)
161 err_mes = str +
" is incorrectly in the position of Symptom_KE_ID:";
168 this->
ErrorMessage(
"Could not find the KE" + str_ID +
" for a symptom");
173 if(str.compare(
"No_of_causal_chains:") != 0)
175 err_mes = str +
" is incorrectly in the position of No_of_causal_chains:";
180 for(k = 0; k < n_KU; k++)
184 fin >> str >> str_ID;
185 if(str.compare(
"KU_ID:") != 0)
187 err_mes = str +
" is incorrectly in the position of KU_ID:";
194 this->
ErrorMessage(
"Could not find the KU" + str_ID +
" for a symptom");
203 if(str.compare(
"Response_Procedure_Name:") != 0)
205 err_mes = str +
" is incorrectly in the position of Response_Procedure_Name:";
211 if(str.compare(
"Response_Procedure_Step:") != 0)
213 err_mes = str +
" is incorrectly in the position of Response_Procedure_Step:";
241 cout <<
r5pars_.timesno <<
" " << str <<
" in EventSchemaBase.cpp" <<
'\n';
242 ofstream fout(
"err messages.txt", ios::app);
243 fout <<
r5pars_.timesno <<
" " << str <<
'\n';
254 str_ID =
"Diagnose_Investigator_";
257 str_ID += conv.str();
258 _diagnose_invest_pt->
m_ID = str_ID;
274 if(
e->m_event_KE_pt == _KE_pt)
276 found_DI_pt =
e.get();
285 Label *label_group_pt;
297 if(found_ES_pt != NULL)
break;
299 if(
e->m_event_KE_pt->m_negation != _KE_pt->
m_negation)
302 label_group_pt = RM_pt->
m_IB->CheckWhetherASentenceContainIndefiniteItem(
e->m_event_KE_pt->m_SentenceUnit_pt);
303 if(label_group_pt != NULL)
307 found_ES_pt =
e.get();
312 if(
e->m_event_KE_pt == _KE_pt)
314 found_ES_pt =
e.get();
328 for(
auto &SI_e : DI_e->m_symptom_invest_list)
330 new_SI_case_bl =
false;
336 new_SI_case_bl =
true;
344 new_SI_case_bl =
true;
351 if(new_SI_case_bl ==
true)
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));
367 e->DITrackTheOngoingInvestigation();
381 float highest_score = 0;
383 bool ongoing_bl =
false;
384 bool generated_bl =
false;
426 invest_pt->
m_note =
"by event schema";
473 if(invest_pt->
m_ID ==
"Investigator_308")
482 if(create_bl ==
false)
489 {
return generated_bl;}
496 if(ongoing_bl)
break;
497 DI_e->SearchForTheToBeInvestigatedSI();
498 if(DI_e->m_ongoing_SI != NULL)
500 if(DI_e->m_ongoing_SI->m_confirmed_case_list.size() == 0 || DI_e->m_ongoing_SI->m_independent_symptom_probability < 0.02)
503 ongoing_SI_pt = DI_e->m_ongoing_SI;
507 else if(DI_e->m_tbi_SI != NULL)
509 score = DI_e->m_confidence;
516 if(score > highest_score && DI_e->m_confidence > this->m_active_investigation_threshold && DI_e->m_confidence < 0.92)
518 highest_score = score;
523 this->
m_timing =
r5pars_.timesno + 672.96 * exp(-2.5*DI_e->m_confidence) * 1.5;
529 if(ongoing_bl ==
true)
536 if(invest_pt->
m_ID ==
"Investigator_229")
545 str +=
", working on ";
546 str += invest_pt->
m_ID;
561 str +=
", Plan to investigate ";
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;
587 ofstream fout(_path.c_str(), ios::out);
598 fout <<
"; Status: ";
601 fout <<
"Confirmed by: ";
603 fout << last_confirmed->m_invest_pt->m_ID <<
" " << last_confirmed->m_confirmed_time;
607 fout <<
"Voided by: ";
609 fout << last_voided->m_invest_pt->m_ID;
613 fout <<
"Exception found: ";
615 fout << last_exception->m_invest_pt->m_ID <<
" " << last_exception->m_exception_time;
619 fout <<
"Rejected by: ";
621 fout << last_rejected->m_invest_pt->m_ID <<
" " << last_rejected->m_rejection_time;
625 fout <<
"Unfinished: ";
629 fout <<
"miscellaneous";
634 fout << ce->m_invest_pt->m_ID <<
"||";
639 fout << ce->m_invest_pt->m_ID <<
"||";
645 fout << ce->m_invest_pt->m_ID <<
"||";
650 fout << ce->m_invest_pt->m_ID <<
"||";
655 fout << ce->m_invest_pt->m_ID <<
"||";
660 fout << ce->m_invest_pt->m_ID <<
"||";
664 fout <<
'\n' <<
"Timeline of the confidence level";
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";
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';
705 Integrated_prob_itr++;
710 symp_confidence_itr++;
716 fout <<
"Other evidence information: " <<
'\n';
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';
727 for(str_itr = this->
m_debug_info.begin(); str_itr != this->m_debug_info.end(); str_itr++)
744 bool match_bl =
false;
745 bool exist_bl =
false;
795 if(case_e->m_invest_pt == _invest_pt)
800 if(exist_bl ==
false)
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;
819 cout <<
":\n" << str <<
'\n';
822 ofstream fout(
"RMI.txt", ios::app);
823 fout <<
"\n" <<
"Time: " <<
r5pars_.timesno <<
":\n" << str <<
'\n';
836 if(
e->m_procedure_step_pt != NULL &&
e->m_procedure_entered_bl ==
false)
838 e->CheckforPotentialProcedureBranching();
848 e->ConvertESUinfoToString();
874 {this->
ErrorMessage(
"this->m_event_schema_list.size() != 0");
return;}
876 {this->
ErrorMessage(
"this->m_diagnose_invest_list.size() != 0");
return;}
878 {this->
ErrorMessage(
"this->m_interested_invest_list.size() != 0");
return;}
880 {this->
ErrorMessage(
"this->m_interested_invest_link_list.size() != 0");
return;}
882 {this->
ErrorMessage(
"this->m_debug_info.size() != 0");
return;}
890 auto es_pt = std::make_unique<EventSchemaUnit>();
891 es_pt->CopyESUInfoWithoutPointerFromAnother(
e.get());
897 auto di_pt = std::make_unique<DiagnoseInvestigator>();
898 di_pt->CopyDiagnoseInvestigatorInfoFromAnother(
e.get());
902 vector<string>::iterator str_itr;
918 vector<Investigator *>::iterator invest_itr;
924 ID = (*invest_itr)->m_ID;
937 vector<InvestigatorLink *>::iterator link_itr;
942 ID = (*link_itr)->m_ID;
962 if(found_di != NULL)
break;
977 if(found_SI != NULL)
break;
978 for(
auto &SI_e : DI_e->m_symptom_invest_list)
980 if(found_SI != NULL)
break;
981 if(SI_e->m_ID == _ID)
982 {found_SI = SI_e.get();}
1000 {this->
ErrorMessage(
"this->m_timed_DI == NULL");
return;}
1013 vector<string >::iterator str_itr;
1017 if(invest_pt == NULL)
1034 {esu_e->BuildConnectionsForThisESU(_pt);}
1038 {di_e->BuildConnectionsForThisDiagnoseInvestigator(_pt);}
1047 if(found_esu != NULL)
break;
1049 {found_esu =
e.get();}
1059 if(found_symp != NULL)
break;
1060 for(
auto &symp_e : schema_e->m_symptom_list)
1062 if(found_symp != NULL)
break;
1063 if(symp_e->m_ID == _ID)
1064 {found_symp = symp_e.get();}
1074 e->UpdateDiagnoseInvestigatorBranchingInfo(_pt);
1102 for(
auto &SI_e : DI_e->m_symptom_invest_list)
1130 {case_pt = case_pt;}
1158 bool normal_bl =
true;
1168 if(
e->m_claim_bl ==
true)
1169 {normal_bl =
false;}
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
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
Statement * m_event_statement_pt
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
IDElement * m_ES_base_ID_pt
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 CrossCheckProcedureUse()
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 *)
IDElement * m_KElement_ID_pt
bool m_active_investigation
bool m_root_of_a_thought_line
void CrankTheActivationToOne()
float m_interest_from_SymptomInvestigator
Statement * m_Statement_pt
SentenceUnit * m_SentenceUnit_pt
std::unique_ptr< ReasonMachine > m_RM
std::map< std::string, ProcedureStep * > procedure_map
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()
std::string getODMDirectory()
Investigator * m_invest_pt
void RemoveADeterminedCaseFromCandiateList(SymptomCase *_case_pt)
float m_last_case_end_time
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)
float m_independent_symptom_probability
bool m_need_to_invest_opposite_bl
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
void BoostTheActivationOfOngoingInvestigation()
constexpr int FindMatchingStatement
constexpr int SearchPossibleCauses
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.