Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ExplicitQualitativeCheckResult.cpp
Go to the documentation of this file.
4
6
7#include <algorithm>
8
12
13namespace storm {
14namespace modelchecker {
15
16template<typename ValueType>
18 : states(storm::storage::BitVector(state + 1)), truthValues(1, value) {
19 states.set(state);
20}
21
22template<typename ValueType>
24 std::optional<std::shared_ptr<storm::storage::Scheduler<ValueType>>> scheduler)
25 : states(truthValues.size(), true), truthValues(truthValues), scheduler(scheduler) {
26 // Intentionally left empty.
27}
28
29template<typename ValueType>
31 std::optional<std::shared_ptr<storm::storage::Scheduler<ValueType>>> scheduler)
32 : states(truthValues.size(), true), truthValues(std::move(truthValues)), scheduler(scheduler) {
33 // Intentionally left empty.
34}
35
36template<typename ValueType>
38 std::optional<std::shared_ptr<storm::storage::Scheduler<ValueType>>> scheduler)
39 : states(std::move(states)), truthValues(std::move(truthValues)), scheduler(scheduler) {
40 STORM_LOG_ASSERT(this->states.getNumberOfSetBits() == this->truthValues.size(), "Expected one truth value per selected state.");
41}
42
43template<typename ValueType>
44std::unique_ptr<CheckResult> ExplicitQualitativeCheckResult<ValueType>::clone() const {
45 return std::make_unique<ExplicitQualitativeCheckResult<ValueType>>(*this);
46}
47
48template<typename ValueType>
49void ExplicitQualitativeCheckResult<ValueType>::performLogicalOperation(ExplicitQualitativeCheckResult<ValueType>& first, QualitativeCheckResult const& second,
50 bool logicalAnd) {
51 STORM_LOG_THROW(second.isExplicitQualitativeCheckResult(), storm::exceptions::InvalidOperationException,
52 "Cannot perform logical 'and' on check results of incompatible type.");
53 ExplicitQualitativeCheckResult<ValueType> const& secondCheckResult = static_cast<ExplicitQualitativeCheckResult<ValueType> const&>(second);
54 STORM_LOG_THROW(first.states == secondCheckResult.states && first.truthValues.size() == secondCheckResult.truthValues.size(),
55 storm::exceptions::InvalidOperationException, "Cannot perform logical 'and' on check results of incompatible type.");
56 if (logicalAnd) {
57 first.truthValues &= secondCheckResult.truthValues;
58 } else {
59 first.truthValues |= secondCheckResult.truthValues;
60 }
61}
62
63template<typename ValueType>
65 performLogicalOperation(*this, other, true);
66 return *this;
67}
68
69template<typename ValueType>
71 performLogicalOperation(*this, other, false);
72 return *this;
73}
74
75template<typename ValueType>
77 return !truthValues.empty();
78}
79
80template<typename ValueType>
82 return truthValues.full();
83}
84
85template<typename ValueType>
87 return truthValues.getNumberOfSetBits();
88}
89
90template<typename ValueType>
92 return state < states.size() && states.get(state);
93}
94
95template<typename ValueType>
96uint64_t ExplicitQualitativeCheckResult<ValueType>::getOffset(storm::storage::sparse::state_type state) const {
97 STORM_LOG_ASSERT(this->hasValueForState(state), "State '" << state << "' has no value.");
98 return states.getNumberOfSetBitsBeforeIndex(state);
99}
100
101template<typename ValueType>
103 return truthValues.get(this->getOffset(state));
104}
105
106template<typename ValueType>
110
111template<typename ValueType>
115
116template<typename ValueType>
120
121template<typename ValueType>
123 return true;
124}
125
126template<typename ValueType>
128 return states.full();
129}
130
131template<typename ValueType>
135
136template<typename ValueType>
137std::ostream& ExplicitQualitativeCheckResult<ValueType>::writeToStream(std::ostream& out) const {
138 if (!this->isResultForAllStates() && truthValues.size() == 1) {
139 out << (truthValues.get(0) ? "true" : "false");
140 } else if (truthValues.full()) {
141 out << "{true}";
142 } else if (truthValues.empty()) {
143 out << "{false}";
144 } else {
145 out << "{true, false}";
146 }
147 return out;
148}
149
150template<typename ValueType>
152 STORM_LOG_THROW(filter.isExplicitQualitativeCheckResult(), storm::exceptions::InvalidOperationException,
153 "Cannot filter explicit check result with non-explicit filter.");
154 STORM_LOG_THROW(filter.isResultForAllStates(), storm::exceptions::InvalidOperationException, "Cannot filter check result with non-complete filter.");
156 vector_type const& filterTruthValues = explicitFilter.getTruthValuesVector();
157
158 // Line the filter up with the states this result has truth values for. The two need not span the same range
159 // of states, e.g. if this result holds a truth value for a single state only.
160 uint64_t const numStates = std::max(filterTruthValues.size(), states.size());
161 storm::storage::BitVector available = states;
162 available.resize(numStates);
163 storm::storage::BitVector selected(filterTruthValues);
164 selected.resize(numStates);
165 STORM_LOG_THROW(selected.isSubsetOf(available), storm::exceptions::InvalidOperationException,
166 "The check result fails to contain some results referred to by the filter.");
167
168 truthValues = truthValues % (selected % available);
169 states = filterTruthValues;
170}
171
172template<typename ValueType>
174 return static_cast<bool>(scheduler);
175}
176
177template<typename ValueType>
179 this->scheduler = std::move(scheduler);
180}
181
182template<typename ValueType>
184 STORM_LOG_THROW(this->hasScheduler(), storm::exceptions::InvalidOperationException, "Unable to retrieve non-existing scheduler.");
185 return *scheduler.value();
186}
187
188template<typename ValueType>
190 STORM_LOG_THROW(this->hasScheduler(), storm::exceptions::InvalidOperationException, "Unable to retrieve non-existing scheduler.");
191 return *scheduler.value();
192}
193
194template<typename JsonRationalType>
195void insertJsonEntry(storm::json<JsonRationalType>& json, uint64_t const& id, bool value,
196 std::optional<storm::storage::sparse::Valuations> const& stateValuations = std::nullopt,
197 std::optional<storm::models::sparse::StateLabeling> const& stateLabels = std::nullopt) {
199 if (stateValuations) {
200 entry["s"] = stateValuations->template toJson<JsonRationalType>(id);
201 } else {
202 entry["s"] = id;
203 }
204 entry["v"] = value;
205 if (stateLabels) {
206 auto labs = stateLabels->getLabelsOfState(id);
207 entry["l"] = labs;
208 }
209 json.push_back(std::move(entry));
210}
211
212template<typename ValueType>
213template<typename JsonRationalType>
214storm::json<JsonRationalType> ExplicitQualitativeCheckResult<ValueType>::toJson(std::optional<storm::storage::sparse::Valuations> const& stateValuations,
215 std::optional<storm::models::sparse::StateLabeling> const& stateLabels) const {
217 this->forEachState(
218 [&](storm::storage::sparse::state_type state, bool truthValue) { insertJsonEntry(result, state, truthValue, stateValuations, stateLabels); });
219 return result;
220}
221
222// Explicit template instantiations
224template storm::json<double> ExplicitQualitativeCheckResult<double>::toJson<double>(std::optional<storm::storage::sparse::Valuations> const&,
225 std::optional<storm::models::sparse::StateLabeling> const&) const;
226
228 std::optional<storm::storage::sparse::Valuations> const&, std::optional<storm::models::sparse::StateLabeling> const&) const;
229
232 std::optional<storm::storage::sparse::Valuations> const&, std::optional<storm::models::sparse::StateLabeling> const&) const;
234 std::optional<storm::storage::sparse::Valuations> const&, std::optional<storm::models::sparse::StateLabeling> const&) const;
235
238 std::optional<storm::storage::sparse::Valuations> const&, std::optional<storm::models::sparse::StateLabeling> const&) const;
240 std::optional<storm::storage::sparse::Valuations> const&, std::optional<storm::models::sparse::StateLabeling> const&) const;
241
243template storm::json<double> ExplicitQualitativeCheckResult<storm::Interval>::toJson<double>(std::optional<storm::storage::sparse::Valuations> const&,
244 std::optional<storm::models::sparse::StateLabeling> const&) const;
246 std::optional<storm::storage::sparse::Valuations> const&, std::optional<storm::models::sparse::StateLabeling> const&) const;
247
248} // namespace modelchecker
249} // namespace storm
ExplicitQualitativeCheckResult< ValueType > & asExplicitQualitativeCheckResult()
virtual bool isExplicitQualitativeCheckResult() const
A qualitative check result over the states of a sparse model.
bool hasValueForState(storm::storage::sparse::state_type state) const
Retrieves whether the result holds a truth value for the given state.
storm::storage::Scheduler< ValueType > const & getScheduler() const
virtual void filter(QualitativeCheckResult const &filter) override
Filters the current result wrt.
storm::json< JsonRationalType > toJson(std::optional< storm::storage::sparse::Valuations > const &stateValuations=std::nullopt, std::optional< storm::models::sparse::StateLabeling > const &stateLabels=std::nullopt) const
virtual QualitativeCheckResult & operator&=(QualitativeCheckResult const &other) override
virtual std::unique_ptr< CheckResult > clone() const override
storm::storage::BitVector const & getStates() const
Retrieves the states this result holds truth values for.
virtual QualitativeCheckResult & operator|=(QualitativeCheckResult const &other) override
void setScheduler(std::unique_ptr< storm::storage::Scheduler< ValueType > > &&scheduler)
ExplicitQualitativeCheckResult(storm::storage::sparse::state_type state, bool value)
Creates a result that holds the given truth value for the given state only.
vector_type const & getTruthValuesVector() const
Retrieves the truth values, one per state this result is for.
virtual std::ostream & writeToStream(std::ostream &out) const override
bool operator[](storm::storage::sparse::state_type state) const
Retrieves the truth value of the given state.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
void complement()
Negates all bits in the bit vector.
bool isSubsetOf(BitVector const &other) const
Checks whether all bits that are set in the current bit vector are also set in the given bit vector.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
size_t size() const
Retrieves the number of bits this bit vector can store.
void resize(uint64_t newLength, bool init=false)
Resizes the bit vector to hold the given new number of bits.
This class defines which action is chosen in a particular state of a non-deterministic model.
Definition Scheduler.h:18
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
void insertJsonEntry(storm::json< JsonRationalType > &json, uint64_t const &id, bool value, std::optional< storm::storage::sparse::Valuations > const &stateValuations=std::nullopt, std::optional< storm::models::sparse::StateLabeling > const &stateLabels=std::nullopt)
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json
Definition JsonForward.h:11