10#include "../Global/TermConversions.h"
11#include "../Scheduler/Scheduler.h"
12#include "../Crew/OperatorDM.h"
13#include "../Global/SimulationContext.h"
39 string concept_ID, indicator_ID, str, str1, rate_indicator_ID, control_value_indicator_ID;
49 double v1, v2, v3, v4;
58 err_mes =
"could not identify operator type in MentalRepresentation::ReadMentalRepresentationtInfoFromInputFile()";
66 file_name +=
"KB_ODM_Mental_Representation.txt";
70 file_name +=
"KB_OAT_Mental_Representation.txt";
72 err_mes =
"could not identify the operator in MentalRepresentation::ReadMentalRepresentationtInfoFromInputFile()";
77 fin.open(file_name.c_str(), ios::in);
79 err_mes =
"can not find file: " + file_name;
88 for (i = 0; i < n_Unit; i++) {
89 fin >> str >> concept_ID;
90 if (str.compare(
"Parameter_Concept_ID") != 0) {
91 err_mes = concept_ID +
" is not aligned in the right position";
95 fin >> str >> indicator_ID;
96 if (str.compare(
"Corresponding_Value_Indicator") != 0) {
97 err_mes = indicator_ID +
" is not aligned in the right position";
101 fin >> str >> rate_indicator_ID;
102 if (str.compare(
"Corresponding_Rate_Indicator") != 0) {
103 err_mes =
"Corresponding_Rate_Indicator of " + rate_indicator_ID +
" is not aligned in the right position";
108 if (str.compare(
"increase_detect_threshold") != 0) {
109 err_mes =
"increase_dectect_threshold of " + concept_ID +
" is not aligned in the right position";
114 if (str.compare(
"decrease_detect_threshold") != 0) {
115 err_mes =
"decrease_dectect_threshold of " + concept_ID +
" is not aligned in the right position";
120 if (str.compare(
"increase_rate_detect_threshold") != 0) {
121 err_mes =
"increase_rate_detect_threshold of " + concept_ID +
" is not aligned in the right position";
126 if (str.compare(
"decrease_rate_detect_threshold") != 0) {
127 err_mes =
"decrease_rate_detect_threshold of " + concept_ID +
" is not aligned in the right position";
132 auto MRPar_upt = make_unique<MRParameterUnit>();
133 MRPar_pt = MRPar_upt.get();
137 ID_name =
"MR_Parameter_" + conv.str();
138 MRPar_pt->
m_ID = ID_name;
143 err_mes =
"could not find concept: " + concept_ID
144 +
" in semantic base, error location: Mental representation txt file";
158 fin >> str >> n_Unit;
159 if (str.compare(
"No_of_Component_State_Concept") != 0) {
160 err_mes =
"No_of_Component_State_Concept is not aligned in the proper position in Mental Representation txt file";
164 for (i = 0; i < n_Unit; i++) {
165 control_value_indicator_ID =
"NONE";
166 fin >> str >> concept_ID;
167 if (str.compare(
"Component_Concept_ID") != 0) {
168 err_mes =
"Component_Concept_ID of " + concept_ID
169 +
" is not aligned in the proper position in Mental Representation txt file";
173 fin >> str >> n_type;
174 if (str.compare(
"Component_State_Type") != 0) {
175 err_mes =
"Component_State_Type " + concept_ID
176 +
" is not aligned in the proper position in Mental Representation txt file";
180 auto MRComp_upt = make_unique<MRComponentStateUnit>();
181 MRComponentState_pt = MRComp_upt.get();
184 ID_name =
"MR_Component_State_" + conv.str();
185 MRComponentState_pt->
m_ID = ID_name;
191 err_mes =
"could not find a corresponding concept in the semantic base for MR item " + concept_ID;
197 case 0: fin >> str >> str1;
198 if (str.compare(
"Conponent_State_Indicator") != 0) {
199 err_mes =
"MR Item: " + concept_ID +
". Conponent_State_Indicator is not aligned in right posiiton";
205 case 1: fin >> str >> str1;
206 if (str.compare(
"Component_position_Indicator") != 0) {
207 err_mes =
"MR Item: " + concept_ID +
". Component_position_Indicator is not aligned in right posiiton";
213 if (str.compare(
"Component_position_change_detect_threshold") != 0) {
214 err_mes =
"MR Item: " + concept_ID
215 +
". Component_position_change_detect_threshold is not aligned in right posiiton";
227 fin >> str >> n_Unit;
228 if (str.compare(
"No_of_Support_System_Concept") != 0) {
229 err_mes =
"No_of_Support_System_Concept is mis-aligned with " + str;
233 for (i = 0; i < n_Unit; i++) {
234 fin >> str >> concept_ID;
235 if (str.compare(
"Support_System_State_Concept_ID") != 0) {
236 err_mes =
"Support_System_Concept_ID is mis-aligned with" + str;
240 fin >> str >> indicator_ID;
241 if (str.compare(
"Support_System_State_Indicator") != 0) {
242 err_mes =
"Support_System_Indicator is mis-aligned with" + str;
246 auto MRSS_upt = make_unique<MRSupportSystemStateUnit>();
247 MRSupportSystemState_pt = MRSS_upt.get();
251 ID_name =
"MR_Support_System_" + conv.str();
252 MRSupportSystemState_pt->
m_ID = ID_name;
258 err_mes =
"could not find concept: " + concept_ID
259 +
" in semantic base. Error location: Mental representation txt file";
268 fin >> str >> n_Unit;
269 if (str.compare(
"No_of_Alarm_Concept") != 0) {
270 err_mes =
"No_of_Alarm_Concept is mis-aligned with " + str;
274 for (i = 0; i < n_Unit; i++) {
275 fin >> str >> concept_ID;
276 if (str.compare(
"Alarm_Concept_ID") != 0) {
277 err_mes =
"Alarm_Concept_ID is mis-aligned with" + str;
281 fin >> str >> indicator_ID;
282 if (str.compare(
"Alarm_Indicator") != 0) {
283 err_mes =
"Alarm_Indicator is mis-aligned with" + str;
287 auto MRAlarm_upt = make_unique<MRAlarmUnit>();
288 MRAlarm_pt = MRAlarm_upt.get();
292 ID_name =
"MR_Alarm_" + conv.str();
293 MRAlarm_pt->
m_ID = ID_name;
300 err_mes =
"could not find concept: " + concept_ID
301 +
" in semantic base. Error location: Mental representation txt file";
321 for (
auto P_itr = this->
m_MRParameter_list.begin(); P_itr != this->m_MRParameter_list.end() && found ==
false; P_itr++) {
328 for (
auto C_itr = this->
m_MRComponent_list.begin(); C_itr != this->m_MRComponent_list.end() && found ==
false; C_itr++) {
335 for (
auto SS_itr = this->
m_MRSupportSystem_list.begin(); SS_itr != this->m_MRSupportSystem_list.end() && found ==
false;
337 SS_pt = SS_itr->get();
343 for (
auto A_itr = this->
m_MRAlarm_list.begin(); A_itr != this->m_MRAlarm_list.end() && found ==
false; A_itr++) {
362 for (
auto P_itr = this->
m_MRParameter_list.begin(); P_itr != this->m_MRParameter_list.end() && found ==
false; P_itr++) {
378 SS_pt = SS_itr->get();
403 for (
auto P_itr = this->
m_MRParameter_list.begin(); P_itr != this->m_MRParameter_list.end() && found ==
false; P_itr++) {
419 SS_pt = SS_itr->get();
445 int operator_branch_num = 0;
454 if (operator_branch_num > 0) {
494 cout <<
r5pars_.timesno <<
" " << str <<
" in MentalRepresentation.cpp" <<
'\n';
495 ofstream fout(
"err messages.txt", ios::app);
496 fout <<
r5pars_.timesno <<
" " << str <<
'\n';
507 ofstream fout(_path.c_str(), ios::out);
508 fout <<
"ID" <<
'\t';
509 fout <<
"Reading History" <<
'\n';
512 for (
auto A_itr = this->
m_MRAlarm_list.begin(); A_itr != this->m_MRAlarm_list.end(); A_itr++) {
516 if (
e->m_perceived_state ==
true) {
517 fout <<
"ON" <<
'\t';
519 fout <<
"OFF" <<
'\t';
524 fout <<
"ON" <<
'\t';
526 fout <<
"OFF" <<
'\t';
532 fout <<
e->m_time_perceived <<
'\t';
541 for (
auto P_itr = this->
m_MRParameter_list.begin(); P_itr != this->m_MRParameter_list.end(); P_itr++) {
546 fout <<
e->m_perceived_value;
556 fout <<
e->m_time_perceived;
569 fout <<
e->m_perceived_value;
579 fout <<
e->m_time_perceived;
589 for (
auto C_itr = this->
m_MRComponent_list.begin(); C_itr != this->m_MRComponent_list.end(); C_itr++) {
594 if (
e->m_perceived_state ==
true) {
595 fout <<
"ON" <<
'\t';
597 fout <<
"OFF" <<
'\t';
602 fout <<
"ON" <<
'\t';
604 fout <<
"OFF" <<
'\t';
610 fout <<
e->m_time_perceived <<
'\t';
620 fout <<
e->m_perceived_value <<
'\t';
628 fout <<
e->m_time_perceived <<
'\t';
640 for (
auto SS_itr = this->
m_MRSupportSystem_list.begin(); SS_itr != this->m_MRSupportSystem_list.end(); SS_itr++) {
641 SS_pt = SS_itr->get();
644 if (
e->m_perceived_state ==
true) {
645 fout <<
"ON" <<
'\t';
647 fout <<
"OFF" <<
'\t';
652 fout <<
"ON" <<
'\t';
654 fout <<
"OFF" <<
'\t';
660 fout <<
e->m_time_perceived <<
'\t';
678 float value1, value2;
680 SentenceUnit increase_sent, decrease_sent, open_bigger_sent, close_smaller_sent;
681 SentenceUnit turn_on_sent, turn_off_sent, ON_sent, OFF_sent;
682 SentenceUnit *increase_sent_pt = NULL, *decrease_sent_pt = NULL;
683 SentenceUnit *open_bigger_sent_pt = NULL, *close_smaller_sent_pt = NULL;
684 SentenceUnit *turn_on_sent_pt = NULL, *turn_off_sent_pt = NULL;
697 if (ID_pt == NULL) {
return; }
699 case 1: S_schema_pt = NULL;
832 if (S_schema_pt != NULL) {
833 new_statement_pt = NULL;
836 found_sent_pt = NULL;
840 ON_sent_pt = &ON_sent;
843 OFF_sent_pt = &OFF_sent;
845 }
else if (A_pt != NULL) {
848 ON_sent_pt = &ON_sent;
851 OFF_sent_pt = &OFF_sent;
853 }
else if (SS_pt != NULL) {
856 ON_sent_pt = &ON_sent;
859 OFF_sent_pt = &OFF_sent;
861 if (ON_sent_pt != NULL) {
867 }
else if (OFF_sent_pt != NULL) {
875 if (found_sent_pt != NULL) {
876 auto stmt = make_unique<Statement>();
877 stmt->m_sent_pt = found_sent_pt;
879 stmt->m_factual_type = 2;
880 }
else { stmt->m_factual_type = 3; }
882 stmt->m_state =
true;
885 new_statement_pt = stmt.get();
889 }
else if (A_pt != NULL) {
891 }
else if (SS_pt != NULL) {
901 S_new_schema_pt = NULL;
902 turn_on_sent_pt = NULL;
903 turn_off_sent_pt = NULL;
904 new_statement_pt = NULL;
905 new_statement_pt = NULL;
907 if (_statement_pt->
m_state ==
false) {
return; }
921 if (S_schema_pt != NULL) {
936 if (S_new_schema_pt != NULL) {
939 turn_on_sent_pt = &turn_on_sent;
944 turn_on_sent_pt = NULL;
946 turn_off_sent_pt = &turn_off_sent;
948 turn_off_sent_pt->m_sentence_type = 1;
949 turn_off_sent_pt->m_process_pt = RM_pt->
m_Concept_Base->getTurnOffPt();
951 turn_off_sent_pt = NULL;
953 if (found_sent_pt == NULL) { this->
ErrorMessage(
"Error!"); }
958 found_sent_pt = NULL;
961 }
else if (A_pt != NULL) {
964 found_sent_pt = NULL;
967 }
else if (SS_pt != NULL) {
970 found_sent_pt = NULL;
975 if (found_sent_pt != NULL) {
976 auto stmt = make_unique<Statement>();
979 stmt->m_factual_type = 2;
980 }
else { stmt->m_factual_type = 3; }
981 stmt->m_state = _statement_pt->
m_state;
982 stmt->m_sent_pt = found_sent_pt;
985 new_statement_pt = stmt.get();
990 }
else if (A_pt != NULL) {
992 }
else if (SS_pt != NULL) {
997 auto inv = make_unique<Investigator>();
998 inv->m_note =
"by a statement";
999 inv->m_motivation = 1;
1000 inv->m_Statement_pt = new_statement_pt;
1004 inv->m_root_of_a_thought_line =
true;
1005 invest_pt =
inv.get();
1015 }
else if (A_pt != NULL) {
1020 }
else if (SS_pt != NULL) {
1030 case 3: new_statement_pt = NULL;
1041 && _statement_pt->
m_state ==
true) {
1042 increase_sent_pt = &increase_sent;
1048 && _statement_pt->
m_state ==
true) {
1049 decrease_sent_pt = &decrease_sent;
1051 decrease_sent_pt->m_sentence_type = 1;
1052 decrease_sent_pt->m_process_pt = RM_pt->
m_Concept_Base->getDecreasePt();
1055 && _statement_pt->
m_state ==
false) {
1056 increase_sent_pt = &increase_sent;
1062 && _statement_pt->
m_state ==
false) {
1063 decrease_sent_pt = &decrease_sent;
1065 decrease_sent_pt->m_sentence_type = 1;
1066 decrease_sent_pt->m_process_pt = RM_pt->
m_Concept_Base->getDecreasePt();
1069 if (increase_sent_pt != NULL) {
1071 increase_sent_pt = NULL;
1072 }
else if (decrease_sent_pt != NULL) {
1074 decrease_sent_pt = NULL;
1076 if (found_sent_pt != NULL) {
1077 auto stmt = make_unique<Statement>();
1078 stmt->m_sent_pt = found_sent_pt;
1081 stmt->m_factual_type = 2;
1082 }
else { stmt->m_factual_type = 3; }
1083 stmt->m_state =
true;
1096 new_statement_pt = stmt.get();
1104 new_statement_pt = NULL;
1108 new_statement_pt = stmt.get();
1127 && _statement_pt->
m_state ==
true) {
1128 open_bigger_sent_pt = &open_bigger_sent;
1134 && _statement_pt->
m_state ==
true) {
1135 close_smaller_sent_pt = &close_smaller_sent;
1137 close_smaller_sent_pt->m_sentence_type = 1;
1138 close_smaller_sent_pt->m_process_pt = RM_pt->
m_Concept_Base->getCloseSmallerPt();
1141 && _statement_pt->
m_state ==
false) {
1142 open_bigger_sent_pt = &open_bigger_sent;
1148 && _statement_pt->
m_state ==
false) {
1149 close_smaller_sent_pt = &close_smaller_sent;
1151 close_smaller_sent_pt->m_sentence_type = 1;
1152 close_smaller_sent_pt->m_process_pt = RM_pt->
m_Concept_Base->getCloseSmallerPt();
1155 if (open_bigger_sent_pt != NULL) {
1157 open_bigger_sent_pt = NULL;
1158 }
else if (close_smaller_sent_pt != NULL) {
1160 close_smaller_sent_pt = NULL;
1162 if (found_sent_pt != NULL) {
1163 auto stmt = make_unique<Statement>();
1164 stmt->m_sent_pt = found_sent_pt;
1167 stmt->m_factual_type = 2;
1168 }
else { stmt->m_factual_type = 3; }
1169 stmt->m_state =
true;
1171 new_statement_pt = stmt.get();
1205 && _statement_pt->
m_state ==
true) {
1206 open_bigger_sent_pt = &open_bigger_sent;
1212 && _statement_pt->
m_state ==
true) {
1213 close_smaller_sent_pt = &close_smaller_sent;
1215 close_smaller_sent_pt->m_sentence_type = 1;
1216 close_smaller_sent_pt->m_process_pt = RM_pt->
m_Concept_Base->getCloseSmallerPt();
1219 && _statement_pt->
m_state ==
false) {
1220 open_bigger_sent_pt = &open_bigger_sent;
1226 && _statement_pt->
m_state ==
false) {
1227 close_smaller_sent_pt = &close_smaller_sent;
1229 close_smaller_sent_pt->m_sentence_type = 1;
1230 close_smaller_sent_pt->m_process_pt = RM_pt->
m_Concept_Base->getCloseSmallerPt();
1233 if (open_bigger_sent_pt != NULL) {
1235 open_bigger_sent_pt = NULL;
1236 }
else if (close_smaller_sent_pt != NULL) {
1238 close_smaller_sent_pt = NULL;
1240 if (found_sent_pt != NULL) {
1241 auto stmt = make_unique<Statement>();
1242 stmt->m_sent_pt = found_sent_pt;
1245 stmt->m_factual_type = 2;
1246 }
else { stmt->m_factual_type = 3; }
1247 stmt->m_state =
true;
1249 new_statement_pt = stmt.get();
1271 if (new_statement_pt != NULL) {
1273 auto inv = make_unique<Investigator>();
1274 inv->m_note =
"by a statement";
1275 inv->m_motivation = 1;
1276 inv->m_Statement_pt = new_statement_pt;
1279 inv->m_invest_dormant =
false;
1281 inv->m_root_of_a_thought_line =
true;
1282 invest_pt =
inv.get();
1304 this->
ErrorMessage(
"this->m_MRParameter_list.size() != 0");
1310 auto p = make_unique<MRParameterUnit>();
1311 p->CopyMRParameterUnitInforFromAnother(P_itr->get());
1331 this->
ErrorMessage(
"this->m_MRComponent_list.size() != 0");
1335 auto c = make_unique<MRComponentStateUnit>();
1336 c->CopyMRComponentStateInfoFromAnother(C_itr->get());
1356 this->
ErrorMessage(
"this->m_MRSupportSystem_list.size() != 0");
1360 auto ss = make_unique<MRSupportSystemStateUnit>();
1361 ss->CopyMRSupportSystemStateUnitInfoFromAnother(SS_itr->get());
1380 this->
ErrorMessage(
"this->m_MRAlarm_list.size() != 0");
1385 auto a = make_unique<MRAlarmUnit>();
1386 a->CopyMRAlarmUnitInfoFromAnother(A_itr->get());
1393 while (found ==
false && A_src_itr != _MR_pt->
m_MRAlarm_list.end()) {
1406 for (
auto P_itr = this->
m_MRParameter_list.begin(); P_itr != this->m_MRParameter_list.end() && found_pt == NULL; P_itr++) {
1407 if ((*P_itr)->m_ID == _ID) { found_pt = (
IDElement *) P_itr->get(); }
1410 if ((*C_itr)->m_ID == _ID) { found_pt = (
IDElement *) C_itr->get(); }
1414 if ((*SS_itr)->m_ID == _ID) { found_pt = (
IDElement *) SS_itr->get(); }
1417 if ((*A_itr)->m_ID == _ID) { found_pt = (
IDElement *) A_itr->get(); }
1423 for (
auto P_itr = this->
m_MRParameter_list.begin(); P_itr != this->m_MRParameter_list.end();
1424 P_itr++) { (*P_itr)->BuildConnectionsForThisMRParameter(_pt); }
1425 for (
auto C_itr = this->
m_MRComponent_list.begin(); C_itr != this->m_MRComponent_list.end();
1426 C_itr++) { (*C_itr)->BuildConnectionsForThisMRComponentState(_pt); }
1428 SS_itr++) { (*SS_itr)->BuildConnectionsForThisMRSupportSystemStateUnit(_pt); }
1429 for (
auto A_itr = this->
m_MRAlarm_list.begin(); A_itr != this->m_MRAlarm_list.end();
1430 A_itr++) { (*A_itr)->BuildConnectionsForThisMRAlarmUnit(_pt); }
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
void ReadAlarmIndication(double)
std::vector< std::unique_ptr< MRStateSchema > > m_history_state_list
Statement * m_recent_state_statement
std::string m_alarm_indicator_name
Statement * m_recent_action_statement
std::unique_ptr< MRStateSchema > m_recent_state
std::unique_ptr< MRStateSchema > m_recent_state
IDElement * m_Concept_ID_pt
Statement * m_recent_state_statement
std::string Control_Value_Indicator_ID
void ReadComponentStateIndication(double)
std::string Component_State_Indicator_ID
std::vector< std::unique_ptr< MRValueSchema > > m_history_position_value
Statement * m_recent_action_statement
std::unique_ptr< MRValueSchema > m_recent_position_value
std::vector< std::unique_ptr< MRStateSchema > > m_history_state
std::string m_parameter_concept_ID
float m_decrease_rate_threshold
void ReadParameterRate(double)
Statement * m_recent_trend
std::string m_parameter_indicator_ID
std::unique_ptr< MRValueSchema > m_recent_parameter_rate
IDElement * m_Concept_ID_pt
std::vector< std::unique_ptr< MRValueSchema > > m_parameter_history_rate
void UpdateTheRelevantInvestigator(int)
float m_increase_rate_threshold
float m_decrease_threshold
float m_increase_threshold
std::string m_parameter_rate_indicator_ID
void ReadParameterValue(double)
std::vector< std::unique_ptr< MRValueSchema > > m_parameter_history_value
std::unique_ptr< MRValueSchema > m_recent_parameter_value
void ReadSupportSystemStateIndication(double)
Statement * m_recent_action_statement
IDElement * m_Concept_ID_pt
Statement * m_recent_state_statement
std::string Support_System_State_Indicator_ID
std::unique_ptr< MRStateSchema > m_recent_state
std::vector< std::unique_ptr< MRStateSchema > > m_history_state
std::vector< std::unique_ptr< MRAlarmUnit > > m_MRAlarm_list
std::vector< std::unique_ptr< MRParameterUnit > > m_MRParameter_list
void FirstRoundCheckOftheMR()
decltype(m_MRAlarm_list) ::iterator m_MR_A_itr
decltype(m_MRSupportSystem_list) ::iterator m_MR_SS_itr
std::vector< std::unique_ptr< MRComponentStateUnit > > m_MRComponent_list
bool m_first_round_initiated_bl
std::vector< std::unique_ptr< MRSupportSystemStateUnit > > m_MRSupportSystem_list
virtual ~MentalRepresentation()
bool m_check_value_or_rate
void CopyMentalRepresentationFromAnother(MentalRepresentation *)
IDElement * CheckExistenceByIndicationName(std::string)
IDElement * CheckExistenceByConceptName(std::string)
void SaveMentalRepresentationInforToFile(std::string _path)
void ReadMentalRepresentationtInfoFromInputFile()
decltype(m_MRParameter_list) ::iterator m_MR_P_itr
void UpdateMRwithNewInference(Statement *)
void ErrorMessage(std::string)
IDElement * FindMRUnitByID(std::string)
decltype(m_MRComponent_list) ::iterator m_MR_C_itr
IDElement * CheckExistenceByConceptStrict(IDElement *)
void BuildConnectionsForMentalRepresentation(void *)
std::unique_ptr< ReasonMachine > m_RM
std::unique_ptr< KBConcept > m_Concept_Base
bool m_first_round_check_done
void WaitOneStepThereIsOneOrMoreOperatorBranches()
void AddDeltaToCognitiveLoad(float)
void AddANewStatement(Statement *)
SentenceUnit * CheckExistInSemanticPoolBySentence(SentenceUnit *)
void AddDeltaToSystemDynamics(float)
void AddNewInvestigator(Investigator *)
std::string getOATDirectory()
std::string getODMDirectory()
IDElement * m_comparison_pt
void RefreshStatementEndTimeToCurrentTime(int)
IDElement * m_investigator_ID_pt
float GetTimeBoundLater()
Scheduler SScheduler
Simulation scheduling, parses CLI options.
OperatorAT Action_Taker
Crew action execution model.
OperatorDM Decision_Maker
Crew decision-making model.
BranchRecord Branch_center
Dynamic event tree state.