1#include "storm-config.h"
24std::shared_ptr<storm::pars::FeasibilitySynthesisTask const> makeTask(
25 std::shared_ptr<storm::logic::Formula const>
const& formulaWithBound,
27 std::shared_ptr<storm::logic::Formula> clone = formulaWithBound->clone();
28 clone->asOperatorFormula().removeBound();
30 t.setBound(formulaWithBound->asOperatorFormula().getBound());
34 return std::make_shared<storm::pars::FeasibilitySynthesisTask const>(std::move(t));
37std::shared_ptr<storm::logic::Formula const> parseSingleFormula(std::string
const& formulaString,
storm::prism::Program const& program) {
39 return formulas.at(0);
47 carl::VariablePool::getInstance().clear();
48 std::string prismSource =
52 " s : [0..2] init 0;\n"
53 " [] s=0 -> p : (s'=1) + (1-p) : (s'=2);\n"
54 " [] s=1 -> (s'=1);\n"
55 " [] s=2 -> (s'=2);\n"
57 "label \"target\" = s=1;\n";
61 auto formula = parseSingleFormula(
"P>=0.51 [F \"target\"]", program);
62 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
65 auto task = makeTask(formula);
68 auto result = searcher.
run(env(), task);
71 EXPECT_GE(result.value, 0.5);
74 std::shared_ptr<storm::logic::Formula> clone = formula->clone();
75 clone->asOperatorFormula().removeBound();
79 auto verifyResult = verifier.
check(env(), result.valuation);
80 uint64_t initialState = dtmc->getInitialStates().getNextSetIndex(0);
81 double verifiedValue = verifyResult->template asExplicitQuantitativeCheckResult<double>().getFiniteValueVector()[initialState];
83 EXPECT_NEAR(result.value, verifiedValue, 1e-6);
84 EXPECT_GE(verifiedValue, 0.5);
95 carl::VariablePool::getInstance().clear();
96 std::string prismSource =
100 " s : [0..2] init 0;\n"
101 " [] s=0 -> p : (s'=1) + (1-p) : (s'=2);\n"
102 " [] s=1 -> (s'=1);\n"
103 " [] s=2 -> (s'=2);\n"
105 "label \"target\" = s=1;\n";
109 auto formula = parseSingleFormula(
"P>=0.51 [F \"target\"]", program);
110 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
113 auto task = makeTask(formula);
116 auto result = searcher.
run(env(), task);
118 "ScpResult<storm::RationalNumber>::value must be held in an exact, infinity-capable rational type, not double.");
124 EXPECT_GE(result.value, exactThreshold);
129 std::shared_ptr<storm::logic::Formula> clone = formula->clone();
130 clone->asOperatorFormula().removeBound();
135 auto verifyResult = verifier.
check(env(), result.valuation);
136 uint64_t initialState = dtmc->getInitialStates().getNextSetIndex(0);
137 storm::RationalNumber verifiedValue =
138 verifyResult->template asExplicitQuantitativeCheckResult<storm::RationalNumber>().getFiniteValueVector()[initialState];
140 EXPECT_EQ(result.value, verifiedValue);
141 EXPECT_GE(verifiedValue, exactThreshold);
145 carl::VariablePool::getInstance().clear();
146 std::string prismSource =
150 " s : [0..2] init 0;\n"
151 " [] s=0 -> p : (s'=1) + (1-p) : (s'=2);\n"
152 " [] s=1 -> (s'=1);\n"
153 " [] s=2 -> (s'=2);\n"
155 "label \"target\" = s=1;\n";
160 auto formula = parseSingleFormula(
"P<=0.3 [F \"target\"]", program);
161 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
164 auto task = makeTask(formula);
166 auto result = searcher.
run(env(), task);
169 EXPECT_LE(result.value, 0.3);
173 carl::VariablePool::getInstance().clear();
174 std::string prismSource =
178 " s : [0..2] init 0;\n"
179 " [] s=0 -> p : (s'=1) + (1-p) : (s'=2);\n"
180 " [] s=1 -> (s'=1);\n"
181 " [] s=2 -> (s'=2);\n"
183 "label \"target\" = s=1;\n";
188 auto formula = parseSingleFormula(
"P>=0.99 [F \"target\"]", program);
189 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
193 ASSERT_EQ(1u, vars.size());
194 carl::Variable var = *vars.begin();
199 auto task = makeTask(formula, region);
204 auto result = searcher.
run(env(), task);
213std::string
const TwoActionMdpSource =
217 " s : [0..2] init 0;\n"
218 " [a] s=0 -> p : (s'=1) + (1-p) : (s'=2);\n"
219 " [b] s=0 -> 0.1 : (s'=1) + 0.9 : (s'=2);\n"
220 " [] s=1 -> (s'=1);\n"
221 " [] s=2 -> (s'=2);\n"
223 "label \"target\" = s=1;\n";
226std::string
const TwoParameterMdpSource =
231 " s : [0..2] init 0;\n"
232 " [a] s=0 -> p : (s'=1) + (1-p) : (s'=2);\n"
233 " [b] s=0 -> q : (s'=1) + (1-q) : (s'=2);\n"
234 " [] s=1 -> (s'=1);\n"
235 " [] s=2 -> (s'=2);\n"
237 "label \"target\" = s=1;\n";
245 carl::VariablePool::getInstance().clear();
249 auto formula = parseSingleFormula(
"P<=0.3 [F \"target\"]", program);
250 std::shared_ptr<storm::models::sparse::Mdp<storm::RationalFunction>> mdp =
253 auto task = makeTask(formula);
255 auto result = searcher.
run(env(), task);
258 EXPECT_LE(result.value, 0.3);
265 carl::VariablePool::getInstance().clear();
269 auto formula = parseSingleFormula(
"P>=0.7 [F \"target\"]", program);
270 std::shared_ptr<storm::models::sparse::Mdp<storm::RationalFunction>> mdp =
273 auto task = makeTask(formula);
275 auto result = searcher.
run(env(), task);
278 EXPECT_GE(result.value, 0.7);
283 carl::VariablePool::getInstance().clear();
287 auto formula = parseSingleFormula(
"Pmax<=0.3 [F \"target\"]", program);
288 std::shared_ptr<storm::models::sparse::Mdp<storm::RationalFunction>> mdp =
291 auto task = makeTask(formula);
293 auto result = searcher.
run(env(), task);
296 EXPECT_LE(result.value, 0.3);
302 carl::VariablePool::getInstance().clear();
306 auto formula = parseSingleFormula(
"Pmax>=0.7 [F \"target\"]", program);
307 std::shared_ptr<storm::models::sparse::Mdp<storm::RationalFunction>> mdp =
310 auto task = makeTask(formula);
317 carl::VariablePool::getInstance().clear();
318 std::string prismSource =
321 " s : [0..1] init 0;\n"
322 " [] s=0 -> (s'=0);\n"
323 " [] s=1 -> (s'=1);\n"
325 "label \"target\" = s=0;\n";
329 auto formula = parseSingleFormula(
"P>=0.5 [F \"target\"]", program);
330 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
333 auto task = makeTask(formula);
335 auto result = searcher.
run(env(), task);
338 EXPECT_DOUBLE_EQ(1.0, result.value);
339 EXPECT_EQ(0u, result.iterations);
344 carl::VariablePool::getInstance().clear();
345 std::string prismSource =
348 " s : [0..1] init 0;\n"
349 " [] s=0 -> (s'=0);\n"
350 " [] s=1 -> (s'=1);\n"
352 "label \"target\" = s=1;\n";
356 auto formula = parseSingleFormula(
"P>=0.1 [F \"target\"]", program);
357 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
360 auto task = makeTask(formula);
362 auto result = searcher.
run(env(), task);
365 EXPECT_DOUBLE_EQ(0.0, result.value);
366 EXPECT_EQ(0u, result.iterations);
372 carl::VariablePool::getInstance().clear();
373 std::string prismSource =
377 " s : [0..2] init 0;\n"
378 " [] s=0 -> p : (s'=1) + (1-p) : (s'=2);\n"
379 " [] s=1 -> (s'=1);\n"
380 " [] s=2 -> (s'=2);\n"
382 "label \"target\" = s=1;\n";
386 auto formula = parseSingleFormula(
"P>=0.99 [F \"target\"]", program);
387 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
391 ASSERT_EQ(1u, vars.size());
392 carl::Variable var = *vars.begin();
397 auto task = makeTask(formula, region);
401 auto result = searcher.
run(env(), task);
413 carl::VariablePool::getInstance().clear();
414 std::string prismSource =
418 " s : [0..2] init 0;\n"
419 " [] s=0 -> p : (s'=1) + (1-p) : (s'=2);\n"
420 " [] s=1 -> (s'=1);\n"
421 " [] s=2 -> (s'=2);\n"
423 "label \"target\" = s=1;\n";
427 auto formula = parseSingleFormula(
"P>0.5 [F \"target\"]", program);
428 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
431 auto task = makeTask(formula);
433 auto result = searcher.
run(env(), task);
436 EXPECT_GT(result.value, 0.5);
437 EXPECT_GT(result.iterations, 0u);
443 carl::VariablePool::getInstance().clear();
447 auto formula = parseSingleFormula(
"P>=0.7 [F \"target\"]", program);
448 std::shared_ptr<storm::models::sparse::Mdp<storm::RationalFunction>> mdp =
454 for (
auto const& v : vars) {
455 if (v.name() ==
"p") {
463 auto task = makeTask(formula, region);
475std::string
const RetryUntilSuccessDtmcSource =
479 " s : [0..1] init 0;\n"
480 " [] s=0 -> p : (s'=1) + (1-p) : (s'=0);\n"
481 " [] s=1 -> (s'=1);\n"
486 "label \"target\" = s=1;\n";
495 carl::VariablePool::getInstance().clear();
499 auto formula = parseSingleFormula(
"R<=1.5 [F \"target\"]", program);
500 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
503 auto task = makeTask(formula);
505 auto result = searcher.
run(env(), task);
508 EXPECT_LE(result.value, 1.5);
510 std::shared_ptr<storm::logic::Formula> clone = formula->clone();
511 clone->asOperatorFormula().removeBound();
515 auto verifyResult = verifier.
check(env(), result.valuation);
516 uint64_t initialState = dtmc->getInitialStates().getNextSetIndex(0);
517 double verifiedValue = verifyResult->template asExplicitQuantitativeCheckResult<double>().getFiniteValueVector()[initialState];
519 EXPECT_NEAR(result.value, verifiedValue, 1e-6);
520 EXPECT_LE(verifiedValue, 1.5);
526 carl::VariablePool::getInstance().clear();
531 auto formula = parseSingleFormula(
"R>=5 [F \"target\"]", program);
532 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
535 auto task = makeTask(formula);
537 auto result = searcher.
run(env(), task);
540 EXPECT_GE(result.value, 5.0);
547std::string
const RetryUntilSuccessWithParametricCostSource =
552 " s : [0..1] init 0;\n"
553 " [] s=0 -> p : (s'=1) + (1-p) : (s'=0);\n"
554 " [] s=1 -> (s'=1);\n"
559 "label \"target\" = s=1;\n";
570 carl::VariablePool::getInstance().clear();
575 auto formula = parseSingleFormula(
"R<=2 [F \"target\"]", program);
576 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
580 ASSERT_EQ(1u, vars.size());
581 carl::Variable varC = *vars.begin();
589 auto task = makeTask(formula, region);
598 carl::VariablePool::getInstance().clear();
603 auto formula = parseSingleFormula(
"R<=2 [F \"target\"]", program);
604 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
609 ASSERT_EQ(1u, probVars.size());
610 ASSERT_EQ(1u, rewVars.size());
611 carl::Variable varP = *probVars.begin();
612 carl::Variable varC = *rewVars.begin();
621 auto task = makeTask(formula, region);
623 auto result = searcher.
run(env(), task);
626 EXPECT_LE(result.value, 2.0);
636std::string
const RetryOrGiveUpMdpSource =
640 " s : [0..2] init 0;\n"
641 " [a] s=0 -> p : (s'=1) + (1-p) : (s'=0);\n"
642 " [b] s=0 -> (s'=2);\n"
643 " [] s=1 -> (s'=1);\n"
644 " [] s=2 -> (s'=2);\n"
649 "label \"target\" = s=1;\n";
661 carl::VariablePool::getInstance().clear();
665 auto formula = parseSingleFormula(
"R>=5 [F \"target\"]", program);
666 std::shared_ptr<storm::models::sparse::Mdp<storm::RationalFunction>> mdp =
669 auto task = makeTask(formula);
671 auto result = searcher.
run(env(), task);
674 EXPECT_GE(result.value, 5.0);
683 carl::VariablePool::getInstance().clear();
687 auto formula = parseSingleFormula(
"R<=3 [F \"target\"]", program);
688 std::shared_ptr<storm::models::sparse::Mdp<storm::RationalFunction>> mdp =
691 auto task = makeTask(formula);
693 auto result = searcher.
run(env(), task);
696 EXPECT_EQ(0u, result.iterations);
704 carl::VariablePool::getInstance().clear();
709 auto formula = parseSingleFormula(
"R<=3 [F \"target\"]", program);
710 std::shared_ptr<storm::models::sparse::Mdp<storm::RationalFunction>> mdp =
713 auto task = makeTask(formula);
715 auto result = searcher.
run(env(), task);
718 "ScpResult<storm::RationalNumber>::value must be held in an extended (infinity-capable) rational type.");
720 EXPECT_EQ(0u, result.iterations);
722 EXPECT_TRUE(result.value.isPositiveInfinity());
727std::string
const TwoNamedRewardModelsDtmcSource =
731 " s : [0..1] init 0;\n"
732 " [] s=0 -> p : (s'=1) + (1-p) : (s'=0);\n"
733 " [] s=1 -> (s'=1);\n"
735 "rewards \"cost1\"\n"
738 "rewards \"cost2\"\n"
741 "label \"target\" = s=1;\n";
750 carl::VariablePool::getInstance().clear();
754 auto formulaCost1 = parseSingleFormula(
"R{\"cost1\"}<=1.5 [F \"target\"]", program);
755 auto formulaCost2 = parseSingleFormula(
"R{\"cost2\"}<=1.5 [F \"target\"]", program);
756 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
761 auto task = makeTask(formulaCost1);
763 auto result = searcher.
run(env(), task);
766 EXPECT_LE(result.value, 1.5);
771 std::shared_ptr<storm::logic::Formula> clone = formulaCost1->clone();
772 clone->asOperatorFormula().removeBound();
775 auto verifyResult = verifier.
check(env(), result.valuation);
776 uint64_t initialState = dtmc->getInitialStates().getNextSetIndex(0);
777 double verifiedValue = verifyResult->template asExplicitQuantitativeCheckResult<double>().getFiniteValueVector()[initialState];
778 EXPECT_NEAR(result.value, verifiedValue, 1e-6);
784 carl::VariablePool::getInstance().clear();
789 auto formulaCost1 = parseSingleFormula(
"R{\"cost1\"}<=1.5 [F \"target\"]", program);
790 auto formulaCost2 = parseSingleFormula(
"R{\"cost2\"}<=1.5 [F \"target\"]", program);
791 std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc =
794 ASSERT_FALSE(dtmc->hasUniqueRewardModel());
796 auto unnamedFormula = parseSingleFormula(
"R<=1.5 [F \"target\"]", program);
797 auto task = makeTask(unnamedFormula);
TEST_P(SparseScpInstantiationSearcherTest, FindsCertifiedWitness_Dtmc)
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SparseScpInstantiationSearcherTest)
INSTANTIATE_TEST_SUITE_P(LpSolvers, SparseScpInstantiationSearcherTest, testing::ValuesIn(storm::pars::scp::testutils::lpSolversUnderTest()), storm::pars::scp::testutils::LpSolverTest::solverName)
Class to efficiently check a formula on a parametric model with different parameter instantiations.
virtual std::unique_ptr< CheckResult > check(Environment const &env, storm::utility::parametric::Valuation< typename SparseModelType::ValueType > const &valuation) override
void specifyFormula(CheckTask< storm::logic::Formula, typename SparseModelType::ValueType > const &checkTask)
This class represents a discrete-time Markov chain.
This class represents a (discrete-time) Markov decision process.
Finds a parameter valuation satisfying an unbounded reachability threshold property (probability or r...
ScpResult< ConstantType > run(storm::Environment const &env, std::shared_ptr< storm::pars::FeasibilitySynthesisTask const > const &task)
static std::string solverName(testing::TestParamInfo< storm::solver::LpSolverType > const &info)
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...
Program preprocess(std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantDefinitions) const
Preprocesses the program by defining the given constant definitions, substituting constants and formu...
storm::utility::parametric::Valuation< ParametricType > Valuation
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)
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())
std::set< storm::RationalFunctionVariable > getRewardParameters(Model< storm::RationalFunction > const &model)
Get all parameters occurring in rewards.
std::set< storm::RationalFunctionVariable > getProbabilityParameters(Model< storm::RationalFunction > const &model)
Get all probability parameters occurring on transitions.
std::vector< storm::solver::LpSolverType > lpSolversUnderTest()
bool isInfinity(ValueType const &a)
TargetType convertNumber(SourceType const &number)
storm::utility::ExtendedValueType< RationalNumber > ExtendedRationalNumber
The rational number type extended with the two infinities.
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)
Configuration for the SCP feasibility search (SparseScpInstantiationSearcher).
uint64_t maxIterations
Maximum number of SCP iterations before giving up.