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