9#include "../Crew/OperatorDM.h"
10#include "../Crew/OperatorAT.h"
11#include "../Branch/BranchProcedureStep.h"
12#include "../Crew/DecisionProcedureStep.h"
13#include "../Branch/BranchRecord.h"
14#include "../Procedure/Procedures.h"
15#include "../Global/fmodule.h"
18#include "../Global/SimulationContext.h"
137 auto symp_invest_owned = make_unique<SymptomInvestigator>();
138 auto symp_invest_pt = symp_invest_owned.get();
142 str_ID = this->
m_ID +
"_SI_" + conv.str();
143 symp_invest_pt->m_ID = str_ID;
144 symp_invest_pt->m_DI_ID_pt = (
IDElement*)
this;
145 symp_invest_pt->m_event_symptom_pt = event_symp.get();
146 symp_invest_pt->m_operator = this->
m_operator;
148 symp_invest_pt->InitiationOfthisSymptomInvestigator();
155 auto tvn_owned = make_unique<TimeValueNoteUnit>();
156 tvn_owned->m_time =
r5pars_.timesno;
177 cout <<
r5pars_.timesno <<
" " << str <<
'\n';
178 ofstream fout(
"err messages.txt", ios::app);
179 fout <<
r5pars_.timesno <<
" " << str <<
'\n';
189 int consistance_level;
193 vector<KnowledgeUnit *>::reverse_iterator KU_ritr;
194 vector<IDElement *>::iterator ID_itr;
199 consistance_level = 0;
200 auto SI_pt = SI_up.get();
201 invest_pt = _invest_pt;
203 for(KU_ritr = SI_pt->m_event_symptom_pt->m_KU_list.rbegin(); KU_ritr != SI_pt->m_event_symptom_pt->m_KU_list.rend() && jump_out_bl ==
false; KU_ritr++)
210 found_invest_link_pt = NULL;
216 found_invest_link_pt = invest_link_pt;
219 if(found_invest_link_pt == NULL)
235 if(consistance_level > 0)
237 case_pt = SI_pt->FindASymptomCaseByInvestigator(invest_pt);
246 if(consistance_level == SI_pt->m_event_symptom_pt->m_KU_list.size())
253 SI_pt->RemoveADeterminedCaseFromCandiateList(case_pt);
254 SI_pt->m_confirmed_case_list.push_back(unique_ptr<SymptomCase>(case_pt));
255 SI_pt->m_last_case_end_time =
r5pars_.timesno;
261 if(SI_pt->m_symptom_KE_pt->m_ID ==
"KE_air_ejector_radiation_>_10")
272 SI_pt->RemoveADeterminedCaseFromCandiateList(case_pt);
273 SI_pt->m_partial_consistant_case_list.push_back(unique_ptr<SymptomCase>(case_pt));
289 float* arg1 = (
float*)a;
290 float* arg2 = (
float*)b;
299 int N_consistant_symptom = 0;
300 int N_disabled_symptom = 0;
301 int N_setback_symptom = 0;
302 int N_unexplored_symptom = 0;
303 int N_voided_symptom = 0;
304 float maximum_symp_confidence = 0;
306 float Integrated_prob = 1;
308 float other_confidence = 0;
309 float new_confidence;
319 vector<float> ConfidenceArray(
size);
328 bool vagabond_reset =
false;
336 OtherConfidenceArray[i] = tvn->m_value;
339 qsort(OtherConfidenceArray.data(), this->m_other_evidence_list.size(),
sizeof(
float),
compare_floats);
341 if(this->m_other_evidence_list.size() > 0)
343 other_confidence = OtherConfidenceArray[0];
356 if(SI->m_confirmed_case_list.size() > 0)
358 N_consistant_symptom ++;
360 else if(SI->m_exception_case_list.size() > 0 )
362 N_disabled_symptom ++;
364 else if(SI->m_voided_case_list.size() > 0 )
368 else if(SI->m_rejected_case_list.size() > 0 )
370 N_setback_symptom ++;
374 N_unexplored_symptom ++;
377 if(SI->m_independent_symptom_probability > maximum_symp_confidence)
379 maximum_symp_confidence = SI->m_independent_symptom_probability;
381 ConfidenceArray[i] = SI->m_independent_symptom_probability;
387 {Integrated_prob = ConfidenceArray[0];}
390 for(i = 1; i <
size; i++)
400 this->
ErrorMessage(
"Exception! All the symptoms are disabled!");
404 this->
ErrorMessage(
"this->m_event_schema_pt->m_symptom_list.size() - N_disabled_symptom - N_voided_symptom == 0");
413 new_confidence = pow(new_confidence, (1+0.3*N_setback_symptom));
417 new_confidence = pow(new_confidence, (1+N_setback_symptom));
451 for(
auto &SI : this->m_symptom_invest_list)
454 conv << SI->m_independent_symptom_probability;
469 for(
auto &SI : this->m_symptom_invest_list)
473 {vagabond_reset =
true;}
475 if(SI->m_confirmed_case_list.size() > 0)
478 modulator *= 1 - SI->m_independent_symptom_probability;
480 else if(SI->m_exception_case_list.size() > 0)
482 else if(SI->m_rejected_case_list.size() > 0)
487 for(
auto &sc : SI->m_candidate_case_list)
489 sc->m_invest_pt->BoostAttentionofThisByDiagnosisInvestigation(SI->m_attention_level, vagabond_reset);
557 SI->SITrackTheOngoingInvestigation();
572 vector<KnowledgeUnit *>::iterator KU_itr;
573 float rejection_time = 0;
574 float confirmed_time = 0;
575 float retrieve_score, retrieve_score2;
589 if(SI->m_candidate_case_list.size() > 0)
591 if(SI->m_confirmed_case_list.size() == 0 || SI->m_independent_symptom_probability < ((
EventSchemaBase *)(this->m_ES_base_ID_pt))->m_active_investigation_threshold)
593 for(
auto &sc : SI->m_candidate_case_list)
595 if(SI->m_need_to_invest_opposite_bl ==
true)
597 if(sc->m_invest_pt->m_KElement_ID_pt == (
IDElement *)(SI->m_opposite_KE_pt))
600 else if(sc->m_invest_pt->m_KElement_ID_pt == (
IDElement *)(SI->m_symptom_KE_pt))
604 if(SI->m_voided_case_list.size() > 0 || SI->m_exception_case_list.size() > 0)
612 if(SI->m_confirmed_case_list.size() == 0)
614 if(SI->m_rejected_case_list.size() > 0 && SI->m_exception_case_list.size() == 0)
616 if(found_rejected_SI == NULL)
618 found_rejected_SI = SI.get();
621 else if(rejection_time > SI->m_last_case_end_time)
623 found_rejected_SI = SI.get();
627 else if(SI->m_voided_case_list.size() > 0)
629 else if(SI->m_exception_case_list.size() == 0)
632 KU_itr = SI->m_event_symptom_pt->m_KU_list.begin();
633 while(KU_itr != SI->m_event_symptom_pt->m_KU_list.end())
635 retrieve_score2 *= (*KU_itr)->m_forward_retrieve_weight;
638 if(found_unexplored_SI == NULL)
640 found_unexplored_SI = SI.get();
641 retrieve_score = retrieve_score2;
645 if(retrieve_score2 > retrieve_score)
647 found_unexplored_SI = SI.get();
648 retrieve_score = retrieve_score2;
653 else if(SI->m_voided_case_list.size() > 0)
655 else if(SI->m_independent_symptom_probability < 0.09)
657 if(found_explored_SI == NULL)
659 found_explored_SI = SI.get();
662 else if(confirmed_time > SI->m_last_case_end_time)
664 found_explored_SI = SI.get();
673 if(found_unexplored_SI != NULL)
675 this->
m_tbi_SI = found_unexplored_SI;
679 if(found_rejected_SI)
683 else if(found_explored_SI == NULL)
716 string current_procedure_name, current_step_name;
741 auto bps_owned = make_unique<BranchProcedureStep>();
742 b_procedure_step_pt = bps_owned.get();
746 b_procedure_step_pt->
setStepName(current_step_name);
753 auto bi_owned = make_unique<ProcedureBranchingInfo>();
754 branch_info = bi_owned.get();
767 auto bps_owned = make_unique<BranchProcedureStep>();
768 b_procedure_step_pt = bps_owned.get();
778 auto bi_owned = make_unique<ProcedureBranchingInfo>();
779 branch_info = bi_owned.get();
796 map<string, ProcedureStep *>::iterator procedure_map_itr;
797 vector<unique_ptr<ProcedureStepUnit>>::iterator step_unit_itr;
826 if(current_procedure_step_pt == 0)
831 if(current_procedure_step_pt->
getProcedureName().compare(this->m_procedure_step_pt->getCurrentProcedureName()) == 0)
852 step_unit_pt = step_unit_itr->get();
880 string current_procedure_name, current_step_name;
883 vector<int>::iterator i_itr;
884 vector<int>::iterator i_type_itr;
885 vector<unique_ptr<ProcedureStepUnit>>::iterator ps_unit_itr;
887 bool found_bl =
false;
888 bool bps_existing =
false;
889 int state_of_activation;
893 int prior_choice = 0;
913 if(current_procedure_name.compare(this->m_wm_procedure_step_pt->getCurrentProcedureName()) != 0
914 || current_step_name.compare(this->m_wm_procedure_step_pt->getCurrentStepName()) != 0)
945 state_of_activation = (*ps_unit_itr)->getStateOfActivation();
970 if(prior_choice == 0)
972 else if(prior_choice == 1)
974 else if(prior_choice == 2)
982 if(prior_choice != 2)
984 auto bi_owned = make_unique<ProcedureBranchingInfo>();
985 branch_info = bi_owned.get();
997 auto bps_owned = make_unique<BranchProcedureStep>();
998 b_procedure_step_pt = bps_owned.get();
1005 if(prior_choice == 0)
1007 else if(prior_choice == 2)
1010 if(prior_choice != 1)
1016 if(prior_choice != 1)
1018 auto bi_owned = make_unique<ProcedureBranchingInfo>();
1019 branch_info = bi_owned.get();
1034 else if(current_i > this->m_wm_i_list[0])
1040 {bps_existing =
true;}
1042 {bps_existing =
false;}
1050 auto bps_owned = make_unique<BranchProcedureStep>();
1051 b_procedure_step_pt = bps_owned.get();
1058 if(prior_choice == 0)
1060 else if(prior_choice == 1)
1062 else if(prior_choice == 2)
1065 {this->
ErrorMessage(
"the prior_choice type could not be recognized");
return;}
1066 if(prior_choice != 2)
1071 if(prior_choice != 2)
1073 auto bi_owned = make_unique<ProcedureBranchingInfo>();
1074 branch_info = bi_owned.get();
1087 unique_ptr<BranchProcedureStep> bps_owned;
1088 if(bps_existing ==
true)
1092 bps_owned = make_unique<BranchProcedureStep>();
1093 b_procedure_step_pt = bps_owned.get();
1096 b_procedure_step_pt->
setStepName(current_step_name);
1102 if(prior_choice == 0)
1104 else if(prior_choice == 2)
1106 else if(prior_choice == 1)
1108 if(bps_existing ==
true)
1117 {this->
ErrorMessage(
"the prior_choice could not be recognized");}
1118 if(prior_choice != 1 && bps_existing ==
false)
1123 if(prior_choice != 1)
1125 auto bi_owned = make_unique<ProcedureBranchingInfo>();
1126 branch_info = bi_owned.get();
1141 i_itr = this->m_wm_i_list.begin();
1143 this->m_wm_i_list.erase(i_itr);
1156 if(name1.compare(name2) != 0)
1159 if(prior_choice == 0)
1161 else if(prior_choice == 2)
1163 else if(prior_choice == 1 || prior_choice == 3)
1170 {this->
ErrorMessage(
"the prior_choice could not be recognized");
return;}
1173 if(prior_choice == 0 || prior_choice == 2)
1175 auto bi_owned = make_unique<ProcedureBranchingInfo>();
1176 branch_info = bi_owned.get();
1189 auto bps_owned = make_unique<BranchProcedureStep>();
1190 b_procedure_step_pt = bps_owned.get();
1197 if(prior_choice == 0)
1199 else if(prior_choice == 1)
1201 else if(prior_choice == 2 || prior_choice == 3)
1204 {this->
ErrorMessage(
"the prior choice could not be recognized");
return;}
1206 if(prior_choice == 0 || prior_choice == 1)
1211 if(prior_choice == 0 || prior_choice == 1)
1213 auto bi_owned = make_unique<ProcedureBranchingInfo>();
1214 branch_info = bi_owned.get();
1227 auto bps_owned = make_unique<BranchProcedureStep>();
1228 b_procedure_step_pt = bps_owned.get();
1231 b_procedure_step_pt->
setStepName(current_step_name);
1236 if(prior_choice == 0)
1238 else if(prior_choice == 3)
1240 else if(prior_choice == 1 || prior_choice == 2)
1243 {this->
ErrorMessage(
"the prior_choice could not be recognized");
return;}
1245 if(prior_choice == 0 || prior_choice == 3)
1249 if(prior_choice == 0 || prior_choice == 3)
1251 auto bi_owned = make_unique<ProcedureBranchingInfo>();
1252 branch_info = bi_owned.get();
1268 else if((this->
m_claim_bl ==
true) && (
r5pars_.timesno - this->m_claim_time > this->m_event_schema_pt->m_max_delay))
1278 auto bps_owned = make_unique<BranchProcedureStep>();
1279 b_procedure_step_pt = bps_owned.get();
1289 auto bi_owned = make_unique<ProcedureBranchingInfo>();
1290 branch_info = bi_owned.get();
1354 {this->
ErrorMessage(
"this->m_wm_i_list.size() != 0");
return;}
1356 {this->
ErrorMessage(
"this->m_wm_type_list.size() != 0");
return;}
1358 {this->
ErrorMessage(
"this->m_confidence_history.size() != 0");
return;}
1360 {this->
ErrorMessage(
"this->m_confidence_timeline.size() != 0");
return;}
1367 vector<int>::iterator int_itr;
1368 vector<float>::iterator fl_itr;
1426 vector<string>::iterator str_itr;
1435 {this->
ErrorMessage(
"this->m_other_evidence_list.size() > 0");}
1438 auto tvn_owned = make_unique<TimeValueNoteUnit>();
1439 tvn_owned->CopyFromAnotherTimeValueNoteUnit(tvn.get());
1522 auto si_owned = make_unique<SymptomInvestigator>();
1523 si_owned->CopySymptomInvestigatorInfoFromAnother(si.get());
1532 auto bi_owned = make_unique<ProcedureBranchingInfo>();
1533 bi_owned->s_branching_choice = bh->s_branching_choice;
1534 bi_owned->s_branching_time = bh->s_branching_time;
1535 bi_owned->s_branching_type = bh->s_branching_type;
1536 bi_owned->s_current_procedure_name = bh->s_current_procedure_name;
1537 bi_owned->s_current_step_name = bh->s_current_step_name;
1538 bi_owned->s_procedure_name = bh->s_procedure_name;
1539 bi_owned->s_step_name = bh->s_step_name;
1544 auto bi_owned = make_unique<ProcedureBranchingInfo>();
1545 bi_owned->s_branching_choice = bi->s_branching_choice;
1546 bi_owned->s_branching_time = bi->s_branching_time;
1547 bi_owned->s_branching_type = bi->s_branching_type;
1548 bi_owned->s_current_procedure_name = bi->s_current_procedure_name;
1549 bi_owned->s_current_step_name = bi->s_current_step_name;
1550 bi_owned->s_procedure_name = bi->s_procedure_name;
1551 bi_owned->s_step_name = bi->s_step_name;
1560 map<string, ProcedureStep *>::iterator procedure_map_itr;
1578 if(this->
m_wm_procedure_name.compare(
"NONE") != 0 && this->m_wm_procedure_step_name.compare(
"NONE") != 0)
1601 {this->
ErrorMessage(
"this->m_tbi_SI == NULL");
return;}
1622 {this->
ErrorMessage(
"this->m_label_ID_pt == NULL");
return;}
1626 if(this->
m_ID_KE.compare(
"") != 0)
1630 {this->
ErrorMessage(
"this->m_event_KE_pt == NULL");
return;}
1638 {this->
ErrorMessage(
"this->m_event_statement_pt == NULL");
return;}
1642 if(this->
m_ID_es.compare(
"") != 0)
1646 {this->
ErrorMessage(
"this->m_event_schema_pt == NULL");
return;}
1654 symp->BuildConnectionsForThisSymptomInvestigator(_pt);
1664 string next_procedure_name;
1665 string next_step_name;
1673 size_t found_idx = 0;
1679 {this->
ErrorMessage(
"bp_pt->procedure_step.size() == 0");
return;}
1681 {this->
ErrorMessage(
"bp_pt->procedure_step.size() > 1");
return;}
1692 if(info->s_procedure_name.compare(next_procedure_name) == 0)
1694 if(info->s_step_name.compare(next_step_name) == 0)
1697 found_info_pt = info.get();
1706 if(found_info_pt == NULL)
1707 {this->
ErrorMessage(
"Fail: found_info == NULL");
return;}
1712 if((type == 1 && choice == 2) || (type == 21 && choice == 2) || (type == 22 && choice == 1) || (type == 3 && choice == 2) || (type == 4))
1724 for(
auto ritr = this->
m_branching_history_list.rbegin(); ritr != this->m_branching_history_list.rend() && found_info_pt == NULL; ritr++)
1726 if((*ritr)->s_branching_type != type)
1728 if((*ritr)->s_current_procedure_name.compare(procedure_name) == 0 && (*ritr)->s_step_name.compare(step_name) == 0)
1730 found_info_pt = ritr->get();
1734 if(found_info_pt != NULL)
1757 bool exist_bl =
false;
1758 bool seen_before =
false;
1782 if(exist_bl ==
true)
1786 bool update_number =
false;
1790 if(seen_before)
break;
1796 tvn->m_time =
r5pars_.timesno;
1798 tvn->m_note = invest_pt->
m_ID;
1799 update_number =
true;
1804 if(seen_before ==
false)
1806 auto other_evidence_owned = make_unique<TimeValueNoteUnit>();
1810 other_evidence_owned->m_time =
r5pars_.timesno;
1811 this->m_other_evidence_list.push_back(std::move(other_evidence_owned));
1812 update_number =
true;
1815 if(update_number ==
true)
static int compare_floats(const void *a, const void *b)
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
One alternative of a BranchCluster, i.e. one PE node of the DET.
void addProcedureStep(int, BranchProcedureStep *)
BranchUnit ODM_branch
Pending crew forks of the decision maker, action taker and consultant.
std::vector< std::shared_ptr< BranchProcedureStep > > procedure_step
void setSenderAndReceiver(int, int)
void setTypeOfPauseActivity(int)
std::string getProcedureName()
std::string getLastProcedureName()
void setStepName(std::string)
void setLastProcedureName(std::string)
void setLastStepName(std::string)
void setProcedureName(std::string)
std::string getStepName()
std::vector< float > m_confidence_timeline
float m_branching_3_1_prob
void SearchForTheToBeInvestigatedSI()
float m_diagnose_claim_threshold
std::vector< std::unique_ptr< SymptomInvestigator > > m_symptom_invest_list
std::vector< float > m_coverage_list
void InitiationOfthisDiagnoseInvestigator(float, IDElement *)
IDElement * m_label_ID_pt
void CopyDiagnoseInvestigatorInfoFromAnother(DiagnoseInvestigator *)
std::string m_procedure_step_name
SymptomInvestigator * m_ongoing_SI
float m_coverage_coefficient
void UpdateForOtherEvidenceNotListedInEventSchema(IDElement *)
void UpdateTheInterestLevelOfDI()
float m_branching_2_2_prob
EventSchemaUnit * m_event_schema_pt
std::vector< int > m_N_setback_list
SymptomInvestigator * m_tbi_SI
ProcedureStep * m_procedure_step_pt
void TerminateTheCurrentProcedureStep()
int FindARecentSimilarBranching(int, std::string, std::string)
std::string m_ID_ongoing_SI
KnowledgeElement * m_event_KE_pt
std::string m_wm_procedure_name
void DITrackTheOngoingInvestigation()
std::vector< std::unique_ptr< ProcedureBranchingInfo > > m_branching_info_list
std::vector< std::unique_ptr< ProcedureBranchingInfo > > m_branching_history_list
void ClearTheInfomationAboutTheCurrentProcedureStep()
std::vector< int > m_N_voided_list
std::string m_wm_procedure_step_name
void UpdateThisDiagnoseWithAnConfirmedInvestigator(Investigator *_invest_pt)
Statement * m_event_statement_pt
std::vector< std::unique_ptr< TimeValueNoteUnit > > m_other_evidence_list
std::vector< int > m_wm_type_list
virtual ~DiagnoseInvestigator()
std::vector< float > m_confidence_history
void UpdateDiagnoseInvestigatorBranchingInfo(void *)
std::vector< int > m_N_disabled_list
void ReadCurrentProcedureStepInformation()
std::vector< std::string > m_symp_confidence_list
float m_branching_3_2_prob
void CalculateTheConfidenceLeveloftheDiagnoseInvestigator()
void ErrorMessage(std::string str)
void CheckforPotentialProcedureBranching()
std::vector< float > m_Integrated_prob_list
void TriggerBranchingWhenClaimADiagnose()
bool m_contain_transfer_point_to_associate_procedure_bl
IDElement * m_ES_base_ID_pt
std::string m_procedure_name
void BuildConnectionsForThisDiagnoseInvestigator(void *)
std::vector< int > m_wm_i_list
float m_branching_2_1_prob
ProcedureStep * m_wm_procedure_step_pt
float m_confidence_from_others
bool m_procedure_entered_bl
bool m_terminate_investigation
std::string m_ID_statement
std::vector< std::unique_ptr< EventSymptomUnit > > m_symptom_list
ProcedureStep * m_procedure_step_pt
KnowledgeElement * m_event_KE_pt
float m_diagnose_claim_threshold
void CopyIDElementToRestartInfo(IDElement *)
std::string getCurrentProceduralStepName()
DecisionProcedureStep * getCurrentProcedureStepPtr(int)
std::string getCurrentProcedureName()
KnowledgeUnit * m_K_unit_pt
IDElement * m_downstream_ID_pt
float m_probability_update_time
IDElement * m_KElement_ID_pt
std::vector< IDElement * > m_downstream_ID_list
float m_independent_probability
std::unique_ptr< ReasonMachine > m_RM
std::string getProcedureName()
int getTypeOfNonResponseAction()
std::unique_ptr< ProcedureStepInfo > non_response_procedure
std::vector< std::unique_ptr< ProcedureStepUnit > > procedure_step_unit
std::string getNextProcedureName()
std::string getCurrentProcedureName()
std::string getCurrentStepName()
void resetStateOfActivation()
std::map< std::string, ProcedureStep * > procedure_map
std::unique_ptr< KBConcept > m_Concept_Base
KnowledgeElement * FindKnowledgeElementByID(std::string)
KnowledgeElement * FindAKEbySentenceAndNegationSign(SentenceUnit *, bool)
float m_ability_of_integrating_evidence
ProblemSolvingStyle m_problem_solving_style
Statement * FindStatementByID(std::string)
std::unique_ptr< EventSchemaBase > m_event_schema_base
Investigator * m_buffer_invest_pt
IDElement * GetLabelOfThisSentence()
void setStateOfActivation(int)
Investigator * m_invest_pt
float m_last_case_end_time
KnowledgeElement * m_symptom_KE_pt
void setTimerAndProbability(double, double)
int size
Total number of MPI processes.
constexpr int FollowProcedure
std::string s_current_procedure_name
std::string s_current_step_name
std::string s_procedure_name
Procedures All_procedure
Emergency operating procedures.
OperatorAT Action_Taker
Crew action execution model.
OperatorDM Decision_Maker
Crew decision-making model.
BranchRecord Branch_center
Dynamic event tree state.