3#include <unordered_map>
17namespace transformer {
19template<
typename ValueType,
typename RewardModelType>
35 if (rewardModel.second.hasStateRewards()) {
40 if (timeRewardModelName) {
42 std::vector<ValueType> timeRewardVector;
43 timeRewardVector.reserve(exitRates.size());
44 for (
auto const& r : exitRates) {
45 timeRewardVector.push_back(storm::utility::one<ValueType>() / r);
47 RewardModelType timeRewards(std::move(timeRewardVector));
48 auto insertRes = dtmcComponents.
rewardModels.insert(std::make_pair(*timeRewardModelName, std::move(timeRewards)));
49 STORM_LOG_THROW(insertRes.second, storm::exceptions::InvalidArgumentException,
50 "Could not insert auxiliary reward model " << *timeRewardModelName <<
" because a model with this name already exists.");
53 return std::make_shared<storm::models::sparse::Dtmc<ValueType, RewardModelType>>(std::move(dtmcComponents));
56template<
typename ValueType,
typename RewardModelType>
61 std::move(ctmc.getStateLabeling()), std::move(ctmc.getRewardModels()));
62 dtmcComponents.
choiceLabeling = std::move(ctmc.getOptionalChoiceLabeling());
63 dtmcComponents.
stateValuations = std::move(ctmc.getOptionalStateValuations());
64 dtmcComponents.
choiceOrigins = std::move(ctmc.getOptionalChoiceOrigins());
67 std::vector<ValueType>& exitRates = ctmc.getExitRateVector();
72 if (rewardModel.second.hasStateRewards()) {
77 if (timeRewardModelName) {
79 storm::utility::vector::applyPointwise<ValueType, ValueType>(exitRates, exitRates,
80 [&](ValueType
const& r) -> ValueType {
return storm::utility::one<ValueType>() / r; });
81 RewardModelType timeRewards(std::move(exitRates));
82 auto insertRes = dtmcComponents.
rewardModels.insert(std::make_pair(*timeRewardModelName, std::move(timeRewards)));
83 STORM_LOG_THROW(insertRes.second, storm::exceptions::InvalidArgumentException,
84 "Could not insert auxiliary reward model " << *timeRewardModelName <<
" because a model with this name already exists.");
88 return std::make_shared<storm::models::sparse::Dtmc<ValueType, RewardModelType>>(std::move(dtmcComponents));
91template<
typename ValueType,
typename RewardModelType>
106template<
typename ValueType,
typename RewardModelType>
108 std::vector<std::shared_ptr<storm::logic::Formula const>>
const& formulas, std::string
const& timeRewardName) {
109 std::vector<std::shared_ptr<storm::logic::Formula const>> result;
111 for (
auto const& f : formulas) {
114 if (preservesFormula(*newF)) {
115 result.push_back(newF);
117 STORM_LOG_INFO(
"Continuous to discrete time transformation does not preserve formula " << *f);
123template<
typename ValueType,
typename RewardModelType>
126 STORM_LOG_THROW(ma.
isClosed(), storm::exceptions::InvalidArgumentException,
"Transformation of MA to its underlying MDP is only possible for closed MAs");
137 std::vector<ValueType>
const& exitRates = ma.
getExitRates();
139 if (rewardModel.second.hasStateRewards()) {
140 auto& stateRewards = rewardModel.second.getStateRewardVector();
141 for (uint_fast64_t state = 0; state < stateRewards.size(); ++state) {
143 stateRewards[state] /= exitRates[state];
145 stateRewards[state] = storm::utility::zero<ValueType>();
151 if (timeRewardModelName) {
153 std::vector<ValueType> timeRewardVector(exitRates.size(), storm::utility::zero<ValueType>());
155 timeRewardVector[state] = storm::utility::one<ValueType>() / exitRates[state];
157 RewardModelType timeRewards(std::move(timeRewardVector));
158 auto insertRes = mdpComponents.
rewardModels.insert(std::make_pair(*timeRewardModelName, std::move(timeRewards)));
159 STORM_LOG_THROW(insertRes.second, storm::exceptions::InvalidArgumentException,
160 "Could not insert auxiliary reward model " << *timeRewardModelName <<
" because a model with this name already exists.");
163 return std::make_shared<storm::models::sparse::Mdp<ValueType, RewardModelType>>(std::move(mdpComponents));
166template<
typename ValueType,
typename RewardModelType>
169 STORM_LOG_THROW(ma.isClosed(), storm::exceptions::InvalidArgumentException,
"Transformation of MA to its underlying MDP is only possible for closed MAs");
170 std::vector<ValueType>& exitRates = ma.getExitRates();
174 std::move(ma.getRewardModels()));
175 mdpComponents.
choiceLabeling = std::move(ma.getOptionalChoiceLabeling());
176 mdpComponents.
stateValuations = std::move(ma.getOptionalStateValuations());
177 mdpComponents.
choiceOrigins = std::move(ma.getOptionalChoiceOrigins());
183 if (rewardModel.second.hasStateRewards()) {
184 auto& stateRewards = rewardModel.second.getStateRewardVector();
185 for (uint_fast64_t state = 0; state < stateRewards.size(); ++state) {
186 if (ma.getMarkovianStates().get(state)) {
187 stateRewards[state] /= exitRates[state];
189 stateRewards[state] = storm::utility::zero<ValueType>();
195 if (timeRewardModelName) {
197 std::vector<ValueType> timeRewardVector(exitRates.size(), storm::utility::zero<ValueType>());
198 for (
auto state : ma.getMarkovianStates()) {
199 timeRewardVector[state] = storm::utility::one<ValueType>() / exitRates[state];
201 RewardModelType timeRewards(std::move(timeRewardVector));
202 auto insertRes = mdpComponents.
rewardModels.insert(std::make_pair(*timeRewardModelName, std::move(timeRewards)));
203 STORM_LOG_THROW(insertRes.second, storm::exceptions::InvalidArgumentException,
204 "Could not insert auxiliary reward model " << *timeRewardModelName <<
" because a model with this name already exists.");
207 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(uint_fast64_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