23template<
typename ValueType,
typename RewardModelType>
27 std::unordered_map<std::string, RewardModelType>
const& rewardModels)
33template<
typename ValueType,
typename RewardModelType>
36 std::unordered_map<std::string, RewardModelType>&& rewardModels)
38 std::move(transitionMatrix),
std::move(stateLabeling),
std::move(rewardModels), true,
std::move(markovianStates))) {
42template<
typename ValueType,
typename RewardModelType>
50 this->turnRatesToProbabilities();
52 closed = this->checkIsClosed();
55template<
typename ValueType,
typename RewardModelType>
58 markovianStates(
std::move(components.markovianStates.get())) {
59 if (components.exitRates) {
60 exitRates = std::move(components.exitRates.get());
63 if (components.rateTransitions) {
64 this->turnRatesToProbabilities();
66 closed = this->checkIsClosed();
69template<
typename ValueType,
typename RewardModelType>
74template<
typename ValueType,
typename RewardModelType>
76 if (!this->hasZenoCycle.is_initialized()) {
77 this->hasZenoCycle = this->checkContainsZenoCycle();
79 return this->hasZenoCycle.get();
82template<
typename ValueType,
typename RewardModelType>
84 return isMarkovianState(state) && (this->getTransitionMatrix().getRowGroupSize(state) > 1);
87template<
typename ValueType,
typename RewardModelType>
89 return this->markovianStates.get(state);
92template<
typename ValueType,
typename RewardModelType>
94 return !this->markovianStates.get(state);
97template<
typename ValueType,
typename RewardModelType>
99 return this->exitRates;
102template<
typename ValueType,
typename RewardModelType>
104 return this->exitRates;
107template<
typename ValueType,
typename RewardModelType>
109 return this->exitRates[state];
112template<
typename ValueType,
typename RewardModelType>
117template<
typename ValueType,
typename RewardModelType>
119 return this->markovianStates;
122template<
typename ValueType,
typename RewardModelType>
127 for (
auto state : this->getMarkovianStates()) {
128 if (this->getTransitionMatrix().getRowGroupSize(state) > 1) {
130 keptChoices.
set(this->getTransitionMatrix().getRowGroupIndices()[state],
false);
132 this->markovianStates.set(state,
false);
133 exitRates[state] = storm::utility::zero<ValueType>();
137 if (!keptChoices.
full()) {
147template<
typename ValueType,
typename RewardModelType>
149 bool assertRates = (this->exitRates.size() == this->getNumberOfStates());
151 STORM_LOG_THROW(this->exitRates.empty(), storm::exceptions::InvalidArgumentException,
"The specified exit rate vector has an unexpected size.");
152 this->exitRates.reserve(this->getNumberOfStates());
156 for (uint_fast64_t state = 0; state < this->getNumberOfStates(); ++state) {
157 uint_fast64_t row = this->getTransitionMatrix().getRowGroupIndices()[state];
158 if (this->markovianStates.get(state)) {
160 STORM_LOG_THROW(this->exitRates[state] == this->getTransitionMatrix().getRowSum(row), storm::exceptions::InvalidArgumentException,
161 "The specified exit rate is inconsistent with the rate matrix. Difference is "
162 << (this->exitRates[state] - this->getTransitionMatrix().getRowSum(row)) <<
".");
164 this->exitRates.push_back(this->getTransitionMatrix().getRowSum(row));
166 for (
auto& transition : this->getTransitionMatrix().getRow(row)) {
167 transition.setValue(transition.getValue() / this->exitRates[state]);
172 STORM_LOG_THROW(comparator.
isZero(this->exitRates[state]), storm::exceptions::InvalidArgumentException,
173 "The specified exit rate for (non-Markovian) choice should be 0.");
175 this->exitRates.push_back(storm::utility::zero<ValueType>());
178 for (; row < this->getTransitionMatrix().getRowGroupIndices()[state + 1]; ++row) {
179 STORM_LOG_THROW(comparator.
isOne(this->getTransitionMatrix().getRowSum(row)), storm::exceptions::InvalidArgumentException,
180 "Entries of transition matrix do not sum up to one for (non-Markovian) choice "
181 << row <<
" of state " << state <<
" (sum is " << this->getTransitionMatrix().getRowSum(row) <<
").");
186template<
typename ValueType,
typename RewardModelType>
188 return isClosed() && markovianStates.full();
191template<
typename ValueType,
typename RewardModelType>
194 for (uint_fast64_t state = 0; state < this->getNumberOfStates(); ++state) {
196 if (this->getNumberOfChoices(state) > 1) {
198 STORM_LOG_ASSERT(isProbabilisticState(state),
"State is not probabilistic.");
205template<
typename ValueType,
typename RewardModelType>
207 for (
auto state : markovianStates) {
208 if (this->getTransitionMatrix().getRowGroupSize(state) > 1) {
215template<
typename ValueType,
typename RewardModelType>
217 STORM_LOG_THROW(isConvertibleToCtmc(), storm::exceptions::InvalidArgumentException,
"MA cannot be converted to CTMC.");
220 this->getRewardModels(),
false);
222 components.
exitRates = this->getExitRates();
223 if (this->hasChoiceLabeling()) {
226 if (this->hasStateValuations()) {
229 if (this->hasChoiceOrigins()) {
232 return std::make_shared<storm::models::sparse::Ctmc<ValueType, RewardModelType>>(std::move(components));
235template<
typename ValueType,
typename RewardModelType>
237 if (isClosed() && markovianStates.empty()) {
242 return !statesWithZenoCycle.
empty();
245template<
typename ValueType,
typename RewardModelType>
247 this->printModelInformationHeaderToStream(out);
248 out <<
"Choices: \t" << this->getNumberOfChoices() <<
'\n';
249 out <<
"Markovian St.: \t" << this->getMarkovianStates().getNumberOfSetBits() <<
'\n';
250 out <<
"Max. Rate: \t";
251 if (this->getMarkovianStates().empty()) {
254 out << this->getMaximalExitRate();
257 this->printModelInformationFooterToStream(out);
261#ifdef STORM_HAVE_CARL
This class represents a Markov automaton.
void close()
Closes the Markov automaton.
MarkovAutomaton(storm::storage::SparseMatrix< ValueType > const &transitionMatrix, storm::models::sparse::StateLabeling const &stateLabeling, storm::storage::BitVector const &markovianStates, std::unordered_map< std::string, RewardModelType > const &rewardModels=std::unordered_map< std::string, RewardModelType >())
Constructs a model from the given data.
bool containsZenoCycle() const
Retrieves whether the Markov automaton contains Zeno cycles.
bool isClosed() const
Retrieves whether the Markov automaton is closed.
std::shared_ptr< storm::models::sparse::Ctmc< ValueType, RewardModelType > > convertToCtmc() const
Convert the MA to a CTMC.
bool isProbabilisticState(storm::storage::sparse::state_type state) const
Retrieves whether the given state is a probabilistic state.
bool isMarkovianState(storm::storage::sparse::state_type state) const
Retrieves whether the given state is a Markovian state.
bool hasOnlyTrivialNondeterminism() const
bool isConvertibleToCtmc() const
Determines whether the Markov automaton can be converted to a CTMC without changing any measures.
virtual void printModelInformationToStream(std::ostream &out) const override
Prints information about the model to the specified stream.
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.
ValueType const & getExitRate(storm::storage::sparse::state_type state) const
Retrieves the exit rate of the given state.
ValueType getMaximalExitRate() const
Retrieves the maximal exit rate over all states of the model.
bool isHybridState(storm::storage::sparse::state_type state) const
Retrieves whether the given state is a hybrid state, i.e.
CRewardModelType RewardModelType
The base class of sparse nondeterministic models.
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.
bool full() const
Retrieves whether all bits are set in this bit vector.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
void set(uint_fast64_t index, bool value=true)
Sets the given truth value at the given index.
A class that holds a possibly non-square matrix in the compressed row storage format.
bool isOne(ValueType const &value) const
bool isZero(ValueType const &value) const
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
storm::storage::BitVector performProb0E(storm::models::sparse::NondeterministicModel< T, RM > const &model, storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates)
Computes the sets of states that have probability 0 of satisfying phi until psi under at least one po...
VT max_if(std::vector< VT > const &values, storm::storage::BitVector const &filter)
Computes the maximum of the entries from the values that are selected by the (non-empty) filter.
std::optional< storm::storage::sparse::StateValuations > stateValuations
storm::storage::SparseMatrix< ValueType > transitionMatrix
std::optional< std::shared_ptr< storm::storage::sparse::ChoiceOrigins > > choiceOrigins
std::optional< storm::models::sparse::ChoiceLabeling > choiceLabeling
boost::optional< std::vector< ValueType > > exitRates