Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DAProductBuilderTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
4#include <memory>
5#include <sstream>
6#include <string>
7
18
19TEST(DAProductBuilderTest_aUb, Dtmc) {
20#ifndef STORM_HAVE_Z3
21 GTEST_SKIP() << "Z3 not available.";
22#endif
23 storm::prism::Program program = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/dtmc/die.pm");
24
25 std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program).build();
26 auto dtmc = std::dynamic_pointer_cast<storm::models::sparse::Dtmc<double>>(model);
27
28 std::string aUb =
29 "HOA: v1\n"
30 "States: 3\n"
31 "Start: 0\n"
32 "acc-name: Rabin 1\n"
33 "Acceptance: 2 (Fin(0) & Inf(1))\n"
34 "AP: 2 \"a\" \"b\""
35 "--BODY--\n"
36 "State: 0 \"a U b\" \n { 0 }\n"
37 " 2 /* !a & !b */\n"
38 " 0 /* a & !b */\n"
39 " 1 /* !a & b */\n"
40 " 1 /* a & b */\n"
41 "State: 1 { 1 }\n"
42 " 1 1 1 1 /* four transitions on one line */\n"
43 "State: 2 \"sink state\" { 0 }\n"
44 " 2 2 2 2\n"
45 "--END--\n";
46
47 std::istringstream in = std::istringstream(aUb);
49 ASSERT_NO_THROW(da = storm::automata::DeterministicAutomaton::parse(in));
50
51 std::vector<storm::storage::BitVector> apLabels;
52 storm::storage::BitVector apA(dtmc->getNumberOfStates(), true);
53 apA.set(2, false);
54 storm::storage::BitVector apB(dtmc->getNumberOfStates(), false);
55 apB.set(7);
56
57 // std::cout << "apA: " << apA << "\n";
58 // std::cout << "apB: " << apB << "\n";
59 apLabels.push_back(apA);
60 apLabels.push_back(apB);
61
62 storm::transformer::DAProductBuilder productBuilder(*da, apLabels);
63 auto product = productBuilder.build(*dtmc, dtmc->getInitialStates());
64
65 // std::ofstream modelDot;
66 // storm::io::openFile("model.dot", modelDot);
67 // dtmc->writeDotToStream(modelDot);
68 // storm::io::closeFile(modelDot);
69
70 // std::ofstream productDot;
71 // storm::io::openFile("product.dot", modelDot);
72 // product->getProductModel().writeDotToStream(productDot);
73 // storm::io::closeFile(productDot);
74
75 // product->printMapping(std::cout);
76
77 // for (unsigned int i = 0; i < product->getAcceptance()->getNumberOfAcceptanceSets(); i++) {
78 // std::cout << i << ": " << product->getAcceptance()->getAcceptanceSet(i) << "\n";
79 // }
80
82 scc.insert(7);
83 ASSERT_EQ(product->getAcceptance()->isAccepting(scc), 1);
84 scc.insert(8);
85 ASSERT_EQ(product->getAcceptance()->isAccepting(scc), false);
86 scc.insert(12);
87 ASSERT_EQ(product->getAcceptance()->isAccepting(scc), false);
88}
89
90TEST(DAProductBuilderTest_aWb, Dtmc) {
91#ifndef STORM_HAVE_Z3
92 GTEST_SKIP() << "Z3 not available.";
93#endif
94 storm::prism::Program program = storm::parser::PrismParser::parse(STORM_TEST_RESOURCES_DIR "/dtmc/die.pm");
95
96 std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitModelBuilder<double>(program).build();
97 auto dtmc = std::dynamic_pointer_cast<storm::models::sparse::Dtmc<double>>(model);
98
99 std::string aUb =
100 "HOA: v1\n"
101 "States: 3\n"
102 "Start: 0\n"
103 "acc-name: Rabin 1\n"
104 "Acceptance: 2 (Fin(0) & Inf(1))\n"
105 "AP: 2 \"a\" \"b\""
106 "--BODY--\n"
107 "State: 0 \"a U b\" \n"
108 " 2 /* !a & !b */\n"
109 " 0 /* a & !b */\n"
110 " 1 /* !a & b */\n"
111 " 1 /* a & b */\n"
112 "State: 1 { 1 }\n"
113 " 1 1 1 1 /* four transitions on one line */\n"
114 "State: 2 \"sink state\" { 0 }\n"
115 " 2 2 2 2\n"
116 "--END--\n";
117
118 std::istringstream in = std::istringstream(aUb);
120 ASSERT_NO_THROW(da = storm::automata::DeterministicAutomaton::parse(in));
121
122 // NOTE: the following relies on the fact that the exploration order of the
123 // states in the transformation from PRISM program to explicit model is fixed...
124 // Would be better to add labels and get the corresponding states from those labels
125
126 std::vector<storm::storage::BitVector> apLabels;
127 storm::storage::BitVector apA(dtmc->getNumberOfStates(), true);
128 apA.set(2, false);
129 storm::storage::BitVector apB(dtmc->getNumberOfStates(), false);
130 apB.set(7);
131
132 apLabels.push_back(apA);
133 apLabels.push_back(apB);
134
135 storm::transformer::DAProductBuilder productBuilder(*da, apLabels);
136 auto product = productBuilder.build(*dtmc, dtmc->getInitialStates());
137
139 scc.insert(7);
140 ASSERT_EQ(product->getAcceptance()->isAccepting(scc), true);
141 scc.insert(8);
142 ASSERT_EQ(product->getAcceptance()->isAccepting(scc), true);
143 scc.insert(12);
144 ASSERT_EQ(product->getAcceptance()->isAccepting(scc), false);
145}
TEST(DAProductBuilderTest_aUb, Dtmc)
std::shared_ptr< DeterministicAutomaton > ptr
static DeterministicAutomaton::ptr parse(std::istream &in)
std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > build()
Convert the program given at construction time to an abstract model.
This class represents a discrete-time Markov chain.
Definition Dtmc.h:13
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.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
void insert(value_type const &state)
Inserts the given element into this SCC.
DAProduct< Model >::ptr build(const Model &originalModel, const storm::storage::BitVector &statesOfInterest) const