Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
NextStateGenerator.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
17
18namespace storm {
19namespace expressions {
20template<typename V>
21class ExpressionEvaluator;
22class SimpleValuation;
23} // namespace expressions
24namespace generator {
26
27enum class ModelType { DTMC, CTMC, MDP, MA, POMDP, SMG };
28
29template<typename ValueType, typename StateType = uint32_t>
30class NextStateGenerator;
31
36template<typename ValueType, typename StateType = uint32_t>
38 public:
39 virtual ~ActionMask() = default;
48 virtual bool query(storm::generator::NextStateGenerator<ValueType, StateType> const& generator, uint64_t actionIndex) = 0;
49};
50
55template<typename ValueType, typename StateType = uint32_t>
56class StateValuationFunctionMask : public ActionMask<ValueType, StateType> {
57 public:
58 StateValuationFunctionMask(std::function<bool(storm::expressions::SimpleValuation const&, uint64_t)> const& f);
59 virtual ~StateValuationFunctionMask() = default;
60 bool query(storm::generator::NextStateGenerator<ValueType, StateType> const& generator, uint64_t actionIndex) override;
61
62 private:
63 std::function<bool(storm::expressions::SimpleValuation, uint64_t)> func;
64};
65
66template<typename ValueType, typename StateType>
68 public:
69 typedef std::function<StateType(CompressedState const&)> StateToIdCallback;
70
72 NextStateGeneratorOptions const& options, std::shared_ptr<ActionMask<ValueType, StateType>> const& = nullptr);
73
79 std::shared_ptr<ActionMask<ValueType, StateType>> const& = nullptr);
80
82
83 uint64_t getStateSize() const;
84 virtual ModelType getModelType() const = 0;
85 virtual bool isDeterministicModel() const = 0;
86 virtual bool isDiscreteTimeModel() const = 0;
87 virtual bool isPartiallyObservable() const = 0;
88 virtual std::vector<StateType> getInitialStates(StateToIdCallback const& stateToIdCallback) = 0;
89
92
95
96 void load(CompressedState const& state);
97 virtual StateBehavior<ValueType, StateType> expand(StateToIdCallback const& stateToIdCallback) = 0;
98 bool satisfies(storm::expressions::Expression const& expression) const;
99
101 virtual void addStateValuation(storm::storage::sparse::state_type const& currentStateIndex,
102 storm::storage::sparse::StateValuationsBuilder& valuationsBuilder) const;
105
106 virtual std::size_t getNumberOfRewardModels() const = 0;
108
109 std::string stateToString(CompressedState const& state) const;
110
111 storm::json<ValueType> currentStateToJson(bool onlyObservable = false) const;
113
114 uint32_t observabilityClass(CompressedState const& state) const;
115
116 virtual std::map<std::string, storm::storage::PlayerIndex> getPlayerNameToIndexMap() const;
117
119 std::vector<StateType> const& initialStateIndices = {},
120 std::vector<StateType> const& deadlockStateIndices = {},
121 std::vector<StateType> const& unexploredStateIndices = {}) = 0;
122
124
125 VariableInformation const& getVariableInformation() const;
126
127 virtual std::shared_ptr<storm::storage::sparse::ChoiceOrigins> generateChoiceOrigins(std::vector<boost::any>& dataForChoiceOrigins) const;
128
134 void remapStateIds(std::function<StateType(StateType const&)> const& remapping);
135
136 protected:
138
142 bool isSpecialLabel(std::string const& label) const;
143
148 std::vector<StateType> const& initialStateIndices, std::vector<StateType> const& deadlockStateIndices,
149 std::vector<StateType> const& unexploredStateIndices,
150 std::vector<std::pair<std::string, storm::expressions::Expression>> labelsAndExpressions);
151
162
164
165 virtual void extendStateInformation(storm::json<BaseValueType>& stateInfo) const;
166
168
170
173
175 std::shared_ptr<storm::expressions::ExpressionManager const> expressionManager;
176
178 std::vector<std::pair<storm::expressions::Expression, bool>> terminalStates;
179
182
184 std::unique_ptr<storm::expressions::ExpressionEvaluator<BaseValueType>> evaluator;
185
188
191
194
196 // TODO consider using a BitVectorHashMap for this?
197 mutable std::unordered_map<storm::storage::BitVector, uint32_t> observabilityMap;
200
202 boost::optional<std::vector<uint64_t>> overlappingGuardStates;
203
204 std::shared_ptr<ActionMask<ValueType, StateType>> actionMask;
205};
206} // namespace generator
207} // namespace storm
This class is responsible for managing a set of typed variables and all expressions using these varia...
A simple implementation of the valuation interface.
Action masks are arguments you can give to the state generator that limit which states are generated.
virtual ~ActionMask()=default
virtual bool query(storm::generator::NextStateGenerator< ValueType, StateType > const &generator, uint64_t actionIndex)=0
This method is called to check whether an action should be expanded.
virtual std::shared_ptr< storm::storage::sparse::ChoiceOrigins > generateChoiceOrigins(std::vector< boost::any > &dataForChoiceOrigins) const
virtual std::map< std::string, storm::storage::PlayerIndex > getPlayerNameToIndexMap() const
std::shared_ptr< storm::expressions::ExpressionManager const > expressionManager
The expression manager used for evaluating expressions.
virtual storm::storage::sparse::StateValuations makeObservationValuation() const
Adds the valuation for the currently loaded state.
bool isSpecialLabel(std::string const &label) const
Checks if the input label has a special purpose (e.g.
std::unique_ptr< storm::expressions::ExpressionEvaluator< BaseValueType > > evaluator
An evaluator used to evaluate expressions.
std::shared_ptr< ActionMask< ValueType, StateType > > actionMask
virtual storm::storage::BitVector evaluateObservationLabels(CompressedState const &state) const =0
void initializeSpecialStates()
Initializes the out-of-bounds state and states with overlapping guards.
std::string stateToString(CompressedState const &state) const
virtual storm::storage::sparse::StateValuationsBuilder initializeStateValuationsBuilder() const
Initializes a builder for state valuations by adding the appropriate variables.
storm::utility::ConstantsComparator< ValueType > comparator
A comparator used to approximately compare constants, e.g., whether they sum to one....
std::function< StateType(CompressedState const &)> StateToIdCallback
void postprocess(StateBehavior< ValueType, StateType > &result)
boost::optional< std::vector< uint64_t > > overlappingGuardStates
A map that stores the indices of states with overlapping guards.
CompressedState const * state
The currently loaded state.
uint32_t observabilityClass(CompressedState const &state) const
virtual void extendStateInformation(storm::json< BaseValueType > &stateInfo) const
virtual ModelType getModelType() const =0
NextStateGeneratorOptions const & getOptions() const
std::vector< std::pair< storm::expressions::Expression, bool > > terminalStates
The expressions that define terminal states.
storm::expressions::SimpleValuation currentStateToSimpleValuation() const
CompressedState outOfBoundsState
A state that encodes the outOfBoundsState.
virtual bool isDiscreteTimeModel() const =0
storm::storage::BitVector mask
The mask to compute the observability class (Constructed upon first use)
storm::json< ValueType > currentStateToJson(bool onlyObservable=false) const
void load(CompressedState const &state)
virtual storm::storage::sparse::StateValuationsBuilder initializeObservationValuationsBuilder() const
bool satisfies(storm::expressions::Expression const &expression) const
std::unordered_map< storm::storage::BitVector, uint32_t > observabilityMap
The observability classes handed out so far.
virtual std::vector< StateType > getInitialStates(StateToIdCallback const &stateToIdCallback)=0
virtual storm::builder::RewardModelInformation getRewardModelInformation(uint64_t const &index) const =0
virtual void addStateValuation(storm::storage::sparse::state_type const &currentStateIndex, storm::storage::sparse::StateValuationsBuilder &valuationsBuilder) const
Adds the valuation for the currently loaded state to the given builder.
NextStateGeneratorOptions options
The options to be used for next-state generation.
void remapStateIds(std::function< StateType(StateType const &)> const &remapping)
Performs a remapping of all values stored by applying the given remapping.
storm::IntervalBaseType< ValueType > BaseValueType
VariableInformation const & getVariableInformation() const
virtual bool isPartiallyObservable() const =0
virtual bool isDeterministicModel() const =0
virtual std::size_t getNumberOfRewardModels() const =0
virtual void unpackTransientVariableValuesIntoEvaluator(CompressedState const &state, storm::expressions::ExpressionEvaluator< BaseValueType > &evaluator) const
Sets the values of all transient variables in the current state to the given evaluator.
virtual StateBehavior< ValueType, StateType > expand(StateToIdCallback const &stateToIdCallback)=0
VariableInformation variableInformation
Information about how the variables are packed.
virtual storm::models::sparse::StateLabeling label(storm::storage::sparse::StateStorage< StateType > const &stateStorage, std::vector< StateType > const &initialStateIndices={}, std::vector< StateType > const &deadlockStateIndices={}, std::vector< StateType > const &unexploredStateIndices={})=0
A particular instance of the action mask that uses a callback function to evaluate whether an action ...
bool query(storm::generator::NextStateGenerator< ValueType, StateType > const &generator, uint64_t actionIndex) override
This method is called to check whether an action should be expanded.
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
storm::builder::BuilderOptions NextStateGeneratorOptions
typename detail::IntervalMetaProgrammingHelper< ValueType >::BaseType IntervalBaseType
Helper to access the type in which interval boundaries are stored.
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json
Definition JsonForward.h:10