Storm
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
26template<typename ValueType>
27class StandardRewardModel;
28
32template<class CValueType, class CRewardModelType = StandardRewardModel<CValueType>>
33class Model : public storm::models::Model<CValueType> {
34 public:
35 typedef CValueType ValueType;
36 typedef CRewardModelType RewardModelType;
38
41
50
51 virtual ~Model() = default;
52
60
68
74 virtual uint_fast64_t getNumberOfStates() const override;
75
81 virtual uint_fast64_t getNumberOfTransitions() const override;
82
88 virtual uint_fast64_t getNumberOfChoices() const override;
89
96
103
110 storm::storage::BitVector const& getStates(std::string const& label) const;
111
118 bool hasLabel(std::string const& label) const;
119
126
133
139 std::unordered_map<std::string, RewardModelType> const& getRewardModels() const;
140
146 std::unordered_map<std::string, RewardModelType>& getRewardModels();
147
153 virtual bool hasRewardModel(std::string const& rewardModelName) const override;
154
160 RewardModelType const& getRewardModel(std::string const& rewardModelName) const;
161
167 RewardModelType& getRewardModel(std::string const& rewardModelName);
168
175
182
188 virtual bool hasUniqueRewardModel() const override;
189
195 virtual std::string const& getUniqueRewardModelName() const override;
196
202 bool hasRewardModel() const;
203
209 uint_fast64_t getNumberOfRewardModels() const;
210
216 void addRewardModel(std::string const& rewardModelName, RewardModelType const& rewModel);
217
222 bool removeRewardModel(std::string const& rewardModelName);
223
227 void restrictRewardModels(std::set<std::string> const& keptRewardModels);
228
235
242
248 bool hasChoiceLabeling() const;
249
257
263 std::optional<storm::models::sparse::ChoiceLabeling> const& getOptionalChoiceLabeling() const;
264
270 std::optional<storm::models::sparse::ChoiceLabeling>& getOptionalChoiceLabeling();
271
277 bool hasStateValuations() const;
278
286
292 std::optional<storm::storage::sparse::StateValuations> const& getOptionalStateValuations() const;
293
299 std::optional<storm::storage::sparse::StateValuations>& getOptionalStateValuations();
300
306 bool hasChoiceOrigins() const;
307
314 std::shared_ptr<storm::storage::sparse::ChoiceOrigins> const& getChoiceOrigins() const;
315
321 std::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>> const& getOptionalChoiceOrigins() const;
322
328 std::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>>& getOptionalChoiceOrigins();
329
335 virtual void printModelInformationToStream(std::ostream& out) const override;
336
337 bool isSinkState(uint64_t sink) const;
338
353 virtual void writeDotToStream(std::ostream& outStream, size_t maxWidthLabel = 30, bool includeLabeling = true,
354 storm::storage::BitVector const* subsystem = nullptr, std::vector<ValueType> const* firstValue = nullptr,
355 std::vector<ValueType> const* secondValue = nullptr, std::vector<uint64_t> const* stateColoring = nullptr,
356 std::vector<std::string> const* colors = nullptr, std::vector<uint_fast64_t>* scheduler = nullptr,
357 bool finalizeOutput = true) const;
358
362 virtual void writeJsonToStream(std::ostream& outStream) const;
363
370 std::set<std::string> getLabelsOfState(storm::storage::sparse::state_type state) const;
371
372 virtual bool isSparseModel() const override;
373
374 virtual bool supportsParameters() const override;
375
382 virtual bool hasParameters() const override;
383
384 virtual bool isExact() const override;
385
392 virtual bool supportsUncertainty() const;
393
401 virtual bool hasUncertainty() const;
402
403 virtual std::size_t hash() const;
404
405 protected:
406 RewardModelType& rewardModel(std::string const& rewardModelName);
413
420
426 void printModelInformationHeaderToStream(std::ostream& out) const;
427
434 void printModelInformationFooterToStream(std::ostream& out) const;
435
441 void printRewardModelsInformationToStream(std::ostream& out) const;
442
448 virtual std::string additionalDotStateInfo(uint64_t state) const;
449
450 private:
451 // Upon construction of a model, this function asserts that the specified components are valid
452 void assertValidityOfComponents(storm::storage::sparse::ModelComponents<ValueType, RewardModelType> const& components) const;
453
454 // A matrix representing transition relation.
456
457 // The labeling of the states.
459
460 // The reward models of the model.
461 std::unordered_map<std::string, RewardModelType> rewardModels;
462
463 // If set, a vector representing the labels of choices.
464 std::optional<storm::models::sparse::ChoiceLabeling> choiceLabeling;
465
466 // if set, retrieves for each state the variable valuation that this state represents
467 std::optional<storm::storage::sparse::StateValuations> stateValuations;
468
469 // if set, gives information about where each choice originates w.r.t. the input model description
470 std::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>> choiceOrigins;
471};
472
478std::set<storm::RationalFunctionVariable> getProbabilityParameters(Model<storm::RationalFunction> const& model);
479
485std::set<storm::RationalFunctionVariable> getRewardParameters(Model<storm::RationalFunction> const& model);
486
492std::set<storm::RationalFunctionVariable> getRateParameters(Model<storm::RationalFunction> const& model);
493
499std::set<storm::RationalFunctionVariable> getAllParameters(Model<storm::RationalFunction> const& model);
500} // namespace sparse
501} // namespace models
502} // 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:33
storm::models::sparse::ChoiceLabeling const & getChoiceLabeling() const
Retrieves the labels for the choices of the model.
Definition Model.cpp:334
RewardModelType const & getUniqueRewardModel() const
Retrieves the unique reward model, if there exists exactly one.
Definition Model.cpp:303
bool hasRewardModel() const
Retrieves whether the model has at least one reward model.
Definition Model.cpp:298
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:197
virtual std::size_t hash() const
Definition Model.cpp:395
virtual bool hasUncertainty() const
Checks whether the model actually is uncertain, i.e., whether there is a non-singleton transition rel...
Definition Model.cpp:674
Model(Model< ValueType, RewardModelType > const &other)=default
void setInitialStates(storm::storage::BitVector const &states)
Overwrites the initial states of the model.
Definition Model.cpp:182
void setTransitionMatrix(storm::storage::SparseMatrix< ValueType > const &transitionMatrix)
Sets the transition matrix of the model.
Definition Model.cpp:621
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:423
virtual void printModelInformationToStream(std::ostream &out) const override
Prints information about the model to the specified stream.
Definition Model.cpp:389
Model & operator=(Model< ValueType, RewardModelType > const &other)=default
std::unordered_map< std::string, RewardModelType > const & getRewardModels() const
Retrieves the reward models.
Definition Model.cpp:699
void restrictRewardModels(std::set< std::string > const &keptRewardModels)
Removes all reward models whose name is not in the given set.
Definition Model.cpp:274
bool hasStateValuations() const
Retrieves whether this model was build with state valuations.
Definition Model.cpp:349
storm::storage::BitVector const & getStates(std::string const &label) const
Returns the sets of states labeled with the given label.
Definition Model.cpp:187
bool removeRewardModel(std::string const &rewardModelName)
Removes the reward model with the given name from the model.
Definition Model.cpp:264
void printRewardModelsInformationToStream(std::ostream &out) const
Prints information about the reward models to the specified stream.
Definition Model.cpp:437
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:616
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:379
RewardModelType & rewardModel(std::string const &rewardModelName)
Definition Model.cpp:212
virtual uint_fast64_t getNumberOfChoices() const override
Returns the number of choices ine the model.
Definition Model.cpp:172
storm::storage::sparse::StateValuations const & getStateValuations() const
Retrieves the valuations of the states of the model.
Definition Model.cpp:354
virtual bool isSparseModel() const override
Checks whether the model is a sparse model.
Definition Model.cpp:644
void addRewardModel(std::string const &rewardModelName, RewardModelType const &rewModel)
Adds a reward model to the model.
Definition Model.cpp:254
virtual storm::storage::SparseMatrix< ValueType >::const_rows getRows(storm::storage::sparse::state_type state) const
Returns an object representing the matrix rows associated with the given state.
Definition Model.cpp:157
std::shared_ptr< storm::storage::sparse::ChoiceOrigins > const & getChoiceOrigins() const
Retrieves the origins of the choices of the model.
Definition Model.cpp:374
virtual bool supportsUncertainty() const
Does it support uncertainty (e.g., via interval-valued entries).
Definition Model.cpp:654
storm::storage::SparseMatrix< ValueType > getBackwardTransitions() const
Retrieves the backward transition relation of the model, i.e.
Definition Model.cpp:152
bool isSinkState(uint64_t sink) const
Definition Model.cpp:631
bool hasChoiceLabeling() const
Retrieves whether this model has a labeling of the choices.
Definition Model.cpp:329
uint_fast64_t getNumberOfRewardModels() const
Retrieves the number of reward models associated with this model.
Definition Model.cpp:315
virtual ~Model()=default
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
Definition Model.cpp:319
static const storm::models::ModelRepresentation Representation
Definition Model.h:37
virtual void writeJsonToStream(std::ostream &outStream) const
Writes a JSON representation of the model to the given stream.
Definition Model.cpp:523
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:415
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:339
CRewardModelType RewardModelType
Definition Model.h:36
virtual bool supportsParameters() const override
Checks whether the model supports parameters.
Definition Model.cpp:649
virtual bool hasUniqueRewardModel() const override
Retrieves whether the model has a unique reward model.
Definition Model.cpp:287
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:611
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:359
virtual uint_fast64_t getNumberOfTransitions() const override
Returns the number of (non-zero) transitions of the model.
Definition Model.cpp:167
virtual bool isExact() const override
Checks whether the model is exact.
Definition Model.cpp:689
bool hasChoiceOrigins() const
Retrieves whether this model was build with choice origins.
Definition Model.cpp:369
virtual bool hasParameters() const override
Checks whether the model has parameters.
Definition Model.cpp:659
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:162
bool hasLabel(std::string const &label) const
Retrieves whether the given label is a valid label in this model.
Definition Model.cpp:192
RewardModelType const & getRewardModel(std::string const &rewardModelName) const
Retrieves the reward model with the given name, if one exists.
Definition Model.cpp:218
virtual std::string const & getUniqueRewardModelName() const override
Retrieves the name of the unique reward model, if there exists exactly one.
Definition Model.cpp:292
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:177
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:18
This class represents a number of consecutive rows of the matrix.
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:716
std::set< storm::RationalFunctionVariable > getRewardParameters(Model< storm::RationalFunction > const &model)
Get all parameters occurring in rewards.
Definition Model.cpp:707
std::set< storm::RationalFunctionVariable > getProbabilityParameters(Model< storm::RationalFunction > const &model)
Get all probability parameters occurring on transitions.
Definition Model.cpp:703
std::set< storm::RationalFunctionVariable > getAllParameters(Model< storm::RationalFunction > const &model)
Get all parameters (probability, rewards, and rates) occurring in the model.
Definition Model.cpp:728
storage::BitVector BitVector
LabParser.cpp.
Definition cli.cpp:18