Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StatePermuterTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
6#include "storm/api/storm.h"
10
11namespace {
12
13class StatePermuterTest : public ::testing::Test {
14 protected:
15 void SetUp() override {
16#ifndef STORM_HAVE_Z3
17 GTEST_SKIP() << "Z3 not available.";
18#endif
19 }
20};
21
22void testStatePermuter(std::string const& prismModelFile, std::string const& formulaString) {
23 storm::prism::Program program = storm::parser::PrismParser::parse(prismModelFile, true);
25 auto model = storm::api::buildSparseModel<double>(program, formulas);
26 auto task = storm::api::createTask<double>(formulas.front(), false);
27 ASSERT_EQ(1ull, model->getInitialStates().getNumberOfSetBits()) << "For model " << prismModelFile << ".";
28
29 auto computeValue = [&task](auto m) {
30 auto result = storm::api::verifyWithSparseEngine(m, task);
31 return result->template asExplicitQuantitativeCheckResult<double>()[*m->getInitialStates().begin()];
32 };
33 auto const modelVal = computeValue(model);
34
35 auto checkOrder = [&model, &computeValue, &modelVal, &prismModelFile](storm::utility::permutation::OrderKind order) {
36 auto permutation = storm::utility::permutation::createPermutation(order, model->getTransitionMatrix(), model->getInitialStates());
37 auto permutedModel = storm::transformer::permuteStates(*model, permutation);
38 EXPECT_EQ(permutedModel->getNumberOfStates(), model->getNumberOfStates())
39 << "Failed for order " << storm::utility::permutation::orderKindtoString(order) << " and model " << prismModelFile << ".";
40 EXPECT_EQ(permutedModel->getNumberOfTransitions(), model->getNumberOfTransitions())
41 << "Failed for order " << storm::utility::permutation::orderKindtoString(order) << " and model " << prismModelFile << ".";
42 auto permVal = computeValue(permutedModel);
43 EXPECT_LE(std::abs(permVal - modelVal) / modelVal, 1e-4)
44 << "Relative difference between original model result (" << modelVal << ") and permuted model result (" << permVal
45 << ") is too high.\nFailed for order " << storm::utility::permutation::orderKindtoString(order) << " and model " << prismModelFile << ".";
46 return permutedModel;
47 };
48
49 auto permutedModel = checkOrder(storm::utility::permutation::OrderKind::Random);
50 permutedModel = checkOrder(storm::utility::permutation::OrderKind::Dfs);
51 EXPECT_EQ(0ull, *permutedModel->getInitialStates().begin()) << "Failed for model " << prismModelFile;
52 permutedModel = checkOrder(storm::utility::permutation::OrderKind::Bfs);
53 EXPECT_EQ(0ull, *permutedModel->getInitialStates().begin()) << "Failed for model " << prismModelFile;
55 EXPECT_EQ(permutedModel->getNumberOfStates() - 1, *permutedModel->getInitialStates().begin()) << "Failed for model " << prismModelFile;
57 EXPECT_EQ(permutedModel->getNumberOfStates() - 1, *permutedModel->getInitialStates().begin()) << "Failed for model " << prismModelFile;
58}
59TEST_F(StatePermuterTest, BrpTest) {
60 testStatePermuter(STORM_TEST_RESOURCES_DIR "/dtmc/brp-16-2.pm", "P=? [ F \"target\"]");
61}
62
63TEST_F(StatePermuterTest, ClusterTest) {
64 testStatePermuter(STORM_TEST_RESOURCES_DIR "/ctmc/cluster2.sm", " R{\"num_repairs\"}=? [C<=200]");
65}
66
67TEST_F(StatePermuterTest, Coin22Test) {
68 testStatePermuter(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2.nm", "Rmax=? [ F \"finished\"]");
69}
70
71TEST_F(StatePermuterTest, StreamTest) {
72 testStatePermuter(STORM_TEST_RESOURCES_DIR "/ma/stream2.ma", "R{\"buffering\"}max=? [ F \"done\"]");
73}
74} // namespace
TEST_F(AssumptionCheckerTest, Brp_no_bisimulation)
static storm::prism::Program parse(std::string const &filename, bool prismCompatability=false)
Parses the given file into the PRISM storage classes assuming it complies with the PRISM syntax.
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::unique_ptr< storm::modelchecker::CheckResult > verifyWithSparseEngine(storm::Environment const &env, std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > const &dtmc, storm::modelchecker::CheckTask< storm::logic::Formula, ValueType > const &task)
std::shared_ptr< storm::models::sparse::Model< ValueType > > permuteStates(storm::models::sparse::Model< ValueType > const &originalModel, std::vector< uint64_t > const &permutation)
Applies the given permutation to the states of the given model.
OrderKind
The order in which the states of a matrix are visited in a depth-first search or breadth-first search...
Definition permutation.h:21
std::string orderKindtoString(OrderKind order)
Converts the given order to a string.
std::vector< index_type > createPermutation(OrderKind order, storm::storage::SparseMatrix< ValueType > const &transitionMatrix, storm::storage::BitVector const &initialStates)
Creates a permutation that orders the states of the given matrix in the given exploration order.