Storm 1.14.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 <memory>
4#include <optional>
5#include <unordered_map>
6#include <vector>
7
11#include "storm/models/Model.h"
21
22namespace storm {
23namespace storage {
24class BitVector;
25}
26
27namespace models {
28namespace sparse {
29
33template<class CValueType, class CRewardModelType>
34class Model : public storm::models::Model<CValueType> {
35 public:
36 typedef CValueType ValueType;
37 typedef CRewardModelType RewardModelType;
39
42
51
52 virtual ~Model() = default;
53
60
66 void setStochasticTolerance(ValueType const& tolerance);
67
75
81 virtual uint_fast64_t getNumberOfStates() const override;
82
88 virtual uint_fast64_t getNumberOfTransitions() const override;
89
95 virtual uint_fast64_t getNumberOfChoices() const override;
96
103
110
117 storm::storage::BitVector const& getStates(std::string const& label) const;
118
125 bool hasLabel(std::string const& label) const;
126
133
140
146 std::unordered_map<std::string, RewardModelType> const& getRewardModels() const;
147
153 std::unordered_map<std::string, RewardModelType>& getRewardModels();
154
160 virtual bool hasRewardModel(std::string const& rewardModelName) const override;
161
167 RewardModelType const& getRewardModel(std::string const& rewardModelName) const;
168
174 RewardModelType& getRewardModel(std::string const& rewardModelName);
175
182
189
195 virtual bool hasUniqueRewardModel() const override;
196
202 virtual std::string const& getUniqueRewardModelName() const override;
203
209 bool hasRewardModel() const;
210
216 uint_fast64_t getNumberOfRewardModels() const;
217
223 void addRewardModel(std::string const& rewardModelName, RewardModelType const& rewModel);
224
229 bool removeRewardModel(std::string const& rewardModelName);
230
234 void restrictRewardModels(std::set<std::string> const& keptRewardModels);
235
242
249
255 bool hasChoiceLabeling() const;
256
264
270 std::optional<storm::models::sparse::ChoiceLabeling> const& getOptionalChoiceLabeling() const;
271
277 std::optional<storm::models::sparse::ChoiceLabeling>& getOptionalChoiceLabeling();
278
284 bool hasStateValuations() const;
285
293
299 std::optional<storm::storage::sparse::Valuations> const& getOptionalStateValuations() const;
300
306 std::optional<storm::storage::sparse::Valuations>& getOptionalStateValuations();
307
313 bool hasChoiceOrigins() const;
314
321 std::shared_ptr<storm::storage::sparse::ChoiceOrigins> const& getChoiceOrigins() const;
322
328 std::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>> const& getOptionalChoiceOrigins() const;
329
335 std::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>>& getOptionalChoiceOrigins();
336
342 virtual void printModelInformationToStream(std::ostream& out) const override;
343
344 bool isSinkState(uint64_t sink) const;
345
360 virtual void writeDotToStream(std::ostream& outStream, size_t maxWidthLabel = 30, bool includeLabeling = true,
361 storm::storage::BitVector const* subsystem = nullptr, std::vector<ValueType> const* firstValue = nullptr,
362 std::vector<ValueType> const* secondValue = nullptr, std::vector<uint64_t> const* stateColoring = nullptr,
363 std::vector<std::string> const* colors = nullptr, std::vector<uint_fast64_t>* scheduler = nullptr,
364 bool finalizeOutput = true) const;
365
369 virtual void writeJsonToStream(std::ostream& outStream) const;
370
377 std::set<std::string> getLabelsOfState(storm::storage::sparse::state_type state) const;
378
379 virtual bool isSparseModel() const override;
380
381 virtual bool supportsParameters() const override;
382
389 virtual bool hasParameters() const override;
390
391 virtual bool isExact() const override;
392
399 virtual bool supportsUncertainty() const override;
400
408 virtual bool hasUncertainty() const;
409
410 virtual std::size_t hash() const;
411
412 protected:
413 RewardModelType& rewardModel(std::string const& rewardModelName);
414
420 void printModelInformationHeaderToStream(std::ostream& out) const;
421
428 void printModelInformationFooterToStream(std::ostream& out) const;
429
435 void printRewardModelsInformationToStream(std::ostream& out) const;
436
442 virtual std::string additionalDotStateInfo(uint64_t state) const;
443
444 private:
445 // Upon construction of a model, this function asserts that the specified components are valid
446 void assertValidityOfComponents(storm::storage::sparse::ModelComponents<ValueType, RewardModelType> const& components) const;
447
448 // A matrix representing transition relation.
450
451 // The labeling of the states.
453
454 // The reward models of the model.
455 std::unordered_map<std::string, RewardModelType> rewardModels;
456
457 // If set, a vector representing the labels of choices.
458 std::optional<storm::models::sparse::ChoiceLabeling> choiceLabeling;
459
460 // if set, retrieves for each state the variable valuation that this state represents
461 std::optional<storm::storage::sparse::Valuations> stateValuations;
462
463 // if set, gives information about where each choice originates w.r.t. the input model description
464 std::optional<std::shared_ptr<storm::storage::sparse::ChoiceOrigins>> choiceOrigins;
465
466 // The tolerance up to which the model components are considered valid. Stored as a heap-allocated value to avoid
467 // requiring the value type to be complete at the point of instantiation of the class template.
468 std::unique_ptr<ValueType> stochasticTolerance;
469};
470
476std::set<storm::RationalFunctionVariable> getProbabilityParameters(Model<storm::RationalFunction> const& model);
477
483std::set<storm::RationalFunctionVariable> getRewardParameters(Model<storm::RationalFunction> const& model);
484
490std::set<storm::RationalFunctionVariable> getRateParameters(Model<storm::RationalFunction> const& model);
491
497std::set<storm::RationalFunctionVariable> getAllParameters(Model<storm::RationalFunction> const& model);
498
499// Must precede the extern template below, which would otherwise be the point of instantiation.
500template<>
502
503// Instantiated in Model.cpp; prevents hidden consumers from duplicating the vtable/RTTI.
504extern template class Model<double>;
506extern template class Model<storm::RationalNumber>;
508extern template class Model<storm::Interval>;
509extern template class Model<storm::RationalInterval>;
510extern template class Model<storm::RationalFunction>;
511
512} // namespace sparse
513} // namespace models
514} // 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:34
storm::models::sparse::ChoiceLabeling const & getChoiceLabeling() const
Retrieves the labels for the choices of the model.
Definition Model.cpp:363
RewardModelType const & getUniqueRewardModel() const
Retrieves the unique reward model, if there exists exactly one.
Definition Model.cpp:332
storm::models::sparse::StateLabeling & getStateLabeling()
Returns the state labeling associated with this model.
Definition Model.cpp:353
std::optional< storm::storage::sparse::Valuations > const & getOptionalStateValuations() const
Retrieves an optional value that contains the state valuations if there are some.
Definition Model.cpp:388
bool hasRewardModel() const
Retrieves whether the model has at least one reward model.
Definition Model.cpp:327
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:226
virtual std::size_t hash() const
Definition Model.cpp:424
virtual bool hasUncertainty() const
Checks whether the model actually is uncertain, i.e., whether there is a non-singleton transition rel...
Definition Model.cpp:693
void setInitialStates(storm::storage::BitVector const &states)
Overwrites the initial states of the model.
Definition Model.cpp:211
virtual bool supportsUncertainty() const override
Does it support uncertainty (e.g., via interval-valued entries).
Definition Model.cpp:673
Model & operator=(Model< ValueType, RewardModelType > const &other)
Definition Model.cpp:41
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:452
virtual void printModelInformationToStream(std::ostream &out) const override
Prints information about the model to the specified stream.
Definition Model.cpp:418
std::unordered_map< std::string, RewardModelType > const & getRewardModels() const
Retrieves the reward models.
Definition Model.cpp:728
RewardModelType & getRewardModel(std::string const &rewardModelName)
Retrieves the reward model with the given name, if one exists.
Definition Model.cpp:265
void restrictRewardModels(std::set< std::string > const &keptRewardModels)
Removes all reward models whose name is not in the given set.
Definition Model.cpp:303
bool hasStateValuations() const
Retrieves whether this model was build with state valuations.
Definition Model.cpp:378
storm::storage::BitVector const & getStates(std::string const &label) const
Returns the sets of states labeled with the given label.
Definition Model.cpp:216
bool removeRewardModel(std::string const &rewardModelName)
Removes the reward model with the given name from the model.
Definition Model.cpp:293
void printRewardModelsInformationToStream(std::ostream &out) const
Prints information about the reward models to the specified stream.
Definition Model.cpp:466
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:645
storm::storage::sparse::Valuations const & getStateValuations() const
Retrieves the valuations of the states of the model.
Definition Model.cpp:383
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:408
std::optional< storm::models::sparse::ChoiceLabeling > & getOptionalChoiceLabeling()
Retrieves an optional value that contains the choice labeling if there is one.
Definition Model.cpp:373
RewardModelType & rewardModel(std::string const &rewardModelName)
Definition Model.cpp:241
virtual uint_fast64_t getNumberOfChoices() const override
Returns the number of choices ine the model.
Definition Model.cpp:201
virtual bool isSparseModel() const override
Checks whether the model is a sparse model.
Definition Model.cpp:663
void addRewardModel(std::string const &rewardModelName, RewardModelType const &rewModel)
Adds a reward model to the model.
Definition Model.cpp:283
ValueType const & getStochasticTolerance() const
Retrieves the tolerance up to which the model components are considered valid.
Definition Model.cpp:713
std::shared_ptr< storm::storage::sparse::ChoiceOrigins > const & getChoiceOrigins() const
Retrieves the origins of the choices of the model.
Definition Model.cpp:403
void setStochasticTolerance(ValueType const &tolerance)
Sets the tolerance up to which the model components are considered valid.
Definition Model.cpp:718
Model(Model< ValueType, RewardModelType > const &other)
Definition Model.cpp:28
storm::storage::SparseMatrix< ValueType > getBackwardTransitions() const
Retrieves the backward transition relation of the model, i.e.
Definition Model.cpp:186
bool isSinkState(uint64_t sink) const
Definition Model.cpp:650
bool hasChoiceLabeling() const
Retrieves whether this model has a labeling of the choices.
Definition Model.cpp:358
std::unordered_map< std::string, RewardModelType > & getRewardModels()
Retrieves the reward models.
Definition Model.cpp:723
uint_fast64_t getNumberOfRewardModels() const
Retrieves the number of reward models associated with this model.
Definition Model.cpp:344
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:413
virtual ~Model()=default
Model(ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > &&components)
Definition Model.cpp:70
virtual bool hasRewardModel(std::string const &rewardModelName) const override
Retrieves whether the model has a reward model with the given name.
Definition Model.cpp:236
storm::storage::SparseMatrix< ValueType > & getTransitionMatrix()
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:231
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
Definition Model.cpp:348
static const storm::models::ModelRepresentation Representation
Definition Model.h:38
virtual void writeJsonToStream(std::ostream &outStream) const
Writes a JSON representation of the model to the given stream.
Definition Model.cpp:552
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:444
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:368
CRewardModelType RewardModelType
Definition Model.h:37
virtual bool supportsParameters() const override
Checks whether the model supports parameters.
Definition Model.cpp:668
virtual bool hasUniqueRewardModel() const override
Retrieves whether the model has a unique reward model.
Definition Model.cpp:316
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:640
Model(ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > const &components)
Constructs a model from the given data.
Definition Model.cpp:56
std::optional< storm::storage::sparse::Valuations > & getOptionalStateValuations()
Retrieves an optional value that contains the state valuations if there are some.
Definition Model.cpp:393
virtual uint_fast64_t getNumberOfTransitions() const override
Returns the number of (non-zero) transitions of the model.
Definition Model.cpp:196
virtual bool isExact() const override
Checks whether the model is exact.
Definition Model.cpp:708
bool hasChoiceOrigins() const
Retrieves whether this model was build with choice origins.
Definition Model.cpp:398
virtual bool hasParameters() const override
Checks whether the model has parameters.
Definition Model.cpp:678
RewardModelType & getUniqueRewardModel()
Retrieves the unique reward model, if there exists exactly one.
Definition Model.cpp:338
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:191
bool hasLabel(std::string const &label) const
Retrieves whether the given label is a valid label in this model.
Definition Model.cpp:221
RewardModelType const & getRewardModel(std::string const &rewardModelName) const
Retrieves the reward model with the given name, if one exists.
Definition Model.cpp:247
virtual std::string const & getUniqueRewardModelName() const override
Retrieves the name of the unique reward model, if there exists exactly one.
Definition Model.cpp:321
storm::storage::BitVector const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:206
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.
Provides access to valuations of variables for a set of entities (e.g.
Definition Valuations.h:28
std::set< storm::RationalFunctionVariable > getRateParameters(Model< storm::RationalFunction > const &model)
Get all parameters occurring in rates.
Definition Model.cpp:745
std::set< storm::RationalFunctionVariable > getRewardParameters(Model< storm::RationalFunction > const &model)
Get all parameters occurring in rewards.
Definition Model.cpp:736
std::set< storm::RationalFunctionVariable > getProbabilityParameters(Model< storm::RationalFunction > const &model)
Get all probability parameters occurring on transitions.
Definition Model.cpp:732
std::set< storm::RationalFunctionVariable > getAllParameters(Model< storm::RationalFunction > const &model)
Get all parameters (probability, rewards, and rates) occurring in the model.
Definition Model.cpp:757