1#include "storm-config.h"
21class SynthesisApiTest :
public ::testing::Test {
23 void SetUp()
override {
25#ifndef STORM_HAVE_SMT_SOLVER
26 GTEST_SKIP() <<
"No SMT solver available.";
30 void build(std::string
const& probability =
"p", std::string
const& rewards =
"",
bool mdp =
false) {
32 "const double p; const double r;\nmodule simple\n s : [0..2] init 0;\n"
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,
38 program = program.preprocess(
"");
39 storm::builder::BuilderOptions options({formula(
"P=? [F \"target\"]")}, program);
40 options.setBuildAllRewardModels(
true);
44 std::shared_ptr<storm::logic::Formula const> formula(std::string
const& text)
const {
48 Region region(std::string
const& text =
"0.2<=p<=0.8")
const {
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);
65 storm::Environment environment;
66 storm::prism::Program program;
67 std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model;
70TEST_F(SynthesisApiTest, VerificationEnginesAndOverloads) {
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\"]");
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));
85TEST_F(SynthesisApiTest, PlaEnginesAndInfeasibility) {
87 for (
auto engine : {Engine::ParameterLifting, Engine::ExactParameterLifting, Engine::ValidatingParameterLifting, Engine::RobustParameterLifting}) {
88 SCOPED_TRACE(
static_cast<int>(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);
95 EXPECT_EQ(Status::AllViolated, result.status);
96 EXPECT_FALSE(result.witness);
100TEST_F(SynthesisApiTest, FeasibilityMethodsAndOverloads) {
101 build(
"p",
"rewards \"cost\"\n s=0 : r;\nendrewards\n");
102 std::vector<Method> methods{Method::PLA, Method::GD};
104 methods.push_back(Method::SCP);
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));
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);
122 EXPECT_EQ(Status::Unknown, result.status);
123 EXPECT_FALSE(result.witness);
127TEST_F(SynthesisApiTest, SingletonRegions) {
130 EXPECT_TRUE(
storm::api::verify(environment, model, formula(
"P>=0.5 [F \"target\"]"), half));
131 for (
auto method : {Method::PLA, Method::GD}) {
133 ASSERT_EQ(Status::ExistsSat, result.status);
134 ASSERT_TRUE(result.witness);
135 EXPECT_EQ(half, result.witness->valuation.begin()->second);
137 EXPECT_EQ(Status::AllViolated, result.status);
138 EXPECT_FALSE(result.witness);
142TEST_F(SynthesisApiTest, InvalidInput) {
144 auto property = formula(
"P>=0.5 [F \"target\"]");
145 EXPECT_THROW(
storm::api::verify(environment,
nullptr, property, 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);
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);
157TEST_F(SynthesisApiTest, RegionRequirements) {
160 auto property = formula(
"P<=1 [F \"target\"]");
161 EXPECT_THROW(
storm::api::verify(environment, model, property, zero), storm::exceptions::NotSupportedException);
163 EXPECT_TRUE(
storm::api::verify(environment, model, property, zero, Engine::RobustParameterLifting));
165 EXPECT_THROW(
storm::api::verify(environment, model, property, region()), storm::exceptions::NotSupportedException);
168 EXPECT_TRUE(
storm::api::verify(environment, model, property, region(), Engine::RobustParameterLifting));
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);
178 storm::exceptions::NotSupportedException);
182TEST_F(SynthesisApiTest, MdpSchedulerQuantification) {
183 build(
"p",
"",
true);
184 auto box = region(
"0.4<=p<=0.8");
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\"]"}) {
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);
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);
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));
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);
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)
bool verify(storm::Environment const &env, std::shared_ptr< Model > const &model, std::shared_ptr< storm::logic::Formula const > const &formula, Region const ®ion, 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 ®ion, 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())
RegionResult
The results for a single Parameter Region.
RegionCheckEngine
The considered engine for region checking.
Engine
An enumeration of all engines.
void clearRFVariablePool()
Clears the global pool of rational-function variables.