28 STORM_LOG_ASSERT(i + 1 < csr->size(),
"CSR index out of bounds: " << (i + 1) <<
" >= " << csr->size());
29 return std::ranges::iota_view(csr.value()[i], csr.value()[i + 1]);
32 return std::ranges::iota_view(i, i + 1);
36template<
typename ValueType>
39 bool const hasRowGroups = tsIndex.
numPlayers >= 1;
41 hasRowGroups ? tsIndex.numStates : 0u);
42 for (uint64_t stateIndex{0}; stateIndex < tsIndex.numStates; ++stateIndex) {
45 builder.newRowGroup(*choices.begin());
47 for (
auto const choiceIndex : choices) {
48 STORM_LOG_ASSERT(choiceIndex < tsIndex.numChoices,
"Choice index out of bounds.");
51 STORM_LOG_ASSERT(branchTarget < tsIndex.numStates,
"Branch target index out of bounds: " << branchTarget <<
" >= " << tsIndex.numStates);
52 builder.addNextValue(choiceIndex, branchTarget, branchValues[branchIndex]);
59template<
typename ValueType>
66template<
typename ValueType>
69 std::ranges::views::transform([&defaultValue](
auto) -> ValueType {
return defaultValue; });
74 STORM_LOG_THROW(umbBitVector.size() >= size, storm::exceptions::WrongFormatException,
75 "Bit vector has unexpected size: " << umbBitVector.size() <<
" < " << size);
82 STORM_LOG_THROW(umbBitVector.has_value(), storm::exceptions::WrongFormatException,
"BitVector is not given but expected.");
95 if (umbModel.
index.
aps().has_value()) {
97 for (
auto const& [apName, apIndex] : aps.value()) {
98 STORM_LOG_THROW(umbModel.
aps().has_value() && umbModel.
aps()->contains(apName), storm::exceptions::WrongFormatException,
99 "Atomic proposition '" << apName <<
"' mentioned in index but no files were found.");
101 "Atomic proposition '" << apName <<
"' must be of boolean type.");
102 STORM_LOG_THROW(apIndex.appliesTo.size() == 1 && apIndex.appliesToStates(), storm::exceptions::WrongFormatException,
103 "Atomic proposition '" << apName <<
"' must apply only to states.");
104 auto const& ap = umbModel.
aps()->at(apName);
105 auto labelName = apIndex.alias.value_or(apName);
106 STORM_LOG_THROW(ap.states.has_value(), storm::exceptions::WrongFormatException,
"Atomic proposition '" << apName <<
"' has no states values");
108 "Label '" << labelName <<
"' already exists in state labeling.");
112 return stateLabelling;
122 bool const hasActionStrings = !actionStrings.empty();
123 STORM_LOG_THROW(!hasActionStrings || actionStrings.size() == numActions, storm::exceptions::WrongFormatException,
124 "Number of action strings does not match number of actions.");
127 uint64_t
const emptyActionIndex = hasActionStrings ? std::ranges::find(actionStrings,
"") - actionStrings.begin() : numActions;
130 auto const& choiceToChoiceAction = umbModel.
choiceActions->values.value();
132 for (uint64_t choiceIndex = 0; choiceIndex < numChoices; ++choiceIndex) {
133 auto const actionIndex = choiceToChoiceAction[choiceIndex];
134 STORM_LOG_ASSERT(actionIndex < numActions,
"Choice to action mapping out of bounds.");
135 if (hasActionStrings && actionIndex == emptyActionIndex) {
138 actionToLabels[actionIndex].set(choiceIndex);
142 if (hasActionStrings) {
143 for (uint64_t actionIndex = 0; actionIndex < numActions; ++actionIndex) {
144 if (actionIndex == emptyActionIndex) {
147 choiceLabeling.
addLabel(std::string(actionStrings[actionIndex]), std::move(actionToLabels[actionIndex]));
151 for (uint64_t actionIndex = 0; actionIndex < numActions; ++actionIndex) {
152 choiceLabeling.
addLabel(
"a" + std::to_string(actionIndex), std::move(actionToLabels[actionIndex]));
155 return choiceLabeling;
158template<
typename ValueType>
161 std::unordered_map<std::string, RewardModel> rewardModels;
164 for (
auto const& [rewName, rewIndex] : rewards.value()) {
166 "Reward " << rewName <<
"' mentioned in index but no files were found.");
167 auto const& rew = umbModel.
rewards()->at(rewName);
168 auto usedRewName = rewIndex.alias.value_or(rewName);
169 STORM_LOG_THROW(!rewardModels.contains(usedRewName), storm::exceptions::WrongFormatException,
170 "Reward '" << usedRewName <<
"' already exists in reward models.");
172 "Reward type for reward '" << rewName <<
"' must be numeric.");
173 std::optional<std::vector<ValueType>> stateRewards, stateActionRewards;
174 std::optional<storm::storage::SparseMatrix<ValueType>> transitionRewards;
175 if (rewIndex.appliesToStates() && rew.states.has_value()) {
178 if (rewIndex.appliesToChoices() && rew.choices.has_value()) {
181 if (rewIndex.appliesToBranches() && rew.branches.has_value()) {
184 STORM_LOG_THROW(!rewIndex.appliesToObservations(), storm::exceptions::NotSupportedException,
185 "Observation rewards are not supported for reward '" << rewName <<
"'.");
186 STORM_LOG_THROW(!rewIndex.appliesToPlayers(), storm::exceptions::NotSupportedException,
187 "Player rewards are not supported for reward '" << rewName <<
"'.");
188 rewardModels.emplace(std::move(usedRewName), RewardModel(std::move(stateRewards), std::move(stateActionRewards), std::move(transitionRewards)));
194template<
typename ValueType>
202 uint64_t numNormalized{0};
204 auto updateNormStats = [&numNormalized, &maxDiff](
auto const& rowSum) {
210 for (uint64_t rowIndex = 0; rowIndex < result.getRowCount(); ++rowIndex) {
211 auto const rowSum = result.getRowSum(rowIndex);
214 updateNormStats(rowSum.lower());
215 for (
auto& entry : result.getRow(rowIndex)) {
216 entry.setValue({entry.getValue().lower() / rowSum.lower(), entry.getValue().upper()});
219 updateNormStats(rowSum.upper());
220 for (
auto& entry : result.getRow(rowIndex)) {
221 entry.setValue({entry.getValue().lower(), entry.getValue().upper() / rowSum.upper()});
226 updateNormStats(rowSum);
227 for (
auto& entry : result.getRow(rowIndex)) {
228 entry.setValue(entry.getValue() / rowSum);
234 "Branch probabilities are given in an imprecise type but an exact model was requested. Probabilities for "
235 << numNormalized <<
" choices were normalized to ensure they sum up to 1. Maximum diff to 1 was " << maxDiff <<
".");
244template<
typename ValueType>
251 "Branch probability type must be given in the UMB model index.");
257 "Choice actions mentioned in the index but no files given.");
262 "State valuations mentioned in the index but no files given.");
263 STORM_LOG_THROW(
false, storm::exceptions::NotSupportedException,
"State valuations for UMB models are not yet supported.");
271 if (modelType == Ctmc || modelType == MarkovAutomaton) {
273 "Exit rates are required for CTMC and Markov automaton models but not present in the UMB model.");
275 if (modelType == MarkovAutomaton) {
283 }
else if (modelType == Pomdp) {
285 storm::exceptions::NotSupportedException,
"Only state observations are currently supported for POMDP models.");
287 "Only deterministic state observations are currently supported for POMDP models.");
289 "State observations are required for POMDP models but not present in the UMB model.");
291 }
else if (modelType == Smg) {
302 "Number of player names does not match number of players in the UMB model index.");
304 for (uint64_t i = 0; i < names.size(); ++i) {
309 STORM_LOG_THROW(modelType ==
Dtmc || modelType ==
Mdp, storm::exceptions::NotSupportedException,
"Unexpected model type for UMB import: " << modelType);
321 STORM_LOG_THROW(ts.branchProbabilityType.has_value(), storm::exceptions::NotSupportedException,
"Models without branch values are not supported.");
325 switch (ts.numPlayers) {
329 return ts.numObservations == 0 ?
Mdp : Pomdp;
331 STORM_LOG_THROW(ts.numObservations == 0, storm::exceptions::NotSupportedException,
332 "Multiplayer partially observable models are not supported.");
336 STORM_LOG_THROW(ts.numPlayers == 0, storm::exceptions::NotSupportedException,
"Stochastic time models with multiple players are not supported.");
338 case UrgentStochastic:
339 STORM_LOG_THROW(ts.numPlayers == 1, storm::exceptions::NotSupportedException,
340 "Urgent stochastic time models with multiple or no players are not supported.");
341 return MarkovAutomaton;
343 STORM_LOG_THROW(
false, storm::exceptions::UnexpectedException,
"Unexpected transition system time type" << ts.time <<
".");
346template<
typename ValueType>
349 "Models without branch values are not supported.");
354 bool const haveInterval = haveDoubleInterval || haveRationalInterval;
359 STORM_LOG_ASSERT(useDefault || useDouble || useRational,
"Unexpected value type option: " <<
static_cast<int>(options.valueType) <<
".");
362 if constexpr (std::is_same_v<ValueType, double>) {
363 return useDouble || (useDefault && haveDouble);
364 }
else if constexpr (std::is_same_v<ValueType, storm::RationalNumber>) {
365 return useRational || (useDefault && haveRational);
370 if constexpr (std::is_same_v<ValueType, storm::Interval>) {
371 return useDouble || (useDefault && haveDoubleInterval);
372 }
else if constexpr (std::is_same_v<ValueType, storm::RationalInterval>) {
373 return useRational || (useDefault && haveRationalInterval);
380template<
typename ValueType>
396 "Could not derive a supported value type for the UMB model with branch probabilities of type "
storm::models::sparse::Dtmc< double > Dtmc
storm::models::sparse::Mdp< double > Mdp
This class manages the labeling of the choice space with a number of (atomic) labels.
void addLabel(std::string const &label)
Adds a new label to the labelings.
bool containsLabel(std::string const &label) const
Checks whether a label is registered within this labeling.
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.
void resize(uint64_t newLength, bool init=false)
Resizes the bit vector to hold the given new number of bits.
A class that can be used to build a sparse matrix by adding value by value.
A class that holds a possibly non-square matrix in the compressed row storage format.
Represents a model in the UMB format.
TO1< bool > stateIsMarkovian
void validateOrThrow() const
Validates the UmbModel.
storm::OptionalRef< Annotation > rewards(bool createIfMissing=false)
TO1< AnyValueType > branchToProbability
std::optional< ActionLabels > choiceActions
TO1< bool > stateIsInitial
TO1< AnyValueType > stateToExitRate
TO1< uint32_t > stateToPlayer
TO1< uint64_t > branchToTarget
std::optional< Observations > stateObservations
storm::OptionalRef< Annotation > aps(bool createIfMissing=false)
static auto applyDecodedVector(auto &&func, storm::umb::GenericVector const &input, storm::umb::SizedType const &sourceType)
returns func(<decoded_input>) where <decoded_input> is a range that (if necessary) decodes and conver...
static std::vector< ValueType > createDecodedVector(storm::umb::GenericVector const &input, storm::umb::SizedType const &sourceType)
#define STORM_LOG_WARN(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_WARN_COND(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
std::shared_ptr< storm::models::sparse::Model< ValueType > > constructSparseModel(storm::umb::UmbModel const &umbModel, ImportOptions const &options)
auto csrRange(auto &&csr, uint64_t i)
storm::models::sparse::StateLabeling constructStateLabeling(storm::umb::UmbModel const &umbModel)
auto constructRewardModels(storm::umb::UmbModel const &umbModel)
storm::storage::SparseMatrix< ValueType > createBranchMatrix(storm::umb::UmbModel const &umbModel, std::ranges::input_range auto &&branchValues)
storm::storage::SparseMatrix< ValueType > constructTransitionMatrix(storm::umb::UmbModel const &umbModel)
storm::storage::BitVector createBitVector(storm::umb::VectorType< bool > const &umbBitVector, uint64_t size)
storm::models::sparse::ChoiceLabeling constructChoiceLabeling(storm::umb::UmbModel const &umbModel)
std::optional< VectorType< T > > OptionalVectorType
template std::shared_ptr< storm::models::sparse::Model< storm::RationalNumber > > sparseModelFromUmb< storm::RationalNumber >(storm::umb::UmbModel const &umbModel, ImportOptions const &options)
bool isNumericType(Type const type)
template std::shared_ptr< storm::models::sparse::Model< storm::Interval > > sparseModelFromUmb< storm::Interval >(storm::umb::UmbModel const &umbModel, ImportOptions const &options)
std::conditional_t< std::is_same_v< T, bool >, storm::storage::BitVector, std::vector< T > > VectorType
bool deriveValueType(storm::umb::ModelIndex const &index, ImportOptions const &options)
Returns true iff the given umb model with the given options should have ValueType as its ValueType.
bool isBooleanType(Type const type)
std::shared_ptr< storm::models::sparse::Model< ValueType > > sparseModelFromUmb(storm::umb::UmbModel const &umbModel, ImportOptions const &options)
Constructs a sparse model from the given UMB model.
template std::shared_ptr< storm::models::sparse::Model< storm::RationalInterval > > sparseModelFromUmb< storm::RationalInterval >(storm::umb::UmbModel const &umbModel, ImportOptions const &options)
template std::shared_ptr< storm::models::sparse::Model< double > > sparseModelFromUmb< double >(storm::umb::UmbModel const &umbModel, ImportOptions const &options)
storm::models::ModelType deriveModelType(storm::umb::ModelIndex const &index)
Derives the model type from the given UMB model index.
auto stringVectorView(SEQ< char > const &strings, CSR const &stringMapping)
std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > buildModelFromComponents(storm::models::ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > &&components)
bool isOne(ValueType const &a)
ValueType abs(ValueType const &number)
carl::Interval< double > Interval
Interval type.
constexpr bool IsIntervalType
Helper to check if a type is an interval.
typename detail::IntervalMetaProgrammingHelper< ValueType >::BaseType IntervalBaseType
Helper to access the type in which interval boundaries are stored.
static const bool IsExact
boost::optional< storm::storage::BitVector > markovianStates
boost::optional< std::vector< storm::storage::PlayerIndex > > statePlayerIndications
std::optional< storm::models::sparse::ChoiceLabeling > choiceLabeling
boost::optional< std::map< std::string, storm::storage::PlayerIndex > > playerNameToIndexMap
std::optional< std::vector< uint32_t > > observabilityClasses
boost::optional< std::vector< ValueType > > exitRates
bool buildChoiceLabeling
Controls building of choice labelings.
bool buildStateValuations
Controls building of state valuations.
uint64_t numChoiceActions
std::optional< SizedType > exitRateType
std::optional< SizedType > branchProbabilityType
std::optional< storm::SerializedEnum< ObservationsApplyToDeclaration > > observationsApplyTo
std::optional< std::vector< std::string > > playerNames
std::optional< SizedType > observationProbabilityType
storm::OptionalRef< AnnotationMap > rewards(bool createIfMissing=false)
struct storm::umb::ModelIndex::TransitionSystem transitionSystem
std::optional< Valuations > valuations
storm::OptionalRef< AnnotationMap > aps(bool createIfMissing=false)
std::optional< Values > states