← Documentation
ADS-IDAC Engine 5.0.0
CommunicationPlace.cpp
Go to the documentation of this file.
1// CommunicationPlace.cpp: implementation of the CommunicationPlace class.
2//
4
5#include <string>
6#include <boost/serialization/export.hpp>
7
9#include <boost/archive/binary_oarchive.hpp>
10#include <boost/archive/binary_iarchive.hpp>
11BOOST_CLASS_EXPORT_IMPLEMENT(CommunicationPlace)
12using namespace std;
13
15// Construction/Destruction
17
19
20}
21
23}
26 HW_reliability.clear();
27 SS_reliability.clear();
28 new_alarm.clear();
29}
32}
35 HW_reliability.clear();
36 SS_reliability.clear();
37 new_alarm.clear();
38}
40 int n_return;
42 n_return += new_alarm.size();
43 return n_return;
44}
46 for (auto &e : action) {
47 if (e->getSender() == sim::Source::Plant) {
48 e->setSender(e->getIntendedReceiver());
49 e->setIntendedReceiver(sim::Source::Plant);
50 }
51 }
52 for (auto &e : alarm_state) {
53 if (e->getSender() == sim::Source::Plant) {
54 e->setSender(e->getIntendedReceiver());
55 e->setIntendedReceiver(sim::Source::Plant);
56 }
57 }
58 for (auto &e : component_state) {
59 if (e->getSender() == sim::Source::Plant) {
60 e->setSender(e->getIntendedReceiver());
61 e->setIntendedReceiver(sim::Source::Plant);
62 }
63 }
64 for (auto &e : support_system_state) {
65 if (e->getSender() == sim::Source::Plant) {
66 e->setSender(e->getIntendedReceiver());
67 e->setIntendedReceiver(sim::Source::Plant);
68 }
69 }
70 for (auto &e : parameter_value) {
71 if (e->getSender() == sim::Source::Plant) {
72 e->setSender(e->getIntendedReceiver());
73 e->setIntendedReceiver(sim::Source::Plant);
74 }
75 }
76 for (auto &e : parameter_difference) {
77 if (e->getSender() == sim::Source::Plant) {
78 e->setSender(e->getIntendedReceiver());
79 e->setIntendedReceiver(sim::Source::Plant);
80 }
81 }
82 for (auto &e : parameter_trend) {
83 if (e->getSender() == sim::Source::Plant) {
84 e->setSender(e->getIntendedReceiver());
85 e->setIntendedReceiver(sim::Source::Plant);
86 }
87 }
88}
90 this->copyBranchUnit((BranchUnit &) _cp);
91 for (auto &e : _cp.HW_reliability) {
92 auto p = make_shared<BranchSystemAction>();
93 p->copyBranchSystemAction(*e);
94 this->HW_reliability.push_back(std::move(p));
95 }
96 for (auto &e : _cp.SS_reliability) {
97 auto p = make_shared<BranchSupportSystemAction>();
98 p->copyBranchSupportSystemAction(*e);
99 this->SS_reliability.push_back(std::move(p));
100 }
101 for (auto &e : _cp.new_alarm) {
102 auto p = make_shared<BranchSystemAlarmState>();
103 p->copyBranchSystemAlarmState(*e);
104 this->new_alarm.push_back(std::move(p));
105 }
106}
108 string str;
109 double probability;
110//
111 fout << this->getNumberOfItemInCommunicationPlace() << ' ';
112 for (auto &e : goal) { e->saveInfoToFile(fout); }
113 for (auto &e : strategy) { e->saveInfoToFile(fout); }
114 for (auto &e : subgoal) { e->saveInfoToFile(fout); }
115 for (auto &e : diagnosis) { e->saveInfoToFile(fout); }
116 for (auto &e : action_objective) { e->saveInfoToFile(fout); }
117 for (auto &e : action_pack) { e->saveInfoToFile(fout); }
118 for (auto &e : action) { e->saveInfoToFile(fout); }
119 for (auto &e : alarm_state) { e->saveInfoToFile(fout); }
120 for (auto &e : component_state) { e->saveInfoToFile(fout); }
121 for (auto &e : support_system_state) { e->saveInfoToFile(fout); }
122 for (auto &e : parameter_trend) { e->saveInfoToFile(fout); }
123 for (auto &e : parameter_value) { e->saveInfoToFile(fout); }
124 for (auto &e : parameter_difference) { e->saveInfoToFile(fout); }
125 for (auto &e : procedure_step) { e->saveInfoToFile(fout); }
126 for (auto &e : instinctive_response_procedure) { e->saveInfoToFile(fout); }
127 for (auto &e : info_gather_mode) { e->saveInfoToFile(fout); }
128 for (auto &e : mental_belief) { e->saveInfoToFile(fout); }
129 for (auto &e : this->scanned_parameter) { e->saveInfoToFile(fout); }
130 if (HW_reliability.size() > 0 && SS_reliability.size() && new_alarm.size() > 0) {
131 str = '"';
132 probability = 1.0;
133 for (auto &e : HW_reliability) {
134 str += e->getDisplayName();
135 probability *= e->getProbability();
136 if (e->getFunctionalState() == sim::State::Failed) {
137 str += "_failed;";
138 } else {
139 str += "_success;";
140 }
141 }
142 for (auto &e : SS_reliability) {
143 str += e->getDisplayName();
144 probability *= e->getProbability();
145 if (e->getFunctionalState() == sim::State::Failed) {
146 str += "_failed;";
147 } else {
148 str += "_success;";
149 }
150 }
151 for (auto &e : new_alarm) {
152 str += e->getAlarmName();
153 str += ";";
154 }
155 str += '"';
156 auto &hw_first = HW_reliability.front();
157 fout << ' ' << sim::Source::Plant << ' ' << sim::Action::Direct << ' ' << sim::None << " Multi_Comp_Failure_And_Alarm " << probability << ' '
158 << hw_first->getTimeOfCommunication() << ' ' << hw_first->getRemainingTime()
159 << " 0.0 0 "
160 << str << '\n';
161 } else if (HW_reliability.size() > 0) {
162 if (HW_reliability.size() == 1) {
163 HW_reliability.front()->saveInfoToFile(fout);
164 } else {
165 str = '"';
166 probability = 1.0;
167 for (auto &e : HW_reliability) {
168 str += e->getDisplayName();
169 probability *= e->getProbability();
170 if (e->getFunctionalState() == sim::State::Failed) {
171 str += "_failed;";
172 } else {
173 str += "_success;";
174 }
175 }
176 str += '"';
177 auto &hw_first = HW_reliability.front();
178 fout << ' ' << sim::Source::Plant << ' ' << sim::Action::Direct << ' ' << sim::None << " Multi_Comp_Failure " << probability << ' '
179 << hw_first->getTimeOfCommunication() << ' ' << hw_first->getRemainingTime()
180 << " 0.0 0 "
181 << str << '\n';
182 }
183 } else if (SS_reliability.size() > 0) {
184 if (SS_reliability.size() == 1) {
185 SS_reliability.front()->saveInfoToFile(fout);
186 } else {
187 str = '"';
188 probability = 1.0;
189 for (auto &e : SS_reliability) {
190 str += e->getDisplayName();
191 probability *= e->getProbability();
192 if (e->getFunctionalState() == sim::State::Failed) {
193 str += "_failed;";
194 } else {
195 str += "_success;";
196 }
197 }
198 str += '"';
199 auto &ss_first = SS_reliability.front();
200 fout << ' ' << sim::Source::Plant << ' ' << sim::Action::Direct << ' ' << sim::None << " Multi_Comp_Failure " << probability << ' '
201 << ss_first->getTimeOfCommunication() << ' ' << ss_first->getRemainingTime()
202 << " 0.0 0 "
203 << str << '\n';
204 }
205 } else if (new_alarm.size() > 0) {
206 if (new_alarm.size() == 1) {
207 new_alarm.front()->saveInfoToFile(fout);
208 } else {
209 str = '"';
210 probability = 1.0;
211 for (auto &e : new_alarm) {
212 str += e->getAlarmName();
213 str += ";";
214 }
215 str += '"';
216 auto &na_first = new_alarm.front();
217 fout << ' ' << sim::Source::Plant << ' ' << sim::Action::SendInfo << ' ' << sim::None << " Multi_Alarms " << probability << ' '
218 << na_first->getTimeAtWhichThisAlarmIsActivated() << ' ' << na_first->getRemainingTime()
219 << " 0.0 0 "
220 << str << '\n';
221 }
222 } else {
223 }
224}
226 int n;
227 n = this->getNumberOfItemInBranchUnit();
228 if (new_alarm.size() > 0 || HW_reliability.size() > 0 || SS_reliability.size() > 0) n++;
229 return n;
230}
232 int i, num;
233 num = HW_reliability.size();
234 fout << num << '\n';
235 for (i = 0; i < num; i++) {
236 HW_reliability.at(i)->saveBranchSystemActionToFile(fout);
237 }
238 num = SS_reliability.size();
239 fout << num << '\n';
240 for (i = 0; i < num; i++) {
241 SS_reliability.at(i)->saveBranchSupportSystemActionToFile(fout);
242 }
243 num = new_alarm.size();
244 fout << num << '\n';
245 for (i = 0; i < num; i++) {
246 new_alarm.at(i)->saveBranchSystemAlarmStateToFile(fout);
247 }
248 this->saveBranchUnitToFile(fout);
249}
251 int i, num;
252 fin >> num;
253 for (i = 0; i < num; i++) {
254 auto p = make_shared<BranchSystemAction>();
255 p->retrieveBranchSystemActionFromFile(fin);
256 this->HW_reliability.push_back(std::move(p));
257 }
258 fin >> num;
259 for (i = 0; i < num; i++) {
260 auto p = make_shared<BranchSupportSystemAction>();
261 p->retrieveBranchSupportSystemActionFromFile(fin);
262 this->SS_reliability.push_back(std::move(p));
263 }
264 fin >> num;
265 for (i = 0; i < num; i++) {
266 auto p = make_shared<BranchSystemAlarmState>();
267 p->retrieveBranchSystemAlarmStateFromFile(fin);
268 this->new_alarm.push_back(std::move(p));
269 }
271}
document e
std::vector< std::shared_ptr< BranchSubGoal > > subgoal
Definition: BranchUnit.h:55
void copyBranchUnit(BranchUnit &)
Definition: BranchUnit.cpp:158
std::vector< std::shared_ptr< BranchExpectedParameterTrend > > parameter_trend
Definition: BranchUnit.h:63
std::vector< std::shared_ptr< BranchInfoGatherMode > > info_gather_mode
Definition: BranchUnit.h:68
std::vector< std::shared_ptr< BranchProcedureStep > > instinctive_response_procedure
Definition: BranchUnit.h:67
std::vector< std::shared_ptr< BranchGoal > > goal
Definition: BranchUnit.h:53
void clearBranchUnitAllPointers()
Definition: BranchUnit.cpp:128
std::vector< std::shared_ptr< BranchActionPack > > action_pack
Definition: BranchUnit.h:58
std::vector< std::shared_ptr< BranchExpectedSupportSystemState > > support_system_state
Definition: BranchUnit.h:62
std::vector< std::shared_ptr< BranchExpectedParameterDifference > > parameter_difference
Definition: BranchUnit.h:65
std::vector< std::shared_ptr< BranchDiagnosis > > diagnosis
Definition: BranchUnit.h:56
int getNumberOfItemInBranchUnit()
Definition: BranchUnit.cpp:251
std::vector< std::shared_ptr< BranchExpectedMentalBelief > > mental_belief
Definition: BranchUnit.h:69
std::vector< std::shared_ptr< BranchExpectedParameterValue > > parameter_value
Definition: BranchUnit.h:64
std::vector< std::shared_ptr< BranchScannedParameter > > scanned_parameter
Definition: BranchUnit.h:70
void clearBranchUnit()
Definition: BranchUnit.cpp:108
std::vector< std::shared_ptr< BranchExpectedComponentState > > component_state
Definition: BranchUnit.h:61
std::vector< std::shared_ptr< BranchStrategy > > strategy
Definition: BranchUnit.h:54
void saveBranchUnitToFile(std::ofstream &)
Definition: BranchUnit.cpp:261
std::vector< std::shared_ptr< BranchProcedureStep > > procedure_step
Definition: BranchUnit.h:66
int getTotalPiecesOfInfo()
Definition: BranchUnit.cpp:149
std::vector< std::shared_ptr< BranchExpectedAlarmState > > alarm_state
Definition: BranchUnit.h:60
std::vector< std::shared_ptr< BranchAction > > action
Definition: BranchUnit.h:59
std::vector< std::shared_ptr< BranchActionObjective > > action_objective
Definition: BranchUnit.h:57
void retrieveBranchUnitFromFile(std::ifstream &)
Definition: BranchUnit.cpp:301
void clearCommunicationPlaceAllPointers()
std::vector< std::shared_ptr< BranchSystemAction > > HW_reliability
void clearCommunicationPlaceForRestart()
std::vector< std::shared_ptr< BranchSystemAlarmState > > new_alarm
void retrieveCommunicationPlaceFromFile(std::ifstream &)
std::vector< std::shared_ptr< BranchSupportSystemAction > > SS_reliability
void saveInfoToFileAsBranchForADSV1(std::ostream &)
void copyCommunicationPlace(CommunicationPlace &)
void saveCommunicationPlaceToFile(std::ofstream &)
constexpr int SendInfo
Definition: SimConstants.h:204
constexpr int Direct
Definition: SimConstants.h:202
constexpr int Plant
Definition: SimConstants.h:135
constexpr int Failed
Definition: SimConstants.h:103
constexpr int None
Definition: SimConstants.h:75