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>
27 double max_priority = -1.0e8;
28 decltype(
grouped_info)::reverse_iterator grouped_info_itr;
30 while (grouped_info_itr !=
grouped_info.rend() && !found) {
32 working_memory = grouped_info_itr->get();
39 if ((*grouped_info_itr)->getPriority() > max_priority) {
40 working_memory = grouped_info_itr->get();
46 return working_memory;
76 bool is_included, inclusion_1;
77 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
84 sd_pt = sd_map_itr->second;
90 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {
92 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
95 (*grouped_info_itr)->perceived_alarms.push_back(shared_ptr<MentalAlarm>(_ms, [](
MentalAlarm*){}));
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: "
116 <<
" can not be identified in KB.system_decomposition_map\n";
126 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
134 sd_pt = sd_map_itr->second;
137 grouped_info_itr++) {
140 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {
142 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
145 (*grouped_info_itr)->action.push_back(shared_ptr<DecisionAction>(_mc, [](
DecisionAction*){}));
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: "
166 <<
" can not be identified in KB.system_decomposition_map\n";
176 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
184 sd_pt = sd_map_itr->second;
189 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {
191 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
194 (*grouped_info_itr)->perceived_component_state.push_back(shared_ptr<MentalComponentState>(_mc, [](
MentalComponentState*){}));
210 ofstream fout(
"err messages.txt", ios::app);
211 cout <<
"ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedComponentState component: "
213 <<
" can not be identified in KB.system_decomposition_map" << endl;
214 fout <<
r5pars_.timesno <<
" ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedComponentState component: "
216 <<
" can not be identified in KB.system_decomposition_map\n";
226 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
234 sd_pt = sd_map_itr->second;
239 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {
241 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
244 (*grouped_info_itr)->perceived_support_system_state.push_back(shared_ptr<MentalSupportSystemState>(_mss, [](
MentalSupportSystemState*){}));
260 ofstream fout(
"err messages.txt", ios::app);
261 cout <<
"ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedSupportSystemState support system: "
263 <<
" can not be identified in KB.system_decomposition_map" << endl;
264 fout <<
r5pars_.timesno <<
" ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedSupportSystemState support system: "
266 <<
" can not be identified in KB.system_decomposition_map\n";
274 bool is_included, inclusion_1;
275 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
283 sd_pt = sd_map_itr->second;
288 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {
290 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
293 (*grouped_info_itr)->perceived_parameter_value.push_back(shared_ptr<MentalParameterValue>(_mpv, [](
MentalParameterValue*){}));
309 ofstream fout(
"err messages.txt", ios::app);
310 cout <<
"ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterValue Parameter: "
312 <<
" can not be identified in KB.system_decomposition_map" << endl;
313 fout <<
r5pars_.timesno <<
" ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterValue Parameter: "
315 <<
" can not be identified in KB.system_decomposition_map\n";
323 bool is_included, inclusion_1;
324 map<string, KBSystemDecompositionUnit *>::iterator sd_map_itr;
332 sd_pt = sd_map_itr->second;
337 while (i < sd_pt->getNumberOfRelatedSubsystem() && !is_included) {
339 is_included = (*grouped_info_itr)->checkWhetherSubSystemIsIncluded(subsystem_n);
342 (*grouped_info_itr)->perceived_parameter_trend.push_back(shared_ptr<MentalParameterTrend>(_mpt, [](
MentalParameterTrend*){}));
358 ofstream fout(
"err messages.txt", ios::app);
359 cout <<
"ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterTrend Parameter: "
361 <<
" can not be identified in KB.system_decomposition_map" << endl;
362 fout <<
r5pars_.timesno <<
" ShortTermMemory::checkAndGenerateInfoChunkMentalForRelatedParameterTrend Parameter: "
364 <<
" can not be identified in KB.system_decomposition_map\n";
408 bool is_included =
false;
418 if ((*ritr)->diagnosisIsIncluded(_dia_name)) {
420 updated = (*ritr)->activateTheDiagnosis(_dia_name);
445 double max_priority = -1.0e8;
448 if ((*grouped_info_itr)->getPriority() > max_priority) {
449 max_priority = (*grouped_info_itr)->getPriority();
450 _wm = grouped_info_itr->get();
463 auto i_chunk = make_unique<InfoChunkMental>();
469 i_chunk->goal.push_back(goal_sp);
470 i_chunk->strategy.push_back(strategy_sp);
481 for (i = 0; i < n; i++) {
484 i_chunk_pt = info_itr->get();
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);
522 (*grouped_info_itr)->clearInfoChunkMentalPointers();
536 (*grouped_info_itr)->clearInfoChunkMental();
550 (*grouped_info_itr)->clearInfoChunkMentalPointers();
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>());
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++) {
583 if (fabs((*goal_itr)->getTimeAtWhichThisInfoIsPerceived() - (*goal_itr1)->getTimeAtWhichThisInfoIsPerceived())
586 grouped_info_pt->
goal.push_back(*goal_itr1);
591 for (
auto strategy_itr = (*grouped_info_itr)->strategy.begin(); strategy_itr != (*grouped_info_itr)->strategy.end();
596 if (fabs((*strategy_itr)->getTimeAtWhichThisInfoIsPerceived()
597 - (*strategy_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
599 grouped_info_pt->
strategy.push_back(*strategy_itr1);
604 for (
auto subgoal_itr = (*grouped_info_itr)->subgoal.begin(); subgoal_itr != (*grouped_info_itr)->subgoal.end();
610 (*subgoal_itr)->getTimeAtWhichThisInfoIsPerceived() - (*subgoal_itr1)->getTimeAtWhichThisInfoIsPerceived())
613 grouped_info_pt->
subgoal.push_back(*subgoal_itr1);
618 for (
auto diagnosis_itr = (*grouped_info_itr)->diagnosis.begin(); diagnosis_itr != (*grouped_info_itr)->diagnosis.end();
623 if (fabs((*diagnosis_itr)->getTimeAtWhichThisInfoIsPerceived()
624 - (*diagnosis_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
626 grouped_info_pt->
diagnosis.push_back(*diagnosis_itr1);
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++) {
636 if (fabs((*action_objective_itr)->getTimeAtWhichThisInfoIsPerceived()
637 - (*action_objective_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
641 action_objective_itr1++;
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++) {
649 if (fabs((*action_pack_itr)->getTimeAtWhichThisInfoIsPerceived()
650 - (*action_pack_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
652 grouped_info_pt->
action_pack.push_back(*action_pack_itr1);
657 for (
auto action_itr = (*grouped_info_itr)->action.begin(); action_itr != (*grouped_info_itr)->action.end();
663 (*action_itr)->getTimeAtWhichThisInfoIsPerceived() - (*action_itr1)->getTimeAtWhichThisInfoIsPerceived())
666 grouped_info_pt->
action.push_back(*action_itr1);
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++) {
676 if (((*procedure_step_itr)->getProcedureName() == (*procedure_step_itr1)->getProcedureName()) &&
677 ((*procedure_step_itr)->getStepName() == (*procedure_step_itr1)->getStepName())) {
681 procedure_step_itr1++;
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++) {
689 if (fabs((*perceived_alarms_itr)->getTimeAtWhichThisInfoIsPerceived()
690 - (*perceived_alarms_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
694 perceived_alarms_itr1++;
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++) {
703 if (fabs((*perceived_component_state_itr)->getTimeAtWhichThisInfoIsPerceived()
704 - (*perceived_component_state_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
708 perceived_component_state_itr1++;
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++) {
717 if (fabs((*perceived_support_system_state_itr)->getTimeAtWhichThisInfoIsPerceived()
718 - (*perceived_support_system_state_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
722 perceived_support_system_state_itr1++;
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++) {
731 if (fabs((*perceived_parameter_value_itr)->getTimeAtWhichThisInfoIsPerceived()
732 - (*perceived_parameter_value_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
736 perceived_parameter_value_itr1++;
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++) {
745 if (fabs((*perceived_parameter_trend_itr)->getTimeAtWhichThisInfoIsPerceived()
746 - (*perceived_parameter_trend_itr1)->getTimeAtWhichThisInfoIsPerceived()) < 0.001) {
750 perceived_parameter_trend_itr1++;
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++) {
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";
785 fout <<
"ShortTermMemory\n";
788 fout <<
"Info_Chunks " << num <<
'\n';
790 (*grouped_info_itr)->saveInfoChunkMentalToFile(fout);
804 if (str !=
"ShortTermMemory") {
805 ofstream fout(
"err messages.txt", ios::app);
806 cout <<
"ShortTermMemory::retrieveShortTermMemoryFromFile File retrieval error in previous function" << endl;
808 <<
" ShortTermMemory::retrieveShortTermMemoryFromFile File retrieval error in previous function\n";
818 if (str !=
"Info_Chunks") {
819 ofstream fout(
"err messages.txt", ios::app);
820 cout <<
"ShortTermMemory::retrieveShortTermMemoryFromFile File retrieval error in perceived_info" << endl;
822 <<
" ShortTermMemory::retrieveShortTermMemoryFromFile File retrieval error in perceived_info\n";
829 for (i = 0; i < num; i++) {
830 auto p = make_unique<InfoChunkMental>();
831 p->retrieveInfoChunkMentalFromFile(fin);
835 (*grouped_info_itr)->replaceObjecByPointerForGroupedInfoAll(this->
perceived_info);
845 bool found_goal =
false;
849 while (goal_itr != goal_end && !found_goal) {
851 current_goal = (*goal_itr)->getDecision();
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()
void clearCommunicationPlaceAll()
std::string getDisplayName()
std::string getDisplayName()
std::list< int > related_subsystem
std::vector< std::shared_ptr< MentalSupportSystemState > > perceived_support_system_state
int getTotalNumberOfFailedDiagnosis()
std::vector< std::shared_ptr< MentalParameterValue > > perceived_parameter_value
std::vector< std::shared_ptr< DecisionSubGoal > > subgoal
std::vector< std::shared_ptr< MentalParameterTrend > > perceived_parameter_trend
std::vector< std::shared_ptr< DecisionStrategy > > strategy
int getTotalNumberOfAlarmPerceived()
std::vector< std::shared_ptr< DecisionAction > > action
void addANewGoal(int, int)
void copyInfoChunk(InfoChunk &)
std::vector< std::shared_ptr< DecisionActionPack > > action_pack
void saveInfoChunkToFile(std::ofstream &)
void addANewStrategy(int, int)
void pointToAvtiveGoalAndStrategy(InfoChunk &)
std::vector< std::shared_ptr< DecisionGoal > > goal
std::vector< std::shared_ptr< DecisionDiagnosis > > diagnosis
std::vector< std::shared_ptr< MentalAlarm > > perceived_alarms
std::vector< std::shared_ptr< MentalComponentState > > perceived_component_state
std::vector< std::shared_ptr< DecisionProcedureStep > > procedure_step
double getTotalWeightOfAlarmPerceived()
int getTotalPieceOfInfoPerceived()
std::vector< std::shared_ptr< DecisionActionObjective > > action_objective
void retrieveInfoChunkFromFile(std::ifstream &)
int getRelatedSubsystem(int)
int getNumberOfRelatedSubsystem()
std::map< std::string, KBSystemDecompositionUnit * > system_decomposition_map
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 &)
int getTotalNumberOfInfoChunk()
void checkAndGenerateInfoChunkMentalForRelatedComponentState(MentalComponentState *, KB &)
CommunicationPlace new_info
int getTotalFailedDiagnosis()
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
void checkAndGenerateInfoChunkMentalForRelatedParameterTrend(MentalParameterTrend *, KB &)
void checkAndGenerateInfoChunkMentalForDiagnosis(DecisionDiagnosis *)
int getTotalFailedActionPack()
double getTotalWeightOfAlarmPerceived()
void setStateOfActivation(int)
int getStateOfActivation()
void saveTimerToFile(std::ofstream &)
void retrieveTimerFromFile(std::ifstream &)
constexpr int Interrupted
BranchRecord Branch_center
Dynamic event tree state.