Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DftInstantiator.cpp
Go to the documentation of this file.
1#include "DftInstantiator.h"
4
5namespace storm::dft {
6namespace transformations {
7
8template<typename ParametricType, typename ConstantType>
10
11template<typename ParametricType, typename ConstantType>
12std::shared_ptr<storm::dft::storage::DFT<ConstantType>> DftInstantiator<ParametricType, ConstantType>::instantiate(
15 for (size_t i = 0; i < dft.nrElements(); ++i) {
16 std::shared_ptr<storm::dft::storage::elements::DFTElement<ParametricType> const> element = dft.getElement(i);
17 switch (element->type()) {
19 // Instantiate probability distributions
20 auto be = std::static_pointer_cast<storm::dft::storage::elements::DFTBE<ParametricType> const>(element);
21 switch (be->beType()) {
23 auto beConst = std::static_pointer_cast<storm::dft::storage::elements::BEConst<ParametricType> const>(element);
24 builder.addBasicElementConst(beConst->name(), beConst->canFail());
25 break;
26 }
28 auto beProb = std::static_pointer_cast<storm::dft::storage::elements::BEProbability<ParametricType> const>(element);
29 ConstantType activeFailureProbability = instantiate_helper(beProb->activeFailureProbability(), valuation);
30 ConstantType dormancyFactor = instantiate_helper(beProb->dormancyFactor(), valuation);
31 builder.addBasicElementProbability(beProb->name(), activeFailureProbability, dormancyFactor);
32 break;
33 }
35 auto beExp = std::static_pointer_cast<storm::dft::storage::elements::BEExponential<ParametricType> const>(element);
36 ConstantType activeFailureRate = instantiate_helper(beExp->activeFailureRate(), valuation);
37 ConstantType dormancyFactor = instantiate_helper(beExp->dormancyFactor(), valuation);
38 builder.addBasicElementExponential(beExp->name(), activeFailureRate, dormancyFactor, beExp->isTransient());
39 break;
40 }
42 auto beErlang = std::static_pointer_cast<storm::dft::storage::elements::BEErlang<ParametricType> const>(element);
43 ConstantType activeFailureRate = instantiate_helper(beErlang->activeFailureRate(), valuation);
44 ConstantType dormancyFactor = instantiate_helper(beErlang->dormancyFactor(), valuation);
45 builder.addBasicElementErlang(beErlang->name(), activeFailureRate, beErlang->phases(), dormancyFactor);
46 break;
47 }
49 auto beWeibull = std::static_pointer_cast<storm::dft::storage::elements::BEWeibull<ParametricType> const>(element);
50 ConstantType shape = instantiate_helper(beWeibull->shape(), valuation);
51 ConstantType rate = instantiate_helper(beWeibull->rate(), valuation);
52 builder.addBasicElementWeibull(beWeibull->name(), shape, rate);
53 break;
54 }
56 auto beLogNormal = std::static_pointer_cast<storm::dft::storage::elements::BELogNormal<ParametricType> const>(element);
57 ConstantType mean = instantiate_helper(beLogNormal->mean(), valuation);
58 ConstantType stddev = instantiate_helper(beLogNormal->standardDeviation(), valuation);
59 builder.addBasicElementLogNormal(beLogNormal->name(), mean, stddev);
60 break;
61 }
63 auto beSamples = std::static_pointer_cast<storm::dft::storage::elements::BESamples<ParametricType> const>(element);
64 std::map<ConstantType, ConstantType> activeSamples{};
65 for (auto &[time, prob] : beSamples->activeSamples()) {
66 ConstantType timeInst = instantiate_helper(time, valuation);
67 ConstantType probInst = instantiate_helper(prob, valuation);
68 activeSamples[timeInst] = probInst;
69 }
70 builder.addBasicElementSamples(beSamples->name(), activeSamples);
71 break;
72 }
73 default:
74 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "BE type '" << be->beType() << "' not known.");
75 break;
76 }
77 break;
78 }
79 // We cannot use cloneElement() as ValueType differs between the original element and the clone.
81 builder.addAndGate(element->name(), getChildrenVector(element));
82 break;
84 builder.addOrGate(element->name(), getChildrenVector(element));
85 break;
87 auto vot = std::static_pointer_cast<storm::dft::storage::elements::DFTVot<ParametricType> const>(element);
88 builder.addVotingGate(vot->name(), vot->threshold(), getChildrenVector(vot));
89 break;
90 }
92 auto pand = std::static_pointer_cast<storm::dft::storage::elements::DFTPand<ParametricType> const>(element);
93 builder.addPandGate(pand->name(), getChildrenVector(pand), pand->isInclusive());
94 break;
95 }
97 auto por = std::static_pointer_cast<storm::dft::storage::elements::DFTPor<ParametricType> const>(element);
98 builder.addPorGate(por->name(), getChildrenVector(por), por->isInclusive());
99 break;
100 }
102 builder.addSpareGate(element->name(), getChildrenVector(element));
103 break;
105 builder.addSequenceEnforcer(element->name(), getChildrenVector(element));
106 break;
108 builder.addMutex(element->name(), getChildrenVector(element));
109 break;
111 auto dependency = std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<ParametricType> const>(element);
112 // Instantiate probability
113 ConstantType probability = instantiate_helper(dependency->probability(), valuation);
114 std::vector<std::string> children = {dependency->triggerEvent()->name()};
115 for (auto const &depEvent : dependency->dependentEvents()) {
116 children.push_back(depEvent->name());
117 }
118 builder.addPdep(dependency->name(), children, probability);
119 break;
120 }
121 default:
122 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "DFT type '" << element->type() << "' not known.");
123 break;
124 }
125 }
126
127 builder.setTopLevel(dft.getTopLevelElement()->name());
128 return std::make_shared<storm::dft::storage::DFT<ConstantType>>(builder.build());
129}
130
131template<typename ParametricType, typename ConstantType>
133 std::shared_ptr<storm::dft::storage::elements::DFTElement<ParametricType> const> element) {
134 std::vector<std::string> children;
135 auto elementWithChildren = std::static_pointer_cast<storm::dft::storage::elements::DFTChildren<ParametricType> const>(element);
136 for (auto const &child : elementWithChildren->children()) {
137 children.push_back(child->name());
138 }
139 return children;
140}
141
142template<typename ParametricType, typename ConstantType>
144 // TODO write some checks
145}
146
147// Explicitly instantiate the class.
149
150} // namespace transformations
151} // 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:39
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:41