Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StatePermuterTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
4#include "storm/api/storm.h"
8#include "test/storm_gtest.h"
9
10namespace {
11
12class StatePermuterTest : public ::testing::Test {
13 protected:
14 void SetUp() override {
15#ifndef STORM_HAVE_Z3
16 GTEST_SKIP() << "Z3 not available.";
17#endif
18 }
19};
20
21void testStatePermuter(std::string const& prismModelFile, std::string const& formulaString) {
22 storm::prism::Program program = storm::parser::PrismParser::parse(prismModelFile, true);
24 auto model = storm::api::buildSparseModel<double>(program, formulas);
25 auto task = storm::api::createTask<double>(formulas.front(), false);
26 ASSERT_EQ(1ull, model->getInitialStates().getNumberOfSetBits()) << "For model " << prismModelFile << ".";
27
28 auto computeValue = [&task](auto m) {
29 auto result = storm::api::verifyWithSparseEngine(m, task);
30 return result->template asExplicitQuantitativeCheckResult<double>()[*m->getInitialStates().begin()];
31 };
32 auto const modelVal = computeValue(model);
33
34 auto checkOrder = [&model, &computeValue, &modelVal, &prismModelFile](storm::utility::permutation::OrderKind order) {
35 auto permutation = storm::utility::permutation::createPermutation(order, model->getTransitionMatrix(), model->getInitialStates());
36 auto permutedModel = storm::transformer::permuteStates(*model, permutation);
37 EXPECT_EQ(permutedModel->getNumberOfStates(), model->getNumberOfStates())
38 << "Failed for order " << storm::utility::permutation::orderKindtoString(order) << " and model " << prismModelFile << ".";
39 EXPECT_EQ(permutedModel->getNumberOfTransitions(), model->getNumberOfTransitions())
40 << "Failed for order " << storm::utility::permutation::orderKindtoString(order) << " and model " << prismModelFile << ".";
41 auto permVal = computeValue(permutedModel);
42 EXPECT_LE(std::abs(permVal - modelVal) / modelVal, 1e-4)
43 << "Relative difference between original model result (" << modelVal << ") and permuted model result (" << permVal
44 << ") is too high.\nFailed for order " << storm::utility::permutation::orderKindtoString(order) << " and model " << prismModelFile << ".";
45 return permutedModel;
46 };
47
48 auto permutedModel = checkOrder(storm::utility::permutation::OrderKind::Random);
49 permutedModel = checkOrder(storm::utility::permutation::OrderKind::Dfs);
50 EXPECT_EQ(0ull, *permutedModel->getInitialStates().begin()) << "Failed for model " << prismModelFile;
51 permutedModel = checkOrder(storm::utility::permutation::OrderKind::Bfs);
52 EXPECT_EQ(0ull, *permutedModel->getInitialStates().begin()) << "Failed for model " << prismModelFile;
54 EXPECT_EQ(permutedModel->getNumberOfStates() - 1, *permutedModel->getInitialStates().begin()) << "Failed for model " << prismModelFile;
56 EXPECT_EQ(permutedModel->getNumberOfStates() - 1, *permutedModel->getInitialStates().begin()) << "Failed for model " << prismModelFile;
57}
58TEST_F(StatePermuterTest, BrpTest) {
59 testStatePermuter(STORM_TEST_RESOURCES_DIR "/dtmc/brp-16-2.pm", "P=? [ F \"target\"]");
60}
61
62TEST_F(StatePermuterTest, ClusterTest) {
63 testStatePermuter(STORM_TEST_RESOURCES_DIR "/ctmc/cluster2.sm", " R{\"num_repairs\"}=? [C<=200]");
64}
65
66TEST_F(StatePermuterTest, Coin22Test) {
67 testStatePermuter(STORM_TEST_RESOURCES_DIR "/mdp/coin2-2.nm", "Rmax=? [ F \"finished\"]");
68}
69
70TEST_F(StatePermuterTest, StreamTest) {
71 testStatePermuter(STORM_TEST_RESOURCES_DIR "/ma/stream2.ma", "R{\"buffering\"}max=? [ F \"done\"]");
72}
73} // 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.