5#include "storm-config.h"
29class SparseValueTypeValueIterationEnvironment {
31 static const bool isExact =
false;
42class SparseValueTypeLinearProgrammingEnvironment {
44 static const bool isExact =
false;
55class SparseSoundEnvironment {
57 static const bool isExact =
false;
67class SparseRationalLinearProgrammingEnvironment {
69 static const bool isExact =
true;
79template<
typename TestType>
80class LraMdpPrctlModelCheckerTest :
public ::testing::Test {
82 typedef typename TestType::ValueType
ValueType;
85 LraMdpPrctlModelCheckerTest() : _environment(TestType::createEnvironment()) {}
87 void SetUp()
override {
89 GTEST_SKIP() <<
"Z3 not available.";
97 return storm::utility::convertNumber<ValueType>(input);
102 bool isSparseModel()
const {
103 return std::is_same<typename TestType::ModelType, SparseModelType>::value;
106 std::pair<std::shared_ptr<SparseModelType>, std::vector<std::shared_ptr<storm::logic::Formula const>>> buildModelFormulas(
107 std::string
const& pathToPrismFile, std::string
const& formulasAsString, std::string
const& constantDefinitionString =
"")
const {
108 std::pair<std::shared_ptr<SparseModelType>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result;
112 result.first = storm::api::buildSparseModel<ValueType>(program, result.second)->template as<SparseModelType>();
116 std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> getTasks(
117 std::vector<std::shared_ptr<storm::logic::Formula const>>
const& formulas)
const {
118 std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> result;
119 for (
auto const& f : formulas) {
120 result.emplace_back(*f);
129typedef ::testing::Types<SparseValueTypeValueIterationEnvironment, SparseValueTypeLinearProgrammingEnvironment, SparseSoundEnvironment
130#ifdef STORM_HAVE_Z3_OPTIMIZE
132 SparseRationalLinearProgrammingEnvironment
139TYPED_TEST(LraMdpPrctlModelCheckerTest, LRA_SingleMec) {
140 typedef typename TestFixture::ValueType
ValueType;
143 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp;
156 ap.addLabelToState(
"a", 1);
164 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
167 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[0], this->precision());
168 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[1], this->precision());
172 result = checker.check(this->env(), *formula);
175 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[0], this->precision());
176 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[1], this->precision());
188 ap.addLabelToState(
"a", 1);
196 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
199 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[0], this->precision());
200 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[1], this->precision());
204 result = checker.check(this->env(), *formula);
207 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[0], this->precision());
208 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[1], this->precision());
223 ap.addLabelToState(
"a", 2);
225 ap.addLabelToState(
"b", 0);
227 ap.addLabelToState(
"c", 0);
228 ap.addLabelToState(
"c", 2);
236 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
239 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[0], this->precision());
240 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[1], this->precision());
241 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[2], this->precision());
245 result = checker.check(this->env(), *formula);
248 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[0], this->precision());
249 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[1], this->precision());
250 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[2], this->precision());
254 result = checker.check(this->env(), *formula);
257 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult3[0], this->precision());
258 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult3[1], this->precision());
259 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult3[2], this->precision());
263 result = checker.check(this->env(), *formula);
266 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult4[0], this->precision());
267 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult4[1], this->precision());
268 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult4[2], this->precision());
272 result = checker.check(this->env(), *formula);
275 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult5[0], this->precision());
276 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult5[1], this->precision());
277 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult5[2], this->precision());
281 result = checker.check(this->env(), *formula);
284 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult6[0], this->precision());
285 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult6[1], this->precision());
286 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult6[2], this->precision());
291 typedef typename TestFixture::ValueType
ValueType;
294 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp;
312 ap.addLabelToState(
"a", 0);
314 ap.addLabelToState(
"b", 1);
316 ap.addLabelToState(
"c", 2);
324 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
327 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult1[0], this->precision());
328 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult1[1], this->precision());
329 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult1[2], this->precision());
333 result = checker.check(this->env(), *formula);
336 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[0], this->precision());
337 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[1], this->precision());
338 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[2], this->precision());
342 result = checker.check(this->env(), *formula);
345 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult3[0], this->precision());
346 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult3[1], this->precision());
347 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult3[2], this->precision());
351 result = checker.check(this->env(), *formula);
354 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult4[0], this->precision());
355 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult4[1], this->precision());
356 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult4[2], this->precision());
360 result = checker.check(this->env(), *formula);
363 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult5[0], this->precision());
364 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult5[1], this->precision());
365 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult5[2], this->precision());
369 result = checker.check(this->env(), *formula);
372 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult6[0], this->precision());
373 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult6[1], this->precision());
374 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult6[2], this->precision());
432 ap.addLabelToState(
"a", 1);
433 ap.addLabelToState(
"a", 4);
434 ap.addLabelToState(
"a", 5);
435 ap.addLabelToState(
"a", 7);
436 ap.addLabelToState(
"a", 11);
437 ap.addLabelToState(
"a", 13);
438 ap.addLabelToState(
"a", 14);
446 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
449 EXPECT_NEAR(this->
parseNumber(
"37 / 60"), quantitativeResult1[0], this->precision());
450 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult1[3], this->precision());
451 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[6], this->precision());
452 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[9], this->precision());
453 EXPECT_NEAR(this->
parseNumber(
"31 / 60"), quantitativeResult1[12], this->precision());
454 EXPECT_NEAR(this->
parseNumber(
"101 / 200"), quantitativeResult1[13], this->precision());
455 EXPECT_NEAR(this->
parseNumber(
"31 / 60"), quantitativeResult1[14], this->precision());
459 result = checker.check(this->env(), *formula);
462 EXPECT_NEAR(this->
parseNumber(
"0.1"), quantitativeResult2[0], this->precision());
463 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[3], this->precision());
464 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult2[6], this->precision());
465 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[9], this->precision());
466 EXPECT_NEAR(this->
parseNumber(
"0.1"), quantitativeResult2[12], this->precision());
467 EXPECT_NEAR(this->
parseNumber(
"79 / 300"), quantitativeResult2[13], this->precision());
468 EXPECT_NEAR(this->
parseNumber(
"0.1"), quantitativeResult2[14], this->precision());
472TYPED_TEST(LraMdpPrctlModelCheckerTest, cs_nfail) {
473 typedef typename TestFixture::ValueType
ValueType;
475 std::string formulasString =
"R{\"grants\"}max=? [ MP ]; R{\"grants\"}min=? [ MP ];";
477 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR
"/mdp/cs_nfail3.nm", formulasString);
478 auto model = std::move(modelFormulas.first);
479 auto tasks = this->getTasks(modelFormulas.second);
480 EXPECT_EQ(184ul, model->getNumberOfStates());
481 EXPECT_EQ(541ul, model->getNumberOfTransitions());
483 auto mdp = model->template as<storm::models::sparse::Mdp<ValueType>>();
486 auto result = checker.check(this->env(), tasks[0])->template asExplicitQuantitativeCheckResult<ValueType>();
487 EXPECT_NEAR(this->
parseNumber(
"333/1000"), result[*mdp->getInitialStates().begin()], this->precision());
489 result = checker.check(this->env(), tasks[1])->template asExplicitQuantitativeCheckResult<ValueType>();
490 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