←
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
16
using namespace
std;
17
18
20
// Construction/Destruction
22
23
KnowledgeUnit::KnowledgeUnit
()
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
36
KnowledgeUnit::~KnowledgeUnit
()
37
{
38
39
}
40
41
void
KnowledgeUnit::ReadKnowledgeUnitFromInputFile
(ifstream &fin)
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
}
112
this->
m_backward_retrieve_weight
= f1;
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
221
void
KnowledgeUnit::ErrorMessage
(
string
str)
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
230
void
KnowledgeUnit::ConvertKnowledgeLinkInfoToString
()
231
{
232
this->
m_ID_anscestor
= this->
m_Ancestor_pt
->
m_ID
;
233
this->
m_ID_desscendant
= this->
m_Descendant_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
240
void
KnowledgeUnit::CopyStaticKnowledgeUnitInfoFromAnother
(
KnowledgeUnit
* _KU_pt)
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
;
246
this->
m_forward_retrieve_weight
= _KU_pt->
m_forward_retrieve_weight
;
247
this->
m_backward_retrieve_weight
= _KU_pt->
m_backward_retrieve_weight
;
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
;
257
this->
m_knowledge_strength
= _KU_pt->
m_knowledge_strength
;
258
259
}
260
261
void
KnowledgeUnit::BuildConnectionsToThisKU
(
void
* _pt)
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
*/
274
this->
m_Descendant_pt
= RM_pt->
FindKnowledgeElementByID
(this->
m_ID_desscendant
);
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
278
this->
m_Ancestor_pt
= RM_pt->
FindKnowledgeElementByID
(this->
m_ID_anscestor
);
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
289
this->
m_Permission_pt
= RM_pt->
FindKnowledgeElementByID
(this->
m_ID_permission
);
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
}
KnowledgeUnit.h
ReasonMachine.h
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
g_sim
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
Definition:
SimulationContext.cpp:7
IDElement
Definition:
IDElement.h:12
IDElement::CopyIDElementToRestartInfo
void CopyIDElementToRestartInfo(IDElement *)
Definition:
IDElement.cpp:23
IDElement::m_ID_Type
int m_ID_Type
Definition:
IDElement.h:15
IDElement::m_ID
std::string m_ID
Definition:
IDElement.h:16
KnowledgeElement
Definition:
KnowledgeElement.h:13
KnowledgeNode
Definition:
KnowledgeNode.h:16
KnowledgeUnit
Definition:
KnowledgeUnit.h:12
KnowledgeUnit::m_Descendant_pt
IDElement * m_Descendant_pt
Definition:
KnowledgeUnit.h:24
KnowledgeUnit::ErrorMessage
void ErrorMessage(std::string)
Definition:
KnowledgeUnit.cpp:221
KnowledgeUnit::m_Permission_pt
IDElement * m_Permission_pt
Definition:
KnowledgeUnit.h:26
KnowledgeUnit::m_Ancestor_pt
IDElement * m_Ancestor_pt
Definition:
KnowledgeUnit.h:25
KnowledgeUnit::m_knowledge_strength
float m_knowledge_strength
Definition:
KnowledgeUnit.h:32
KnowledgeUnit::BuildConnectionsToThisKU
void BuildConnectionsToThisKU(void *)
Definition:
KnowledgeUnit.cpp:261
KnowledgeUnit::m_causal_type
int m_causal_type
Definition:
KnowledgeUnit.h:40
KnowledgeUnit::m_accessable_bl
bool m_accessable_bl
Definition:
KnowledgeUnit.h:34
KnowledgeUnit::m_forward_retrieve_weight
double m_forward_retrieve_weight
Definition:
KnowledgeUnit.h:31
KnowledgeUnit::ReadKnowledgeUnitFromInputFile
void ReadKnowledgeUnitFromInputFile(std::ifstream &)
Definition:
KnowledgeUnit.cpp:41
KnowledgeUnit::m_mechanism_type
int m_mechanism_type
Definition:
KnowledgeUnit.h:46
KnowledgeUnit::m_ID_permission
std::string m_ID_permission
Definition:
KnowledgeUnit.h:22
KnowledgeUnit::~KnowledgeUnit
virtual ~KnowledgeUnit()
Definition:
KnowledgeUnit.cpp:36
KnowledgeUnit::CopyStaticKnowledgeUnitInfoFromAnother
void CopyStaticKnowledgeUnitInfoFromAnother(KnowledgeUnit *)
Definition:
KnowledgeUnit.cpp:240
KnowledgeUnit::ConvertKnowledgeLinkInfoToString
void ConvertKnowledgeLinkInfoToString()
Definition:
KnowledgeUnit.cpp:230
KnowledgeUnit::m_inference_type
int m_inference_type
Definition:
KnowledgeUnit.h:35
KnowledgeUnit::m_ID_desscendant
std::string m_ID_desscendant
Definition:
KnowledgeUnit.h:20
KnowledgeUnit::m_deltaT1
float m_deltaT1
Definition:
KnowledgeUnit.h:28
KnowledgeUnit::m_deltaT2
float m_deltaT2
Definition:
KnowledgeUnit.h:29
KnowledgeUnit::m_ID_anscestor
std::string m_ID_anscestor
Definition:
KnowledgeUnit.h:21
KnowledgeUnit::KnowledgeUnit
KnowledgeUnit()
Definition:
KnowledgeUnit.cpp:23
KnowledgeUnit::m_operator
int m_operator
Definition:
KnowledgeUnit.h:33
KnowledgeUnit::m_backward_retrieve_weight
double m_backward_retrieve_weight
Definition:
KnowledgeUnit.h:30
Operator::m_RM
std::unique_ptr< ReasonMachine > m_RM
Definition:
Operator.h:55
ReasonMachine
Definition:
ReasonMachine.h:45
ReasonMachine::FindKnowledgeElementByID
KnowledgeElement * FindKnowledgeElementByID(std::string)
Definition:
ReasonMachine.cpp:2931
ReasonMachine::FindKNByID
KnowledgeNode * FindKNByID(std::string)
Definition:
ReasonMachine.cpp:2942
r5pars_
struct @0 r5pars_
sim::Operator::ODM
constexpr int ODM
Definition:
SimConstants.h:145
sim::Operator::OAT
constexpr int OAT
Definition:
SimConstants.h:144
SimulationContext::Action_Taker
OperatorAT Action_Taker
Crew action execution model.
Definition:
SimulationContext.h:47
SimulationContext::Decision_Maker
OperatorDM Decision_Maker
Crew decision-making model.
Definition:
SimulationContext.h:46
src
ADSIDAC
ReasonMachine
KnowledgeUnit.cpp
Generated by
1.9.4