Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StateValuations.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/optional.hpp>
4#include <cstdint>
5#include <string>
6
13
14namespace storm {
15namespace storage {
16namespace sparse {
17
18class StateValuationsBuilder;
19
20// A structure holding information about the reachable state space that can be retrieved from the outside.
22 public:
24
26 public:
27 friend class StateValuations;
28 StateValuation() = default;
29 StateValuation(std::vector<bool>&& booleanValues, std::vector<int64_t>&& integerValues, std::vector<storm::RationalNumber>&& rationalValues,
30 std::vector<int64_t>&& observationLabelValues = {});
31
32 private:
33 std::vector<bool> booleanValues;
34 std::vector<int64_t> integerValues;
35 std::vector<storm::RationalNumber> rationalValues;
36 std::vector<int64_t> observationLabelValues;
37 };
38
40 public:
41 StateValueIterator(typename std::map<storm::expressions::Variable, uint64_t>::const_iterator variableIt,
42 typename std::map<std::string, uint64_t>::const_iterator labelIt,
43 typename std::map<storm::expressions::Variable, uint64_t>::const_iterator variableBegin,
44 typename std::map<storm::expressions::Variable, uint64_t>::const_iterator variableEnd,
45 typename std::map<std::string, uint64_t>::const_iterator labelBegin,
46 typename std::map<std::string, uint64_t>::const_iterator labelEnd, StateValuation const* valuation);
47 bool operator==(StateValueIterator const& other);
48 bool operator!=(StateValueIterator const& other);
51
52 bool isVariableAssignment() const;
53 bool isLabelAssignment() const;
55 std::string const& getLabel() const;
56 bool isBoolean() const;
57 bool isInteger() const;
58 bool isRational() const;
59
60 std::string const& getName() const;
61
62 // These shall only be called if the variable has the correct type
63 bool getBooleanValue() const;
64 int64_t getIntegerValue() const;
65 storm::RationalNumber getRationalValue() const;
66 int64_t getLabelValue() const;
67
68 private:
69 typename std::map<storm::expressions::Variable, uint64_t>::const_iterator variableIt;
70 typename std::map<std::string, uint64_t>::const_iterator labelIt;
71 typename std::map<storm::expressions::Variable, uint64_t>::const_iterator variableBegin;
72 typename std::map<storm::expressions::Variable, uint64_t>::const_iterator variableEnd;
73 typename std::map<std::string, uint64_t>::const_iterator labelBegin;
74 typename std::map<std::string, uint64_t>::const_iterator labelEnd;
75
76 StateValuation const* const valuation;
77 };
78
80 public:
81 StateValueIteratorRange(std::map<storm::expressions::Variable, uint64_t> const& variableMap, std::map<std::string, uint64_t> const& labelMap,
82 StateValuation const* valuation);
84 StateValueIterator end() const;
85
86 private:
87 std::map<storm::expressions::Variable, uint64_t> const& variableMap;
88 std::map<std::string, uint64_t> const& labelMap;
89 StateValuation const* const valuation;
90 };
91
92 StateValuations() = default;
93 virtual ~StateValuations() = default;
94 virtual std::string getStateInfo(storm::storage::sparse::state_type const& state) const override;
96
97 bool getBooleanValue(storm::storage::sparse::state_type const& stateIndex, storm::expressions::Variable const& booleanVariable) const;
98 int64_t const& getIntegerValue(storm::storage::sparse::state_type const& stateIndex, storm::expressions::Variable const& integerVariable) const;
99 storm::RationalNumber const& getRationalValue(storm::storage::sparse::state_type const& stateIndex,
100 storm::expressions::Variable const& rationalVariable) const;
102 bool isEmpty(storm::storage::sparse::state_type const& stateIndex) const;
103
108
112 std::vector<int64_t> getIntegerValues(storm::expressions::Variable const& integerVariable) const;
113
117 std::vector<storm::RationalNumber> getRationalValues(storm::expressions::Variable const& rationalVariable) const;
118
125 std::string toString(storm::storage::sparse::state_type const& stateIndex, bool pretty = true,
126 boost::optional<std::set<storm::expressions::Variable>> const& selectedVariables = boost::none) const;
127
133 template<typename JsonRationalType = storm::RationalNumber>
135 boost::optional<std::set<storm::expressions::Variable>> const& selectedVariables = boost::none) const;
136
137 // Returns the (current) number of states that this object describes.
138 uint_fast64_t getNumberOfStates() const;
139
140 /*
141 * Derive new state valuations from this by selecting the given states.
142 */
143 StateValuations selectStates(storm::storage::BitVector const& selectedStates) const;
144
145 /*
146 * Derive new state valuations from this by selecting the given states.
147 * If an invalid state index is selected, the corresponding valuation will be empty.
148 */
149 StateValuations selectStates(std::vector<storm::storage::sparse::state_type> const& selectedStates) const;
150
151 StateValuations blowup(std::vector<uint64_t> const& mapNewToOld) const;
152
153 virtual std::size_t hash() const;
154
155 private:
156 StateValuations(std::map<storm::expressions::Variable, uint64_t> const& variableToIndexMap, std::vector<StateValuation>&& valuations);
157 bool assertValuation(StateValuation const& valuation) const;
158 StateValuation const& getValuation(storm::storage::sparse::state_type const& stateIndex) const;
159
160 std::map<storm::expressions::Variable, uint64_t> variableToIndexMap;
161 std::map<std::string, uint64_t> observationLabels;
162 // A mapping from state indices to their variable valuations.
163 std::vector<StateValuation> valuations;
164};
165
167 public:
169
173 void addVariable(storm::expressions::Variable const& variable);
174
175 void addObservationLabel(std::string const& label);
176
183 void addState(storm::storage::sparse::state_type const& state, std::vector<bool>&& booleanValues = {}, std::vector<int64_t>&& integerValues = {});
184
192 void addState(storm::storage::sparse::state_type const& state, std::vector<bool>&& booleanValues, std::vector<int64_t>&& integerValues,
193 std::vector<storm::RationalNumber>&& rationalValues, std::vector<int64_t>&& observationLabelValues = {});
194
199
200 uint64_t getBooleanVarCount() const;
201 uint64_t getIntegerVarCount() const;
202 uint64_t getLabelCount() const;
203
204 private:
205 StateValuations currentStateValuations;
206 uint64_t booleanVarCount;
207 uint64_t integerVarCount;
208 uint64_t rationalVarCount;
209 uint64_t labelCount;
210};
211} // namespace sparse
212} // namespace storage
213} // namespace storm
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
storm::expressions::Variable const & getVariable() const
void addState(storm::storage::sparse::state_type const &state, std::vector< bool > &&booleanValues={}, std::vector< int64_t > &&integerValues={})
Adds a new state.
void addObservationLabel(std::string const &label)
StateValuations build()
Creates the finalized state valuations object.
void addVariable(storm::expressions::Variable const &variable)
Adds a new variable to keep track of for the state valuations.
std::vector< storm::RationalNumber > getRationalValues(storm::expressions::Variable const &rationalVariable) const
Returns a vector of size getNumberOfStates() such that the i'th entry is the value of the given varia...
std::string toString(storm::storage::sparse::state_type const &stateIndex, bool pretty=true, boost::optional< std::set< storm::expressions::Variable > > const &selectedVariables=boost::none) const
Returns a string representation of the valuation.
StateValuations selectStates(storm::storage::BitVector const &selectedStates) const
storm::RationalNumber const & getRationalValue(storm::storage::sparse::state_type const &stateIndex, storm::expressions::Variable const &rationalVariable) const
bool isEmpty(storm::storage::sparse::state_type const &stateIndex) const
Returns true, if this valuation does not contain any value.
std::vector< int64_t > getIntegerValues(storm::expressions::Variable const &integerVariable) const
Returns a vector of size getNumberOfStates() such that the i'th entry is the value of the given varia...
int64_t const & getIntegerValue(storm::storage::sparse::state_type const &stateIndex, storm::expressions::Variable const &integerVariable) const
storm::storage::BitVector getBooleanValues(storm::expressions::Variable const &booleanVariable) const
Returns a vector of size getNumberOfStates() such that the i'th entry is the value of the given varia...
storm::json< JsonRationalType > toJson(storm::storage::sparse::state_type const &stateIndex, boost::optional< std::set< storm::expressions::Variable > > const &selectedVariables=boost::none) const
Returns a JSON representation of this valuation.
StateValuations blowup(std::vector< uint64_t > const &mapNewToOld) const
StateValueIteratorRange at(storm::storage::sparse::state_type const &state) const
virtual std::string getStateInfo(storm::storage::sparse::state_type const &state) const override
bool getBooleanValue(storm::storage::sparse::state_type const &stateIndex, storm::expressions::Variable const &booleanVariable) const
LabParser.cpp.
Definition cli.cpp:18
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json
Definition JsonForward.h:10