Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
EnvironmentFactoryTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
7#include "storm/api/builder.h"
24
25namespace {
26
27template<typename ValueType>
28storm::utility::ExtendedValueType<ValueType> checkInitialState(storm::Environment const& env, std::string const& file, std::string const& formulaString) {
29 auto program = storm::api::parseProgram(file);
31 auto model = storm::api::buildSparseModel<ValueType>(program, formulas);
32 auto task = storm::api::createTask<ValueType>(formulas.front(), true);
33 auto result = storm::api::verifyWithSparseEngine<ValueType>(env, model, task);
34 return result->template asExplicitQuantitativeCheckResult<ValueType>()[*model->getInitialStates().begin()];
35}
36
37} // namespace
38
39class EnvironmentFactoryModelCheckingTest : public ::testing::Test {
40 protected:
41 void SetUp() override {
42#ifndef STORM_HAVE_SMT_SOLVER
43 GTEST_SKIP() << "No SMT solver available.";
44#endif
45 }
46};
47
48TEST(EnvironmentFactoryTest, DefaultEnvironmentIsNotSound) {
50 EXPECT_FALSE(env.solver().isForceSoundness());
51}
52
53TEST(EnvironmentFactoryTest, SoundEnvironmentSelectsSoundMethods) {
55 storm::SolverEnvironment const& solver = env.solver();
56
57 EXPECT_TRUE(solver.isForceSoundness());
58 EXPECT_FALSE(solver.isForceExact());
59
60 // Defaults which are already sound remain untouched
61 EXPECT_EQ(storm::solver::EquationSolverType::Topological, solver.getLinearEquationSolverType());
62 EXPECT_EQ(storm::solver::MinMaxMethod::Topological, solver.minMax().getMethod());
63
64 EXPECT_EQ(storm::solver::EquationSolverType::Native, solver.topological().getUnderlyingEquationSolverType());
65 EXPECT_EQ(storm::solver::MinMaxMethod::OptimisticValueIteration, solver.topological().getUnderlyingMinMaxMethod());
66 EXPECT_EQ(storm::solver::NativeLinearEquationSolverMethod::OptimisticValueIteration, solver.native().getMethod());
67 EXPECT_EQ(storm::solver::EigenLinearEquationSolverMethod::SparseLU, solver.eigen().getMethod());
68 EXPECT_EQ(storm::solver::GameMethod::PolicyIteration, solver.game().getMethod());
69 EXPECT_EQ(storm::solver::LraMethod::ValueIteration, solver.lra().getDetLraMethod());
70 EXPECT_EQ(storm::solver::LraMethod::ValueIteration, solver.lra().getNondetLraMethod());
72
73 // The choices count as defaults, such that e.g. exact mode can still override them
77 EXPECT_TRUE(solver.native().isMethodSetFromDefault());
78 EXPECT_TRUE(solver.eigen().isMethodSetFromDefault());
79 EXPECT_TRUE(solver.minMax().isMethodSetFromDefault());
80 EXPECT_TRUE(solver.game().isMethodSetFromDefault());
81 EXPECT_TRUE(solver.lra().isDetLraMethodSetFromDefault());
82 EXPECT_TRUE(solver.lra().isNondetLraMethodSetFromDefault());
83}
84
85TEST(EnvironmentFactoryTest, ClonedFactoryCreatesSoundEnvironment) {
86 std::unique_ptr<storm::utility::environment::EnvironmentFactory> factory = storm::utility::environment::SoundEnvironmentFactory().clone();
87 EXPECT_TRUE(factory->create().solver().isForceSoundness());
88}
89
90TEST_F(EnvironmentFactoryModelCheckingTest, MatchesSoundCommandLineOption) {
94
96 EXPECT_EQ(cliEnv.solver().isForceSoundness(), env.solver().isForceSoundness());
97
98 double const precision = 1e-6;
99 std::string const dtmcFile = STORM_TEST_RESOURCES_DIR "/dtmc/die.pm";
100 std::string const dtmcFormula = "P=? [F \"one\"]";
101 EXPECT_NEAR(1.0 / 6.0, checkInitialState<double>(env, dtmcFile, dtmcFormula), precision);
102 EXPECT_NEAR(checkInitialState<double>(cliEnv, dtmcFile, dtmcFormula), checkInitialState<double>(env, dtmcFile, dtmcFormula), precision);
103
104 std::string const mdpFile = STORM_TEST_RESOURCES_DIR "/mdp/two_dice.nm";
105 std::string const mdpFormula = "Pmin=? [F \"two\"]";
106 EXPECT_NEAR(1.0 / 36.0, checkInitialState<double>(env, mdpFile, mdpFormula), precision);
107 EXPECT_NEAR(checkInitialState<double>(cliEnv, mdpFile, mdpFormula), checkInitialState<double>(env, mdpFile, mdpFormula), precision);
108}
109
110TEST(EnvironmentFactoryTest, DefaultEnvironmentIsNotExact) {
112 EXPECT_FALSE(env.solver().isForceExact());
113}
114
115TEST(EnvironmentFactoryTest, ExactEnvironmentSelectsExactMethods) {
117 storm::SolverEnvironment const& solver = env.solver();
118
119 EXPECT_TRUE(solver.isForceExact());
120 EXPECT_FALSE(solver.isForceSoundness());
121
122 // Defaults which already support exact computations remain untouched
123 EXPECT_EQ(storm::solver::EquationSolverType::Topological, solver.getLinearEquationSolverType());
124 EXPECT_EQ(storm::solver::MinMaxMethod::Topological, solver.minMax().getMethod());
125
126 EXPECT_EQ(storm::solver::EquationSolverType::Eigen, solver.topological().getUnderlyingEquationSolverType());
127 EXPECT_EQ(storm::solver::MinMaxMethod::PolicyIteration, solver.topological().getUnderlyingMinMaxMethod());
128 EXPECT_EQ(storm::solver::NativeLinearEquationSolverMethod::RationalSearch, solver.native().getMethod());
129 EXPECT_EQ(storm::solver::EigenLinearEquationSolverMethod::SparseLU, solver.eigen().getMethod());
130 EXPECT_EQ(storm::solver::GameMethod::PolicyIteration, solver.game().getMethod());
131 EXPECT_EQ(storm::solver::LraMethod::GainBiasEquations, solver.lra().getDetLraMethod());
132 EXPECT_EQ(storm::solver::LraMethod::LinearProgramming, solver.lra().getNondetLraMethod());
133 EXPECT_EQ(storm::solver::LpSolverType::Z3, solver.getLpSolverType());
134
138 EXPECT_TRUE(solver.native().isMethodSetFromDefault());
139 EXPECT_TRUE(solver.eigen().isMethodSetFromDefault());
140 EXPECT_TRUE(solver.minMax().isMethodSetFromDefault());
141 EXPECT_TRUE(solver.game().isMethodSetFromDefault());
142 EXPECT_TRUE(solver.lra().isDetLraMethodSetFromDefault());
143 EXPECT_TRUE(solver.lra().isNondetLraMethodSetFromDefault());
144 EXPECT_TRUE(solver.isLpSolverTypeSetFromDefaultValue());
145}
146
147TEST(EnvironmentFactoryTest, ClonedFactoryCreatesExactEnvironment) {
148 std::unique_ptr<storm::utility::environment::EnvironmentFactory> factory = storm::utility::environment::ExactEnvironmentFactory().clone();
149 EXPECT_TRUE(factory->create().solver().isForceExact());
150}
151
152TEST_F(EnvironmentFactoryModelCheckingTest, MatchesExactCommandLineOption) {
156
158 EXPECT_EQ(cliEnv.solver().isForceExact(), env.solver().isForceExact());
159
160 std::string const dtmcFile = STORM_TEST_RESOURCES_DIR "/dtmc/die.pm";
161 std::string const dtmcFormula = "P=? [F \"one\"]";
162 EXPECT_EQ(storm::utility::convertNumber<storm::RationalNumber>(std::string("1/6")), checkInitialState<storm::RationalNumber>(env, dtmcFile, dtmcFormula));
163 EXPECT_EQ(checkInitialState<storm::RationalNumber>(cliEnv, dtmcFile, dtmcFormula), checkInitialState<storm::RationalNumber>(env, dtmcFile, dtmcFormula));
164
165 std::string const mdpFile = STORM_TEST_RESOURCES_DIR "/mdp/two_dice.nm";
166 std::string const mdpFormula = "Pmin=? [F \"two\"]";
167 EXPECT_EQ(storm::utility::convertNumber<storm::RationalNumber>(std::string("1/36")), checkInitialState<storm::RationalNumber>(env, mdpFile, mdpFormula));
168 EXPECT_EQ(checkInitialState<storm::RationalNumber>(cliEnv, mdpFile, mdpFormula), checkInitialState<storm::RationalNumber>(env, mdpFile, mdpFormula));
169}
TEST(EnvironmentFactoryTest, DefaultEnvironmentIsNotSound)
TEST_F(EnvironmentFactoryModelCheckingTest, MatchesSoundCommandLineOption)
storm::solver::EigenLinearEquationSolverMethod const & getMethod() const
SolverEnvironment & solver()
ModelCheckerEnvironment & modelchecker()
bool const & isMethodSetFromDefault() const
storm::solver::GameMethod const & getMethod() const
storm::solver::LraMethod const & getNondetLraMethod() const
storm::solver::LraMethod const & getDetLraMethod() const
storm::solver::MinMaxMethod const & getMethod() const
SteadyStateDistributionAlgorithm getSteadyStateDistributionAlgorithm() const
storm::solver::NativeLinearEquationSolverMethod const & getMethod() const
TopologicalSolverEnvironment & topological()
EigenSolverEnvironment & eigen()
MinMaxSolverEnvironment & minMax()
storm::solver::EquationSolverType const & getLinearEquationSolverType() const
bool isLinearEquationSolverTypeSetFromDefaultValue() const
bool isLpSolverTypeSetFromDefaultValue() const
GameSolverEnvironment & game()
storm::solver::LpSolverType const & getLpSolverType() const
NativeSolverEnvironment & native()
LongRunAverageSolverEnvironment & lra()
storm::solver::MinMaxMethod const & getUnderlyingMinMaxMethod() const
storm::solver::EquationSolverType const & getUnderlyingEquationSolverType() const
static storm::Environment buildEnvironment()
void setFromExplodedString(std::vector< std::string > const &commandLineArguments)
This function parses the given command line arguments (represented by several strings) and sets all r...
modules::ModuleSettings const & getModule(std::string const &moduleName) const
Retrieves the settings of the module with the given name.
void restoreDefaults()
Restores the default values for all arguments of all options and marks all options as not set.
virtual storm::Environment create() const
Creates a new environment with default values.
virtual std::unique_ptr< EnvironmentFactory > clone() const override
virtual std::unique_ptr< EnvironmentFactory > clone() const override
storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > createTask(std::shared_ptr< const storm::logic::Formula > const &formula, bool onlyInitialStatesRelevant=false)
std::vector< storm::jani::Property > parsePropertiesForPrismProgram(std::string const &inputString, storm::prism::Program const &program, boost::optional< std::set< std::string > > const &propertyFilter)
storm::prism::Program parseProgram(std::string const &filename, bool prismCompatibility, bool simplify)
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
std::unique_ptr< storm::modelchecker::CheckResult > verifyWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > const &dtmc, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task, bool preferEliminationChecker=false)
std::shared_ptr< storm::models::sparse::Model< ValueType > > buildSparseModel(storm::languages::SymbolicModelDescription const &model, storm::builder::BuilderOptions const &options, typename storm::builder::ExplicitModelBuilder< ValueType >::Options const &explorationOptions=typename storm::builder::ExplicitModelBuilder< ValueType >::Options())
Definition builder.h:118
SettingsManager & mutableManager()
Retrieves the settings manager.
storm::Environment getExactEnvironment()
Creates a new environment which enforces exact computations (via ExactEnvironmentFactory).
storm::Environment getSoundEnvironment()
Creates a new environment which enforces sound computations (via SoundEnvironmentFactory).
std::conditional_t< storm::NumberTraits< ValueType >::HasInfinity, ValueType, ExtendedNumber< ValueType > > ExtendedValueType
The type to use for values that may be infinite.
TargetType convertNumber(SourceType const &number)