1#include "storm-config.h"
23class SparseValueTypeValueIterationEnvironment {
25 static const bool isExact =
false;
36class SparseValueTypeLinearProgrammingEnvironment {
38 static const bool isExact =
false;
49class SparseSoundEnvironment {
51 static const bool isExact =
false;
61class SparseRationalLinearProgrammingEnvironment {
63 static const bool isExact =
true;
73template<
typename TestType>
74class LraMdpPrctlModelCheckerTest :
public ::testing::Test {
76 typedef typename TestType::ValueType
ValueType;
79 LraMdpPrctlModelCheckerTest() : _environment(TestType::createEnvironment()) {}
81 void SetUp()
override {
83 GTEST_SKIP() <<
"Z3 not available.";
91 return storm::utility::convertNumber<ValueType>(input);
96 bool isSparseModel()
const {
97 return std::is_same<typename TestType::ModelType, SparseModelType>::value;
100 std::pair<std::shared_ptr<SparseModelType>, std::vector<std::shared_ptr<storm::logic::Formula const>>> buildModelFormulas(
101 std::string
const& pathToPrismFile, std::string
const& formulasAsString, std::string
const& constantDefinitionString =
"")
const {
102 std::pair<std::shared_ptr<SparseModelType>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result;
106 result.first = storm::api::buildSparseModel<ValueType>(program, result.second)->template as<SparseModelType>();
110 std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> getTasks(
111 std::vector<std::shared_ptr<storm::logic::Formula const>>
const& formulas)
const {
112 std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> result;
113 for (
auto const& f : formulas) {
114 result.emplace_back(*f);
123typedef ::testing::Types<SparseValueTypeValueIterationEnvironment, SparseValueTypeLinearProgrammingEnvironment, SparseSoundEnvironment
124#ifdef STORM_HAVE_Z3_OPTIMIZE
126 SparseRationalLinearProgrammingEnvironment
133TYPED_TEST(LraMdpPrctlModelCheckerTest, LRA_SingleMec) {
134 typedef typename TestFixture::ValueType
ValueType;
137 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp;
150 ap.addLabelToState(
"a", 1);
158 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
161 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[0], this->precision());
162 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[1], this->precision());
166 result = checker.check(this->env(), *formula);
169 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[0], this->precision());
170 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[1], this->precision());
182 ap.addLabelToState(
"a", 1);
190 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
193 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[0], this->precision());
194 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[1], this->precision());
198 result = checker.check(this->env(), *formula);
201 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[0], this->precision());
202 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[1], this->precision());
217 ap.addLabelToState(
"a", 2);
219 ap.addLabelToState(
"b", 0);
221 ap.addLabelToState(
"c", 0);
222 ap.addLabelToState(
"c", 2);
230 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
233 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[0], this->precision());
234 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[1], this->precision());
235 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[2], this->precision());
239 result = checker.check(this->env(), *formula);
242 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[0], this->precision());
243 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[1], this->precision());
244 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[2], this->precision());
248 result = checker.check(this->env(), *formula);
251 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult3[0], this->precision());
252 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult3[1], this->precision());
253 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult3[2], this->precision());
257 result = checker.check(this->env(), *formula);
260 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult4[0], this->precision());
261 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult4[1], this->precision());
262 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult4[2], this->precision());
266 result = checker.check(this->env(), *formula);
269 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult5[0], this->precision());
270 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult5[1], this->precision());
271 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult5[2], this->precision());
275 result = checker.check(this->env(), *formula);
278 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult6[0], this->precision());
279 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult6[1], this->precision());
280 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult6[2], this->precision());
285 typedef typename TestFixture::ValueType
ValueType;
288 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp;
306 ap.addLabelToState(
"a", 0);
308 ap.addLabelToState(
"b", 1);
310 ap.addLabelToState(
"c", 2);
318 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
321 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult1[0], this->precision());
322 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult1[1], this->precision());
323 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult1[2], this->precision());
327 result = checker.check(this->env(), *formula);
330 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[0], this->precision());
331 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[1], this->precision());
332 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[2], this->precision());
336 result = checker.check(this->env(), *formula);
339 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult3[0], this->precision());
340 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult3[1], this->precision());
341 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult3[2], this->precision());
345 result = checker.check(this->env(), *formula);
348 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult4[0], this->precision());
349 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult4[1], this->precision());
350 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult4[2], this->precision());
354 result = checker.check(this->env(), *formula);
357 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult5[0], this->precision());
358 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult5[1], this->precision());
359 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult5[2], this->precision());
363 result = checker.check(this->env(), *formula);
366 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult6[0], this->precision());
367 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult6[1], this->precision());
368 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult6[2], this->precision());
426 ap.addLabelToState(
"a", 1);
427 ap.addLabelToState(
"a", 4);
428 ap.addLabelToState(
"a", 5);
429 ap.addLabelToState(
"a", 7);
430 ap.addLabelToState(
"a", 11);
431 ap.addLabelToState(
"a", 13);
432 ap.addLabelToState(
"a", 14);
440 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
443 EXPECT_NEAR(this->
parseNumber(
"37 / 60"), quantitativeResult1[0], this->precision());
444 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult1[3], this->precision());
445 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[6], this->precision());
446 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[9], this->precision());
447 EXPECT_NEAR(this->
parseNumber(
"31 / 60"), quantitativeResult1[12], this->precision());
448 EXPECT_NEAR(this->
parseNumber(
"101 / 200"), quantitativeResult1[13], this->precision());
449 EXPECT_NEAR(this->
parseNumber(
"31 / 60"), quantitativeResult1[14], this->precision());
453 result = checker.check(this->env(), *formula);
456 EXPECT_NEAR(this->
parseNumber(
"0.1"), quantitativeResult2[0], this->precision());
457 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[3], this->precision());
458 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult2[6], this->precision());
459 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[9], this->precision());
460 EXPECT_NEAR(this->
parseNumber(
"0.1"), quantitativeResult2[12], this->precision());
461 EXPECT_NEAR(this->
parseNumber(
"79 / 300"), quantitativeResult2[13], this->precision());
462 EXPECT_NEAR(this->
parseNumber(
"0.1"), quantitativeResult2[14], this->precision());
466TYPED_TEST(LraMdpPrctlModelCheckerTest, cs_nfail) {
467 typedef typename TestFixture::ValueType
ValueType;
469 std::string formulasString =
"R{\"grants\"}max=? [ MP ]; R{\"grants\"}min=? [ MP ];";
471 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR
"/mdp/cs_nfail3.nm", formulasString);
472 auto model = std::move(modelFormulas.first);
473 auto tasks = this->getTasks(modelFormulas.second);
474 EXPECT_EQ(184ul, model->getNumberOfStates());
475 EXPECT_EQ(541ul, model->getNumberOfTransitions());
477 auto mdp = model->template as<storm::models::sparse::Mdp<ValueType>>();
480 auto result = checker.check(this->env(), tasks[0])->template asExplicitQuantitativeCheckResult<ValueType>();
481 EXPECT_NEAR(this->
parseNumber(
"333/1000"), result[*mdp->getInitialStates().begin()], this->precision());
483 result = checker.check(this->env(), tasks[1])->template asExplicitQuantitativeCheckResult<ValueType>();
484 EXPECT_NEAR(this->
parseNumber(
"0"), result[*mdp->getInitialStates().begin()], this->precision());
SolverEnvironment & solver()
void setNondetLraMethod(storm::solver::LraMethod value, bool isSetFromDefault=false)
void setPrecision(storm::RationalNumber value)
void setForceSoundness(bool value)
LongRunAverageSolverEnvironment & lra()
ExplicitQuantitativeCheckResult< ValueType > & asExplicitQuantitativeCheckResult()
This class represents a (discrete-time) Markov decision process.
This class manages the labeling of the state space with a number of (atomic) labels.
A class that can be used to build a sparse matrix by adding value by value.
void addNextValue(index_type row, index_type column, value_type const &value)
Sets the matrix entry at the given row and column to the given value.
void newRowGroup(index_type startingRow)
Starts a new row group in the matrix.
SparseMatrix< value_type > build(index_type overriddenRowCount=0, index_type overriddenColumnCount=0, index_type overriddenRowGroupCount=0)
A class that holds a possibly non-square matrix in the compressed row storage format.
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)
SFTBDDChecker::ValueType ValueType
NumberType parseNumber(std::string const &value)
Parse number from string.
storm::prism::Program preprocess(storm::prism::Program const &program, std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantDefinitions)
TYPED_TEST(GraphTestAR, SymbolicProb01StochasticGameDieSmall)
TYPED_TEST_SUITE(GraphTestAR, TestingTypes,)
::testing::Types< Cudd, Sylvan > TestingTypes