← Documentation
ADS-IDAC Engine 5.0.0
KnowledgeUnit.cpp
Go to the documentation of this file.
1// KnowledgeUnit.cpp: implementation of the KnowledgeUnit class.
2//
4
5#include <string>
6#include <sstream>
7#include <iostream>
8#include <fstream>
9
10#include "KnowledgeUnit.h"
11#include "ReasonMachine.h"
12#include "../Crew/OperatorDM.h"
13#include "../Crew/OperatorAT.h"
14#include "../Global/SimulationContext.h"
15
16using namespace std;
17
18
20// Construction/Destruction
22
24{
25 this->m_ID_Type = 403;
26 this->m_Ancestor_pt = NULL;
27 this->m_Descendant_pt = NULL;
28 this->m_Permission_pt = NULL;
29 this->m_ID_anscestor = "";
30 this->m_ID_desscendant = "";
31 this->m_ID_permission = "";
32 this->m_accessable_bl = true;
33 this->m_knowledge_strength = 1;
34}
35
37{
38
39}
40
42{
43 string str, str1, str_ID;
44 string err_mes;
45 int v1;
46 float f1;
47
48 KnowledgeElement * KE_pt;
49 KnowledgeNode * KN_pt;
50 string ID_name;
51 stringstream conv;
52
53 ReasonMachine * RM_pt;
54 if (this->m_operator == sim::Operator::ODM)
55 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
56 else if (this->m_operator == sim::Operator::OAT)
57 {RM_pt = g_sim.Action_Taker.m_RM.get();}
58 else
59 {}
60
61 fin >> str;
62 if(str.compare("A_Knowledge_Unit") != 0)
63 {
64 err_mes = str1 + " is misplaced to a place of A_Knowledge_Unit";
65 this->ErrorMessage(err_mes);
66 return;
67 }
68
69 fin >> str >> v1;
70 if(str.compare("Causal_Type:") != 0)
71 {
72 err_mes = "Causal_Type of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
73 this->ErrorMessage(err_mes);
74 return;
75 }
76 this->m_causal_type = v1;
77
78 fin >> str >> v1;
79 if(str.compare("Inference_Type:") != 0)
80 {
81 err_mes = "Inference_Type of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
82 this->ErrorMessage(err_mes);
83 return;
84 }
85 this->m_inference_type = v1;
86
87 fin >> str >> f1;
88 if(str.compare("Knowledge_Unit_Strength:") != 0)
89 {
90 err_mes = "Knowledge_Unit_Strength: " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
91 this->ErrorMessage(err_mes);
92 return;
93 }
94 this->m_knowledge_strength = f1;
95
96 fin >> str >> f1;
97 if(str.compare("Forward_Retrieve_Rate:") != 0)
98 {
99 err_mes = "Forward_Retrieve_Rate of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
100 this->ErrorMessage(err_mes);
101 return;
102 }
103 this->m_forward_retrieve_weight = f1;
104
105 fin >> str >> f1;
106 if(str.compare("Backward_Retrieve_Rate:") != 0)
107 {
108 err_mes = "Backward_Retrieve_Rate of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
109 this->ErrorMessage(err_mes);
110 return;
111 }
113
114 fin >> str >> f1;
115 if(str.compare("Effective_Time_Forward_DeltaT1:") != 0)
116 {
117 err_mes = "Effective_Time_Forward_DeltaT1 of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
118 this->ErrorMessage(err_mes);
119 return;
120 }
121 this->m_deltaT1 = f1;
122
123 fin >> str >> f1;
124 if(str.compare("Effective_Time_Backward_DeltaT2:") != 0)
125 {
126 err_mes = "Effective_Time_Backward_DeltaT2 of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
127 this->ErrorMessage(err_mes);
128 return;
129 }
130 this->m_deltaT2 = f1;
131
132
133 fin >> str >> v1;
134 if(str.compare("UpperStream_Type:") != 0)
135 {
136 err_mes = "UpperStream_Type of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
137 this->ErrorMessage(err_mes);
138 return;
139 }
140
141 fin >> str >> str_ID;
142 if(str.compare("UpperStream_ID:")!=0)
143 {
144 err_mes = "UpperStream_ID of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
145 this->ErrorMessage(err_mes);
146 return;
147 }
148 if(v1==1)
149 {
150 //the upperstream is one KE
151 KE_pt = RM_pt->FindKnowledgeElementByID(str_ID);
152 if(KE_pt == NULL)
153 {
154 err_mes = "error in Knowledge_Unit_Base txt file: could not find KE: " + str_ID;
155 this->ErrorMessage(err_mes);
156 return;
157 }
158 this->m_Ancestor_pt = (IDElement*)KE_pt;
159 }
160 else
161 {
162 //The upperstream is a KnowledgeNode
163 KN_pt = RM_pt->FindKNByID(str_ID);
164 if(KN_pt == NULL)
165 {
166 err_mes = "error in Knowledge_Unit_Base txt file: could not find KN: " + str_ID;
167 this->ErrorMessage(err_mes);
168 return;
169 }
170 this->m_Ancestor_pt = (IDElement *)KN_pt;
171 }
172
173 //add the downstream information
174 fin >> str >> str_ID;
175 if(str.compare("DownStream_ID:")!=0)
176 {
177 err_mes = "DownStream_ID of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
178 this->ErrorMessage(err_mes);
179 return;
180 }
181 KE_pt = RM_pt->FindKnowledgeElementByID(str_ID);
182 if(KE_pt == NULL)
183 {
184 err_mes = "error in Knowledge_Unit_Base txt file: could not find KE: " + str_ID;
185 this->ErrorMessage(err_mes);
186 return;
187 }
188 this->m_Descendant_pt = (IDElement *)KE_pt;
189 this->m_ID = this->m_Ancestor_pt->m_ID + "->" + this->m_Descendant_pt->m_ID;
190
191 //check whether there is a permission KE
192 fin >> str >> v1;
193 if(str.compare("Is_There_A_Permission_Condition:")!=0)
194 {
195 err_mes = "Is_There_A_Permission_Condition of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
196 this->ErrorMessage(err_mes);
197 return;
198 }
199
200 if(v1 == 1)
201 {
202 //Add the permission KnowledgeElement
203 fin >> str >> str_ID;
204 if(str.compare("Permission_ID:")!=0)
205 {
206 err_mes = "Permission_ID of " + this->m_ID + " is missing in file Knowledge_Unit_Base txt file";
207 this->ErrorMessage(err_mes);
208 return;
209 }
210 KE_pt = RM_pt->FindKnowledgeElementByID(str_ID);
211 if(KE_pt == NULL)
212 {
213 err_mes = "error in Knowledge_Unit_Base txt file: could not find KE: " + str_ID;
214 this->ErrorMessage(err_mes);
215 return;
216 }
217 this->m_Permission_pt = (IDElement *)KE_pt;
218 }
219}
220
222{
223 cout << r5pars_.timesno << " " << str << " in KnowledgeUnit.cpp" << '\n';
224 ofstream fout("err messages.txt", ios::app);
225 fout << r5pars_.timesno << " " << str << '\n';
226 fout.close();
227 //r5pars_.terminateall = true;
228}
229
231{
232 this->m_ID_anscestor = this->m_Ancestor_pt->m_ID;
234 if(this->m_Permission_pt != NULL)
235 {
236 this->m_ID_permission = this->m_Permission_pt->m_ID;
237 }
238}
239
241{
242 this->CopyIDElementToRestartInfo((IDElement*) _KU_pt);
243 this->m_operator = _KU_pt->m_operator;
244 this->m_deltaT1 = _KU_pt->m_deltaT1;
245 this->m_deltaT2 = _KU_pt->m_deltaT2;
248 this->m_causal_type = _KU_pt->m_causal_type;
249 this->m_inference_type = _KU_pt->m_inference_type;
250 this->m_mechanism_type = _KU_pt->m_mechanism_type;
251
252 this->m_ID_anscestor = _KU_pt->m_ID_anscestor;
253 this->m_ID_desscendant = _KU_pt->m_ID_desscendant;
254 this->m_ID_permission = _KU_pt->m_ID_permission;
255
256 this->m_accessable_bl = _KU_pt->m_accessable_bl;
258
259}
260
262{
263 ReasonMachine * RM_pt;
264 RM_pt = (ReasonMachine *)_pt;
265/*
266 string m_ID_desscendant;
267 string m_ID_anscestor;
268 string m_ID_permission;
269
270 IDElement * m_Descendant_pt;
271 IDElement * m_Ancestor_pt;
272 IDElement * m_Permission_pt;
273*/
275 if(this->m_Descendant_pt == NULL)
276 {this->ErrorMessage("could not find the descendant of this knowledge unit " + this->m_ID_desscendant); return;}
277
279 if(this->m_Ancestor_pt == NULL)
280 {
281 this->m_Ancestor_pt = RM_pt->FindKNByID(this->m_ID_anscestor);
282 if(this->m_Ancestor_pt == NULL)
283 {this->ErrorMessage("could not find the anscestor of this knowledge unit " + this->m_ID_anscestor); return;}
284 }
285
286 if(this->m_ID_permission.compare("") == 0)
287 {return;}
288
290 if(this->m_Permission_pt == NULL)
291 {
292 this->m_Permission_pt = RM_pt->FindKNByID(this->m_ID_permission);
293 if(this->m_Permission_pt == NULL)
294 {this->ErrorMessage("could not find the permission KE of this knowledge unit " + this->m_ID_permission); return;}
295 }
296}
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
void CopyIDElementToRestartInfo(IDElement *)
Definition: IDElement.cpp:23
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
IDElement * m_Descendant_pt
Definition: KnowledgeUnit.h:24
void ErrorMessage(std::string)
IDElement * m_Permission_pt
Definition: KnowledgeUnit.h:26
IDElement * m_Ancestor_pt
Definition: KnowledgeUnit.h:25
float m_knowledge_strength
Definition: KnowledgeUnit.h:32
void BuildConnectionsToThisKU(void *)
bool m_accessable_bl
Definition: KnowledgeUnit.h:34
double m_forward_retrieve_weight
Definition: KnowledgeUnit.h:31
void ReadKnowledgeUnitFromInputFile(std::ifstream &)
std::string m_ID_permission
Definition: KnowledgeUnit.h:22
virtual ~KnowledgeUnit()
void CopyStaticKnowledgeUnitInfoFromAnother(KnowledgeUnit *)
void ConvertKnowledgeLinkInfoToString()
std::string m_ID_desscendant
Definition: KnowledgeUnit.h:20
std::string m_ID_anscestor
Definition: KnowledgeUnit.h:21
double m_backward_retrieve_weight
Definition: KnowledgeUnit.h:30
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
KnowledgeElement * FindKnowledgeElementByID(std::string)
KnowledgeNode * FindKNByID(std::string)
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.