←
Documentation
ADS-IDAC Engine
5.0.0
KnowledgeNode.cpp
Go to the documentation of this file.
1
// KnowledgeNode.cpp: implementation of the KnowledgeNode class.
2
//
4
5
#include <string>
6
#include <sstream>
7
8
#include "
KnowledgeNode.h
"
9
#include "
ReasonMachine.h
"
10
#include "../Global/fmodule.h"
11
#include "../Crew/OperatorDM.h"
12
#include "../Crew/OperatorAT.h"
13
#include "../Global/SimulationContext.h"
14
15
using namespace
std;
16
17
19
// Construction/Destruction
21
22
KnowledgeNode::KnowledgeNode
()
23
{
24
this->
m_ID_Type
= 402;
25
}
26
27
KnowledgeNode::~KnowledgeNode
()
28
{
29
this->
m_ID_KE_list
.clear();
30
this->
M_KElement_list
.clear();
31
32
}
33
34
void
KnowledgeNode::ReadThisKNinfoFromFile
(ifstream &fin)
35
{
36
string
str, ID_name;
37
int
i, n_unit, v1;
38
KnowledgeElement
* KE_pt;
39
string
err_mes;
40
41
ReasonMachine
* RM_pt;
42
if
(this->
m_operator
==
sim::Operator::ODM
)
43
{RM_pt =
g_sim
.
Decision_Maker
.
m_RM
.get();}
44
else
if
(this->
m_operator
==
sim::Operator::OAT
)
45
{RM_pt =
g_sim
.
Action_Taker
.
m_RM
.get();}
46
else
47
{}
//add error message
48
49
//read the ID name
50
fin >> str >> ID_name;
51
if
(str.compare(
"Knowledge_Node_ID:"
) != 0)
52
{
53
err_mes = ID_name +
" is not in a line with Knowledge_Node_ID:"
;
54
this->
ErrorMessage
(err_mes);
55
return
;
56
}
57
if
(RM_pt->
FindKNByID
(ID_name) != NULL || RM_pt->
FindKnowledgeElementByID
(ID_name) != NULL)
58
{
59
err_mes = ID_name +
" already exists. Use a different ID name"
;
60
this->
ErrorMessage
(err_mes);
61
return
;
62
}
63
this->
m_ID
= ID_name;
64
65
//read the node type
66
//2--and gate; 3--or gate;
67
fin >> str >> v1;
68
if
(str.compare(
"Node_Gate_Type:"
) != 0)
69
{
70
err_mes =
"Node_Gate_Type of "
+ ID_name +
" is not in right position"
;
71
this->
ErrorMessage
(err_mes);
72
return
;
73
}
74
this->
m_Node_Type
= v1;
75
76
fin >> str >> n_unit;
77
if
(str.compare(
"No_of_KE_Units:"
) != 0)
78
{
79
err_mes =
"No_of_KE_Units of "
+ ID_name +
" is missing"
;
80
this->
ErrorMessage
(err_mes);
81
return
;
82
}
83
84
for
(i = 0; i < n_unit; i++)
85
{
86
fin >> ID_name;
87
KE_pt = RM_pt->
FindKnowledgeElementByID
(ID_name);
88
if
(KE_pt == NULL)
89
{
90
err_mes =
"could not find KE: "
+ ID_name +
" for KU: "
+ this->
m_ID
;
91
this->
ErrorMessage
(err_mes);
92
return
;
93
}
94
this->
M_KElement_list
.push_back(KE_pt);
95
}
96
}
97
98
void
KnowledgeNode::ErrorMessage
(
string
str)
99
{
100
cout <<
r5pars_
.timesno <<
" "
<< str <<
"in KnowledgeNode.cpp"
<<
'\n'
;
101
ofstream fout(
"err messages.txt"
, ios::app);
102
fout <<
r5pars_
.timesno <<
" "
<< str <<
'\n'
;
103
fout.close();
104
//r5pars_.terminateall = true;
105
}
106
107
void
KnowledgeNode::ConvertKNinfoToStringForm
()
108
{
109
vector<KnowledgeElement *>::iterator KE_itr;
110
string
ID;
111
if
(this->
m_ID_KE_list
.size() != 0)
112
{
113
this->
ErrorMessage
(
"this->m_ID_KE_list.size() != 0"
);
114
}
115
116
for
(KE_itr = this->
M_KElement_list
.begin(); KE_itr != this->M_KElement_list.end(); KE_itr++)
117
{
118
ID = (*KE_itr)->m_ID;
119
this->
m_ID_KE_list
.push_back(ID);
120
}
121
}
122
123
void
KnowledgeNode::CopyStaticKNinfoFromAnother
(
KnowledgeNode
* _KN_pt)
124
{
125
vector<string>::iterator str_itr;
126
string
ID;
127
this->
CopyIDElementToRestartInfo
((
IDElement
*)_KN_pt);
128
this->
m_Node_Type
= _KN_pt->
m_Node_Type
;
129
this->
m_operator
= _KN_pt->
m_operator
;
130
131
if
(this->
m_ID_KE_list
.size() != 0)
132
{
133
this->
ErrorMessage
(
"this->m_ID_KE_list.size() != 0"
);
134
return
;
135
}
136
for
(str_itr = _KN_pt->
m_ID_KE_list
.begin(); str_itr != _KN_pt->
m_ID_KE_list
.end(); str_itr++)
137
{
138
ID = *str_itr;
139
this->
m_ID_KE_list
.push_back(ID);
140
}
141
}
142
143
void
KnowledgeNode::BuildConnectionsToThisKN
(
void
* _pt)
144
{
145
ReasonMachine
* RM_pt;
146
RM_pt = (
ReasonMachine
*)_pt;
147
/*
148
vector<KnowledgeElement *> M_KElement_list;
149
vector<string> m_ID_KE_list;
150
*/
151
vector<string>::iterator str_itr;
152
KnowledgeElement
* KE_pt;
153
if
(this->
M_KElement_list
.size() != 0)
154
{this->
ErrorMessage
(
"this->M_KElement_list.size() != 0 before building the connection"
);
return
;}
155
for
(str_itr = this->
m_ID_KE_list
.begin(); str_itr != this->m_ID_KE_list.end(); str_itr++)
156
{
157
KE_pt = RM_pt->
FindKnowledgeElementByID
(*str_itr);
158
if
(KE_pt == NULL)
159
{this->
ErrorMessage
(
"could not find this KE for the KN"
+ *str_itr);
return
;}
160
this->
M_KElement_list
.push_back(KE_pt);
161
}
162
}
KnowledgeNode.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
KnowledgeNode::M_KElement_list
std::vector< KnowledgeElement * > M_KElement_list
Definition:
KnowledgeNode.h:28
KnowledgeNode::ConvertKNinfoToStringForm
void ConvertKNinfoToStringForm()
Definition:
KnowledgeNode.cpp:107
KnowledgeNode::ErrorMessage
void ErrorMessage(std::string)
Definition:
KnowledgeNode.cpp:98
KnowledgeNode::m_ID_KE_list
std::vector< std::string > m_ID_KE_list
Definition:
KnowledgeNode.h:29
KnowledgeNode::BuildConnectionsToThisKN
void BuildConnectionsToThisKN(void *)
Definition:
KnowledgeNode.cpp:143
KnowledgeNode::~KnowledgeNode
virtual ~KnowledgeNode()
Definition:
KnowledgeNode.cpp:27
KnowledgeNode::KnowledgeNode
KnowledgeNode()
Definition:
KnowledgeNode.cpp:22
KnowledgeNode::m_operator
int m_operator
Definition:
KnowledgeNode.h:25
KnowledgeNode::ReadThisKNinfoFromFile
void ReadThisKNinfoFromFile(std::ifstream &)
Definition:
KnowledgeNode.cpp:34
KnowledgeNode::CopyStaticKNinfoFromAnother
void CopyStaticKNinfoFromAnother(KnowledgeNode *)
Definition:
KnowledgeNode.cpp:123
KnowledgeNode::m_Node_Type
int m_Node_Type
Definition:
KnowledgeNode.h:26
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
KnowledgeNode.cpp
Generated by
1.9.4