Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DftInstantiator.cpp
Go to the documentation of this file.
2
6
7namespace storm::dft {
8namespace transformations {
9
10template<typename ParametricType, typename ConstantType>
12
13template<typename ParametricType, typename ConstantType>
14std::shared_ptr<storm::dft::storage::DFT<ConstantType>> DftInstantiator<ParametricType, ConstantType>::instantiate(
17 for (size_t i = 0; i < dft.nrElements(); ++i) {
18 std::shared_ptr<storm::dft::storage::elements::DFTElement<ParametricType> const> element = dft.getElement(i);
19 switch (element->type()) {
21 // Instantiate probability distributions
22 auto be = std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ParametricType> const>(element);
23 switch (be->beType()) {
25 auto beConst = std::static_pointer_cast<storm::dft::storage::elements::BEConst<ParametricType> const>(element);
26 builder.addBasicElementConst(beConst->name(), beConst->canFail());
27 break;
28 }
30 auto beProb = std::static_pointer_cast<storm::dft::storage::elements::BEProbability<ParametricType> const>(element);
31 ConstantType activeFailureProbability = instantiate_helper(beProb->activeFailureProbability(), valuation);
32 ConstantType dormancyFactor = instantiate_helper(beProb->dormancyFactor(), valuation);
33 builder.addBasicElementProbability(beProb->name(), activeFailureProbability, dormancyFactor);
34 break;
35 }
37 auto beExp = std::static_pointer_cast<storm::dft::storage::elements::BEExponential<ParametricType> const>(element);
38 ConstantType activeFailureRate = instantiate_helper(beExp->activeFailureRate(), valuation);
39 ConstantType dormancyFactor = instantiate_helper(beExp->dormancyFactor(), valuation);
40 builder.addBasicElementExponential(beExp->name(), activeFailureRate, dormancyFactor, beExp->isTransient());
41 break;
42 }
44 auto beErlang = std::static_pointer_cast<storm::dft::storage::elements::BEErlang<ParametricType> const>(element);
45 ConstantType activeFailureRate = instantiate_helper(beErlang->activeFailureRate(), valuation);
46 ConstantType dormancyFactor = instantiate_helper(beErlang->dormancyFactor(), valuation);
47 builder.addBasicElementErlang(beErlang->name(), activeFailureRate, beErlang->phases(), dormancyFactor);
48 break;
49 }
51 auto beWeibull = std::static_pointer_cast<storm::dft::storage::elements::BEWeibull<ParametricType> const>(element);
52 ConstantType shape = instantiate_helper(beWeibull->shape(), valuation);
53 ConstantType rate = instantiate_helper(beWeibull->rate(), valuation);
54 builder.addBasicElementWeibull(beWeibull->name(), shape, rate);
55 break;
56 }
58 auto beLogNormal = std::static_pointer_cast<storm::dft::storage::elements::BELogNormal<ParametricType> const>(element);
59 ConstantType mean = instantiate_helper(beLogNormal->mean(), valuation);
60 ConstantType stddev = instantiate_helper(beLogNormal->standardDeviation(), valuation);
61 builder.addBasicElementLogNormal(beLogNormal->name(), mean, stddev);
62 break;
63 }
65 auto beSamples = std::static_pointer_cast<storm::dft::storage::elements::BESamples<ParametricType> const>(element);
66 std::map<ConstantType, ConstantType> activeSamples{};
67 for (auto &[time, prob] : beSamples->activeSamples()) {
68 ConstantType timeInst = instantiate_helper(time, valuation);
69 ConstantType probInst = instantiate_helper(prob, valuation);
70 activeSamples[timeInst] = probInst;
71 }
72 builder.addBasicElementSamples(beSamples->name(), activeSamples);
73 break;
74 }
75 default:
76 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "BE type '" << be->beType() << "' not known.");
77 break;
78 }
79 break;
80 }
81 // We cannot use cloneElement() as ValueType differs between the original element and the clone.
83 builder.addAndGate(element->name(), getChildrenVector(element));
84 break;
86 builder.addOrGate(element->name(), getChildrenVector(element));
87 break;
89 auto vot = std::static_pointer_cast<storm::dft::storage::elements::DFTVot<ParametricType> const>(element);
90 builder.addVotingGate(vot->name(), vot->threshold(), getChildrenVector(vot));
91 break;
92 }
94 auto pand = std::static_pointer_cast<storm::dft::storage::elements::DFTPand<ParametricType> const>(element);
95 builder.addPandGate(pand->name(), getChildrenVector(pand), pand->isInclusive());
96 break;
97 }
99 auto por = std::static_pointer_cast<storm::dft::storage::elements::DFTPor<ParametricType> const>(element);
100 builder.addPorGate(por->name(), getChildrenVector(por), por->isInclusive());
101 break;
102 }
104 builder.addSpareGate(element->name(), getChildrenVector(element));
105 break;
107 builder.addSequenceEnforcer(element->name(), getChildrenVector(element));
108 break;
110 builder.addMutex(element->name(), getChildrenVector(element));
111 break;
113 auto dependency = std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<ParametricType> const>(element);
114 // Instantiate probability
115 ConstantType probability = instantiate_helper(dependency->probability(), valuation);
116 std::vector<std::string> children = {dependency->triggerEvent()->name()};
117 for (auto const &depEvent : dependency->dependentEvents()) {
118 children.push_back(depEvent->name());
119 }
120 builder.addPdep(dependency->name(), children, probability);
121 break;
122 }
123 default:
124 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "DFT type '" << element->type() << "' not known.");
125 break;
126 }
127 }
128
129 builder.setTopLevel(dft.getTopLevelElement()->name());
130 return std::make_shared<storm::dft::storage::DFT<ConstantType>>(builder.build());
131}
132
133template<typename ParametricType, typename ConstantType>
135 std::shared_ptr<storm::dft::storage::elements::DFTElement<ParametricType> const> element) {
136 std::vector<std::string> children;
137 auto elementWithChildren = std::static_pointer_cast<storm::dft::storage::elements::DFTChildren<ParametricType> const>(element);
138 for (auto const &child : elementWithChildren->children()) {
139 children.push_back(child->name());
140 }
141 return children;
142}
143
144template<typename ParametricType, typename ConstantType>
146 // TODO write some checks
147}
148
149// Explicitly instantiate the class.
151
152} // namespace transformations
153} // namespace storm::dft
void addPdep(std::string const &name, std::vector< std::string > const &children, ValueType probability)
Create (probabilistic) dependency (PDEP) and add it to DFT.
void addOrGate(std::string const &name, std::vector< std::string > const &children)
Create OR-gate and add it to DFT.
void addVotingGate(std::string const &name, unsigned threshold, std::vector< std::string > const &children)
Create VOTing-gate and add it to DFT.
void addBasicElementSamples(std::string const &name, std::map< ValueType, ValueType > const &activeSamples)
Create BE with distribution given by sample points and add it to DFT.
void addBasicElementErlang(std::string const &name, ValueType rate, unsigned phases, ValueType dormancyFactor)
Create BE with Erlang distribution and add it to DFT.
void addSpareGate(std::string const &name, std::vector< std::string > const &children)
Create SPARE-gate and add it to DFT.
void addBasicElementConst(std::string const &name, bool failed)
Create BE which is constant failed or constant failsafe and add it to DFT.
storm::dft::storage::DFT< ValueType > build()
Create DFT.
void addAndGate(std::string const &name, std::vector< std::string > const &children)
Create AND-gate and add it to DFT.
void addBasicElementProbability(std::string const &name, ValueType probability, ValueType dormancyFactor)
Create BE with constant (Bernoulli) distribution and add it to DFT.
void setTopLevel(std::string const &tle)
Set top level element.
void addBasicElementExponential(std::string const &name, ValueType rate, ValueType dormancyFactor, bool transient=false)
Create BE with exponential distribution and add it to DFT.
void addPorGate(std::string const &name, std::vector< std::string > const &children, bool inclusive=true)
Create POR-gate and add it to DFT.
void addSequenceEnforcer(std::string const &name, std::vector< std::string > const &children)
Create sequence enforcer (SEQ) and add it to DFT.
void addPandGate(std::string const &name, std::vector< std::string > const &children, bool inclusive=true)
Create PAND-gate and add it to DFT.
void addBasicElementWeibull(std::string const &name, ValueType shape, ValueType rate)
Create BE with Weibull distribution and add it to DFT.
void addBasicElementLogNormal(std::string const &name, ValueType mean, ValueType standardDeviation)
Create BE with log-normal distribution and add it to DFT.
void addMutex(std::string const &name, std::vector< std::string > const &children)
Create mutual exclusion-gate (MUTEX) and add it to DFT.
Represents a Dynamic Fault Tree.
Definition DFT.h:52
Abstract base class for DFT elements.
Definition DFTElement.h:38
Instantiator to yield a concrete DFT from a parametric DFT (with parametric failure rates).
DftInstantiator(storm::dft::storage::DFT< ParametricType > const &dft)
Constructor.
std::shared_ptr< storm::dft::storage::DFT< ConstantType > > instantiate(storm::utility::parametric::Valuation< ParametricType > const &valuation)
Evaluates the occurring parametric functions and retrieves the instantiated DFT.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::map< typename VariableType< FunctionType >::type, typename CoefficientType< FunctionType >::type > Valuation
Definition parametric.h:43