Storm 1.13.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Model.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <unordered_map>
5#include <vector>
6
17
18namespace storm {
19namespace storage {
20class BitVector;
21}
22
23namespace models {
24namespace sparse {
25
29template<class CValueType, class CRewardModelType>
30class Model : public storm::models::Model<CValueType> {
31 public:
32 typedef CValueType ValueType;
33 typedef CRewardModelType RewardModelType;
35
38
47
48 virtual ~Model() = default;
49
57
63 virtual uint_fast64_t getNumberOfStates() const override;
64
70 virtual uint_fast64_t getNumberOfTransitions() const override;
71
77 virtual uint_fast64_t getNumberOfChoices() const override;
78
85
92
99 storm::storage::BitVector const& getStates(std::string const& label) const;
100
107 bool hasLabel(std::string const& label) const;
108
115
122
128 std::unordered_map<std::string, RewardModelType> const& getRewardModels() const;
129
135 std::unordered_map<std::string, RewardModelType>& getRewardModels();
136
142 virtual bool hasRewardModel(std::string const& rewardModelName) const override;
143
149 RewardModelType const& getRewardModel(std::string const& rewardModelName) const;
150
156 RewardModelType& getRewardModel(std::string const& rewardModelName);
157
164
171
177 virtual bool hasUniqueRewardModel() const override;
178
184 virtual std::string const& getUniqueRewardModelName() const override;
185
191 bool hasRewardModel() const;
192
198 uint_fast64_t getNumberOfRewardModels() const;
199
205 void addRewardModel(std::string const& rewardModelName, RewardModelType const& rewModel);
206
211 bool removeRewardModel(std::string const& rewardModelName);
212
216 void restrictRewardModels(std::set<std::string> const& keptRewardModels);
217
224
231
237 bool hasChoiceLabeling() const;
238
246
252 std::optional<storm::models::sparse::ChoiceLabeling> const& getOptionalChoiceLabeling() const;
253
259 std::optional<storm::models::sparse::ChoiceLabeling>& getOptionalChoiceLabeling();
260
266 bool hasStateValuations() const;
267
275
281 std::optional<storm::storage::sparse::StateValuations> const& getOptionalStateValuations() const;
282
288 std::optional<storm::storage::sparse::StateValuations>& getOptionalStateValuations();
289
295 bool hasChoiceOrigins() const;
296
303 std::shared_ptr<storm::storage::sparse::ChoiceOrigins> const& getChoiceOrigins() const;
304
310 std::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>> const& getOptionalChoiceOrigins() const;
311
317 std::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>>& getOptionalChoiceOrigins();
318
324 virtual void printModelInformationToStream(std::ostream& out) const override;
325
326 bool isSinkState(uint64_t sink) const;
327
342 virtual void writeDotToStream(std::ostream& outStream, size_t maxWidthLabel = 30, bool includeLabeling = true,
343 storm::storage::BitVector const* subsystem = nullptr, std::vector<ValueType> const* firstValue = nullptr,
344 std::vector<ValueType> const* secondValue = nullptr, std::vector<uint64_t> const* stateColoring = nullptr,
345 std::vector<std::string> const* colors = nullptr, std::vector<uint_fast64_t>* scheduler = nullptr,
346 bool finalizeOutput = true) const;
347
351 virtual void writeJsonToStream(std::ostream& outStream) const;
352
359 std::set<std::string> getLabelsOfState(storm::storage::sparse::state_type state) const;
360
361 virtual bool isSparseModel() const override;
362
363 virtual bool supportsParameters() const override;
364
371 virtual bool hasParameters() const override;
372
373 virtual bool isExact() const override;
374
381 virtual bool supportsUncertainty() const override;
382
390 virtual bool hasUncertainty() const;
391
392 virtual std::size_t hash() const;
393
394 protected:
395 RewardModelType& rewardModel(std::string const& rewardModelName);
396
402 void printModelInformationHeaderToStream(std::ostream& out) const;
403
410 void printModelInformationFooterToStream(std::ostream& out) const;
411
417 void printRewardModelsInformationToStream(std::ostream& out) const;
418
424 virtual std::string additionalDotStateInfo(uint64_t state) const;
425
426 private:
427 // Upon construction of a model, this function asserts that the specified components are valid
428 void assertValidityOfComponents(storm::storage::sparse::ModelComponents<ValueType, RewardModelType> const& components) const;
429
430 // A matrix representing transition relation.
432
433 // The labeling of the states.
435
436 // The reward models of the model.
437 std::unordered_map<std::string, RewardModelType> rewardModels;
438
439 // If set, a vector representing the labels of choices.
440 std::optional<storm::models::sparse::ChoiceLabeling> choiceLabeling;
441
442 // if set, retrieves for each state the variable valuation that this state represents
443 std::optional<storm::storage::sparse::StateValuations> stateValuations;
444
445 // if set, gives information about where each choice originates w.r.t. the input model description
446 std::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>> choiceOrigins;
447};
448
454std::set<storm::RationalFunctionVariable> getProbabilityParameters(Model<storm::RationalFunction> const& model);
455
461std::set<storm::RationalFunctionVariable> getRewardParameters(Model<storm::RationalFunction> const& model);
462
468std::set<storm::RationalFunctionVariable> getRateParameters(Model<storm::RationalFunction> const& model);
469
475std::set<storm::RationalFunctionVariable> getAllParameters(Model<storm::RationalFunction> const& model);
476} // namespace sparse
477} // namespace models
478} // namespace storm
This class manages the labeling of the choice space with a number of (atomic) labels.
Base class for all sparse models.
Definition Model.h:30
storm::models::sparse::ChoiceLabeling const & getChoiceLabeling() const
Retrieves the labels for the choices of the model.
Definition Model.cpp:335
RewardModelType const & getUniqueRewardModel() const
Retrieves the unique reward model, if there exists exactly one.
Definition Model.cpp:304
storm::models::sparse::StateLabeling & getStateLabeling()
Returns the state labeling associated with this model.
Definition Model.cpp:325
bool hasRewardModel() const
Retrieves whether the model has at least one reward model.
Definition Model.cpp:299
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:198
virtual std::size_t hash() const
Definition Model.cpp:396
virtual bool hasUncertainty() const
Checks whether the model actually is uncertain, i.e., whether there is a non-singleton transition rel...
Definition Model.cpp:665
Model(Model< ValueType, RewardModelType > const &other)=default
void setInitialStates(storm::storage::BitVector const &states)
Overwrites the initial states of the model.
Definition Model.cpp:183
virtual bool supportsUncertainty() const override
Does it support uncertainty (e.g., via interval-valued entries).
Definition Model.cpp:645
void printModelInformationFooterToStream(std::ostream &out) const
Prints the information footer (reward models, labels and size in memory) of the model to the specifie...
Definition Model.cpp:424
virtual void printModelInformationToStream(std::ostream &out) const override
Prints information about the model to the specified stream.
Definition Model.cpp:390
Model & operator=(Model< ValueType, RewardModelType > const &other)=default
std::unordered_map< std::string, RewardModelType > const & getRewardModels() const
Retrieves the reward models.
Definition Model.cpp:690
RewardModelType & getRewardModel(std::string const &rewardModelName)
Retrieves the reward model with the given name, if one exists.
Definition Model.cpp:237
void restrictRewardModels(std::set< std::string > const &keptRewardModels)
Removes all reward models whose name is not in the given set.
Definition Model.cpp:275
bool hasStateValuations() const
Retrieves whether this model was build with state valuations.
Definition Model.cpp:350
storm::storage::BitVector const & getStates(std::string const &label) const
Returns the sets of states labeled with the given label.
Definition Model.cpp:188
bool removeRewardModel(std::string const &rewardModelName)
Removes the reward model with the given name from the model.
Definition Model.cpp:265
void printRewardModelsInformationToStream(std::ostream &out) const
Prints information about the reward models to the specified stream.
Definition Model.cpp:438
std::set< std::string > getLabelsOfState(storm::storage::sparse::state_type state) const
Retrieves the set of labels attached to the given state.
Definition Model.cpp:617
std::optional< std::shared_ptr< storm::storage::sparse::ChoiceOrigins > > const & getOptionalChoiceOrigins() const
Retrieves an optional value that contains the choice origins if there are some.
Definition Model.cpp:380
std::optional< storm::models::sparse::ChoiceLabeling > & getOptionalChoiceLabeling()
Retrieves an optional value that contains the choice labeling if there is one.
Definition Model.cpp:345
RewardModelType & rewardModel(std::string const &rewardModelName)
Definition Model.cpp:213
virtual uint_fast64_t getNumberOfChoices() const override
Returns the number of choices ine the model.
Definition Model.cpp:173
storm::storage::sparse::StateValuations const & getStateValuations() const
Retrieves the valuations of the states of the model.
Definition Model.cpp:355
virtual bool isSparseModel() const override
Checks whether the model is a sparse model.
Definition Model.cpp:635
void addRewardModel(std::string const &rewardModelName, RewardModelType const &rewModel)
Adds a reward model to the model.
Definition Model.cpp:255
std::shared_ptr< storm::storage::sparse::ChoiceOrigins > const & getChoiceOrigins() const
Retrieves the origins of the choices of the model.
Definition Model.cpp:375
storm::storage::SparseMatrix< ValueType > getBackwardTransitions() const
Retrieves the backward transition relation of the model, i.e.
Definition Model.cpp:158
bool isSinkState(uint64_t sink) const
Definition Model.cpp:622
bool hasChoiceLabeling() const
Retrieves whether this model has a labeling of the choices.
Definition Model.cpp:330
std::unordered_map< std::string, RewardModelType > & getRewardModels()
Retrieves the reward models.
Definition Model.cpp:685
uint_fast64_t getNumberOfRewardModels() const
Retrieves the number of reward models associated with this model.
Definition Model.cpp:316
std::optional< std::shared_ptr< storm::storage::sparse::ChoiceOrigins > > & getOptionalChoiceOrigins()
Retrieves an optional value that contains the choice origins if there are some.
Definition Model.cpp:385
virtual ~Model()=default
Model(ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > &&components)
Definition Model.cpp:41
virtual bool hasRewardModel(std::string const &rewardModelName) const override
Retrieves whether the model has a reward model with the given name.
Definition Model.cpp:208
storm::storage::SparseMatrix< ValueType > & getTransitionMatrix()
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:203
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
Definition Model.cpp:320
static const storm::models::ModelRepresentation Representation
Definition Model.h:34
virtual void writeJsonToStream(std::ostream &outStream) const
Writes a JSON representation of the model to the given stream.
Definition Model.cpp:524
void printModelInformationHeaderToStream(std::ostream &out) const
Prints the information header (number of states and transitions) of the model to the specified stream...
Definition Model.cpp:416
std::optional< storm::models::sparse::ChoiceLabeling > const & getOptionalChoiceLabeling() const
Retrieves an optional value that contains the choice labeling if there is one.
Definition Model.cpp:340
CRewardModelType RewardModelType
Definition Model.h:33
virtual bool supportsParameters() const override
Checks whether the model supports parameters.
Definition Model.cpp:640
virtual bool hasUniqueRewardModel() const override
Retrieves whether the model has a unique reward model.
Definition Model.cpp:288
virtual void writeDotToStream(std::ostream &outStream, size_t maxWidthLabel=30, bool includeLabeling=true, storm::storage::BitVector const *subsystem=nullptr, std::vector< ValueType > const *firstValue=nullptr, std::vector< ValueType > const *secondValue=nullptr, std::vector< uint64_t > const *stateColoring=nullptr, std::vector< std::string > const *colors=nullptr, std::vector< uint_fast64_t > *scheduler=nullptr, bool finalizeOutput=true) const
Exports the model to the dot-format and prints the result to the given stream.
virtual std::string additionalDotStateInfo(uint64_t state) const
Return a string that is additonally added to the state information in the dot stream.
Definition Model.cpp:612
Model(ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > const &components)
Constructs a model from the given data.
Definition Model.cpp:29
std::optional< storm::storage::sparse::StateValuations > & getOptionalStateValuations()
Retrieves an optional value that contains the state valuations if there are some.
Definition Model.cpp:365
std::optional< storm::storage::sparse::StateValuations > const & getOptionalStateValuations() const
Retrieves an optional value that contains the state valuations if there are some.
Definition Model.cpp:360
virtual uint_fast64_t getNumberOfTransitions() const override
Returns the number of (non-zero) transitions of the model.
Definition Model.cpp:168
virtual bool isExact() const override
Checks whether the model is exact.
Definition Model.cpp:680
bool hasChoiceOrigins() const
Retrieves whether this model was build with choice origins.
Definition Model.cpp:370
virtual bool hasParameters() const override
Checks whether the model has parameters.
Definition Model.cpp:650
RewardModelType & getUniqueRewardModel()
Retrieves the unique reward model, if there exists exactly one.
Definition Model.cpp:310
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:163
bool hasLabel(std::string const &label) const
Retrieves whether the given label is a valid label in this model.
Definition Model.cpp:193
RewardModelType const & getRewardModel(std::string const &rewardModelName) const
Retrieves the reward model with the given name, if one exists.
Definition Model.cpp:219
virtual std::string const & getUniqueRewardModelName() const override
Retrieves the name of the unique reward model, if there exists exactly one.
Definition Model.cpp:293
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:178
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
A class that holds a possibly non-square matrix in the compressed row storage format.
std::set< storm::RationalFunctionVariable > getRateParameters(Model< storm::RationalFunction > const &model)
Get all parameters occurring in rates.
Definition Model.cpp:707
std::set< storm::RationalFunctionVariable > getRewardParameters(Model< storm::RationalFunction > const &model)
Get all parameters occurring in rewards.
Definition Model.cpp:698
std::set< storm::RationalFunctionVariable > getProbabilityParameters(Model< storm::RationalFunction > const &model)
Get all probability parameters occurring on transitions.
Definition Model.cpp:694
std::set< storm::RationalFunctionVariable > getAllParameters(Model< storm::RationalFunction > const &model)
Get all parameters (probability, rewards, and rates) occurring in the model.
Definition Model.cpp:719