Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SynthesisApiTest.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"
13
14namespace {
15
20
21class SynthesisApiTest : public ::testing::Test {
22 protected:
23 void SetUp() override {
25#ifndef STORM_HAVE_SMT_SOLVER
26 GTEST_SKIP() << "No SMT solver available.";
27#endif
28 }
29
30 void build(std::string const& probability = "p", std::string const& rewards = "", bool mdp = false) {
31 program = storm::parser::PrismParser::parseFromString(std::string(mdp ? "mdp\n" : "dtmc\n") +
32 "const double p; const double r;\nmodule simple\n s : [0..2] init 0;\n"
33 " [] s=0 -> " +
34 probability + " : (s'=1) + (1-(" + probability + ")) : (s'=2);\n" +
35 (mdp ? " [] s=0 -> (s'=1);\n [] s=0 -> (s'=2);\n" : "") +
36 " [] s=1 -> (s'=1);\n [] s=2 -> (s'=2);\nendmodule\nlabel \"target\" = s=1;\n" + rewards,
37 "SynthesisApiTest");
38 program = program.preprocess("");
39 storm::builder::BuilderOptions options({formula("P=? [F \"target\"]")}, program);
40 options.setBuildAllRewardModels(true);
42 }
43
44 std::shared_ptr<storm::logic::Formula const> formula(std::string const& text) const {
46 }
47
48 Region region(std::string const& text = "0.2<=p<=0.8") const {
50 }
51
52 bool enableScp() {
53#if defined STORM_HAVE_GLPK
54 environment.solver().setLpSolverType(storm::solver::LpSolverType::Glpk);
55#elif defined STORM_HAVE_HIGHS
56 environment.solver().setLpSolverType(storm::solver::LpSolverType::Highs);
57#elif defined STORM_HAVE_SOPLEX
58 environment.solver().setLpSolverType(storm::solver::LpSolverType::Soplex);
59#else
60 return false;
61#endif
62 return true;
63 }
64
65 storm::Environment environment;
66 storm::prism::Program program;
67 std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model;
68};
69
70TEST_F(SynthesisApiTest, VerificationEnginesAndOverloads) {
71 build();
72 Region::CoefficientType const bound = storm::utility::one<Region::CoefficientType>() / 5;
73 for (auto engine : {Engine::ParameterLifting, Engine::ExactParameterLifting, Engine::ValidatingParameterLifting, Engine::RobustParameterLifting}) {
74 SCOPED_TRACE(static_cast<int>(engine));
75 auto property = formula("P<=0.9 [F \"target\"]");
76 EXPECT_TRUE(storm::api::verify(environment, model, property, region(), engine));
77 EXPECT_TRUE(storm::api::verify(environment, model, property, bound, engine));
78 EXPECT_FALSE(storm::api::verify(environment, model, formula("P>=0.6 [F \"target\"]"), region(), engine));
79 for (auto const& text : {"P<0.5 [F \"target\"]", "P>0.5 [F \"target\"]"}) {
80 EXPECT_FALSE(storm::api::verify(environment, model, formula(text), region("0.4<=p<=0.6"), engine));
81 }
82 }
83}
84
85TEST_F(SynthesisApiTest, PlaEnginesAndInfeasibility) {
86 build();
87 for (auto engine : {Engine::ParameterLifting, Engine::ExactParameterLifting, Engine::ValidatingParameterLifting, Engine::RobustParameterLifting}) {
88 SCOPED_TRACE(static_cast<int>(engine));
89 auto result = storm::api::checkFeasibility(environment, model, formula("P>=0.6 [F \"target\"]"), region(), Method::PLA, engine);
90 ASSERT_EQ(Status::ExistsSat, result.status);
91 ASSERT_TRUE(result.witness);
92 EXPECT_TRUE(region().contains(result.witness->valuation));
93 EXPECT_GE(result.witness->value, 0.6);
94 result = storm::api::checkFeasibility(environment, model, formula("P>=0.9 [F \"target\"]"), region(), Method::PLA, engine);
95 EXPECT_EQ(Status::AllViolated, result.status);
96 EXPECT_FALSE(result.witness);
97 }
98}
99
100TEST_F(SynthesisApiTest, FeasibilityMethodsAndOverloads) {
101 build("p", "rewards \"cost\"\n s=0 : r;\nendrewards\n");
102 std::vector<Method> methods{Method::PLA, Method::GD};
103 if (enableScp()) {
104 methods.push_back(Method::SCP);
105 }
106 Region::CoefficientType const bound = storm::utility::one<Region::CoefficientType>() / 5;
107 auto box = region("0.2<=p<=0.8,0.2<=r<=0.8");
108 auto property = formula("P>=0.6 [F \"target\"]");
109 for (auto method : methods) {
110 SCOPED_TRACE(static_cast<int>(method));
111 for (auto const& result : {storm::api::checkFeasibility(environment, model, property, box, method),
112 storm::api::checkFeasibility(environment, model, property, bound, method)}) {
113 ASSERT_EQ(Status::ExistsSat, result.status);
114 ASSERT_TRUE(result.witness);
115 EXPECT_EQ(2u, result.witness->valuation.size());
116 EXPECT_GE(result.witness->value, 0.6);
117 EXPECT_LE(result.witness->value, 0.8);
118 }
119 }
120 if (enableScp()) {
121 auto result = storm::api::checkFeasibility(environment, model, formula("P>=0.9 [F \"target\"]"), box, Method::SCP);
122 EXPECT_EQ(Status::Unknown, result.status);
123 EXPECT_FALSE(result.witness);
124 }
125}
126
127TEST_F(SynthesisApiTest, SingletonRegions) {
128 build();
129 Region::CoefficientType const half = storm::utility::one<Region::CoefficientType>() / 2;
130 EXPECT_TRUE(storm::api::verify(environment, model, formula("P>=0.5 [F \"target\"]"), half));
131 for (auto method : {Method::PLA, Method::GD}) {
132 auto result = storm::api::checkFeasibility(environment, model, formula("P>=0.5 [F \"target\"]"), half, method);
133 ASSERT_EQ(Status::ExistsSat, result.status);
134 ASSERT_TRUE(result.witness);
135 EXPECT_EQ(half, result.witness->valuation.begin()->second);
136 result = storm::api::checkFeasibility(environment, model, formula("P>0.5 [F \"target\"]"), half, method);
137 EXPECT_EQ(Status::AllViolated, result.status);
138 EXPECT_FALSE(result.witness);
139 }
140}
141
142TEST_F(SynthesisApiTest, InvalidInput) {
143 build();
144 auto property = formula("P>=0.5 [F \"target\"]");
145 EXPECT_THROW(storm::api::verify(environment, nullptr, property, region()), storm::exceptions::InvalidArgumentException);
146 EXPECT_THROW(storm::api::checkFeasibility(environment, model, nullptr, region()), storm::exceptions::InvalidArgumentException);
147 EXPECT_THROW(storm::api::verify(environment, model, formula("P=? [F \"target\"]"), region()), storm::exceptions::NotSupportedException);
148 EXPECT_THROW(storm::api::checkFeasibility(environment, model, formula("P=? [F \"target\"]"), region()), storm::exceptions::NotSupportedException);
149 EXPECT_THROW(storm::api::verify(environment, model, property, Region()), storm::exceptions::InvalidArgumentException);
150 EXPECT_THROW(storm::api::checkFeasibility(environment, model, property, Region()), storm::exceptions::InvalidArgumentException);
151 for (Region::CoefficientType const& invalid : {Region::CoefficientType(-1), Region::CoefficientType(1)}) {
152 EXPECT_THROW(storm::api::verify(environment, model, property, invalid), storm::exceptions::InvalidArgumentException);
153 EXPECT_THROW(storm::api::checkFeasibility(environment, model, property, invalid), storm::exceptions::InvalidArgumentException);
154 }
155}
156
157TEST_F(SynthesisApiTest, RegionRequirements) {
158 build();
160 auto property = formula("P<=1 [F \"target\"]");
161 EXPECT_THROW(storm::api::verify(environment, model, property, zero), storm::exceptions::NotSupportedException);
162 EXPECT_THROW(storm::api::checkFeasibility(environment, model, property, zero, Method::GD), storm::exceptions::NotSupportedException);
163 EXPECT_TRUE(storm::api::verify(environment, model, property, zero, Engine::RobustParameterLifting));
164 build("p+4/5");
165 EXPECT_THROW(storm::api::verify(environment, model, property, region()), storm::exceptions::NotSupportedException);
166 EXPECT_THROW(storm::api::checkFeasibility(environment, model, property, region()), storm::exceptions::NotSupportedException);
167 build("p*p");
168 EXPECT_TRUE(storm::api::verify(environment, model, property, region(), Engine::RobustParameterLifting));
169}
170
171TEST_F(SynthesisApiTest, RobustFormulaRequirements) {
172 build("p", "rewards \"cost\"\n s=0 : r;\nendrewards\n");
173 auto box = region("0.2<=p<=0.8,0.2<=r<=0.8");
174 for (auto const& text : {"P<=0.9 [F<=2 \"target\"]", "R{\"cost\"}<=2 [C<=2]", "R{\"cost\"}<=2 [F \"target\"]"}) {
175 auto property = formula(text);
176 EXPECT_THROW(storm::api::verify(environment, model, property, box, Engine::RobustParameterLifting), storm::exceptions::NotSupportedException);
177 EXPECT_THROW(storm::api::checkFeasibility(environment, model, property, box, Method::PLA, Engine::RobustParameterLifting),
178 storm::exceptions::NotSupportedException);
179 }
180}
181
182TEST_F(SynthesisApiTest, MdpSchedulerQuantification) {
183 build("p", "", true);
184 auto box = region("0.4<=p<=0.8");
185 // Pmin is zero and Pmax is one, so SCP's qualitative shortcut must not bypass the quantifier checks.
186 EXPECT_TRUE(storm::api::verify(environment, model, formula("Pmax>=0.3 [F \"target\"]"), box));
187 for (auto const& text : {"P>=0.6 [F \"target\"]", "P<=0.3 [F \"target\"]"}) {
188 EXPECT_FALSE(storm::api::verify(environment, model, formula(text), box));
189 EXPECT_EQ(Status::AllViolated, storm::api::checkFeasibility(environment, model, formula(text), box).status);
190 }
191 EXPECT_EQ(Status::ExistsSat, storm::api::checkFeasibility(environment, model, formula("Pmax>=0.6 [F \"target\"]"), box).status);
192 EXPECT_EQ(Status::ExistsSat, storm::api::checkFeasibility(environment, model, formula("Pmin<=0.3 [F \"target\"]"), box).status);
193 for (auto const& text : {"Pmax>=0.6 [F \"target\"]", "Pmin<=0.3 [F \"target\"]"}) {
194 EXPECT_THROW(storm::api::checkFeasibility(environment, model, formula(text), box, Method::SCP), storm::exceptions::NotSupportedException);
195 }
196 EXPECT_EQ(Status::ExistsSat, storm::api::checkFeasibility(environment, model, formula("P>=0 [F \"target\"]"), box, Method::SCP).status);
197 EXPECT_THROW(storm::api::verify(environment, model, formula("P<=1 [F \"target\"]"), box, Engine::RobustParameterLifting),
198 storm::exceptions::NotSupportedException);
199 EXPECT_THROW(storm::api::checkFeasibility(environment, model, formula("P>=0.6 [F \"target\"]"), box, Method::GD), storm::exceptions::NotSupportedException);
200}
201
202TEST_F(SynthesisApiTest, RewardFormula) {
203 build("p", "rewards \"cost\"\n s=0 : r;\nendrewards\n");
204 auto box = region("0.5<=p<=0.5,2<=r<=4");
205 EXPECT_TRUE(storm::api::verify(environment, model, formula("R{\"cost\"}<=4 [F !\"init\"]"), box));
206 auto result = storm::api::checkFeasibility(environment, model, formula("R{\"cost\"}>=3 [F !\"init\"]"), box);
207 ASSERT_EQ(Status::ExistsSat, result.status);
208 ASSERT_TRUE(result.witness);
209 EXPECT_TRUE(box.contains(result.witness->valuation));
210 EXPECT_GE(result.witness->value, 3.0);
211}
212
213} // namespace
TEST_F(ConstraintCollectorTest, PolynomialDenominators)
static storm::prism::Program parseFromString(std::string const &input, std::string const &filename, bool prismCompatability=false)
Parses the given input stream into the PRISM storage classes assuming it complies with the PRISM synt...
storm::storage::ParameterRegion< ValueType > parseRegion(std::string const &inputString, std::set< typename storm::storage::ParameterRegion< ValueType >::VariableType > const &consideredVariables)
Definition region.h:135
bool verify(storm::Environment const &env, std::shared_ptr< Model > const &model, std::shared_ptr< storm::logic::Formula const > const &formula, Region const &region, Engine engine)
std::vector< storm::jani::Property > parsePropertiesForPrismProgram(std::string const &inputString, storm::prism::Program const &program, boost::optional< std::set< std::string > > const &propertyFilter)
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
Result< double > checkFeasibility(storm::Environment const &env, std::shared_ptr< Model > const &model, std::shared_ptr< storm::logic::Formula const > const &formula, Region const &region, storm::pars::FeasibilityMethod method, Engine regionEngine)
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
RegionResult
The results for a single Parameter Region.
RegionCheckEngine
The considered engine for region checking.
Engine
An enumeration of all engines.
Definition Engine.h:31
ValueType zero()
Definition constants.cpp:26
ValueType one()
Definition constants.cpp:21
void clearRFVariablePool()
Clears the global pool of rational-function variables.