← Documentation
ADS-IDAC Engine 5.0.0
ShortTermMemory.cpp
Go to the documentation of this file.
1// ShortTermMemory.cpp: implementation of the ShortTermMemory class.
2//
4
5#include "ShortTermMemory.h"
6#include <boost/serialization/export.hpp>
7#include "../Global/SimulationContext.h"
8#include <boost/archive/binary_oarchive.hpp>
9#include <boost/archive/binary_iarchive.hpp>
10BOOST_CLASS_EXPORT_IMPLEMENT(ShortTermMemory)
11using namespace std;
12
13
15// Construction/Destruction
17
20}
21
23}
25 InfoChunkMental *working_memory = 0;
26 bool found = false;
27 double max_priority = -1.0e8;
28 decltype(grouped_info)::reverse_iterator grouped_info_itr;
29 grouped_info_itr = grouped_info.rbegin();
30 while (grouped_info_itr != grouped_info.rend() && !found) {
31 if ((*grouped_info_itr)->getStateOfActivation() == sim::State::Active) {
32 working_memory = grouped_info_itr->get();
33 found = true;
34 }
35 grouped_info_itr++;
36 }
37 if (!found) {
38 for (grouped_info_itr = grouped_info.rbegin(); grouped_info_itr != grouped_info.rend(); grouped_info_itr++) {
39 if ((*grouped_info_itr)->getPriority() > max_priority) {
40 working_memory = grouped_info_itr->get();
41 max_priority = (*grouped_info_itr)->getPriority();
42 }
43 }
44 }
45 working_memory->pointToAvtiveGoalAndStrategy(this->perceived_info);
46 return working_memory;
47}
48
51}
53 int r_n;
55 return r_n;
56}
59}
61 int r_n;
63 return r_n;
64}
66 int r_n;
68 return r_n;
69};
71 int r_n = 0;
72 return r_n;
73}
74// double getIntensiveOfInformationPerceived();
76 bool is_included, inclusion_1;
77 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
78 decltype(grouped_info)::iterator grouped_info_itr;
79 InfoChunkMental *grouped_info_pt;
81 int i, subsystem_n;
82 sd_map_itr = _kb.system_decomposition_map.find(_ms->getAlarmName());
83 if (sd_map_itr != _kb.system_decomposition_map.end()) {//identify the alarm from the systemDecomposition map
84 sd_pt = sd_map_itr->second;
85 inclusion_1 = false;
86 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end();
87 grouped_info_itr++) {//for each info chunk in STM
88 i = 0;
89 is_included = false;
90 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {//the sub-systems relating to the info
91 subsystem_n = sd_pt->getRelatedSubsystem(i);
92 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
93 if (is_included) {
94 inclusion_1 = true;
95 (*grouped_info_itr)->perceived_alarms.push_back(shared_ptr<MentalAlarm>(_ms, [](MentalAlarm*){}));
96 } else {
97 i++;
98 }
99 }
100 }
101 if (!inclusion_1) {
102 grouped_info.push_back(make_unique<InfoChunkMental>());
103 grouped_info_pt = grouped_info.back().get();
104 grouped_info_pt->perceived_alarms.push_back(shared_ptr<MentalAlarm>(_ms, [](MentalAlarm*){}));
105 for (i = 0; i < sd_pt->getNumberOfRelatedSubsystem(); i++) {
106 subsystem_n = sd_pt->getRelatedSubsystem(i);
107 grouped_info_pt->related_subsystem.push_back(subsystem_n);
108 }
109 }
110 } else {//can not find t ecomponent from the map
111 ofstream fout("err messages.txt", ios::app);
112 cout << "ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedAlarm Mental Alarm: " << _ms->getAlarmName()
113 << " can not be identified in KB.system_decomposition_map" << endl;
114 fout << r5pars_.timesno << " ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedAlarm Mental Alarm: "
115 << _ms->getAlarmName()
116 << " can not be identified in KB.system_decomposition_map\n";
117 fout.close();
118 r5pars_.sim_err = true;
119 g_sim.Branch_center.setTempESMessage("ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedAlarm err.");
121 }
122}
124 bool is_included;
125 bool inclusion_1;
126 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
127 decltype(grouped_info)::iterator grouped_info_itr;
128 InfoChunkMental *grouped_info_pt;
130 int i, subsystem_n;
131 //
132 sd_map_itr = _kb.system_decomposition_map.find(_mc->getDisplayName());
133 if (sd_map_itr != _kb.system_decomposition_map.end()) {//identify the alarm from the systemDecomposition map
134 sd_pt = sd_map_itr->second;
135 inclusion_1 = false;
136 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end();
137 grouped_info_itr++) {//for each info chunk in STM
138 i = 0;
139 is_included = false;
140 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {//the sub-systems relating to the info
141 subsystem_n = sd_pt->getRelatedSubsystem(i);
142 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
143 if (is_included) {
144 inclusion_1 = true;
145 (*grouped_info_itr)->action.push_back(shared_ptr<DecisionAction>(_mc, [](DecisionAction*){}));
146 } else {
147 i++;
148 }
149 }
150 }
151 if (!inclusion_1) {
152 grouped_info.push_back(make_unique<InfoChunkMental>());
153 grouped_info_pt = grouped_info.back().get();
154 grouped_info_pt->action.push_back(shared_ptr<DecisionAction>(_mc, [](DecisionAction*){}));
155 for (i = 0; i < sd_pt->getNumberOfRelatedSubsystem(); i++) {
156 subsystem_n = sd_pt->getRelatedSubsystem(i);
157 grouped_info_pt->related_subsystem.push_back(subsystem_n);
158 }
159 }
160 } else {//can not find t ecomponent from the map
161 ofstream fout("err messages.txt", ios::app);
162 cout << "ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedControl control: " << _mc->getDisplayName()
163 << " can not be identified in KB.system_decomposition_map" << endl;
164 fout << r5pars_.timesno << " ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedControl control: "
165 << _mc->getDisplayName()
166 << " can not be identified in KB.system_decomposition_map\n";
167 fout.close();
168 r5pars_.sim_err = true;
169 g_sim.Branch_center.setTempESMessage("ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedAction err.");
171 }
172};
174 bool is_included;
175 bool inclusion_1;
176 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
177 decltype(grouped_info)::iterator grouped_info_itr;
178 InfoChunkMental *grouped_info_pt;
180 int i, subsystem_n;
181 //
182 sd_map_itr = _kb.system_decomposition_map.find(_mc->getDisplayName());
183 if (sd_map_itr != _kb.system_decomposition_map.end()) {//identify the alarm from the systemDecomposition map
184 sd_pt = sd_map_itr->second;
185 inclusion_1 = false;
186 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
187 i = 0;
188 is_included = false;
189 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {//the sub-systems relating to the info
190 subsystem_n = sd_pt->getRelatedSubsystem(i);
191 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
192 if (is_included) {
193 inclusion_1 = true;
194 (*grouped_info_itr)->perceived_component_state.push_back(shared_ptr<MentalComponentState>(_mc, [](MentalComponentState*){}));
195 } else {
196 i++;
197 }
198 }
199 }
200 if (!inclusion_1) {
201 grouped_info.push_back(make_unique<InfoChunkMental>());
202 grouped_info_pt = grouped_info.back().get();
203 grouped_info_pt->perceived_component_state.push_back(shared_ptr<MentalComponentState>(_mc, [](MentalComponentState*){}));
204 for (i = 0; i < sd_pt->getNumberOfRelatedSubsystem(); i++) {
205 subsystem_n = sd_pt->getRelatedSubsystem(i);
206 grouped_info_pt->related_subsystem.push_back(subsystem_n);
207 }
208 }
209 } else {//can not find t ecomponent from the map
210 ofstream fout("err messages.txt", ios::app);
211 cout << "ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedComponentState component: "
212 << _mc->getDisplayName()
213 << " can not be identified in KB.system_decomposition_map" << endl;
214 fout << r5pars_.timesno << " ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedComponentState component: "
215 << _mc->getDisplayName()
216 << " can not be identified in KB.system_decomposition_map\n";
217 fout.close();
218 r5pars_.sim_err = true;
219 g_sim.Branch_center.setTempESMessage("ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedComponentState err.");
221 }
222}
224 bool is_included;
225 bool inclusion_1;
226 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
227 decltype(grouped_info)::iterator grouped_info_itr;
228 InfoChunkMental *grouped_info_pt;
230 int i, subsystem_n;
231 //
232 sd_map_itr = _kb.system_decomposition_map.find(_mss->getDisplayName());
233 if (sd_map_itr != _kb.system_decomposition_map.end()) {//identify the alarm from the systemDecomposition map
234 sd_pt = sd_map_itr->second;
235 inclusion_1 = false;
236 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
237 i = 0;
238 is_included = false;
239 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {//the sub-systems relating to the info
240 subsystem_n = sd_pt->getRelatedSubsystem(i);
241 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
242 if (is_included) {
243 inclusion_1 = true;
244 (*grouped_info_itr)->perceived_support_system_state.push_back(shared_ptr<MentalSupportSystemState>(_mss, [](MentalSupportSystemState*){}));
245 } else {
246 i++;
247 }
248 }
249 }
250 if (!inclusion_1) {
251 grouped_info.push_back(make_unique<InfoChunkMental>());
252 grouped_info_pt = grouped_info.back().get();
253 grouped_info_pt->perceived_support_system_state.push_back(shared_ptr<MentalSupportSystemState>(_mss, [](MentalSupportSystemState*){}));
254 for (i = 0; i < sd_pt->getNumberOfRelatedSubsystem(); i++) {
255 subsystem_n = sd_pt->getRelatedSubsystem(i);
256 grouped_info_pt->related_subsystem.push_back(subsystem_n);
257 }
258 }
259 } else {//can not find support system in map
260 ofstream fout("err messages.txt", ios::app);
261 cout << "ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedSupportSystemState support system: "
262 << _mss->getDisplayName()
263 << " can not be identified in KB.system_decomposition_map" << endl;
264 fout << r5pars_.timesno << " ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedSupportSystemState support system: "
265 << _mss->getDisplayName()
266 << " can not be identified in KB.system_decomposition_map\n";
267 fout.close();
268 r5pars_.sim_err = true;
269 g_sim.Branch_center.setTempESMessage("ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedSupportSystemState err.");
271 }
272}
274 bool is_included, inclusion_1;
275 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
276 decltype(grouped_info)::iterator grouped_info_itr;
277 InfoChunkMental *grouped_info_pt;
279 int i, subsystem_n;
280 //
281 sd_map_itr = _kb.system_decomposition_map.find(_mpv->getDisplayName());
282 if (sd_map_itr != _kb.system_decomposition_map.end()) {//identify the alarm from the systemDecomposition map
283 sd_pt = sd_map_itr->second;
284 inclusion_1 = false;
285 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
286 i = 0;
287 is_included = false;
288 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {//the sub-systems relating to the info
289 subsystem_n = sd_pt->getRelatedSubsystem(i);
290 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
291 if (is_included) {
292 inclusion_1 = true;
293 (*grouped_info_itr)->perceived_parameter_value.push_back(shared_ptr<MentalParameterValue>(_mpv, [](MentalParameterValue*){}));
294 } else {
295 i++;
296 }
297 }
298 }
299 if (!inclusion_1) {
300 grouped_info.push_back(make_unique<InfoChunkMental>());
301 grouped_info_pt = grouped_info.back().get();
302 grouped_info_pt->perceived_parameter_value.push_back(shared_ptr<MentalParameterValue>(_mpv, [](MentalParameterValue*){}));
303 for (i = 0; i < sd_pt->getNumberOfRelatedSubsystem(); i++) {
304 subsystem_n = sd_pt->getRelatedSubsystem(i);
305 grouped_info_pt->related_subsystem.push_back(subsystem_n);
306 }
307 }
308 } else {//can not find the component from the map
309 ofstream fout("err messages.txt", ios::app);
310 cout << "ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterValue Parameter: "
311 << _mpv->getDisplayName()
312 << " can not be identified in KB.system_decomposition_map" << endl;
313 fout << r5pars_.timesno << " ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterValue Parameter: "
314 << _mpv->getDisplayName()
315 << " can not be identified in KB.system_decomposition_map\n";
316 fout.close();
317 r5pars_.sim_err = true;
318 g_sim.Branch_center.setTempESMessage("ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterValue err.");
320 }
321}
323 bool is_included, inclusion_1;
324 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
325 decltype(grouped_info)::iterator grouped_info_itr;
326 InfoChunkMental *grouped_info_pt;
328 int i, subsystem_n;
329 //
330 sd_map_itr = _kb.system_decomposition_map.find(_mpt->getDisplayName());
331 if (sd_map_itr != _kb.system_decomposition_map.end()) {//identify the alarm from the systemDecomposition map
332 sd_pt = sd_map_itr->second;
333 inclusion_1 = false;
334 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
335 i = 0;
336 is_included = false;
337 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {//the sub-systems relating to the info
338 subsystem_n = sd_pt->getRelatedSubsystem(i);
339 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
340 if (is_included) {
341 inclusion_1 = true;
342 (*grouped_info_itr)->perceived_parameter_trend.push_back(shared_ptr<MentalParameterTrend>(_mpt, [](MentalParameterTrend*){}));
343 } else {
344 i++;
345 }
346 }
347 }
348 if (!inclusion_1) {
349 grouped_info.push_back(make_unique<InfoChunkMental>());
350 grouped_info_pt = grouped_info.back().get();
351 grouped_info_pt->perceived_parameter_trend.push_back(shared_ptr<MentalParameterTrend>(_mpt, [](MentalParameterTrend*){}));
352 for (i = 0; i < sd_pt->getNumberOfRelatedSubsystem(); i++) {
353 subsystem_n = sd_pt->getRelatedSubsystem(i);
354 grouped_info_pt->related_subsystem.push_back(subsystem_n);
355 }
356 }
357 } else {//can not find t ecomponent from the map
358 ofstream fout("err messages.txt", ios::app);
359 cout << "ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterTrend Parameter: "
360 << _mpt->getDisplayName()
361 << " can not be identified in KB.system_decomposition_map" << endl;
362 fout << r5pars_.timesno << " ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterTrend Parameter: "
363 << _mpt->getDisplayName()
364 << " can not be identified in KB.system_decomposition_map\n";
365 fout.close();
366 r5pars_.sim_err = true;
367 g_sim.Branch_center.setTempESMessage("ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterTrend err.");
369 }
370}
372 bool found = false;
373 auto dia_ritr = this->perceived_info.diagnosis.rbegin();
374 if (dia_ritr != this->perceived_info.diagnosis.rend() && !found) {
375 if ((*dia_ritr)->getStateOfActivation() == sim::State::Active) {
376 found = true;
377 (*dia_ritr)->setStateOfActivation(sim::State::Failed);
378 }
379 dia_ritr++;
380 }
381 found = false;
382 dia_ritr = this->perceived_info.diagnosis.rbegin();
383 if (dia_ritr != this->perceived_info.diagnosis.rend() && !found) {
384 if ((*dia_ritr)->getStateOfActivation() == sim::State::Pause) {
385 found = true;
386 (*dia_ritr)->setStateOfActivation(sim::State::Active);
387 }
388 dia_ritr++;
389 }
390}
391
393 decltype(grouped_info)::iterator itr;
394 InfoChunkMental *grouped_info_pt;
395 //
396 grouped_info.push_back(make_unique<InfoChunkMental>());
397 grouped_info_pt = grouped_info.back().get();
398 grouped_info_pt->diagnosis.push_back(shared_ptr<DecisionDiagnosis>(_dia, [](DecisionDiagnosis*){}));
399 for (auto dia_itr = this->perceived_info.diagnosis.begin(); dia_itr != this->perceived_info.diagnosis.end(); dia_itr++) {
400 if ((*dia_itr)->getStateOfActivation() == sim::State::Active) {
401 (*dia_itr)->setStateOfActivation(sim::State::Pause);
402 }
403 }
406}
407void ShortTermMemory::checkAndGenerateInfoChunkMentalForDiagnosis(DecisionDiagnosis *_dia) {//called from InfoPreProcessing::infochunking
408 bool is_included = false;
409 bool updated;
410 decltype(grouped_info)::reverse_iterator ritr;
411 decltype(grouped_info)::iterator itr;
412 InfoChunkMental *grouped_info_pt;
413 string _dia_name;
414 //
415 _dia_name = _dia->getDiagnosis();
416 ritr = grouped_info.rbegin();
417 while (ritr != grouped_info.rend() && !is_included) {
418 if ((*ritr)->diagnosisIsIncluded(_dia_name)) {
419 is_included = true;
420 updated = (*ritr)->activateTheDiagnosis(_dia_name);
421 for (itr = grouped_info.begin(); itr != grouped_info.end(); itr++) {
422 if ((*itr)->getStateOfActivation() == sim::State::Active) {
423 (*itr)->setStateOfActivation(sim::State::Pause);
424 }
425 }
426 (*ritr)->setStateOfActivation(sim::State::Active);
427 }
428 ritr++;
429 }
430 if (!is_included) {
431 grouped_info.push_back(make_unique<InfoChunkMental>());
432 grouped_info_pt = grouped_info.back().get();
433 grouped_info_pt->diagnosis.push_back(shared_ptr<DecisionDiagnosis>(_dia, [](DecisionDiagnosis*){}));
434 for (itr = grouped_info.begin(); itr != grouped_info.end(); itr++) {
435 if ((*itr)->getStateOfActivation() == sim::State::Active) {
436 (*itr)->setStateOfActivation(sim::State::Pause);
437 }
438 }
440 }
441}
443 InfoChunkMental *_wm;
444 decltype(grouped_info)::iterator grouped_info_itr;
445 double max_priority = -1.0e8;
446 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
447 (*grouped_info_itr)->calculatePriority();
448 if ((*grouped_info_itr)->getPriority() > max_priority) {
449 max_priority = (*grouped_info_itr)->getPriority();
450 _wm = grouped_info_itr->get();
451 }
452 }
454 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
455 if ((*grouped_info_itr)->getStateOfActivation() == sim::State::Active) {
456 (*grouped_info_itr)->setStateOfActivation(sim::State::Interrupted);
457 }
458 }
460 }
461}
463 auto i_chunk = make_unique<InfoChunkMental>();
464 i_chunk->setStateOfActivation(sim::State::Active);
467 auto goal_sp = this->perceived_info.goal.at(0);
468 auto strategy_sp = this->perceived_info.strategy.at(0);
469 i_chunk->goal.push_back(goal_sp);
470 i_chunk->strategy.push_back(strategy_sp);
471 grouped_info.push_back(std::move(i_chunk));
472}
475 InfoChunkMental *i_chunk_pt = 0;
476 decltype(grouped_info)::iterator info_itr;
477 int i;
478 if (n > grouped_info.size()) {
479 } else {
480 info_itr = grouped_info.begin();
481 for (i = 0; i < n; i++) {
482 info_itr++;
483 }
484 i_chunk_pt = info_itr->get();
485 }
486 return i_chunk_pt;
487}
488/*
489void copyShortTermMemoryToRestartInfo(ShortTermMemory &)
4901. Locate memory for each object within the group_info and copy the content from the reference ShortTermMemory to this ShortTermMemory
4912. Locate memory for each object within the perceived_info and copy the content from the reference ShortTermMemory to this ShortTermMemory
4923. do nothing about the new_info
493*/
495 decltype(grouped_info)::iterator grouped_info_itr;
496 InfoChunkMental *grouped_info_pt;
497 //
503 //
504 for (grouped_info_itr = _stm.grouped_info.begin(); grouped_info_itr != _stm.grouped_info.end(); grouped_info_itr++) {
505 auto p = make_unique<InfoChunkMental>();
506 p->copyInfoChunkMental(**grouped_info_itr);
507 this->grouped_info.push_back(std::move(p));
508 }
510}
511/*
512void clearShortTermMemoryForRestart()
5131. clear the memory located for the objects within the perceived_info
5142. clear the memory located for the pointers within the group_info
5153. clear the memory located for the pointers within the new_info
516*/
518 decltype(grouped_info)::iterator grouped_info_itr;
521 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
522 (*grouped_info_itr)->clearInfoChunkMentalPointers();
523 }
524 grouped_info.clear();
525}
526/*
527void clearShortTermMemoryFromRestartInfo()
5281. clear the memory located for the objects within the perceived_info
5292. clear the memory located for the objects within the group_info
5303. clear the memory located for the pointers within the new_info
531*/
533 decltype(grouped_info)::iterator grouped_info_itr;
535 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
536 (*grouped_info_itr)->clearInfoChunkMental();
537 }
538 grouped_info.clear();
540}
541/*
542void clearShortTermMemoryFromRestartNodeInfoMultiProcessors()
5431. clear the memory located for the objects within the perceived_info
5442. clear the memory located for the objects within the group_info
5453. clear the memory located for the objects within the new_info
546*/
548 decltype(grouped_info)::iterator grouped_info_itr;
549 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
550 (*grouped_info_itr)->clearInfoChunkMentalPointers();
551 }
552 grouped_info.clear();
555}
556/*
557ShortTermMemory::copyShortTermMemoryFromRestartInfo do the following things
558 1. copy all objects of perceived_info with memory located
559 2. add pointers in each group_info so the pointers pointing to the objects within the perceived_info
560 3. do nothing about new_info
561*/
563 bool found;
564 // Iterator types deduced via auto at point of use (vectors now hold shared_ptr<T>)
565 decltype(grouped_info)::iterator grouped_info_itr;
566 InfoChunkMental *grouped_info_pt;
567//
574//
575 for (grouped_info_itr = _stm.grouped_info.begin(); grouped_info_itr != _stm.grouped_info.end(); grouped_info_itr++) {
576 this->grouped_info.push_back(make_unique<InfoChunkMental>());
577 grouped_info_pt = this->grouped_info.back().get();
578 grouped_info_pt->setPriority((*grouped_info_itr)->getPriority());
579 for (auto goal_itr = (*grouped_info_itr)->goal.begin(); goal_itr != (*grouped_info_itr)->goal.end(); goal_itr++) {
580 found = false;
581 auto goal_itr1 = this->perceived_info.goal.begin();
582 while (goal_itr1 != this->perceived_info.goal.end() && !found) {
583 if (fabs((*goal_itr)->getTimeAtWhichThisInfoIsPerceived() - (*goal_itr1)->getTimeAtWhichThisInfoIsPerceived())
584 < 0.001) {
585 found = true;
586 grouped_info_pt->goal.push_back(*goal_itr1);
587 }
588 goal_itr1++;
589 }
590 }
591 for (auto strategy_itr = (*grouped_info_itr)->strategy.begin(); strategy_itr != (*grouped_info_itr)->strategy.end();
592 strategy_itr++) {
593 found = false;
594 auto strategy_itr1 = this->perceived_info.strategy.begin();
595 while (strategy_itr1 != this->perceived_info.strategy.end() && !found) {
596 if (fabs((*strategy_itr)->getTimeAtWhichThisInfoIsPerceived()
597 - (*strategy_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
598 found = true;
599 grouped_info_pt->strategy.push_back(*strategy_itr1);
600 }
601 strategy_itr1++;
602 }
603 }
604 for (auto subgoal_itr = (*grouped_info_itr)->subgoal.begin(); subgoal_itr != (*grouped_info_itr)->subgoal.end();
605 subgoal_itr++) {
606 found = false;
607 auto subgoal_itr1 = this->perceived_info.subgoal.begin();
608 while (subgoal_itr1 != this->perceived_info.subgoal.end() && !found) {
609 if (fabs(
610 (*subgoal_itr)->getTimeAtWhichThisInfoIsPerceived() - (*subgoal_itr1)->getTimeAtWhichThisInfoIsPerceived())
611 < 0.001) {
612 found = true;
613 grouped_info_pt->subgoal.push_back(*subgoal_itr1);
614 }
615 subgoal_itr1++;
616 }
617 }
618 for (auto diagnosis_itr = (*grouped_info_itr)->diagnosis.begin(); diagnosis_itr != (*grouped_info_itr)->diagnosis.end();
619 diagnosis_itr++) {
620 found = false;
621 auto diagnosis_itr1 = this->perceived_info.diagnosis.begin();
622 while (diagnosis_itr1 != this->perceived_info.diagnosis.end() && !found) {
623 if (fabs((*diagnosis_itr)->getTimeAtWhichThisInfoIsPerceived()
624 - (*diagnosis_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
625 found = true;
626 grouped_info_pt->diagnosis.push_back(*diagnosis_itr1);
627 }
628 diagnosis_itr1++;
629 }
630 }
631 for (auto action_objective_itr = (*grouped_info_itr)->action_objective.begin();
632 action_objective_itr != (*grouped_info_itr)->action_objective.end(); action_objective_itr++) {
633 found = false;
634 auto action_objective_itr1 = this->perceived_info.action_objective.begin();
635 while (action_objective_itr1 != this->perceived_info.action_objective.end() && !found) {
636 if (fabs((*action_objective_itr)->getTimeAtWhichThisInfoIsPerceived()
637 - (*action_objective_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
638 found = true;
639 grouped_info_pt->action_objective.push_back(*action_objective_itr1);
640 }
641 action_objective_itr1++;
642 }
643 }
644 for (auto action_pack_itr = (*grouped_info_itr)->action_pack.begin();
645 action_pack_itr != (*grouped_info_itr)->action_pack.end(); action_pack_itr++) {
646 found = false;
647 auto action_pack_itr1 = this->perceived_info.action_pack.begin();
648 while (action_pack_itr1 != this->perceived_info.action_pack.end() && !found) {
649 if (fabs((*action_pack_itr)->getTimeAtWhichThisInfoIsPerceived()
650 - (*action_pack_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
651 found = true;
652 grouped_info_pt->action_pack.push_back(*action_pack_itr1);
653 }
654 action_pack_itr1++;
655 }
656 }
657 for (auto action_itr = (*grouped_info_itr)->action.begin(); action_itr != (*grouped_info_itr)->action.end();
658 action_itr++) {
659 found = false;
660 auto action_itr1 = this->perceived_info.action.begin();
661 while (action_itr1 != this->perceived_info.action.end() && !found) {
662 if (fabs(
663 (*action_itr)->getTimeAtWhichThisInfoIsPerceived() - (*action_itr1)->getTimeAtWhichThisInfoIsPerceived())
664 < 0.001) {
665 found = true;
666 grouped_info_pt->action.push_back(*action_itr1);
667 }
668 action_itr1++;
669 }
670 }
671 for (auto procedure_step_itr = (*grouped_info_itr)->procedure_step.begin();
672 procedure_step_itr != (*grouped_info_itr)->procedure_step.end(); procedure_step_itr++) {
673 found = false;
674 auto procedure_step_itr1 = this->perceived_info.procedure_step.begin();
675 while (procedure_step_itr1 != this->perceived_info.procedure_step.end() && !found) {
676 if (((*procedure_step_itr)->getProcedureName() == (*procedure_step_itr1)->getProcedureName()) &&
677 ((*procedure_step_itr)->getStepName() == (*procedure_step_itr1)->getStepName())) {
678 found = true;
679 grouped_info_pt->procedure_step.push_back(*procedure_step_itr1);
680 }
681 procedure_step_itr1++;
682 }
683 }
684 for (auto perceived_alarms_itr = (*grouped_info_itr)->perceived_alarms.begin();
685 perceived_alarms_itr != (*grouped_info_itr)->perceived_alarms.end(); perceived_alarms_itr++) {
686 found = false;
687 auto perceived_alarms_itr1 = this->perceived_info.perceived_alarms.begin();
688 while (perceived_alarms_itr1 != this->perceived_info.perceived_alarms.end() && !found) {
689 if (fabs((*perceived_alarms_itr)->getTimeAtWhichThisInfoIsPerceived()
690 - (*perceived_alarms_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
691 found = true;
692 grouped_info_pt->perceived_alarms.push_back(*perceived_alarms_itr1);
693 }
694 perceived_alarms_itr1++;
695 }
696 }
697 for (auto perceived_component_state_itr = (*grouped_info_itr)->perceived_component_state.begin();
698 perceived_component_state_itr != (*grouped_info_itr)->perceived_component_state.end();
699 perceived_component_state_itr++) {
700 found = false;
701 auto perceived_component_state_itr1 = this->perceived_info.perceived_component_state.begin();
702 while (perceived_component_state_itr1 != this->perceived_info.perceived_component_state.end() && !found) {
703 if (fabs((*perceived_component_state_itr)->getTimeAtWhichThisInfoIsPerceived()
704 - (*perceived_component_state_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
705 found = true;
706 grouped_info_pt->perceived_component_state.push_back(*perceived_component_state_itr1);
707 }
708 perceived_component_state_itr1++;
709 }
710 }
711 for (auto perceived_support_system_state_itr = (*grouped_info_itr)->perceived_support_system_state.begin();
712 perceived_support_system_state_itr != (*grouped_info_itr)->perceived_support_system_state.end();
713 perceived_support_system_state_itr++) {
714 found = false;
715 auto perceived_support_system_state_itr1 = this->perceived_info.perceived_support_system_state.begin();
716 while (perceived_support_system_state_itr1 != this->perceived_info.perceived_support_system_state.end() && !found) {
717 if (fabs((*perceived_support_system_state_itr)->getTimeAtWhichThisInfoIsPerceived()
718 - (*perceived_support_system_state_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
719 found = true;
720 grouped_info_pt->perceived_support_system_state.push_back(*perceived_support_system_state_itr1);
721 }
722 perceived_support_system_state_itr1++;
723 }
724 }
725 for (auto perceived_parameter_value_itr = (*grouped_info_itr)->perceived_parameter_value.begin();
726 perceived_parameter_value_itr != (*grouped_info_itr)->perceived_parameter_value.end();
727 perceived_parameter_value_itr++) {
728 found = false;
729 auto perceived_parameter_value_itr1 = this->perceived_info.perceived_parameter_value.begin();
730 while (perceived_parameter_value_itr1 != this->perceived_info.perceived_parameter_value.end() && !found) {
731 if (fabs((*perceived_parameter_value_itr)->getTimeAtWhichThisInfoIsPerceived()
732 - (*perceived_parameter_value_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
733 found = true;
734 grouped_info_pt->perceived_parameter_value.push_back(*perceived_parameter_value_itr1);
735 }
736 perceived_parameter_value_itr1++;
737 }
738 }
739 for (auto perceived_parameter_trend_itr = (*grouped_info_itr)->perceived_parameter_trend.begin();
740 perceived_parameter_trend_itr != (*grouped_info_itr)->perceived_parameter_trend.end();
741 perceived_parameter_trend_itr++) {
742 found = false;
743 auto perceived_parameter_trend_itr1 = this->perceived_info.perceived_parameter_trend.begin();
744 while (perceived_parameter_trend_itr1 != this->perceived_info.perceived_parameter_trend.end() && !found) {
745 if (fabs((*perceived_parameter_trend_itr)->getTimeAtWhichThisInfoIsPerceived()
746 - (*perceived_parameter_trend_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
747 found = true;
748 grouped_info_pt->perceived_parameter_trend.push_back(*perceived_parameter_trend_itr1);
749 }
750 perceived_parameter_trend_itr1++;
751 }
752 }
753 for (auto related_subsystem_itr = (*grouped_info_itr)->related_subsystem.begin();
754 related_subsystem_itr != (*grouped_info_itr)->related_subsystem.end(); related_subsystem_itr++) {
755 grouped_info_pt->related_subsystem.push_back(*related_subsystem_itr);
756 }
757 }
758}
760 decltype(grouped_info)::reverse_iterator ritr;//grouped_info;
761 bool found = false;
762 ritr = grouped_info.rbegin();
763 while (ritr != grouped_info.rend() && !found) {
764 if ((*ritr)->getStateOfActivation() == sim::State::Pause) {
765 found = true;
766 (*ritr)->setStateOfActivation(sim::State::Active);
767 }
768 ritr++;
769 }
770 if (!found) {
771 ofstream fout("err messages.txt", ios::app);
772 cout << "ShortTermMemory::activatePausedInfoChunck cound not find paused info chunk" << endl;
773 fout << r5pars_.timesno << " ShortTermMemory::activatePausedInfoChunck cound not find paused info chunk\n";
774 fout.close();
775 r5pars_.sim_err = true;
776 g_sim.Branch_center.setTempESMessage("ShortTermMemory::activatePausedInfoChunck err.");
778 }
779}
783 int num;
784 decltype(grouped_info)::iterator grouped_info_itr;
785 fout << "ShortTermMemory\n";
787 num = grouped_info.size();
788 fout << "Info_Chunks " << num << '\n';
789 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
790 (*grouped_info_itr)->saveInfoChunkMentalToFile(fout);
791 }
792 fout << info_gather_mode << '\n';
797}
799 int i, num;
800 string str;
801 InfoChunkMental *grouped_info_pt;
802 decltype(grouped_info)::iterator grouped_info_itr;
803 fin >> str;
804 if (str != "ShortTermMemory") {
805 ofstream fout("err messages.txt", ios::app);
806 cout << "ShortTermMemory::retrieveShortTermMemoryFromFile File retrieval error in previous function" << endl;
807 fout << r5pars_.timesno
808 << " ShortTermMemory::retrieveShortTermMemoryFromFile File retrieval error in previous function\n";
809 fout.close();
810 r5pars_.sim_err = true;
811 g_sim.Branch_center.setTempESMessage("ShortTermMemory::retrieveShortTermMemoryFromFile Prior error");
813 return;
814 }
816
817 fin >> str >> num;
818 if (str != "Info_Chunks") {
819 ofstream fout("err messages.txt", ios::app);
820 cout << "ShortTermMemory::retrieveShortTermMemoryFromFile File retrieval error in perceived_info" << endl;
821 fout << r5pars_.timesno
822 << " ShortTermMemory::retrieveShortTermMemoryFromFile File retrieval error in perceived_info\n";
823 fout.close();
824 r5pars_.sim_err = true;
825 g_sim.Branch_center.setTempESMessage("ShortTermMemory::retrieveShortTermMemoryFromFile perceived_info error");
827 return;
828 }
829 for (i = 0; i < num; i++) {
830 auto p = make_unique<InfoChunkMental>();
831 p->retrieveInfoChunkMentalFromFile(fin);
832 grouped_info.push_back(std::move(p));
833 }
834 for (grouped_info_itr = grouped_info.begin(); grouped_info_itr != grouped_info.end(); grouped_info_itr++) {
835 (*grouped_info_itr)->replaceObjecByPointerForGroupedInfoAll(this->perceived_info);
836 }
837 fin >> info_gather_mode;
842
843}
845 bool found_goal = false;
846 int current_goal = sim::None;
847 auto goal_itr = this->perceived_info.goal.rbegin();
848 auto goal_end = this->perceived_info.goal.rend();
849 while (goal_itr != goal_end && !found_goal) {
850 if ((*goal_itr)->getStateOfActivation() == sim::State::Active) {
851 current_goal = (*goal_itr)->getDecision();
852 found_goal = true;
853 }
854 goal_itr++;
855 }
856 return current_goal;
857}
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
std::string getAlarmName()
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
void clearCommunicationPlaceAllPointers()
std::string getDisplayName()
std::string getDisplayName()
std::list< int > related_subsystem
void setPriority(double)
std::vector< std::shared_ptr< MentalSupportSystemState > > perceived_support_system_state
Definition: InfoChunk.h:146
int getTotalNumberOfFailedDiagnosis()
Definition: InfoChunk.cpp:75
std::vector< std::shared_ptr< MentalParameterValue > > perceived_parameter_value
Definition: InfoChunk.h:147
std::vector< std::shared_ptr< DecisionSubGoal > > subgoal
Definition: InfoChunk.h:137
void clearInfoChunk()
Definition: InfoChunk.cpp:24
std::vector< std::shared_ptr< MentalParameterTrend > > perceived_parameter_trend
Definition: InfoChunk.h:148
std::vector< std::shared_ptr< DecisionStrategy > > strategy
Definition: InfoChunk.h:136
int getTotalNumberOfAlarmPerceived()
Definition: InfoChunk.cpp:72
std::vector< std::shared_ptr< DecisionAction > > action
Definition: InfoChunk.h:141
void addANewGoal(int, int)
Definition: InfoChunk.cpp:240
void copyInfoChunk(InfoChunk &)
Definition: InfoChunk.cpp:1189
std::vector< std::shared_ptr< DecisionActionPack > > action_pack
Definition: InfoChunk.h:140
void saveInfoChunkToFile(std::ofstream &)
Definition: InfoChunk.cpp:1361
void addANewStrategy(int, int)
Definition: InfoChunk.cpp:246
void pointToAvtiveGoalAndStrategy(InfoChunk &)
Definition: InfoChunk.cpp:643
std::vector< std::shared_ptr< DecisionGoal > > goal
Definition: InfoChunk.h:135
std::vector< std::shared_ptr< DecisionDiagnosis > > diagnosis
Definition: InfoChunk.h:138
std::vector< std::shared_ptr< MentalAlarm > > perceived_alarms
Definition: InfoChunk.h:144
std::vector< std::shared_ptr< MentalComponentState > > perceived_component_state
Definition: InfoChunk.h:145
std::vector< std::shared_ptr< DecisionProcedureStep > > procedure_step
Definition: InfoChunk.h:142
double getTotalWeightOfAlarmPerceived()
Definition: InfoChunk.cpp:64
int getTotalPieceOfInfoPerceived()
Definition: InfoChunk.cpp:58
std::vector< std::shared_ptr< DecisionActionObjective > > action_objective
Definition: InfoChunk.h:139
void retrieveInfoChunkFromFile(std::ifstream &)
Definition: InfoChunk.cpp:1430
Definition: KB.h:46
std::map< std::string, KBSystemDecompositionUnit * > system_decomposition_map
Definition: KB.h:87
std::string getDiagnosis()
virtual ~ShortTermMemory()
void addNewInfoChunkMentalForTheDiagnosis(DecisionDiagnosis *)
Timer support_system_update_time
void calculatePriorityAndSetStateOfActivation()
void clearShortTermMemoryFromRestartNodeInfoMultiProcessors()
int getTotalPieceOfInfoPerceived()
InfoChunkMental * getInfoChunkAt(int)
void checkAndGenerateInfoChunkMentalForRelatedAction(DecisionAction *, KB &)
void retrieveShortTermMemoryFromFile(std::ifstream &)
void activatePausedInfoChunck()
int getTotalNumberOfAlarmPerceived()
Timer parameter_update_time
void copyShortTermMemoryFromRestartInfo(ShortTermMemory &)
void checkAndGenerateInfoChunkMentalForRelatedAlarm(MentalAlarm *, KB &)
void checkAndGenerateInfoChunkMentalForRelatedComponentState(MentalComponentState *, KB &)
CommunicationPlace new_info
void checkAndGenerateInfoChunkMentalForRelatedParameterValue(MentalParameterValue *, KB &)
std::list< std::unique_ptr< InfoChunkMental > > grouped_info
void clearShortTermMemoryFromRestartInfo()
void saveShortTermMemoryToFile(std::ofstream &)
InfoChunkMental * getWorkingMemory()
void clearShortTermMemoryForRestart()
void copyShortTermMemoryToRestartInfo(ShortTermMemory &)
void checkAndGenerateInfoChunkMentalForRelatedSupportSystemState(MentalSupportSystemState *, KB &)
void setInfoGatherMode(int)
void initiationForSimulation()
void failCurrentDiagnosisAndActivateAPausedDiagnosis()
Timer component_update_time
InfoChunk perceived_info
void checkAndGenerateInfoChunkMentalForRelatedParameterTrend(MentalParameterTrend *, KB &)
void checkAndGenerateInfoChunkMentalForDiagnosis(DecisionDiagnosis *)
int getTotalFailedActionPack()
double getTotalWeightOfAlarmPerceived()
void setStateOfActivation(int)
void saveTimerToFile(std::ofstream &)
Definition: Timer.cpp:54
void retrieveTimerFromFile(std::ifstream &)
Definition: Timer.cpp:59
void copyTimer(Timer &)
Definition: Timer.cpp:44
struct @0 r5pars_
constexpr int Failed
Definition: SimConstants.h:103
constexpr int Interrupted
Definition: SimConstants.h:124
constexpr int Active
Definition: SimConstants.h:118
constexpr int New
Definition: SimConstants.h:114
constexpr int Pause
Definition: SimConstants.h:119
constexpr int None
Definition: SimConstants.h:75
BranchRecord Branch_center
Dynamic event tree state.