Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
NondeterministicModelParser.cpp
Go to the documentation of this file.
2
3#include <string>
4#include <vector>
5
11
12namespace storm {
13namespace parser {
14
15template<typename ValueType, typename RewardValueType>
16storm::storage::sparse::ModelComponents<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>
17NondeterministicModelParser<ValueType, RewardValueType>::parseNondeterministicModel(std::string const& transitionsFilename, std::string const& labelingFilename,
18 std::string const& stateRewardFilename,
19 std::string const& transitionRewardFilename,
20 std::string const& choiceLabelingFilename,
21 ExplicitModelParserOptions const& options) {
22 // Parse the transitions.
23 storm::storage::SparseMatrix<ValueType> transitions(
25
26 uint_fast64_t stateCount = transitions.getColumnCount();
27
28 // Parse the state labeling.
29 storm::models::sparse::StateLabeling labeling(storm::parser::SparseItemLabelingParser::parseAtomicPropositionLabeling(stateCount, labelingFilename));
30
31 // Initialize result.
32 storm::storage::sparse::ModelComponents<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>> result(std::move(transitions),
33 std::move(labeling));
34
35 // Only parse state rewards if a file is given.
36 std::optional<std::vector<RewardValueType>> stateRewards;
37 if (!stateRewardFilename.empty()) {
38 stateRewards = std::move(storm::parser::SparseStateRewardParser<RewardValueType>::parseSparseStateReward(stateCount, stateRewardFilename));
39 }
40
41 // Only parse transition rewards if a file is given.
42 std::optional<storm::storage::SparseMatrix<RewardValueType>> transitionRewards;
43 if (!transitionRewardFilename.empty()) {
45 transitionRewardFilename, result.transitionMatrix));
46 }
47
48 if (stateRewards || transitionRewards) {
49 result.rewardModels.insert(std::make_pair(
50 "", storm::models::sparse::StandardRewardModel<RewardValueType>(std::move(stateRewards), std::nullopt, std::move(transitionRewards))));
51 }
52
53 // Only parse choice labeling if a file is given.
54 std::optional<storm::models::sparse::ChoiceLabeling> choiceLabeling;
55 if (!choiceLabelingFilename.empty()) {
56 result.choiceLabeling = storm::parser::SparseItemLabelingParser::parseChoiceLabeling(result.transitionMatrix.getRowCount(), choiceLabelingFilename,
57 result.transitionMatrix.getRowGroupIndices());
58 }
59
60 return result;
61}
62
63template<typename ValueType, typename RewardValueType>
64storm::models::sparse::Mdp<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>
65NondeterministicModelParser<ValueType, RewardValueType>::parseMdp(std::string const& transitionsFilename, std::string const& labelingFilename,
66 std::string const& stateRewardFilename, std::string const& transitionRewardFilename,
67 std::string const& choiceLabelingFilename, ExplicitModelParserOptions const& options) {
68 auto parserResult =
69 parseNondeterministicModel(transitionsFilename, labelingFilename, stateRewardFilename, transitionRewardFilename, choiceLabelingFilename, options);
70
72}
73
76
77} /* namespace parser */
78} /* namespace storm */
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:13
Loads a nondeterministic model (Mdp or Ctmdp) from files.
static storm::models::sparse::Mdp< ValueType, storm::models::sparse::StandardRewardModel< RewardValueType > > parseMdp(std::string const &transitionsFilename, std::string const &labelingFilename, std::string const &stateRewardFilename="", std::string const &transitionRewardFilename="", std::string const &choiceLabelingFilename="", ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Parse a Mdp.
static storm::storage::SparseMatrix< ValueType > parseNondeterministicTransitions(std::string const &filename, ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Load a nondeterministic transition system from file and create a sparse adjacency matrix whose entrie...
static storm::storage::SparseMatrix< ValueType > parseNondeterministicTransitionRewards(std::string const &filename, storm::storage::SparseMatrix< MatrixValueType > const &modelInformation)
Load a nondeterministic transition system from file and create a sparse adjacency matrix whose entrie...
static storm::models::sparse::ChoiceLabeling parseChoiceLabeling(uint_fast64_t choiceCount, std::string const &filename, boost::optional< std::vector< uint_fast64_t > > const &nondeterministicChoiceIndices=boost::none)
Parses the given file and returns the resulting choice labeling.
static storm::models::sparse::StateLabeling parseAtomicPropositionLabeling(uint_fast64_t stateCount, std::string const &filename)
Parses the given file and returns the resulting state labeling.
static std::vector< ValueType > parseSparseStateReward(uint_fast64_t stateCount, std::string const &filename)
Reads a state reward file and puts the result in a state reward vector.
Contains all file parsers and helper classes.