Storm
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
20
21namespace storm::dft {
22namespace builder {
23
27template<typename ValueType, typename StateType = uint32_t>
29 using DFTStatePointer = std::shared_ptr<storm::dft::storage::DFTState<ValueType>>;
31 using ExplorationHeuristicPointer = std::shared_ptr<ExplorationHeuristic>;
32
33 // A structure holding the individual components of a model.
34 struct ModelComponents {
35 // Constructor
36 ModelComponents();
37
38 // The transition matrix.
40
41 // The state labeling.
43
44 // The Markovian states.
45 storm::storage::BitVector markovianStates;
46
47 // The exit rates.
48 std::vector<ValueType> exitRates;
49
50 // A vector that stores a labeling for each choice.
51 boost::optional<storm::models::sparse::ChoiceLabeling> choiceLabeling;
52
53 // A flag indicating if the model is deterministic.
54 bool deterministicModel;
55 };
56
57 // A class holding the information for building the transition matrix.
58 class MatrixBuilder {
59 public:
60 // Constructor
61 MatrixBuilder(bool canHaveNondeterminism);
62
68 void setRemapping(StateType id) {
69 STORM_LOG_ASSERT(id < stateRemapping.size(), "Invalid index for remapping.");
70 stateRemapping[id] = currentRowGroup;
71 }
72
76 void newRowGroup() {
77 if (canHaveNondeterminism) {
78 builder.newRowGroup(currentRow);
79 }
80 ++currentRowGroup;
81 }
82
89 void addTransition(StateType index, ValueType value) {
90 builder.addNextValue(currentRow, index, value);
91 }
92
96 void finishRow() {
97 ++currentRow;
98 }
99
103 void remap() {
104 builder.replaceColumns(stateRemapping, mappingOffset);
105 }
106
112 StateType getCurrentRowGroup() {
113 return currentRowGroup;
114 }
115
123 StateType getRemapping(StateType id) {
124 STORM_LOG_ASSERT(id < stateRemapping.size(), "Invalid index for remapping.");
125 return stateRemapping[id];
126 }
127
128 // Matrix builder.
130
131 // Offset to distinguish states which will not be remapped anymore and those which will.
132 size_t mappingOffset;
133
134 // A mapping from state ids to the row group indices in which they actually reside.
135 // TODO: avoid hack with fixed int type
136 std::vector<uint_fast64_t> stateRemapping;
137
138 private:
139 // Index of the current row group.
140 StateType currentRowGroup;
141
142 // Index of the current row.
143 StateType currentRow;
144
145 // Flag indicating if row groups are needed.
146 bool canHaveNondeterminism;
147 };
148
149 public:
157
165 void buildModel(size_t iteration, double approximationThreshold = 0.0,
167
173 std::shared_ptr<storm::models::sparse::Model<ValueType>> getModel();
174
183 std::shared_ptr<storm::models::sparse::Model<ValueType>> getModelApproximation(bool lowerBound, bool expectedTime);
184
185 private:
191 void exploreStateSpace(double approximationThreshold);
192
196 void initializeNextIteration();
197
201 void buildLabeling();
202
210 StateType getOrAddStateIndex(DFTStatePointer const& state);
211
217 void setMarkovian(bool markovian);
218
225 void changeMatrixBound(storm::storage::SparseMatrix<ValueType>& matrix, bool lowerBound) const;
226
234 ValueType getLowerBound(DFTStatePointer const& state) const;
235
243 ValueType getUpperBound(DFTStatePointer const& state) const;
244
253 ValueType computeMTTFAnd(std::vector<ValueType> const& rates, size_t size) const;
254
263 bool isPriorityGreater(StateType idA, StateType idB) const;
264
265 void printNotExplored() const;
266
275 std::shared_ptr<storm::models::sparse::Model<ValueType>> createModel(bool copy);
276
277 // Initial size of the bitvector.
278 const size_t INITIAL_BITVECTOR_SIZE = 20000;
279 // Offset used for pseudo states.
280 const StateType OFFSET_PSEUDO_STATE = std::numeric_limits<StateType>::max() / 2;
281
282 // Dft
284
285 // General information for state generation
286 // TODO: use const reference
287 std::shared_ptr<storm::dft::storage::DFTStateGenerationInfo> stateGenerationInfo;
288
289 // Heuristic used for approximation
291
292 // Current id for new state
293 size_t newIndex = 0;
294
295 // Whether to use a unique state for all failed states
296 // If used, the unique failed state has the id 0
297 bool uniqueFailedState = false;
298
299 // Id of initial state
300 size_t initialStateIndex = 0;
301
302 // Next state generator for exploring the state space
304
305 // Structure for the components of the model.
306 ModelComponents modelComponents;
307
308 // Structure for the transition matrix builder.
309 MatrixBuilder matrixBuilder;
310
311 // Internal information about the states that were explored.
313
314 // A priority queue of states that still need to be explored.
316
317 // A mapping of not yet explored states from the id to the tuple (state object, heuristic values).
318 std::map<StateType, std::pair<DFTStatePointer, ExplorationHeuristicPointer>> statesNotExplored;
319
320 // Holds all skipped states which were not yet expanded. More concretely it is a mapping from matrix indices
321 // to the corresponding skipped states.
322 // Notice that we need an ordered map here to easily iterate in increasing order over state ids.
323 // TODO remove again
324 std::map<StateType, std::pair<DFTStatePointer, ExplorationHeuristicPointer>> skippedStates;
325
326 // List of independent subtrees and the BEs contained in them.
327 std::vector<std::vector<size_t>> subtreeBEs;
328};
329
330} // namespace builder
331} // namespace 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.
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:52
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:18
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:11
ApproximationHeuristic
Enum representing the heuristic used for deciding which states to expand.