Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DFTBuilder.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <map>
5#include <unordered_map>
6
10
14
15namespace storm::storage {
16// Forward declaration
17template<typename ValueType>
18class DFT;
19} // namespace storm::storage
20
21namespace storm::dft {
22namespace builder {
23
24template<typename ValueType>
26 using DFTElementPointer = std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType>>;
27 using DFTElementCPointer = std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const>;
28 using DFTElementVector = std::vector<DFTElementPointer>;
29 using DFTBEPointer = std::shared_ptr<storm::dft::storage::elements::DFTBE<ValueType>>;
30 using DFTChildrenCPointer = std::shared_ptr<storm::dft::storage::elements::DFTChildren<ValueType> const>;
31 using DFTGatePointer = std::shared_ptr<storm::dft::storage::elements::DFTGate<ValueType>>;
32 using DFTDependencyPointer = std::shared_ptr<storm::dft::storage::elements::DFTDependency<ValueType>>;
33 using DFTRestrictionPointer = std::shared_ptr<storm::dft::storage::elements::DFTRestriction<ValueType>>;
34
35 private:
36 std::size_t mNextId;
37 std::string mTopLevelName;
38 std::unordered_map<std::string, DFTElementPointer> mElements;
39 std::unordered_map<DFTElementPointer, std::vector<std::string>> mChildNames;
40 std::unordered_map<DFTRestrictionPointer, std::vector<std::string>> mRestrictionChildNames;
41 std::unordered_map<DFTDependencyPointer, std::vector<std::string>> mDependencyChildNames;
42 std::unordered_map<std::string, storm::dft::storage::DFTLayoutInfo> mLayoutInfo;
44
45 public:
49 DFTBuilder();
50
56 void addBasicElementConst(std::string const& name, bool failed);
57
65 void addBasicElementProbability(std::string const& name, ValueType probability, ValueType dormancyFactor);
66
74 void addBasicElementExponential(std::string const& name, ValueType rate, ValueType dormancyFactor, bool transient = false);
75
83 void addBasicElementErlang(std::string const& name, ValueType rate, unsigned phases, ValueType dormancyFactor);
84
91 void addBasicElementWeibull(std::string const& name, ValueType shape, ValueType rate);
92
99 void addBasicElementLogNormal(std::string const& name, ValueType mean, ValueType standardDeviation);
100
106 void addBasicElementSamples(std::string const& name, std::map<ValueType, ValueType> const& activeSamples);
107
113 void addAndGate(std::string const& name, std::vector<std::string> const& children);
114
120 void addOrGate(std::string const& name, std::vector<std::string> const& children);
121
128 void addVotingGate(std::string const& name, unsigned threshold, std::vector<std::string> const& children);
129
136 void addPandGate(std::string const& name, std::vector<std::string> const& children, bool inclusive = true);
137
144 void addPorGate(std::string const& name, std::vector<std::string> const& children, bool inclusive = true);
145
151 void addSpareGate(std::string const& name, std::vector<std::string> const& children);
152
158 void addSequenceEnforcer(std::string const& name, std::vector<std::string> const& children);
159
165 void addMutex(std::string const& name, std::vector<std::string> const& children);
166
173 void addPdep(std::string const& name, std::vector<std::string> const& children, ValueType probability);
174
179 void setTopLevel(std::string const& tle);
180
187 void addLayoutInfo(std::string const& name, double x, double y);
188
195
201 void cloneElement(DFTElementCPointer element);
202
209 void cloneElementWithNewChildren(DFTChildrenCPointer elemWithChildren, std::vector<std::string> const& children);
210
211 private:
216 void addElement(DFTElementPointer element);
217
223 void addGate(DFTGatePointer gate, std::vector<std::string> const& children);
224
230 void addDependency(DFTDependencyPointer dependency, std::vector<std::string> const& children);
231
237 void addRestriction(DFTRestrictionPointer restriction, std::vector<std::string> const& children);
238
244 bool nameInUse(std::string const& name) const;
245
251 bool isValidProbability(ValueType value) const;
252
259 enum class topoSortColour { WHITE, BLACK, GREY };
260
267 void topologicalVisit(DFTElementPointer const& element,
268 std::map<DFTElementPointer, topoSortColour, storm::dft::storage::OrderElementsById<ValueType>>& visited,
269 DFTElementVector& visitedElements);
270
275 DFTElementVector sortTopological();
276
284 size_t computeRank(DFTElementPointer const& elem);
285};
286
287} // namespace builder
288} // 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 addLayoutInfo(std::string const &name, double x, double y)
Add layout information for DFT element.
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 cloneElement(DFTElementCPointer element)
Clone element and add it via the builder.
void setTopLevel(std::string const &tle)
Set top level element.
void cloneElementWithNewChildren(DFTChildrenCPointer elemWithChildren, std::vector< std::string > const &children)
Clone element, replace its children with the given children and add it via the builder.
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