←
Documentation
ADS-IDAC Engine
5.0.0
BranchSystemAction.cpp
Go to the documentation of this file.
1
// BranchSystemAction.cpp: implementation of the BranchSystemAction class.
2
//
4
5
#include <sstream>
6
#include "
BranchSystemAction.h
"
7
#include "../Global/ConvertToString.h"
8
#include <boost/serialization/export.hpp>
9
#include "../Global/SimulationContext.h"
10
#include <boost/archive/binary_oarchive.hpp>
11
#include <boost/archive/binary_iarchive.hpp>
12
BOOST_CLASS_EXPORT_IMPLEMENT(
BranchSystemAction
)
13
using namespace
std;
14
15
17
// Construction/Destruction
19
20
BranchSystemAction::BranchSystemAction
() {
21
functional_state
=
sim::State::Unknown
;
22
}
23
24
BranchSystemAction::~BranchSystemAction
() {
25
26
}
27
void
BranchSystemAction::copyBranchSystemAction
(
BranchSystemAction
&_bsp) {
28
this->
copyControlElement
(_bsp);
29
this->
copyCommunication
(_bsp);
30
this->
copyTimerAndProbability
(_bsp);
31
functional_state
= _bsp.
getFunctionalState
();
32
}
33
string
BranchSystemAction::translateMessage
() {
34
string
str;
35
str =
"HWReliability: Sender: "
;
36
str +=
g_sim
.
Translator
.
getString
(this->
getSender
());
37
str +=
"; Receiver: "
;
38
str +=
g_sim
.
Translator
.
getString
(this->
getIntendedReceiver
());
39
str +=
"; Component: "
;
40
str += this->
getDisplayName
();
41
if
(
functional_state
==
sim::State::Succeed
) {
42
str +=
"; Status: Success"
;
43
}
else
if
(
functional_state
==
sim::State::Failed
) {
44
str +=
"; Status: Fail"
;
45
}
else
if
(
functional_state
==
sim::State::Control
) {
46
str +=
"; Status: Maneuver Action"
;
47
}
else
{
48
}
49
str +=
"; Control: "
;
50
str += this->
getCorrespondingComponentNameOfControl
();
51
str +=
"; Probability: "
;
52
std::ostringstream streamObj;
53
streamObj << this->
getProbability
();
54
str += streamObj.str();
55
return
str;
56
}
57
void
BranchSystemAction::saveInfoToFile
(ostream &fout) {
58
fout <<
' '
<< this->
getSender
() <<
' '
<<
sim::Action::Direct
<<
' '
<<
sim::None
<<
' '
<< this->
getDisplayName
() <<
' '
59
<< this->
getProbability
() <<
' '
60
<< this->
getTimeOfCommunication
() <<
' '
<< this->
getAdjustedTimeRequiredToPerformTheAction
() <<
' '
61
<< this->
getControlValue
() <<
" 0 "
;
62
if
(this->
getFunctionalState
() ==
sim::State::Failed
) {
63
fout <<
'"'
<<
"Failed!_Intended_Receiver:"
<<
g_sim
.
Translator
.
getString
(this->
getIntendedReceiver
()) <<
'"'
<<
'\n'
;
64
}
else
{
65
fout <<
'"'
<<
"Success!_Intended_Receiver:"
<<
g_sim
.
Translator
.
getString
(this->
getIntendedReceiver
()) <<
'"'
<<
'\n'
;
66
}
67
}
68
void
BranchSystemAction::setFunctionalState
(
int
n) {
functional_state
= n; }
69
int
BranchSystemAction::getFunctionalState
() {
return
functional_state
; }
70
void
BranchSystemAction::saveBranchSystemActionToFile
(ofstream &fout) {
71
fout <<
functional_state
<<
'\n'
;
72
this->
saveControlElementToFile
(fout);
73
this->
saveCommunicationToFile
(fout);
74
this->
saveTimerAndProbabilityToFile
(fout);
75
}
76
void
BranchSystemAction::retrieveBranchSystemActionFromFile
(ifstream &fin) {
77
fin >>
functional_state
;
78
this->
retrieveControlElementFromFile
(fin);
79
this->
retrieveCommunicationFromFile
(fin);
80
this->
retrieveTimerAndProbabilityFromFile
(fin);
81
}
BranchSystemAction.h
g_sim
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
Definition:
SimulationContext.cpp:7
BranchSystemAction
Definition:
BranchSystemAction.h:22
BranchSystemAction::getFunctionalState
int getFunctionalState()
Definition:
BranchSystemAction.cpp:69
BranchSystemAction::saveBranchSystemActionToFile
void saveBranchSystemActionToFile(std::ofstream &)
Definition:
BranchSystemAction.cpp:70
BranchSystemAction::setFunctionalState
void setFunctionalState(int)
Definition:
BranchSystemAction.cpp:68
BranchSystemAction::translateMessage
std::string translateMessage()
Definition:
BranchSystemAction.cpp:33
BranchSystemAction::functional_state
int functional_state
Definition:
BranchSystemAction.h:45
BranchSystemAction::saveInfoToFile
void saveInfoToFile(std::ostream &)
Definition:
BranchSystemAction.cpp:57
BranchSystemAction::retrieveBranchSystemActionFromFile
void retrieveBranchSystemActionFromFile(std::ifstream &)
Definition:
BranchSystemAction.cpp:76
BranchSystemAction::copyBranchSystemAction
void copyBranchSystemAction(BranchSystemAction &)
Definition:
BranchSystemAction.cpp:27
BranchSystemAction::BranchSystemAction
BranchSystemAction()
Definition:
BranchSystemAction.cpp:20
BranchSystemAction::~BranchSystemAction
virtual ~BranchSystemAction()
Definition:
BranchSystemAction.cpp:24
Communication::getSender
int getSender()
Definition:
Communication.cpp:43
Communication::getTimeOfCommunication
double getTimeOfCommunication()
Definition:
Communication.cpp:47
Communication::saveCommunicationToFile
void saveCommunicationToFile(std::ofstream &)
Definition:
Communication.cpp:60
Communication::getIntendedReceiver
int getIntendedReceiver()
Definition:
Communication.cpp:44
Communication::retrieveCommunicationFromFile
void retrieveCommunicationFromFile(std::ifstream &)
Definition:
Communication.cpp:65
Communication::copyCommunication
void copyCommunication(Communication &)
Definition:
Communication.cpp:52
ControlElement::getDisplayName
std::string getDisplayName()
Definition:
ControlElement.cpp:40
ControlElement::saveControlElementToFile
void saveControlElementToFile(std::ofstream &)
Definition:
ControlElement.cpp:65
ControlElement::retrieveControlElementFromFile
void retrieveControlElementFromFile(std::ifstream &)
Definition:
ControlElement.cpp:70
ControlElement::getCorrespondingComponentNameOfControl
std::string getCorrespondingComponentNameOfControl()
Definition:
ControlElement.cpp:41
ControlElement::getControlValue
double getControlValue()
Definition:
ControlElement.cpp:64
ControlElement::getAdjustedTimeRequiredToPerformTheAction
double getAdjustedTimeRequiredToPerformTheAction()
Definition:
ControlElement.cpp:86
ControlElement::copyControlElement
void copyControlElement(ControlElement &)
Definition:
ControlElement.cpp:52
ConvertToString::getString
std::string getString(int) const
Definition:
ConvertToString.cpp:190
Probability::getProbability
double getProbability()
Definition:
Probability.cpp:27
TimerAndProbability::saveTimerAndProbabilityToFile
void saveTimerAndProbabilityToFile(std::ofstream &)
Definition:
TimerAndProbability.cpp:34
TimerAndProbability::copyTimerAndProbability
void copyTimerAndProbability(TimerAndProbability &)
Definition:
TimerAndProbability.cpp:30
TimerAndProbability::retrieveTimerAndProbabilityFromFile
void retrieveTimerAndProbabilityFromFile(std::ifstream &)
Definition:
TimerAndProbability.cpp:38
sim::Action::Direct
constexpr int Direct
Definition:
SimConstants.h:202
sim::State::Failed
constexpr int Failed
Definition:
SimConstants.h:103
sim::State::Succeed
constexpr int Succeed
Definition:
SimConstants.h:104
sim::State::Control
constexpr int Control
Definition:
SimConstants.h:111
sim::State::Unknown
constexpr int Unknown
Definition:
SimConstants.h:120
sim::None
constexpr int None
Definition:
SimConstants.h:75
SimulationContext::Translator
ConvertToString Translator
Parameter name/value conversion.
Definition:
SimulationContext.h:52
src
ADSIDAC
Branch
BranchSystemAction.cpp
Generated by
1.9.4