12namespace transformer {
14template<
typename ValueType,
typename RewardModelType>
30 if (rewardModel.second.hasStateRewards()) {
35 if (timeRewardModelName) {
37 std::vector<ValueType> timeRewardVector;
38 timeRewardVector.reserve(exitRates.size());
39 for (
auto const& r : exitRates) {
40 timeRewardVector.push_back(storm::utility::one<ValueType>() / r);
42 RewardModelType timeRewards(std::move(timeRewardVector));
43 auto insertRes = dtmcComponents.
rewardModels.insert(std::make_pair(*timeRewardModelName, std::move(timeRewards)));
44 STORM_LOG_THROW(insertRes.second, storm::exceptions::InvalidArgumentException,
45 "Could not insert auxiliary reward model " << *timeRewardModelName <<
" because a model with this name already exists.");
48 return std::make_shared<storm::models::sparse::Dtmc<ValueType, RewardModelType>>(std::move(dtmcComponents));
51template<
typename ValueType,
typename RewardModelType>
56 std::move(ctmc.getStateLabeling()), std::move(ctmc.getRewardModels()));
57 dtmcComponents.
choiceLabeling = std::move(ctmc.getOptionalChoiceLabeling());
58 dtmcComponents.
stateValuations = std::move(ctmc.getOptionalStateValuations());
59 dtmcComponents.
choiceOrigins = std::move(ctmc.getOptionalChoiceOrigins());
62 std::vector<ValueType>& exitRates = ctmc.getExitRateVector();
67 if (rewardModel.second.hasStateRewards()) {
72 if (timeRewardModelName) {
74 storm::utility::vector::applyPointwise<ValueType, ValueType>(exitRates, exitRates,
75 [&](ValueType
const& r) -> ValueType {
return storm::utility::one<ValueType>() / r; });
76 RewardModelType timeRewards(std::move(exitRates));
77 auto insertRes = dtmcComponents.
rewardModels.insert(std::make_pair(*timeRewardModelName, std::move(timeRewards)));
78 STORM_LOG_THROW(insertRes.second, storm::exceptions::InvalidArgumentException,
79 "Could not insert auxiliary reward model " << *timeRewardModelName <<
" because a model with this name already exists.");
83 return std::make_shared<storm::models::sparse::Dtmc<ValueType, RewardModelType>>(std::move(dtmcComponents));
86template<
typename ValueType,
typename RewardModelType>
101template<
typename ValueType,
typename RewardModelType>
103 std::vector<std::shared_ptr<storm::logic::Formula const>>
const& formulas, std::string
const& timeRewardName) {
104 std::vector<std::shared_ptr<storm::logic::Formula const>> result;
106 for (
auto const& f : formulas) {
109 if (preservesFormula(*newF)) {
110 result.push_back(newF);
112 STORM_LOG_INFO(
"Continuous to discrete time transformation does not preserve formula " << *f);
118template<
typename ValueType,
typename RewardModelType>
121 STORM_LOG_THROW(ma.
isClosed(), storm::exceptions::InvalidArgumentException,
"Transformation of MA to its underlying MDP is only possible for closed MAs");
132 std::vector<ValueType>
const& exitRates = ma.
getExitRates();
134 if (rewardModel.second.hasStateRewards()) {
135 auto& stateRewards = rewardModel.second.getStateRewardVector();
136 for (uint_fast64_t state = 0; state < stateRewards.size(); ++state) {
138 stateRewards[state] /= exitRates[state];
140 stateRewards[state] = storm::utility::zero<ValueType>();
146 if (timeRewardModelName) {
148 std::vector<ValueType> timeRewardVector(exitRates.size(), storm::utility::zero<ValueType>());
150 timeRewardVector[state] = storm::utility::one<ValueType>() / exitRates[state];
152 RewardModelType timeRewards(std::move(timeRewardVector));
153 auto insertRes = mdpComponents.
rewardModels.insert(std::make_pair(*timeRewardModelName, std::move(timeRewards)));
154 STORM_LOG_THROW(insertRes.second, storm::exceptions::InvalidArgumentException,
155 "Could not insert auxiliary reward model " << *timeRewardModelName <<
" because a model with this name already exists.");
158 return std::make_shared<storm::models::sparse::Mdp<ValueType, RewardModelType>>(std::move(mdpComponents));
161template<
typename ValueType,
typename RewardModelType>
164 STORM_LOG_THROW(ma.isClosed(), storm::exceptions::InvalidArgumentException,
"Transformation of MA to its underlying MDP is only possible for closed MAs");
165 std::vector<ValueType>& exitRates = ma.getExitRates();
169 std::move(ma.getRewardModels()));
170 mdpComponents.
choiceLabeling = std::move(ma.getOptionalChoiceLabeling());
171 mdpComponents.
stateValuations = std::move(ma.getOptionalStateValuations());
172 mdpComponents.
choiceOrigins = std::move(ma.getOptionalChoiceOrigins());
178 if (rewardModel.second.hasStateRewards()) {
179 auto& stateRewards = rewardModel.second.getStateRewardVector();
180 for (uint_fast64_t state = 0; state < stateRewards.size(); ++state) {
181 if (ma.getMarkovianStates().get(state)) {
182 stateRewards[state] /= exitRates[state];
184 stateRewards[state] = storm::utility::zero<ValueType>();
190 if (timeRewardModelName) {
192 std::vector<ValueType> timeRewardVector(exitRates.size(), storm::utility::zero<ValueType>());
193 for (
auto state : ma.getMarkovianStates()) {
194 timeRewardVector[state] = storm::utility::one<ValueType>() / exitRates[state];
196 RewardModelType timeRewards(std::move(timeRewardVector));
197 auto insertRes = mdpComponents.
rewardModels.insert(std::make_pair(*timeRewardModelName, std::move(timeRewards)));
198 STORM_LOG_THROW(insertRes.second, storm::exceptions::InvalidArgumentException,
199 "Could not insert auxiliary reward model " << *timeRewardModelName <<
" because a model with this name already exists.");
202 return std::make_shared<storm::models::sparse::Mdp<ValueType, RewardModelType>>(std::move(mdpComponents));
std::shared_ptr< Formula > substitute(Formula const &f) const
FragmentSpecification & setNextFormulasAllowed(bool newValue)
FragmentSpecification & setMultiObjectiveFormulasAllowed(bool newValue)
FragmentSpecification & setGloballyFormulasAllowed(bool newValue)
FragmentSpecification & setReachabilityProbabilityFormulasAllowed(bool newValue)
FragmentSpecification & setTotalRewardFormulasAllowed(bool newValue)
FragmentSpecification & setReachabilityRewardFormulasAllowed(bool newValue)
FragmentSpecification & setRewardOperatorsAllowed(bool newValue)
FragmentSpecification & setUntilFormulasAllowed(bool newValue)
FragmentSpecification & setProbabilityOperatorsAllowed(bool newValue)
This class represents a continuous-time Markov chain.
std::vector< ValueType > const & getExitRateVector() const
Retrieves the vector of exit rates of the model.
This class represents a Markov automaton.
bool isClosed() const
Retrieves whether the Markov automaton is closed.
std::vector< ValueType > const & getExitRates() const
Retrieves the vector representing the exit rates of the states.
storm::storage::BitVector const & getMarkovianStates() const
Retrieves the set of Markovian states of the model.
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
std::unordered_map< std::string, RewardModelType > const & getRewardModels() const
Retrieves the reward models.
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.
storm::models::sparse::StateLabeling const & getStateLabeling() const
Returns the state labeling associated with this model.
std::optional< storm::models::sparse::ChoiceLabeling > const & getOptionalChoiceLabeling() const
Retrieves an optional value that contains the choice labeling if there is one.
std::optional< storm::storage::sparse::StateValuations > const & getOptionalStateValuations() const
Retrieves an optional value that contains the state valuations if there are some.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
#define STORM_LOG_INFO(message)
#define STORM_LOG_THROW(cond, exception, message)
FragmentSpecification propositional()
void divideVectorsPointwise(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target)
Divides the two given vectors (pointwise) and writes the result to the target vector.
std::optional< storm::storage::sparse::StateValuations > stateValuations
std::unordered_map< std::string, RewardModelType > rewardModels
storm::storage::SparseMatrix< ValueType > transitionMatrix
std::optional< std::shared_ptr< storm::storage::sparse::ChoiceOrigins > > choiceOrigins
std::optional< storm::models::sparse::ChoiceLabeling > choiceLabeling