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