Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ExplicitDFTModelBuilder.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/optional/optional.hpp>
4#include <limits>
5#include <stack>
6#include <unordered_set>
7
14
21
22namespace storm::dft {
23namespace builder {
24
28template<typename ValueType, typename StateType = uint32_t>
30 using DFTStatePointer = std::shared_ptr<storm::dft::storage::DFTState<ValueType>>;
31 using ExplorationHeuristic = DFTExplorationHeuristic<ValueType>;
32 using ExplorationHeuristicPointer = std::shared_ptr<ExplorationHeuristic>;
33
34 // A structure holding the individual components of a model.
35 struct ModelComponents {
36 // Constructor
37 ModelComponents();
38
39 // The transition matrix.
41
42 // The state labeling.
44
45 // The Markovian states.
46 storm::storage::BitVector markovianStates;
47
48 // The exit rates.
49 std::vector<ValueType> exitRates;
50
51 // A vector that stores a labeling for each choice.
52 boost::optional<storm::models::sparse::ChoiceLabeling> choiceLabeling;
53
54 // A flag indicating if the model is deterministic.
55 bool deterministicModel;
56 };
57
58 // A class holding the information for building the transition matrix.
59 class MatrixBuilder {
60 public:
61 // Constructor
62 MatrixBuilder(bool canHaveNondeterminism);
63
69 void setRemapping(StateType id) {
70 STORM_LOG_ASSERT(id < stateRemapping.size(), "Invalid index for remapping.");
71 stateRemapping[id] = currentRowGroup;
72 }
73
77 void newRowGroup() {
78 if (canHaveNondeterminism) {
79 builder.newRowGroup(currentRow);
80 }
81 ++currentRowGroup;
82 }
83
90 void addTransition(StateType index, ValueType value) {
91 builder.addNextValue(currentRow, index, value);
92 }
93
97 void finishRow() {
98 ++currentRow;
99 }
100
104 void remap() {
105 builder.replaceColumns(stateRemapping, mappingOffset);
106 }
107
113 StateType getCurrentRowGroup() {
114 return currentRowGroup;
115 }
116
124 StateType getRemapping(StateType id) {
125 STORM_LOG_ASSERT(id < stateRemapping.size(), "Invalid index for remapping.");
126 return stateRemapping[id];
127 }
128
129 // Matrix builder.
131
132 // Offset to distinguish states which will not be remapped anymore and those which will.
133 size_t mappingOffset;
134
135 // A mapping from state ids to the row group indices in which they actually reside.
136 // TODO: avoid hack with fixed int type
137 std::vector<uint_fast64_t> stateRemapping;
138
139 private:
140 // Index of the current row group.
141 StateType currentRowGroup;
142
143 // Index of the current row.
144 StateType currentRow;
145
146 // Flag indicating if row groups are needed.
147 bool canHaveNondeterminism;
148 };
149
150 public:
159 storm::dft::storage::DftSymmetries const& symmetries);
160
168 void buildModel(size_t iteration, double approximationThreshold = 0.0,
170
176 std::shared_ptr<storm::models::sparse::Model<ValueType>> getModel();
177
186 std::shared_ptr<storm::models::sparse::Model<ValueType>> getModelApproximation(bool lowerBound, bool expectedTime);
187
188 private:
194 void exploreStateSpace(double approximationThreshold);
195
199 void initializeNextIteration();
200
204 void buildLabeling();
205
213 StateType getOrAddStateIndex(DFTStatePointer const& state);
214
220 void setMarkovian(bool markovian);
221
228 void changeMatrixBound(storm::storage::SparseMatrix<ValueType>& matrix, bool lowerBound) const;
229
237 ValueType getLowerBound(DFTStatePointer const& state) const;
238
246 ValueType getUpperBound(DFTStatePointer const& state) const;
247
256 ValueType computeMTTFAnd(std::vector<ValueType> const& rates, size_t size) const;
257
258 void printNotExplored() const;
259
268 std::shared_ptr<storm::models::sparse::Model<ValueType>> createModel(bool copy);
269
270 // Initial size of the bitvector.
271 const size_t INITIAL_BITVECTOR_SIZE = 20000;
272 // Offset used for pseudo states.
273 const StateType OFFSET_PSEUDO_STATE = std::numeric_limits<StateType>::max() / 2;
274
275 // Dft
277
278 // Environment holding the DFT model-building configuration.
280
281 // General information for state generation
282 // TODO: use const reference
283 std::shared_ptr<storm::dft::storage::DFTStateGenerationInfo> stateGenerationInfo;
284
285 // Heuristic used for approximation
287
288 // Current id for new state
289 size_t newIndex = 0;
290
291 // Whether to use a unique state for all failed states
292 // If used, the unique failed state has the id 0
293 bool uniqueFailedState = false;
294
295 // Id of initial state
296 size_t initialStateIndex = 0;
297
298 // Next state generator for exploring the state space
300
301 // Structure for the components of the model.
302 ModelComponents modelComponents;
303
304 // Structure for the transition matrix builder.
305 MatrixBuilder matrixBuilder;
306
307 // Internal information about the states that were explored.
309
310 // A priority queue of states that still need to be explored.
312
313 // A mapping of not yet explored states from the id to the tuple (state object, heuristic values).
314 std::map<StateType, std::pair<DFTStatePointer, ExplorationHeuristicPointer>> statesNotExplored;
315
316 // Holds all skipped states which were not yet expanded. More concretely it is a mapping from matrix indices
317 // to the corresponding skipped states.
318 // Notice that we need an ordered map here to easily iterate in increasing order over state ids.
319 // TODO remove again
320 std::map<StateType, std::pair<DFTStatePointer, ExplorationHeuristicPointer>> skippedStates;
321
322 // List of independent subtrees and the BEs contained in them.
323 std::vector<std::vector<size_t>> subtreeBEs;
324};
325
326} // namespace builder
327} // namespace storm::dft
Environment for storm-dft.
General super class for approximation heuristics.
std::shared_ptr< storm::models::sparse::Model< ValueType > > getModelApproximation(bool lowerBound, bool expectedTime)
Get the built approximation model for either the lower or upper bound.
std::shared_ptr< storm::models::sparse::Model< ValueType > > getModel()
Get the built model.
ExplicitDFTModelBuilder(storm::dft::DftEnvironment const &env, storm::dft::storage::DFT< ValueType > const &dft, storm::dft::storage::DftSymmetries const &symmetries)
Constructor.
void buildModel(size_t iteration, double approximationThreshold=0.0, storm::dft::builder::ApproximationHeuristic approximationHeuristic=storm::dft::builder::ApproximationHeuristic::DEPTH)
Build model from DFT.
Priority queue based on buckets.
Represents a Dynamic Fault Tree.
Definition DFT.h:50
This class manages the labeling of the state space with a number of (atomic) labels.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
A class that can be used to build a sparse matrix by adding value by value.
A class that holds a possibly non-square matrix in the compressed row storage format.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
ApproximationHeuristic
Enum representing the heuristic used for deciding which states to expand.