Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
CoreSettings.cpp
Go to the documentation of this file.
2
3#include "storm/dd/DdType.h"
14
15namespace storm {
16namespace settings {
17namespace modules {
18
19const std::string CoreSettings::moduleName = "core";
20const std::string CoreSettings::eqSolverOptionName = "eqsolver";
21const std::string CoreSettings::lpSolverOptionName = "lpsolver";
22const std::string CoreSettings::smtSolverOptionName = "smtsolver";
23const std::string CoreSettings::statisticsOptionName = "statistics";
24const std::string CoreSettings::statisticsOptionShortName = "stats";
25const std::string CoreSettings::engineOptionName = "engine";
26const std::string CoreSettings::engineOptionShortName = "e";
27const std::string CoreSettings::ddLibraryOptionName = "ddlib";
28
30 // TODO: We currently never set Gurobi as a default LP solver as
31 // its availability is depending on the license, which may be confusing.
32 // We track this item in #issue 680.
33#if defined STORM_HAVE_HIGHS
34 return "highs";
35#elif defined STORM_HAVE_GLPK
36 return "glpk";
37#elif defined STORM_HAVE_SOPLEX
38 return "soplex";
39#else
40 return "z3";
41#endif
42}
43
45#if defined STORM_DEFAULT_SMT_SOLVER_Z3
46 return "z3";
47#elif defined STORM_DEFAULT_SMT_SOLVER_MATHSAT
48 return "mathsat";
49#elif defined STORM_DEFAULT_SMT_SOLVER_CVC5
50 return "cvc5";
51#else
52 return "z3";
53#endif
54}
55
57 std::vector<std::string> engines;
58 for (auto e : storm::utility::getEngines()) {
59 engines.push_back(storm::utility::toString(e));
60 }
61 engines.push_back("portfolio"); // for backwards compatibility
62
63 this->addOption(storm::settings::OptionBuilder(moduleName, engineOptionName, false, "Sets which engine is used for model building and model checking.")
64 .setShortName(engineOptionShortName)
65 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("name", "The name of the engine to use.")
67 .setDefaultValueString("sparse")
68 .build())
69 .build());
70
71 std::vector<std::string> linearEquationSolver = {"gmm++", "native", "eigen", "elimination", "topological", "acyclic"};
72 this->addOption(
73 storm::settings::OptionBuilder(moduleName, eqSolverOptionName, false, "Sets which solver is preferred for solving systems of linear equations.")
74 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("name", "The name of the solver to prefer.")
75 .addValidatorString(ArgumentValidatorFactory::createMultipleChoiceValidator(linearEquationSolver))
76 .setDefaultValueString("topological")
77 .build())
78 .build());
79
80 // Initialize options for all available DD libraries
81 std::vector<std::string> ddLibraries;
82 std::string ddDefault = "";
84 using Traits = storm::dd::BackendTraits<decltype(type)::value>;
85 if constexpr (Traits::available) {
86 ddLibraries.push_back(std::string(Traits::name));
87 ddDefault = std::string(Traits::name); // Later registered backends take priority as default (Sylvan over CUDD)
88 }
89 });
90 if (!ddLibraries.empty()) {
91 this->addOption(
92 storm::settings::OptionBuilder(moduleName, ddLibraryOptionName, false, "Sets which library is preferred for decision-diagram operations.")
93 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("name", "The name of the library to prefer.")
94 .addValidatorString(ArgumentValidatorFactory::createMultipleChoiceValidator(ddLibraries))
95 .setDefaultValueString(ddDefault)
96 .build())
97 .build());
98 }
99
100 std::vector<std::string> lpSolvers = {"glpk", "gurobi", "highs", "soplex", "z3"};
101 this->addOption(storm::settings::OptionBuilder(moduleName, lpSolverOptionName, false, "Sets which LP solver is preferred.")
102 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("name", "The name of an LP solver.")
103 .addValidatorString(ArgumentValidatorFactory::createMultipleChoiceValidator(lpSolvers))
104 .setDefaultValueString(getDefaultLpSolverAsString())
105 .build())
106 .build());
107
108 std::vector<std::string> smtSolvers;
109#if defined STORM_HAVE_Z3
110 smtSolvers.push_back("z3");
111#endif
112#if defined STORM_HAVE_MATHSAT
113 smtSolvers.push_back("mathsat");
114#endif
115#if defined STORM_HAVE_CVC5
116 smtSolvers.push_back("cvc5");
117#endif
118 // The option always exists, since the solver environment reads it while it is constructed. This also
119 // holds when no SMT solver is compiled in at all: in that case smtSolvers is empty above, but the
120 // choice list must not stay empty because the default value below has to be a valid choice. We thus
121 // keep the (unavailable) compile-time default solver as a placeholder, so the option stays consistent
122 // and asking for a solver only fails when one is actually requested.
123 if (smtSolvers.empty()) {
124 smtSolvers.push_back(getDefaultSmtSolverAsString());
125 }
126 this->addOption(storm::settings::OptionBuilder(moduleName, smtSolverOptionName, false, "Sets which SMT solver is preferred.")
127 .addArgument(storm::settings::ArgumentBuilder::createStringArgument("name", "The name of an SMT solver.")
128 .addValidatorString(ArgumentValidatorFactory::createMultipleChoiceValidator(smtSolvers))
129 .setDefaultValueString(getDefaultSmtSolverAsString())
130 .build())
131 .build());
132 this->addOption(storm::settings::OptionBuilder(moduleName, statisticsOptionName, false, "Sets whether to display statistics if available.")
133 .setShortName(statisticsOptionShortName)
134 .build());
135}
136
137storm::solver::EquationSolverType CoreSettings::getEquationSolver() const {
138 std::string equationSolverName = this->getOption(eqSolverOptionName).getArgumentByName("name").getValueAsString();
139 if (equationSolverName == "gmm++") {
140 return storm::solver::EquationSolverType::Gmmxx;
141 } else if (equationSolverName == "native") {
142 return storm::solver::EquationSolverType::Native;
143 } else if (equationSolverName == "eigen") {
144 return storm::solver::EquationSolverType::Eigen;
145 } else if (equationSolverName == "elimination") {
146 return storm::solver::EquationSolverType::Elimination;
147 } else if (equationSolverName == "topological") {
148 return storm::solver::EquationSolverType::Topological;
149 } else if (equationSolverName == "acyclic") {
150 return storm::solver::EquationSolverType::Acyclic;
151 }
152 STORM_LOG_THROW_UNCONDITIONALLY(storm::exceptions::IllegalArgumentValueException, "Unknown equation solver '" << equationSolverName << "'.");
153}
154
156 return this->getOption(eqSolverOptionName).getHasOptionBeenSet();
157}
158
160 return !this->getOption(eqSolverOptionName).getHasOptionBeenSet() || this->getOption(eqSolverOptionName).getArgumentByName("name").wasSetFromDefaultValue();
161}
162
163storm::solver::LpSolverType CoreSettings::getLpSolver() const {
164 std::string lpSolverName = this->getOption(lpSolverOptionName).getArgumentByName("name").getValueAsString();
165 if (lpSolverName == "glpk") {
166 return storm::solver::LpSolverType::Glpk;
167 } else if (lpSolverName == "gurobi") {
168 return storm::solver::LpSolverType::Gurobi;
169 } else if (lpSolverName == "highs") {
170 return storm::solver::LpSolverType::Highs;
171 } else if (lpSolverName == "soplex") {
172 return storm::solver::LpSolverType::Soplex;
173 } else if (lpSolverName == "z3") {
174 return storm::solver::LpSolverType::Z3;
175 }
176 STORM_LOG_THROW_UNCONDITIONALLY(storm::exceptions::IllegalArgumentValueException, "Unknown LP solver '" << lpSolverName << "'.");
177}
178
180 return !this->getOption(lpSolverOptionName).getHasOptionBeenSet() || this->getOption(lpSolverOptionName).getArgumentByName("name").wasSetFromDefaultValue();
181}
182
183storm::solver::SmtSolverType CoreSettings::getSmtSolver() const {
184 std::string smtSolverName = this->getOption(smtSolverOptionName).getArgumentByName("name").getValueAsString();
185 if (smtSolverName == "z3") {
186 return storm::solver::SmtSolverType::Z3;
187 } else if (smtSolverName == "mathsat") {
188 return storm::solver::SmtSolverType::Mathsat;
189 } else if (smtSolverName == "cvc5") {
190 return storm::solver::SmtSolverType::Cvc5;
191 }
192 STORM_LOG_THROW_UNCONDITIONALLY(storm::exceptions::IllegalArgumentValueException, "Unknown SMT solver '" << smtSolverName << "'.");
193}
194
196 return !this->getOption(smtSolverOptionName).getHasOptionBeenSet() ||
197 this->getOption(smtSolverOptionName).getArgumentByName("name").wasSetFromDefaultValue();
198}
199
201 std::string ddLibraryAsString = this->getOption(ddLibraryOptionName).getArgumentByName("name").getValueAsString();
202 // Defaults to the first registered backend (CUDD) if the name is not known.
205 if (ddLibraryAsString == storm::dd::BackendTraits<decltype(type)::value>::name) {
206 result = decltype(type)::value;
207 }
208 });
209 return result;
210}
211
213 return !this->getOption(ddLibraryOptionName).getArgumentByName("name").getHasBeenSet() ||
214 this->getOption(ddLibraryOptionName).getArgumentByName("name").wasSetFromDefaultValue();
215}
216
218 return this->getOption(statisticsOptionName).getHasOptionBeenSet();
219}
220
222 return engine;
223}
224
226 this->engine = newEngine;
227}
228
230 // Finalize engine.
231 std::string engineStr = this->getOption(engineOptionName).getArgumentByName("name").getValueAsString();
232 engine = storm::utility::engineFromString(engineStr);
233 STORM_LOG_THROW(engine != storm::utility::Engine::Unknown, storm::exceptions::IllegalArgumentValueException, "Unknown engine '" << engineStr << "'.");
234}
235
237 return true;
238}
239
240} // namespace modules
241} // namespace settings
242} // namespace storm
virtual std::string getValueAsString() const =0
Retrieves the value of this argument as a string.
virtual bool getHasBeenSet() const
Retrieves whether the argument has been set.
virtual bool wasSetFromDefaultValue() const =0
static ArgumentBuilder createStringArgument(std::string const &name, std::string const &description)
Creates a string argument with the given parameters.
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
storm::solver::LpSolverType getLpSolver() const
Retrieves the selected LP solver.
storm::dd::DdType getDdLibraryType() const
Retrieves the selected library for DD-related operations.
bool isShowStatisticsSet() const
Retrieves whether statistics are to be shown.
storm::solver::EquationSolverType getEquationSolver() const
Retrieves the selected equation solver.
bool isEquationSolverSetFromDefaultValue() const
Retrieves whether the equation solver has been set from its default value.
bool isEquationSolverSet() const
Retrieves whether a equation solver has been set.
bool isSmtSolverSetFromDefaultValue() const
Retrieves whether the smt solver has been set from its default value.
CoreSettings()
Creates a new set of core settings.
bool isLpSolverSetFromDefaultValue() const
Retrieves whether the lp solver has been set from its default value.
void finalize() override
Prepares the modules for further usage, should be called at the end of the initialization,...
void setEngine(storm::utility::Engine const &engine)
Sets the engine for further usage.
bool check() const override
Checks whether the settings are consistent.
storm::solver::SmtSolverType getSmtSolver() const
Retrieves the selected SMT solver.
bool isDdLibraryTypeSetFromDefaultValue() const
Retrieves whether the selected DD library is set from its default value.
static const std::string moduleName
storm::utility::Engine getEngine() const
Retrieves the selected engine.
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.
#define STORM_LOG_THROW_UNCONDITIONALLY(exception, message)
Definition macros.h:48
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
std::string getDefaultSmtSolverAsString()
std::string getDefaultLpSolverAsString()
Engine
An enumeration of all engines.
Definition Engine.h:31
std::string toString(Engine const &engine)
Returns a string representation of the given engine.
Definition Engine.cpp:35
std::vector< Engine > getEngines()
Returns a list of all available engines (excluding Unknown).
Definition Engine.cpp:27
Engine engineFromString(std::string const &engineStr)
Parses the string representation of an engine and returns the corresponding engine.
Definition Engine.cpp:64
The contract of a DD backend.