← 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
15using namespace std;
16
17
19// Construction/Destruction
21
23{
24 this->m_ID_Type = 402;
25}
26
28{
29 this->m_ID_KE_list.clear();
30 this->M_KElement_list.clear();
31
32}
33
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
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
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
124{
125 vector<string>::iterator str_itr;
126 string ID;
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
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}
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
std::vector< KnowledgeElement * > M_KElement_list
Definition: KnowledgeNode.h:28
void ConvertKNinfoToStringForm()
void ErrorMessage(std::string)
std::vector< std::string > m_ID_KE_list
Definition: KnowledgeNode.h:29
void BuildConnectionsToThisKN(void *)
virtual ~KnowledgeNode()
void ReadThisKNinfoFromFile(std::ifstream &)
void CopyStaticKNinfoFromAnother(KnowledgeNode *)
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.