Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
GuaranteedLabelSet.h
Go to the documentation of this file.
1#pragma once
2
3#include <queue>
4#include <utility>
5
9
10namespace storm {
11namespace counterexamples {
12
20template<typename T>
21std::vector<storm::storage::FlatSet<uint_fast64_t>> getGuaranteedLabelSets(storm::models::sparse::Model<T> const& model,
22 std::vector<storm::storage::FlatSet<uint_fast64_t>> const& labelSets,
23 storm::storage::BitVector const& psiStates,
24 storm::storage::FlatSet<uint_fast64_t> const& relevantLabels) {
25 STORM_LOG_THROW(model.getNumberOfChoices() == labelSets.size(), storm::exceptions::InvalidArgumentException,
26 "The given number of labels does not match the number of choices.");
27
28 // Get some data from the model for convenient access.
29 storm::storage::SparseMatrix<T> const& transitionMatrix = model.getTransitionMatrix();
30 std::vector<uint_fast64_t> const& nondeterministicChoiceIndices = transitionMatrix.getRowGroupIndices();
31 storm::storage::SparseMatrix<T> backwardTransitions = model.getBackwardTransitions();
32
33 // Now we compute the set of labels that is present on all paths from the initial to the target states.
34 std::vector<storm::storage::FlatSet<uint_fast64_t>> analysisInformation(model.getNumberOfStates(), relevantLabels);
35
36 std::queue<uint_fast64_t> worklist;
37 storm::storage::BitVector statesInWorkList(model.getNumberOfStates());
38 storm::storage::BitVector markedStates(model.getNumberOfStates());
39
40 // Initially, put all predecessors of target states in the worklist and empty the analysis information them.
41 for (auto state : psiStates) {
42 analysisInformation[state] = storm::storage::FlatSet<uint_fast64_t>();
43 for (auto const& predecessorEntry : backwardTransitions.getRow(state)) {
44 if (predecessorEntry.getColumn() != state && !statesInWorkList.get(predecessorEntry.getColumn()) && !psiStates.get(predecessorEntry.getColumn())) {
45 worklist.push(predecessorEntry.getColumn());
46 statesInWorkList.set(predecessorEntry.getColumn());
47 markedStates.set(state);
48 }
49 }
50 }
51
52 while (!worklist.empty()) {
53 uint_fast64_t const& currentState = worklist.front();
54
55 size_t analysisInformationSizeBefore = analysisInformation[currentState].size();
56
57 // Iterate over the successor states for all choices and compute new analysis information.
58 for (uint_fast64_t currentChoice = nondeterministicChoiceIndices[currentState]; currentChoice < nondeterministicChoiceIndices[currentState + 1];
59 ++currentChoice) {
60 bool modifiedChoice = false;
61
62 for (auto const& entry : transitionMatrix.getRow(currentChoice)) {
63 if (markedStates.get(entry.getColumn())) {
64 modifiedChoice = true;
65 break;
66 }
67 }
68
69 // If we can reach the target state with this choice, we need to intersect the current
70 // analysis information with the union of the new analysis information of the target state
71 // and the choice labels.
72 if (modifiedChoice) {
73 for (auto const& entry : transitionMatrix.getRow(currentChoice)) {
74 if (markedStates.get(entry.getColumn())) {
76 std::set_intersection(analysisInformation[currentState].begin(), analysisInformation[currentState].end(),
77 analysisInformation[entry.getColumn()].begin(), analysisInformation[entry.getColumn()].end(),
78 std::inserter(tmpIntersection, tmpIntersection.begin()));
79 std::set_intersection(analysisInformation[currentState].begin(), analysisInformation[currentState].end(),
80 labelSets[currentChoice].begin(), labelSets[currentChoice].end(),
81 std::inserter(tmpIntersection, tmpIntersection.begin()));
82 analysisInformation[currentState] = std::move(tmpIntersection);
83 }
84 }
85 }
86 }
87
88 // If the analysis information changed, we need to update it and put all the predecessors of this
89 // state in the worklist.
90 if (analysisInformation[currentState].size() != analysisInformationSizeBefore) {
91 for (auto const& predecessorEntry : backwardTransitions.getRow(currentState)) {
92 // Only put the predecessor in the worklist if it's not already a target state.
93 if (!psiStates.get(predecessorEntry.getColumn()) && !statesInWorkList.get(predecessorEntry.getColumn())) {
94 worklist.push(predecessorEntry.getColumn());
95 statesInWorkList.set(predecessorEntry.getColumn());
96 }
97 }
98 markedStates.set(currentState, true);
99 } else {
100 markedStates.set(currentState, false);
101 }
102
103 worklist.pop();
104 statesInWorkList.set(currentState, false);
105 }
106
107 return analysisInformation;
108}
109
117template<typename T>
119 std::vector<storm::storage::FlatSet<uint_fast64_t>> const& labelSets,
120 storm::storage::BitVector const& psiStates,
121 storm::storage::FlatSet<uint_fast64_t> const& relevantLabels) {
122 std::vector<storm::storage::FlatSet<uint_fast64_t>> guaranteedLabels = getGuaranteedLabelSets(model, labelSets, psiStates, relevantLabels);
123
124 storm::storage::FlatSet<uint_fast64_t> knownLabels(relevantLabels);
126 for (auto initialState : model.getInitialStates()) {
127 std::set_intersection(knownLabels.begin(), knownLabels.end(), guaranteedLabels[initialState].begin(), guaranteedLabels[initialState].end(),
128 std::inserter(tempIntersection, tempIntersection.end()));
129 std::swap(knownLabels, tempIntersection);
130 }
131
132 return knownLabels;
133}
134
135} // namespace counterexamples
136} // namespace storm
Base class for all sparse models.
Definition Model.h:33
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:197
virtual uint_fast64_t getNumberOfChoices() const override
Returns the number of choices ine the model.
Definition Model.cpp:172
storm::storage::SparseMatrix< ValueType > getBackwardTransitions() const
Retrieves the backward transition relation of the model, i.e.
Definition Model.cpp:152
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:162
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:177
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRow(index_type row) const
Returns an object representing the given row.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::vector< storm::storage::FlatSet< uint_fast64_t > > getGuaranteedLabelSets(storm::models::sparse::Model< T > const &model, std::vector< storm::storage::FlatSet< uint_fast64_t > > const &labelSets, storm::storage::BitVector const &psiStates, storm::storage::FlatSet< uint_fast64_t > const &relevantLabels)
Computes a set of labels that is executed along all paths from any state to a target state.
storm::storage::FlatSet< uint_fast64_t > getGuaranteedLabelSet(storm::models::sparse::Model< T > const &model, std::vector< storm::storage::FlatSet< uint_fast64_t > > const &labelSets, storm::storage::BitVector const &psiStates, storm::storage::FlatSet< uint_fast64_t > const &relevantLabels)
Computes a set of labels that is executed along all paths from an initial state to a target state.
boost::container::flat_set< Key, std::less< Key >, boost::container::new_allocator< Key > > FlatSet
Redefinition of flat_set was needed, because from Boost 1.70 on the default allocator is set to void.
Definition BoostTypes.h:13
LabParser.cpp.
Definition cli.cpp:18