Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
POMDPSettings.cpp
Go to the documentation of this file.
2
3#include <charconv>
4#include <limits>
5#include <ranges>
6
11
13
14namespace storm {
15namespace settings {
16namespace modules {
17
18const std::string POMDPSettings::moduleName = "pomdp";
19const std::string noCanonicOption = "nocanonic";
20const std::string exportAsParametricModelOption = "parametric-drn";
21const std::string exportPolicyOption = "export-policy";
22const std::string beliefExplorationOption = "belief-exploration";
23const std::vector<std::string> beliefExplorationModes = {"both", "discretize", "unfold"};
24const std::string qualitativeReductionOption = "qualitativereduction";
25const std::string analyzeUniqueObservationsOption = "uniqueobservations";
26const std::string selfloopReductionOption = "selfloopreduction";
27const std::string memoryBoundOption = "memorybound";
28const std::string memoryPatternOption = "memorypattern";
29const std::vector<std::string> memoryPatterns = {"trivial", "fixedcounter", "selectivecounter", "ring", "fixedring", "settablebits", "full"};
30const std::string checkFullyObservableOption = "check-fully-observable";
31const std::string isQualitativeOption = "qualitative-analysis";
32const std::string isBoundedToUnboundedReachabilityTransformationOption = "unfold-reward-bound";
33const std::string isRewardObservableOption = "reward-aware";
34
37 "If this is set, actions will not be ordered canonically. Could yield incorrect results.")
38 .build());
39 this->addOption(
40 storm::settings::OptionBuilder(moduleName, exportAsParametricModelOption, false, "Export the parametric file.")
41 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("filename", "The name of the file to which to write the model.").build())
42 .build());
43 this->addOption(
45 "Export the policy generated by belief space unfolding. With clipping, export is approximate: continuation "
46 "actions may be unspecified, and the policy value on the original POMDP may differ from the reported result.")
47 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("filename", "The name of the file to which to write the policy.").build())
48 .build());
50 "Reduces the model size by performing qualitative analysis (E.g. merge states with prob. 1.")
51 .build());
52 this->addOption(
53 storm::settings::OptionBuilder(moduleName, analyzeUniqueObservationsOption, false, "Computes the states with a unique observation").build());
54 this->addOption(storm::settings::OptionBuilder(moduleName, selfloopReductionOption, false, "Reduces the model size by removing self loop actions").build());
56 "Sets the maximal number of allowed memory states (1 means memoryless schedulers).")
57 .addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("bound", "The maximal number of memory states.")
58 .setDefaultValueUnsignedInteger(1)
60 .build())
61 .build());
62 this->addOption(storm::settings::OptionBuilder(moduleName, memoryPatternOption, false, "Sets the pattern of the considered memory structure")
63 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("name", "Pattern name.")
65 .setDefaultValueString("full")
66 .build())
67 .build());
68 this->addOption(storm::settings::OptionBuilder(moduleName, beliefExplorationOption, false, "Analyze the POMDP by exploring the belief space.")
70 "mode", "Sets whether lower bounds, upper bounds, or interval bounds are computed.")
72 .setDefaultValueString("both")
73 .makeOptional()
74 .build())
75 .build());
76 this->addOption(
77 storm::settings::OptionBuilder(moduleName, checkFullyObservableOption, false, "Performs standard model checking on the underlying MDP").build());
78 this->addOption(storm::settings::OptionBuilder(moduleName, isQualitativeOption, false, "Sets the option qualitative analysis").build());
80 "Transforms reward-bounded reachability properties to an unbounded problem on an unfolded POMDP.")
81 .build());
82 this->addOption(storm::settings::OptionBuilder(moduleName, isRewardObservableOption, false, "Makes rewards observable for bounded reachability properties.")
84 "levelwidths", "Comma-separated reward level widths (integers from 0 to INT64_MAX).")
85 .setDefaultValueString("")
86 .makeOptional()
87 .build())
88 .build());
89}
90
92 return this->getOption(noCanonicOption).getHasOptionBeenSet();
93}
94
96 return this->getOption(exportAsParametricModelOption).getHasOptionBeenSet();
97}
98
100 return this->getOption(exportAsParametricModelOption).getArgumentByName("filename").getValueAsString();
101}
102
104 return this->getOption(exportPolicyOption).getHasOptionBeenSet();
105}
106
108 return this->getOption(exportPolicyOption).getArgumentByName("filename").getValueAsString();
109}
110
112 return this->getOption(qualitativeReductionOption).getHasOptionBeenSet();
113}
114
116 return this->getOption(analyzeUniqueObservationsOption).getHasOptionBeenSet();
117}
118
120 return this->getOption(selfloopReductionOption).getHasOptionBeenSet();
121}
122
124 return this->getOption(beliefExplorationOption).getHasOptionBeenSet();
125}
126
128 std::string arg = this->getOption(beliefExplorationOption).getArgumentByName("mode").getValueAsString();
129 return isBeliefExplorationSet() && (arg == "discretize" || arg == "both");
130}
131
133 std::string arg = this->getOption(beliefExplorationOption).getArgumentByName("mode").getValueAsString();
134 return isBeliefExplorationSet() && (arg == "unfold" || arg == "both");
135}
136
138 return this->getOption(checkFullyObservableOption).getHasOptionBeenSet();
139}
140
142 return this->getOption(isQualitativeOption).getHasOptionBeenSet();
143}
144
146 return this->getOption(isBoundedToUnboundedReachabilityTransformationOption).getHasOptionBeenSet();
147}
148
150 return this->getOption(isRewardObservableOption).getHasOptionBeenSet();
151}
152
154 auto const input = this->getOption(isRewardObservableOption).getArgumentByName("levelwidths").getValueAsString();
155 if (input.empty()) {
156 return {};
157 }
158 std::vector<uint64_t> result;
159 for (auto&& range : input | std::ranges::views::split(',')) {
160 std::string const token(range.begin(), range.end());
161 uint64_t width = 0;
162 auto const [end, error] = std::from_chars(token.data(), token.data() + token.size(), width);
163 STORM_LOG_THROW(error == std::errc{} && end == token.data() + token.size() && width <= std::numeric_limits<int64_t>::max(),
164 storm::exceptions::InvalidArgumentException,
165 "Invalid reward level width '" << token << "'. Expected an unsigned integer fitting in int64_t.");
166 result.push_back(width);
167 }
168 return result;
169}
170
172 return this->getOption(memoryBoundOption).getArgumentByName("bound").getValueAsUnsignedInteger();
173}
174
176 auto pattern = this->getOption(memoryPatternOption).getArgumentByName("name").getValueAsString();
177 if (pattern == "trivial") {
179 } else if (pattern == "fixedcounter") {
181 } else if (pattern == "selectivecounter") {
183 } else if (pattern == "ring") {
185 } else if (pattern == "fixedring") {
187 } else if (pattern == "settablebits") {
189 } else if (pattern == "full") {
191 }
192 STORM_LOG_THROW_UNCONDITIONALLY(storm::exceptions::InvalidArgumentException, "The name of the memory pattern is unknown.");
193}
194
196
198 STORM_LOG_THROW(getMemoryPattern() != storm::storage::PomdpMemoryPattern::Trivial || getMemoryBound() == 1, storm::exceptions::InvalidArgumentException,
199 "Memory bound greater one is not possible with the trivial memory pattern.");
200 STORM_LOG_THROW(!isExportPolicySet() || isBeliefExplorationUnfoldSet(), storm::exceptions::InvalidArgumentException,
201 "Policy export requires belief-space unfolding. Use '--belief-exploration unfold' or '--belief-exploration both'.");
202 return true;
203}
204
205} // namespace modules
206} // namespace settings
207} // namespace storm
virtual std::string getValueAsString() const =0
Retrieves the value of this argument as a string.
virtual uint_fast64_t getValueAsUnsignedInteger() const =0
Retrieves the value of this argument as an unsigned integer.
static ArgumentBuilder createUnsignedIntegerArgument(std::string const &name, std::string const &description)
Creates an unsigned integer argument with the given parameters.
static ArgumentBuilder createStringArgument(std::string const &name, std::string const &description)
Creates a string argument with the given parameters.
static std::shared_ptr< ArgumentValidator< uint64_t > > createUnsignedGreaterValidator(uint64_t lowerBound)
static std::shared_ptr< ArgumentValidator< std::string > > createMultipleChoiceValidator(std::vector< std::string > const &choices)
This class provides the interface to create an option...
ArgumentBase const & getArgumentByName(std::string const &argumentName) const
Returns a reference to the argument with the specified long name.
Definition Option.cpp:79
bool getHasOptionBeenSet() const
Retrieves whether the option has been set.
Definition Option.cpp:125
ModuleSettings(std::string const &moduleName)
Constructs a new settings object.
void addOption(std::shared_ptr< Option > const &option)
Adds and registers the given option.
Option & getOption(std::string const &longName)
Retrieves the option with the given long name.
void finalize() override
Prepares the modules for further usage, should be called at the end of the initialization,...
POMDPSettings()
Creates a new set of POMDP settings.
bool check() const override
Checks whether the settings are consistent.
std::string getExportToParametricFilename() const
storm::storage::PomdpMemoryPattern getMemoryPattern() const
static const std::string moduleName
std::vector< uint64_t > getLevelWidthForBoundedReachability() const
#define STORM_LOG_THROW_UNCONDITIONALLY(exception, message)
Definition macros.h:48
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
const std::string memoryPatternOption
const std::string beliefExplorationOption
const std::string isQualitativeOption
const std::string analyzeUniqueObservationsOption
const std::string isBoundedToUnboundedReachabilityTransformationOption
const std::string memoryBoundOption
const std::string isRewardObservableOption
const std::string noCanonicOption
const std::string exportPolicyOption
const std::string checkFullyObservableOption
const std::string exportAsParametricModelOption
const std::vector< std::string > beliefExplorationModes
const std::string selfloopReductionOption
const std::string qualitativeReductionOption
const std::vector< std::string > memoryPatterns
The contract of a DD backend.