← Documentation
ADS-IDAC Engine 5.0.0
InstantiationBase.cpp
Go to the documentation of this file.
1// InstantiationBase.cpp: implementation of the InstantiationBase class.
2//
4
5#include "InstantiationBase.h"
6#include "../Crew/OperatorDM.h"
7#include "../Crew/OperatorAT.h"
8#include "ReasonMachine.h"
9#include "../Global/SimulationContext.h"
10using namespace std;
11
12
14// Construction/Destruction
16
18{
19
20}
21
23{
24
25 this->m_label_list.clear();
26 this->m_instantiation_list.clear();
27
28}
29
31{
32 ReasonMachine * RM_pt;
33 if (this->m_operator == sim::Operator::ODM)
34 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
35 else if (this->m_operator == sim::Operator::OAT)
36 {RM_pt = g_sim.Action_Taker.m_RM.get();}
37 else
38 {}//add error message
39
40 string file_name, name;
41 string err_mes;
42 string str, str1, str2;
43 int n_Unit, i, j, n_member;
44 bool found_file;
45 ifstream fin;
46 ConceptComposedUnit * CC_pt;
47 Label * label_pt;
48 Instantiation * Inst_pt;
49 IDElement * ID_pt;
50 vector<IDElement*>::iterator ID_itr;
51
52 if (this->m_operator == sim::Operator::ODM)
53 {file_name = g_sim.SScheduler.getODMDirectory();
54 file_name += "RM//";
55 file_name += "KB_ODM_Instantiation_Base.txt";}
56 else if (this->m_operator == sim::Operator::OAT)
57 {file_name = g_sim.SScheduler.getOATDirectory();
58 file_name += "RM//";
59 file_name += "KB_OAT_Instantiation_Base.txt";}
60 fin.open(file_name.c_str(), ios::in);
61 if(!fin.is_open()){
62 err_mes = "can not find file: " + file_name;
63 this->ErrorMessage(err_mes);
64 found_file = false;
65 return; //has to return and close this program if there is an error
66 }
67 else{
68 fin >> str >> n_Unit;
69 if(str.compare("Number_of_Instantiation_Label_Groups:") != 0)
70 {
71 err_mes = str + " is incorrectly in the position of Number_of_Instantiation_Label_Groups:";
72 this->ErrorMessage(err_mes);
73 return;
74 }
75 for (i = 0; i < n_Unit; i++)
76 {
77 auto label_owned = std::make_unique<Label>();
78 label_pt = label_owned.get();
79 this->m_label_list.push_back(std::move(label_owned));
80 fin >> str >> name;
81 if(str.compare("Group_Name:") != 0)
82 {
83 err_mes = str + " is incorrectly in the position of Group_Name:";
84 this->ErrorMessage(err_mes);
85 return;
86 }
87 label_pt->m_lable_name = name;
88
89 fin >> str >> n_member;
90 if(str.compare("Number_of_Members:") != 0)
91 {
92 err_mes = str + " is incorrectly in the position of Number_of_Members:";
93 this->ErrorMessage(err_mes);
94 return;
95 }
96 fin >> str;
97 if(str.compare("Member_list:") != 0)
98 {
99 err_mes = str + " is incorrectly in the position of Member_list:";
100 this->ErrorMessage(err_mes);
101 return;
102 }
103 for(j = 0; j < n_member; j++)
104 {
105 fin >> name;
106 ID_pt = NULL;
107 ID_pt = RM_pt->m_Concept_Base->CheckExistanceOfConcept(name);
108 if(ID_pt == NULL)
109 {
110 err_mes = "could not find " + name + " in the concept base";
111 this->ErrorMessage(err_mes);
112 return;
113 }
114 label_pt->m_label_option_list.push_back(ID_pt);
115 }
116 }
117 fin >> str >> n_Unit;
118 if(str.compare("Number_of_Instantiation_Groups:") != 0)
119 {
120 err_mes = str + " is incorrectly in the position of Number_of_Instantiation_Label_Groups:";
121 this->ErrorMessage(err_mes);
122 return;
123 }
124 for(i = 0; i < n_Unit; i++)
125 {
126 auto inst_owned = std::make_unique<Instantiation>();
127 Inst_pt = inst_owned.get();
128 fin >> str >> name;
129 if(str.compare("Indefinite_Concept:") != 0)
130 {
131 err_mes = str + " is incorrectly in the position of Indefinite_Concept:";
132 this->ErrorMessage(err_mes);
133 return;
134 }
136 {
137 err_mes = name + " already existed in the list";
138 this->ErrorMessage(err_mes);
139 return;
140 }
141 this->m_instantiation_list.push_back(std::move(inst_owned));
142 Inst_pt->m_indefinite_instance_pt = RM_pt->m_Concept_Base->checkExistanceOfConceptComposedUnit(name);
143 if(Inst_pt->m_indefinite_instance_pt == NULL)
144 {
145 err_mes = "could not find " + name + " in the Concept Base";
146 this->ErrorMessage(err_mes);
147 return;
148 }
149 fin >> str >> name;
150 if(str.compare("Corresponding_Basic_Group:") != 0)
151 {
152 err_mes = str + " is incorrectly in the position of Corresponding_Basic_Group:";
153 this->ErrorMessage(err_mes);
154 return;
155 }
156 Inst_pt->m_ID_lable_group_name = name;
157 Inst_pt->m_label_pt = this->CheckExistanceOfLabelGroupByName(name);
158 if(Inst_pt->m_label_pt == NULL)
159 {
160 err_mes = "could not find " + name + " in the Label list";
161 this->ErrorMessage(err_mes);
162 return;
163 }
164 fin >> str >> n_member;
165 if(str.compare("Number_of_Member:") != 0)
166 {
167 err_mes = str + " is incorrectly in the position of Number_of_Member:";
168 this->ErrorMessage(err_mes);
169 return;
170 }
171 fin >> str;
172 if(str.compare("Member_list:") != 0)
173 {
174 err_mes = str + " is incorrectly in the position of Member_list:";
175 this->ErrorMessage(err_mes);
176 return;
177 }
178 for(j=0; j<n_member; j++)
179 {
180 fin >> name;
181 CC_pt = NULL;
182 CC_pt = RM_pt->m_Concept_Base->checkExistanceOfConceptComposedUnit(name);
183 if(ID_pt == NULL)
184 {
185 err_mes = "could not find " + name + " in the concept base";
186 this->ErrorMessage(err_mes);
187 return;
188 }
189 Inst_pt->m_instance_list.push_back(CC_pt);
191 for(ID_itr = Inst_pt->m_label_pt->m_label_option_list.begin(); ID_itr != Inst_pt->m_label_pt->m_label_option_list.end(); ID_itr ++)
192 {
193 if(CC_pt->CheckWhetherThisConceptContainASubConceptByPt(*ID_itr) == true)
194 {
195 CC_pt->m_label_ID_pt = *ID_itr;
196 break;
197 }
198 }
199 if(CC_pt->m_label_ID_pt == NULL)
200 {
201 err_mes = "could not find a label option for " + CC_pt->m_ID;
202 this->ErrorMessage(err_mes);
203 return;
204 }
205 }
206 }
207 }
208
209}
210
212{
213 cout << r5pars_.timesno << " " << str << " in InstantiationBase.cpp" << '\n';
214 ofstream fout("err messages.txt", ios::app);
215 fout << r5pars_.timesno << " " << str << '\n';
216 fout.close();
217 //r5pars_.terminateall = true;
218}
219
221{
222 Label * label_pt = NULL;
223 for(auto &e : this->m_label_list)
224 {
225 if(e->m_lable_name == name)
226 {
227 label_pt = e.get();
228 }
229 }
230 return label_pt;
231}
232
234{
235 Instantiation * Inst_pt = NULL;
236 for(auto &e : this->m_instantiation_list)
237 {
238 if(e->m_indefinite_instance_pt->m_ID == name)
239 {
240 Inst_pt = e.get();
241 }
242 }
243 return Inst_pt;
244}
245
247{
248 Label * lb_pt = NULL;
249 ConceptComposedUnit * CC_pt = NULL;
250 if(_sent_pt->m_subject_pt->m_ID_Type == 002)
251 {
252 CC_pt = (ConceptComposedUnit *)(_sent_pt->m_subject_pt);
253 for(auto &e : this->m_instantiation_list)
254 {
255 if(e->m_indefinite_instance_pt == CC_pt)
256 {
257 if(lb_pt == NULL)
258 {
259 lb_pt = e->m_label_pt;
260 }
261 else if(lb_pt != e->m_label_pt )
262 {
263 this->ErrorMessage("Error: " + _sent_pt->m_ID + " contains more than one indefinite items!");
264 return NULL;
265 }
266 }
267 }
268 }
269
270 if(_sent_pt->m_object_pt == NULL)
271 {
272 return lb_pt;
273 }
274 if(_sent_pt->m_object_pt->m_ID_Type == 002)
275 {
276 CC_pt = (ConceptComposedUnit *)(_sent_pt->m_object_pt);
277 for(auto &e : this->m_instantiation_list)
278 {
279 if(e->m_indefinite_instance_pt == CC_pt)
280 {
281 if(lb_pt == NULL)
282 {
283 lb_pt = e->m_label_pt;
284 }
285 else if(lb_pt != e->m_label_pt )
286 {
287 this->ErrorMessage("Error: " + _sent_pt->m_ID + " contains more than one indefinite items!");
288 return NULL;
289 }
290 }
291 }
292 }
293
294 return lb_pt;
295
296}
297
299{
300 Label * found_label_group_pt = NULL;
301
302 for(auto &label_e : this->m_label_list)
303 {
304 if(found_label_group_pt != NULL) break;
305 for(auto *ID_e : label_e->m_label_option_list)
306 {
307 if(ID_e == _ID_pt)
308 {
309 found_label_group_pt = label_e.get();
310 break;
311 }
312 }
313 }
314 return found_label_group_pt;
315}
316
318{//this function does not establish the pointer connections
319 Label * label_pt;
320 Instantiation * inst_pt;
321
322 this->m_operator = _IB_pt->m_operator;
323
324 if(this->m_label_list.size() != 0)
325 {
326 this->ErrorMessage("this->m_label_list.size() != 0");
327 }
328 for(auto &e : _IB_pt->m_label_list)
329 {
330 auto label_owned = std::make_unique<Label>();
331 label_owned->CopyLabelInfoFromAnotherLabel(e.get());
332 this->m_label_list.push_back(std::move(label_owned));
333 }
334
335 if(this->m_instantiation_list.size() != 0)
336 {
337 this->ErrorMessage("this->m_instantiation_list.size() != 0");
338 }
339 for(auto &e : _IB_pt->m_instantiation_list)
340 {
341 auto inst_owned = std::make_unique<Instantiation>();
342 inst_owned->CopyInfoFromAnotherInstantiationGroup(e.get());
343 this->m_instantiation_list.push_back(std::move(inst_owned));
344 }
345
346}
347
349{
350 for(auto &e : this->m_label_list)
351 {
352 e->ConvertLabelInfoToStringForm();
353 }
354 for(auto &e : this->m_instantiation_list)
355 {
356 e->ConvertInstantiationInfoToString();
357 }
358}
359
361{
362 ReasonMachine * RM_pt;
363 RM_pt = (ReasonMachine *)_pt;
364
365 //vector<unique_ptr<Label>> m_label_list;
366 for(auto &e : this->m_label_list)
367 {e->BuildConnectionsForThisLabel(_pt);}
368
369 //vector<unique_ptr<Instantiation>> m_instantiation_list;
370 for(auto &e : this->m_instantiation_list)
371 {e->BuildConnectionsForThisInstantiation(_pt);}
372}
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
document e
IDElement * m_Indefinite_Concept_ID_pt
bool CheckWhetherThisConceptContainASubConceptByPt(IDElement *)
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
void ErrorMessage(std::string)
void ReadInstantiationBaseFromInputFile()
Label * CheckWhetherASentenceContainIndefiniteItem(SentenceUnit *)
std::vector< std::unique_ptr< Instantiation > > m_instantiation_list
Instantiation * CheckExistanceOfInstantiationGroupByIndefiniteConceptName(std::string)
Label * FindLabelGroupByLabelID(IDElement *)
void BuildConnectionsForTheInstantiationBase(void *)
std::vector< std::unique_ptr< Label > > m_label_list
Label * CheckExistanceOfLabelGroupByName(std::string)
void CopyInstantiationBaseFromAnotherIB(InstantiationBase *_IB_pt)
ConceptComposedUnit * m_indefinite_instance_pt
Definition: Instantiation.h:22
Label * m_label_pt
Definition: Instantiation.h:21
std::vector< ConceptComposedUnit * > m_instance_list
Definition: Instantiation.h:23
std::string m_ID_lable_group_name
Definition: Instantiation.h:27
Definition: Label.h:13
std::vector< IDElement * > m_label_option_list
Definition: Label.h:21
std::string m_lable_name
Definition: Label.h:20
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
std::unique_ptr< KBConcept > m_Concept_Base
std::string getOATDirectory()
Definition: Scheduler.cpp:622
std::string getODMDirectory()
Definition: Scheduler.cpp:619
IDElement * m_object_pt
Definition: SentenceUnit.h:41
IDElement * m_subject_pt
Definition: SentenceUnit.h:40
struct @0 r5pars_
constexpr int ODM
Definition: SimConstants.h:145
constexpr int OAT
Definition: SimConstants.h:144
Scheduler SScheduler
Simulation scheduling, parses CLI options.
OperatorAT Action_Taker
Crew action execution model.
OperatorDM Decision_Maker
Crew decision-making model.