← Documentation
ADS-IDAC Engine 5.0.0
BranchAction.cpp
Go to the documentation of this file.
1// BranchAction.cpp: implementation of the BranchAction class.
2//
4
5#include "BranchAction.h"
6#include <sstream>
7#include "../Global/ConvertToString.h"
8#include "../ControlPanel/ControlPanel.h"
9#include <boost/serialization/export.hpp>
10#include "../Global/SimulationContext.h"
11#include <boost/archive/binary_oarchive.hpp>
12#include <boost/archive/binary_iarchive.hpp>
13BOOST_CLASS_EXPORT_IMPLEMENT(BranchAction)
14using namespace std;
15
16
18// Construction/Destruction
20
22 action_time = -1.0;
23}
24
26
27}
31 this->copyCommunication(_bap);
32 this->copyTimerAndProbability(_bap);
33 this->copyDecisionAction(_bap);
34 this->copyStringContainer(_bap);
36}
38 map<string, SystemControl *>::iterator control_map_itr;
39 SystemControl *sc_ptr;
40 string str, str1, str2, message;
41 int state = sim::None;
42 double contrl_value;
43 str = "ACTION: Sender: ";
44 str += g_sim.Translator.getString(this->getSender());
45 str += "; Receiver: ";
47 str += "; Action: ";
48 str += this->getActionName();
49 message = this->getMessage();
51 //
52 // determine if control is permanently failed
53 control_map_itr = g_sim.Indicator.controls.control_map.find(this->getActionName());
54 if (control_map_itr != g_sim.Indicator.controls.control_map.end()) {
55 sc_ptr = control_map_itr->second;
56 state = sc_ptr->getFunctionalState();
57 }
58 if (this->getActionName().substr(0, 7) == "WAITING") {
59 str += " ; ";
60 str += str2;
61 } else if (state == sim::State::FailedP) {
62 str += " ; ";
63 str += str2;
64 str += " - Permanent Failure";
65 } else {
66 contrl_value = this->getControlValue();
67 str1 = std::to_string(contrl_value);
68 str += " ; Intended_Receiver:";
70 str += "; Control_value:";
71 str += str1;
72 str += " ; ";
73 str += str2;
74 }
75 str += "; New Probability: ";
76 std::ostringstream streamObj;
77 streamObj << this->getProbability();
78 str += streamObj.str();
79 return str;
80}
81void BranchAction::saveInfoToFile(ostream &fout) {
82 string str, str1;
83 double value;
84 fout << ' ' << this->getSender() << ' ' << sim::Action::Direct << ' ' << sim::None << ' ' << this->getActionName() << ' '
85 << this->getProbability() << ' '
86 << this->getTimeOfCommunication() << ' ' << this->getRemainingTime() << ' ' << this->getControlValue() << " 0 ";
88 if (this->getActionName().substr(0, 7) != "WAITING") {
89 value = this->getControlValue();
90 str = to_string(value);
91 fout << '"' << "Intended_Receiver:" << g_sim.Translator.getString(this->getIntendedReceiver()) << ";Control_value:" << str
92 << ';' << str1 << '"' << '\n';
93 } else {
94
95 fout << '"' << str1 << '"' << '\n';
96 }
97}
99 this->saveDecisionActionToFile(fout);
101 this->saveCommunicationToFile(fout);
102 this->saveStringContainerToFile(fout);
103 fout << action_time << '\n';
104}
110 fin >> action_time;
111}
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
void copyBranchAction(BranchAction &)
void saveBranchActionToFile(std::ofstream &)
std::string translateMessage()
virtual ~BranchAction()
double action_time
Definition: BranchAction.h:52
void retrieveBranchActionFromFile(std::ifstream &)
void setActionTime(double)
double getActionTime()
void saveInfoToFile(std::ostream &)
double getTimeOfCommunication()
void saveCommunicationToFile(std::ofstream &)
int getIntendedReceiver()
void retrieveCommunicationFromFile(std::ifstream &)
void copyCommunication(Communication &)
double getControlValue()
std::map< std::string, SystemControl * > control_map
ControlPanelControl controls
Definition: ControlPanel.h:54
std::string removeQuotationAndSpace(std::string)
std::string getString(int) const
std::string getActionName()
void retrieveDecisionActionFromFile(std::ifstream &)
void copyDecisionAction(DecisionAction &)
void saveDecisionActionToFile(std::ofstream &)
double getProbability()
Definition: Probability.cpp:27
void saveStringContainerToFile(std::ofstream &)
std::string message
std::string getMessage()
void copyStringContainer(StringContainer &)
void retrieveStringContainerFromFile(std::ifstream &)
int getFunctionalState()
void saveTimerAndProbabilityToFile(std::ofstream &)
void copyTimerAndProbability(TimerAndProbability &)
void retrieveTimerAndProbabilityFromFile(std::ifstream &)
double getRemainingTime()
Definition: Timer.cpp:31
constexpr int Direct
Definition: SimConstants.h:202
constexpr int FailedP
Definition: SimConstants.h:115
constexpr int None
Definition: SimConstants.h:75
ControlPanel Indicator
Control room panel state.
ConvertToString Translator
Parameter name/value conversion.