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 SparseRationalLinearProgrammingEnvironment>
129TYPED_TEST(LraMdpPrctlModelCheckerTest, LRA_SingleMec) {
130 typedef typename TestFixture::ValueType
ValueType;
133 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp;
146 ap.addLabelToState(
"a", 1);
154 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
157 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[0], this->precision());
158 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[1], this->precision());
162 result = checker.check(this->env(), *formula);
165 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[0], this->precision());
166 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[1], this->precision());
178 ap.addLabelToState(
"a", 1);
186 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
189 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[0], this->precision());
190 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[1], this->precision());
194 result = checker.check(this->env(), *formula);
197 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[0], this->precision());
198 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult2[1], this->precision());
213 ap.addLabelToState(
"a", 2);
215 ap.addLabelToState(
"b", 0);
217 ap.addLabelToState(
"c", 0);
218 ap.addLabelToState(
"c", 2);
226 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
229 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[0], this->precision());
230 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[1], this->precision());
231 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[2], this->precision());
235 result = checker.check(this->env(), *formula);
238 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[0], this->precision());
239 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[1], this->precision());
240 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[2], this->precision());
244 result = checker.check(this->env(), *formula);
247 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult3[0], this->precision());
248 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult3[1], this->precision());
249 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult3[2], this->precision());
253 result = checker.check(this->env(), *formula);
256 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult4[0], this->precision());
257 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult4[1], this->precision());
258 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult4[2], this->precision());
262 result = checker.check(this->env(), *formula);
265 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult5[0], this->precision());
266 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult5[1], this->precision());
267 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult5[2], this->precision());
271 result = checker.check(this->env(), *formula);
274 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult6[0], this->precision());
275 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult6[1], this->precision());
276 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult6[2], this->precision());
281 typedef typename TestFixture::ValueType
ValueType;
284 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp;
302 ap.addLabelToState(
"a", 0);
304 ap.addLabelToState(
"b", 1);
306 ap.addLabelToState(
"c", 2);
314 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
317 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult1[0], this->precision());
318 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult1[1], this->precision());
319 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult1[2], this->precision());
323 result = checker.check(this->env(), *formula);
326 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[0], this->precision());
327 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[1], this->precision());
328 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[2], this->precision());
332 result = checker.check(this->env(), *formula);
335 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult3[0], this->precision());
336 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult3[1], this->precision());
337 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult3[2], this->precision());
341 result = checker.check(this->env(), *formula);
344 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult4[0], this->precision());
345 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult4[1], this->precision());
346 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult4[2], this->precision());
350 result = checker.check(this->env(), *formula);
353 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult5[0], this->precision());
354 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult5[1], this->precision());
355 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult5[2], this->precision());
359 result = checker.check(this->env(), *formula);
362 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult6[0], this->precision());
363 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult6[1], this->precision());
364 EXPECT_NEAR(this->
parseNumber(
"1"), quantitativeResult6[2], this->precision());
422 ap.addLabelToState(
"a", 1);
423 ap.addLabelToState(
"a", 4);
424 ap.addLabelToState(
"a", 5);
425 ap.addLabelToState(
"a", 7);
426 ap.addLabelToState(
"a", 11);
427 ap.addLabelToState(
"a", 13);
428 ap.addLabelToState(
"a", 14);
436 std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(this->env(), *formula);
439 EXPECT_NEAR(this->
parseNumber(
"37 / 60"), quantitativeResult1[0], this->precision());
440 EXPECT_NEAR(this->
parseNumber(
"2/3"), quantitativeResult1[3], this->precision());
441 EXPECT_NEAR(this->
parseNumber(
"0.5"), quantitativeResult1[6], this->precision());
442 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult1[9], this->precision());
443 EXPECT_NEAR(this->
parseNumber(
"31 / 60"), quantitativeResult1[12], this->precision());
444 EXPECT_NEAR(this->
parseNumber(
"101 / 200"), quantitativeResult1[13], this->precision());
445 EXPECT_NEAR(this->
parseNumber(
"31 / 60"), quantitativeResult1[14], this->precision());
449 result = checker.check(this->env(), *formula);
452 EXPECT_NEAR(this->
parseNumber(
"0.1"), quantitativeResult2[0], this->precision());
453 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[3], this->precision());
454 EXPECT_NEAR(this->
parseNumber(
"1/3"), quantitativeResult2[6], this->precision());
455 EXPECT_NEAR(this->
parseNumber(
"0"), quantitativeResult2[9], this->precision());
456 EXPECT_NEAR(this->
parseNumber(
"0.1"), quantitativeResult2[12], this->precision());
457 EXPECT_NEAR(this->
parseNumber(
"79 / 300"), quantitativeResult2[13], this->precision());
458 EXPECT_NEAR(this->
parseNumber(
"0.1"), quantitativeResult2[14], this->precision());
462TYPED_TEST(LraMdpPrctlModelCheckerTest, cs_nfail) {
463 typedef typename TestFixture::ValueType
ValueType;
465 std::string formulasString =
"R{\"grants\"}max=? [ MP ]; R{\"grants\"}min=? [ MP ];";
467 auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR
"/mdp/cs_nfail3.nm", formulasString);
468 auto model = std::move(modelFormulas.first);
469 auto tasks = this->getTasks(modelFormulas.second);
470 EXPECT_EQ(184ul, model->getNumberOfStates());
471 EXPECT_EQ(541ul, model->getNumberOfTransitions());
473 auto mdp = model->template as<storm::models::sparse::Mdp<ValueType>>();
476 auto result = checker.check(this->env(), tasks[0])->template asExplicitQuantitativeCheckResult<ValueType>();
477 EXPECT_NEAR(this->
parseNumber(
"333/1000"), result[*mdp->getInitialStates().begin()], this->precision());
479 result = checker.check(this->env(), tasks[1])->template asExplicitQuantitativeCheckResult<ValueType>();
480 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