← Documentation
ADS-IDAC Engine 5.0.0
Statement.cpp
Go to the documentation of this file.
1// Statement.cpp: implementation of the Statement class.
2//
4
5#include <string>
6#include <sstream>
7#include <iostream>
8#include <fstream>
9
10#include "Statement.h"
11#include "Investigator.h"
12#include "../Global/fmodule.h"
13#include "ReasonMachine.h"
14#include "../Crew/OperatorDM.h"
15#include "../Global/SimulationContext.h"
16
17using namespace std;
18
19
20
22// Construction/Destruction
24
26 //initialize the pointers, set to be NULL
27 this->m_investigator_ID_pt = NULL;
28 this->m_sent_pt = NULL;
29 this->m_diagnose_invest_ID_pt = NULL;
30
31 this->m_ID_investigator = "";
32 this->m_ID_sentence = "";
33 this->m_ID_DI = "";
34 //
35 this->m_state = true;
36 this->m_ID_Type = 101;
37 this->m_tbi_bl = true;
38 this->m_ongoing_bl = true;
39
40 this->m_ID_investigator = "";
41 this->m_ID_sentence = "";
42 this->m_ID_DI = "";
43
44}
45
47
48 this->m_upperstream_statement_list.clear();
49 this->m_downstream_statement_list.clear();
52}
53
54
55
56//DEL void Statement::UpdateEndTime(double _endTime, bool _ongoing)
57//DEL {
58//DEL Investigator * invest_pt;
59//DEL this->m_time_range.m_end_time = _endTime;
60//DEL this->m_ongoing_bl = _ongoing;
61//DEL if(this->m_investigator_ID_pt != NULL)
62//DEL {
63//DEL invest_pt = (Investigator*)(this->m_investigator_ID_pt);
64//DEL }
65//DEL invest_pt->UpdateEffectiveEndTimeRangeFromStatement(_endTime);
66//DEL }
67
69 if (this->m_sent_pt == NULL) { return; }//error message
71}
72
74 Investigator *invest_pt;
75 string prompt;
76 vector<Statement *>::iterator statement_itr;
77
78 ReasonMachine *RM_pt;
79 if (this->m_operator == sim::Operator::ODM) { RM_pt = g_sim.Decision_Maker.m_RM.get(); }
80 else if (this->m_operator == sim::Operator::OAT) { RM_pt = g_sim.Action_Taker.m_RM.get(); }
81 else {}//add error message
82
83 if (_type == 0) { this->m_time_range.m_time_before = r5pars_.timesno; }
84 else if (_type == 1) { this->m_time_range.m_end_time = r5pars_.timesno; }
85 //type 3, not change the time
86
87
88 this->m_last_activated_time = r5pars_.timesno;
90
91 if (this->m_investigator_ID_pt != NULL) {
92 invest_pt = (Investigator *) this->m_investigator_ID_pt;
93 if (invest_pt->m_explained == 1)//caution of this
94 {
95 invest_pt->UpdateEffectiveEndTimeRangeFromStatement(r5pars_.timesno, true);
96 }
97 }
98
99 //print prompt
100 prompt = "A Statement is updated: ";
101
102 if (this->m_sent_pt == NULL) {
103 prompt = "it is NULL!";
104 this->ErrorMessage(prompt);
105 } else {
106 prompt += this->GetThisStatementWords();
107 }
108 this->PrintMessage(prompt);
109
110 for (statement_itr = this->m_downstream_statement_list.begin();
111 statement_itr != this->m_downstream_statement_list.end(); statement_itr++) {
112 (*statement_itr)->RefreshStatementEndTimeToCurrentTime(_type);
113 }
114
115}
116
118 string str;
119
120 ofstream fout("RMI.txt", ios::app);
121 if (this->m_sent_pt == NULL) {
122 str = "This statement is NULL, check the program";
123 cout << str << '\n';
124 fout << str << '\n';
125 } else {
126 str = this->m_sent_pt->m_ID;
127 str += " is ";
128 if (this->m_state == true) {
129 str += "TRUE; ";
130 } else {
131 str += "FALSE; ";
132 }
133 cout << str;
134 fout << str;
135
136 str = "";
137 if (this->m_time_range.m_start_time != 0) {
138 cout << "from " << this->m_time_range.m_start_time << " to " << this->m_time_range.m_end_time << '\n';
139 fout << "from " << this->m_time_range.m_start_time << " to " << this->m_time_range.m_end_time << '\n';
140 } else {
141 cout << "time range ( " << this->m_time_range.m_time_after << ", " << this->m_time_range.m_time_before << ")"
142 << '\n';
143 fout << "time range ( " << this->m_time_range.m_time_after << ", " << this->m_time_range.m_time_before << ")"
144 << '\n';
145 }
146 }
147 fout.close();
148}
149
150void Statement::ErrorMessage(string str) {
151 cout << r5pars_.timesno << " " << str << " in Statement.cpp" << '\n';
152 ofstream fout("err messages.txt", ios::app);
153 fout << r5pars_.timesno << " " << str << '\n';
154 fout.close();
155 //r5pars_.terminateall = true;
156
157
158}
160 string str;
161 stringstream conv;
162 str = this->m_sent_pt->m_ID;
163 str += " is ";
164 if (this->m_state == true) {
165 str += "true";
166 } else {
167 str += "false";
168 }
169 str += ". ";
170 if (this->m_time_range.m_start_time != 0) {
171 str += "started from ";
172 conv.str("");
173 conv << this->m_time_range.m_start_time;
174 str += conv.str();
175 } else {
176 str += "happened after ";
177 conv.str("");
178 conv << this->m_time_range.m_time_after;
179 str += conv.str();
180 }
181 str += " , ";
182
183 if (this->m_time_range.m_end_time != 0) {
184 str += " till ";
185 conv.str("");
186 conv << this->m_time_range.m_end_time;
187 str += conv.str();
188 } else {
189 str += " before ";
190 conv.str("");
191 conv << this->m_time_range.m_time_before;
192 str += conv.str();
193 }
194 return str;
195}
196
197void Statement::PrintMessage(string str) {
198 cout << "Time: " << r5pars_.timesno << ": " << str << '\n';
199
200 //test
201 ofstream fout("RMI.txt", ios::app);
202 fout << "Time: " << r5pars_.timesno << ": " << str << '\n';
203 fout.close();
204}
205
207 this->m_confidence = _upper_statement_pt->m_confidence;
208 this->m_ongoing_bl = _upper_statement_pt->m_ongoing_bl;
209 this->m_time_range.m_end_time = _upper_statement_pt->m_time_range.m_end_time;
210 this->m_time_range.m_start_time = _upper_statement_pt->m_time_range.m_start_time;
211 this->m_time_range.m_time_after = _upper_statement_pt->m_time_range.m_time_after;
212 this->m_time_range.m_time_before = _upper_statement_pt->m_time_range.m_time_before;
213}
214
216/*
217int m_operator;
218 int m_factual_type; //1, reading from control panel; 2, directly inferred; 3, reasoning result from upperstream; 4, probabilistic reasoning result from downstream
219 float m_confidence;
220 bool m_state;
221 double m_last_activated_time;
222 double m_time_generated;
223 bool m_ongoing_bl;
224 bool m_tbi_bl;
225
226*/
227 this->CopyIDElementToRestartInfo((IDElement *) _state_pt);
228 this->CopyActivationToRestartInfo((Activation *) _state_pt);
229
230 this->m_operator = _state_pt->m_operator;
231 this->m_factual_type = _state_pt->m_factual_type;
232 this->m_confidence = _state_pt->m_confidence;
233 this->m_state = _state_pt->m_state;
235 this->m_time_generated = _state_pt->m_time_generated;
236 this->m_ongoing_bl = _state_pt->m_ongoing_bl;
237 this->m_tbi_bl = _state_pt->m_tbi_bl;
239
240 /* TimeRange m_time_range;
241IDElement * m_investigator_ID_pt;
242SentenceUnit * m_sent_pt;
243IDElement * m_diagnose_invest_ID_pt;
244vector<Statement *> m_upperstream_statement_list;
245vector<Statement *> m_downstream_statement_list;
246
247
248string m_ID_investigator;
249string m_ID_sentence;
250string m_ID_DI;
251*/
252 if (_state_pt->m_investigator_ID_pt != NULL) { this->m_ID_investigator = _state_pt->m_investigator_ID_pt->m_ID; }
253 else { this->m_ID_investigator = _state_pt->m_ID_investigator; }
254
255 if (_state_pt->m_sent_pt != NULL) { this->m_ID_sentence = _state_pt->m_sent_pt->m_ID; }
256 else { this->m_ID_sentence = _state_pt->m_ID_sentence; }
257
258 if (_state_pt->m_diagnose_invest_ID_pt != NULL) { this->m_ID_DI = _state_pt->m_diagnose_invest_ID_pt->m_ID; }
259 else { this->m_ID_DI = _state_pt->m_ID_DI; }
260
261 /*
262 vector<string> m_ID_upperstream_statement_list;
263 vector<string> m_ID_downstream_statement_list;
264 */
265
266 vector<string>::iterator str_itr;
267 vector<Statement *>::iterator state_itr;
268 //Statement * state_pt;
269 string ID;
270
271 if (this->m_ID_upperstream_statement_list.size() != 0) {
272 this->ErrorMessage("this->m_ID_upperstream_statement_list.size() != 0");
273 return;
274 }
275 if (this->m_ID_downstream_statement_list.size() != 0) {
276 this->ErrorMessage("this->m_ID_downstream_statement_list.size() != 0");
277 return;
278 }
279
280 if (_state_pt->m_upperstream_statement_list.size() != 0) {//copy from the statement list
281 for (state_itr = _state_pt->m_upperstream_statement_list.begin();
282 state_itr != _state_pt->m_upperstream_statement_list.end(); state_itr++) {
283 ID = (*state_itr)->m_ID;
284 this->m_ID_upperstream_statement_list.push_back(ID);
285 }
286 } else {//copy from the string list;
287 for (str_itr = _state_pt->m_ID_upperstream_statement_list.begin();
288 str_itr != _state_pt->m_ID_upperstream_statement_list.end(); str_itr++) {
289 ID = *str_itr;
290 this->m_ID_upperstream_statement_list.push_back(ID);
291 }
292 }
293
294}
295
297 ReasonMachine *RM_pt;
298 RM_pt = (ReasonMachine *) _pt;
299
300 //SentenceUnit * m_sent_pt;
301 this->m_sent_pt = RM_pt->SearchSentenceByID(this->m_ID_sentence);
302 if (this->m_sent_pt == NULL) {
303 this->ErrorMessage("could not find the sentence for this statement " + this->m_ID_sentence);
304 return;
305 }
306
307 //IDElement * m_investigator_ID_pt;
308 if (this->m_ID_investigator.compare("") != 0) {
309 this->m_investigator_ID_pt = (IDElement *) (RM_pt->FindInvestigatorByID(this->m_ID_investigator));
310 if (this->m_investigator_ID_pt == NULL) {
311 this->ErrorMessage("could not find the Investigator for this statement" + this->m_ID_investigator);
312 return;
313 }
314 }
315 //IDElement * m_diagnose_invest_ID_pt;
316 if (this->m_ID_DI.compare("") != 0) {
318 (IDElement *) (RM_pt->m_event_schema_base->FindDiagnoseInvestigatorByID(this->m_ID_DI));
319 if (this->m_diagnose_invest_ID_pt == NULL) {
320 this->ErrorMessage("could not find the Investigator " + this->m_ID_DI);
321 return;
322 }
323 }
324
325 Statement *state_pt;
326 vector<string>::iterator str_itr;
327
328 if (this->m_upperstream_statement_list.size() != 0) {
329 this->ErrorMessage("this->m_upperstream_statement_list.size() != 0 before rebuild the connection");
330 return;
331 }
332 if (this->m_downstream_statement_list.size() != 0) {
333 this->ErrorMessage("this->m_downstream_statement_list.size() != 0 before rebuild the connection");
334 return;
335 }
336
337 //vector<Statement *> m_upperstream_statement_list;
338 for (str_itr = this->m_ID_upperstream_statement_list.begin(); str_itr != this->m_ID_upperstream_statement_list.end();
339 str_itr++) {
340 state_pt = RM_pt->FindStatementByID(*str_itr);
341 if (state_pt == NULL) {
342 this->ErrorMessage("could not find the upperstream statement " + *str_itr);
343 return;
344 }
345 this->m_upperstream_statement_list.push_back(state_pt);
346 }
347 //vector<Statement *> m_downstream_statement_list;
348 for (str_itr = this->m_ID_downstream_statement_list.begin(); str_itr != this->m_ID_downstream_statement_list.end();
349 str_itr++) {
350 state_pt = RM_pt->FindStatementByID(*str_itr);
351 if (state_pt == NULL) {
352 this->ErrorMessage("could not find the downstream statement " + *str_itr);
353 return;
354 }
355 this->m_downstream_statement_list.push_back(state_pt);
356 }
357}
358
359//DEL void Statement::ActivateRelatedInvestigatorIfNeeded()
360//DEL {
361//DEL Investigator * invest_pt;
362//DEL if(this->m_)
363//DEL
364//DEL }
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
double m_change_ratio
Definition: Activation.h:19
double m_activation
Definition: Activation.h:22
void CopyActivationToRestartInfo(Activation *)
Definition: Activation.cpp:48
void CopyIDElementToRestartInfo(IDElement *)
Definition: IDElement.cpp:23
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
void UpdateEffectiveEndTimeRangeFromStatement(double, bool)
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
SentenceUnit * SearchSentenceByID(std::string)
void ActivationUpdateByRefreshAStatement(Statement *)
Statement * FindStatementByID(std::string)
Investigator * FindInvestigatorByID(std::string)
std::unique_ptr< EventSchemaBase > m_event_schema_base
IDElement * m_diagnose_invest_ID_pt
Definition: Statement.h:44
std::vector< Statement * > m_downstream_statement_list
Definition: Statement.h:46
void PropagateFullActivationToSemanticSentence()
Definition: Statement.cpp:68
void ErrorMessage(std::string)
Definition: Statement.cpp:150
std::string m_ID_sentence
Definition: Statement.h:49
float m_confidence
Definition: Statement.h:34
std::vector< Statement * > m_upperstream_statement_list
Definition: Statement.h:45
void PrintThisStatement()
Definition: Statement.cpp:117
void BuildConnectionsToThisStatement(void *)
Definition: Statement.cpp:296
std::vector< std::string > m_ID_upperstream_statement_list
Definition: Statement.h:51
int m_operator
Definition: Statement.h:32
bool m_tbi_bl
Definition: Statement.h:39
TimeRange m_time_range
Definition: Statement.h:40
bool m_ongoing_bl
Definition: Statement.h:38
virtual ~Statement()
Definition: Statement.cpp:46
void CopyStatementInfoFromAnother(Statement *)
Definition: Statement.cpp:215
double m_last_activated_time
Definition: Statement.h:36
std::vector< std::string > m_ID_downstream_statement_list
Definition: Statement.h:52
int m_factual_type
Definition: Statement.h:33
std::string GetThisStatementWords()
Definition: Statement.cpp:159
SentenceUnit * m_sent_pt
Definition: Statement.h:43
std::string m_ID_DI
Definition: Statement.h:50
void CopyAuxInfoFromUpperstreamStatement(Statement *)
Definition: Statement.cpp:206
void RefreshStatementEndTimeToCurrentTime(int)
Definition: Statement.cpp:73
IDElement * m_investigator_ID_pt
Definition: Statement.h:42
bool m_state
Definition: Statement.h:35
std::string m_ID_investigator
Definition: Statement.h:48
void PrintMessage(std::string)
Definition: Statement.cpp:197
double m_time_generated
Definition: Statement.h:37
float m_start_time
Definition: TimeRange.h:21
float m_time_before
Definition: TimeRange.h:19
void CopyTimeRangeFromAnother(TimeRange &)
Definition: TimeRange.cpp:91
float m_time_after
Definition: TimeRange.h:18
float m_end_time
Definition: TimeRange.h:20
struct @0 r5pars_
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.