Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
NondeterministicSparseTransitionParserTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
12
13TEST(NondeterministicSparseTransitionParserTest, NonExistingFile) {
14 // No matter what happens, please do NOT create a file with the name "nonExistingFile.not"!
17 storm::exceptions::FileIoException);
18
21 STORM_TEST_RESOURCES_DIR "/nonExistingFile.not", nullInformation),
22 storm::exceptions::FileIoException);
23}
24
25TEST(NondeterministicSparseTransitionParserTest, BasicTransitionsParsing) {
26 // Parse a nondeterministic transitions file and test the result.
29
30 // Test the row mapping, i.e. at which row which state starts.
31 ASSERT_EQ(6ul, result.getRowGroupCount());
32 ASSERT_EQ(7ul, result.getRowGroupIndices().size());
33 ASSERT_EQ(0ul, result.getRowGroupIndices()[0]);
34 ASSERT_EQ(4ul, result.getRowGroupIndices()[1]);
35 ASSERT_EQ(5ul, result.getRowGroupIndices()[2]);
36 ASSERT_EQ(7ul, result.getRowGroupIndices()[3]);
37 ASSERT_EQ(8ul, result.getRowGroupIndices()[4]);
38 ASSERT_EQ(9ul, result.getRowGroupIndices()[5]);
39 ASSERT_EQ(11ul, result.getRowGroupIndices()[6]);
40
41 // Test the transition matrix.
42 ASSERT_EQ(6ul, result.getColumnCount());
43 ASSERT_EQ(11ul, result.getRowCount());
44 ASSERT_EQ(22ul, result.getEntryCount());
45
46 // Test every entry of the matrix.
48
49 ASSERT_EQ(0ul, cIter->getColumn());
50 ASSERT_EQ(0.9, cIter->getValue());
51 cIter++;
52 ASSERT_EQ(1ul, cIter->getColumn());
53 ASSERT_EQ(0.1, cIter->getValue());
54 cIter++;
55 ASSERT_EQ(1ul, cIter->getColumn());
56 ASSERT_EQ(0.2, cIter->getValue());
57 cIter++;
58 ASSERT_EQ(2ul, cIter->getColumn());
59 ASSERT_EQ(0.2, cIter->getValue());
60 cIter++;
61 ASSERT_EQ(3ul, cIter->getColumn());
62 ASSERT_EQ(0.2, cIter->getValue());
63 cIter++;
64 ASSERT_EQ(4ul, cIter->getColumn());
65 ASSERT_EQ(0.2, cIter->getValue());
66 cIter++;
67 ASSERT_EQ(5ul, cIter->getColumn());
68 ASSERT_EQ(0.2, cIter->getValue());
69 cIter++;
70 ASSERT_EQ(5ul, cIter->getColumn());
71 ASSERT_EQ(1, cIter->getValue());
72 cIter++;
73 ASSERT_EQ(0ul, cIter->getColumn());
74 ASSERT_EQ(0.1, cIter->getValue());
75 cIter++;
76 ASSERT_EQ(4ul, cIter->getColumn());
77 ASSERT_EQ(0.9, cIter->getValue());
78 cIter++;
79 ASSERT_EQ(2ul, cIter->getColumn());
80 ASSERT_EQ(1, cIter->getValue());
81 cIter++;
82 ASSERT_EQ(2ul, cIter->getColumn());
83 ASSERT_EQ(0.5, cIter->getValue());
84 cIter++;
85 ASSERT_EQ(3ul, cIter->getColumn());
86 ASSERT_EQ(0.5, cIter->getValue());
87 cIter++;
88 ASSERT_EQ(2ul, cIter->getColumn());
89 ASSERT_EQ(1, cIter->getValue());
90 cIter++;
91 ASSERT_EQ(2ul, cIter->getColumn());
92 ASSERT_EQ(0.001, cIter->getValue());
93 cIter++;
94 ASSERT_EQ(3ul, cIter->getColumn());
95 ASSERT_EQ(0.999, cIter->getValue());
96 cIter++;
97 ASSERT_EQ(1ul, cIter->getColumn());
98 ASSERT_EQ(0.7, cIter->getValue());
99 cIter++;
100 ASSERT_EQ(4ul, cIter->getColumn());
101 ASSERT_EQ(0.3, cIter->getValue());
102 cIter++;
103 ASSERT_EQ(1ul, cIter->getColumn());
104 ASSERT_EQ(0.2, cIter->getValue());
105 cIter++;
106 ASSERT_EQ(4ul, cIter->getColumn());
107 ASSERT_EQ(0.2, cIter->getValue());
108 cIter++;
109 ASSERT_EQ(5ul, cIter->getColumn());
110 ASSERT_EQ(0.6, cIter->getValue());
111 cIter++;
112 ASSERT_EQ(5ul, cIter->getColumn());
113 ASSERT_EQ(1, cIter->getValue());
114}
115
116TEST(NondeterministicSparseTransitionParserTest, BasicTransitionsRewardsParsing) {
117 // Parse a nondeterministic transitions file and test the result.
121 STORM_TEST_RESOURCES_DIR "/rew/mdp_general.trans.rew", modelInformation));
122
123 // Test the transition matrix.
124 ASSERT_EQ(6ul, result.getColumnCount());
125 ASSERT_EQ(11ul, result.getRowCount());
126 ASSERT_EQ(17ul, result.getEntryCount());
127
128 // Test every entry of the matrix.
130
131 ASSERT_EQ(0ul, cIter->getColumn());
132 ASSERT_EQ(1, cIter->getValue());
133 cIter++;
134 ASSERT_EQ(1ul, cIter->getColumn());
135 ASSERT_EQ(30, cIter->getValue());
136 cIter++;
137 ASSERT_EQ(1ul, cIter->getColumn());
138 ASSERT_EQ(15.2, cIter->getValue());
139 cIter++;
140 ASSERT_EQ(2ul, cIter->getColumn());
141 ASSERT_EQ(75, cIter->getValue());
142 cIter++;
143 ASSERT_EQ(5ul, cIter->getColumn());
144 ASSERT_EQ(2.45, cIter->getValue());
145 cIter++;
146 ASSERT_EQ(5ul, cIter->getColumn());
147 ASSERT_EQ(1, cIter->getValue());
148 cIter++;
149 ASSERT_EQ(0ul, cIter->getColumn());
150 ASSERT_EQ(0.114, cIter->getValue());
151 cIter++;
152 ASSERT_EQ(4ul, cIter->getColumn());
153 ASSERT_EQ(90, cIter->getValue());
154 cIter++;
155 ASSERT_EQ(2ul, cIter->getColumn());
156 ASSERT_EQ(1, cIter->getValue());
157 cIter++;
158 ASSERT_EQ(2ul, cIter->getColumn());
159 ASSERT_EQ(55, cIter->getValue());
160 cIter++;
161 ASSERT_EQ(3ul, cIter->getColumn());
162 ASSERT_EQ(87, cIter->getValue());
163 cIter++;
164 ASSERT_EQ(2ul, cIter->getColumn());
165 ASSERT_EQ(13, cIter->getValue());
166 cIter++;
167 ASSERT_EQ(3ul, cIter->getColumn());
168 ASSERT_EQ(999, cIter->getValue());
169 cIter++;
170 ASSERT_EQ(1ul, cIter->getColumn());
171 ASSERT_EQ(0.7, cIter->getValue());
172 cIter++;
173 ASSERT_EQ(4ul, cIter->getColumn());
174 ASSERT_EQ(0.3, cIter->getValue());
175 cIter++;
176 ASSERT_EQ(1ul, cIter->getColumn());
177 ASSERT_EQ(0.1, cIter->getValue());
178 cIter++;
179 ASSERT_EQ(5ul, cIter->getColumn());
180 ASSERT_EQ(6, cIter->getValue());
181}
182
183TEST(NondeterministicSparseTransitionParserTest, Whitespaces) {
184 // Test the resilience of the parser against whitespaces.
185 // Do so by comparing the hashes of the transition matices and the rowMapping vectors element by element.
188 storm::storage::SparseMatrix<double> whitespaceResult =
190 ASSERT_EQ(correctResult.hash(), whitespaceResult.hash());
191 ASSERT_EQ(correctResult.getRowGroupIndices().size(), whitespaceResult.getRowGroupIndices().size());
192 for (uint_fast64_t i = 0; i < correctResult.getRowGroupIndices().size(); i++) {
193 ASSERT_EQ(correctResult.getRowGroupIndices()[i], whitespaceResult.getRowGroupIndices()[i]);
194 }
195
196 // Do the same (minus the unused rowMapping) for the corresponding transition rewards file (with and without whitespaces)
198 STORM_TEST_RESOURCES_DIR "/rew/mdp_general.trans.rew", correctResult)
199 .hash();
201 STORM_TEST_RESOURCES_DIR "/rew/mdp_whitespaces.trans.rew", whitespaceResult)
202 .hash());
203}
204
205TEST(NondeterministicSparseTransitionParserTest, MixedTransitionOrder) {
206 // Since the MatrixBuilder needs sequential input of new elements reordering of transitions or states should throw an exception.
208 storm::parser::NondeterministicSparseTransitionParser<>::parseNondeterministicTransitions(STORM_TEST_RESOURCES_DIR "/tra/mdp_mixedStateOrder.tra"),
209 storm::exceptions::InvalidArgumentException);
210
211 storm::storage::SparseMatrix<double> modelInformation =
214 STORM_TEST_RESOURCES_DIR "/rew/mdp_mixedStateOrder.trans.rew", modelInformation),
215 storm::exceptions::InvalidArgumentException);
216}
217
218TEST(NondeterministicSparseTransitionParserTest, FixDeadlocks) {
219 // Set the fixDeadlocks flag temporarily. It is set to its old value once the deadlockOption object is destructed.
220 std::unique_ptr<storm::settings::SettingMemento> fixDeadlocks = storm::settings::mutableBuildSettings().overrideDontFixDeadlocksSet(false);
221
222 // Parse a transitions file with the fixDeadlocks Flag set and test if it works.
225
226 ASSERT_EQ(8ul, result.getRowGroupIndices().size());
227 ASSERT_EQ(9ul, result.getRowGroupIndices()[5]);
228 ASSERT_EQ(10ul, result.getRowGroupIndices()[6]);
229 ASSERT_EQ(12ul, result.getRowGroupIndices()[7]);
230
231 ASSERT_EQ(7ul, result.getColumnCount());
232 ASSERT_EQ(12ul, result.getRowCount());
233 ASSERT_EQ(23ul, result.getEntryCount());
234
236
237 ASSERT_EQ(1ul, cIter->getColumn());
238 ASSERT_EQ(0.7, cIter->getValue());
239 cIter++;
240 ASSERT_EQ(4ul, cIter->getColumn());
241 ASSERT_EQ(0.3, cIter->getValue());
242 cIter++;
243 ASSERT_EQ(5ul, cIter->getColumn());
244 ASSERT_EQ(1, cIter->getValue());
245 cIter++;
246 ASSERT_EQ(1ul, cIter->getColumn());
247 ASSERT_EQ(0.2, cIter->getValue());
248 cIter++;
249 ASSERT_EQ(4ul, cIter->getColumn());
250 ASSERT_EQ(0.2, cIter->getValue());
251 cIter++;
252 ASSERT_EQ(5ul, cIter->getColumn());
253 ASSERT_EQ(0.6, cIter->getValue());
254 cIter++;
255 ASSERT_EQ(5ul, cIter->getColumn());
256 ASSERT_EQ(1, cIter->getValue());
257}
258
259TEST(NondeterministicSparseTransitionParserTest, DontFixDeadlocks) {
260 // Try to parse a transitions file containing a deadlock state with the fixDeadlocksFlag unset. This should throw an exception.
261 std::unique_ptr<storm::settings::SettingMemento> dontFixDeadlocks = storm::settings::mutableBuildSettings().overrideDontFixDeadlocksSet(true);
262
265 storm::exceptions::WrongFormatException);
266}
267
268TEST(NondeterministicSparseTransitionParserTest, DoubledLines) {
269 // There is a redundant line in the transition file. As the transition already exists this should throw an exception.
271 storm::parser::NondeterministicSparseTransitionParser<>::parseNondeterministicTransitions(STORM_TEST_RESOURCES_DIR "/tra/mdp_doubledLines.tra"),
272 storm::exceptions::InvalidArgumentException);
273}
274
275TEST(NondeterministicSparseTransitionParserTest, RewardForNonExistentTransition) {
276 // First parse a transition file. Then parse a transition reward file for the resulting transition matrix.
277 storm::storage::SparseMatrix<double> transitionResult =
279
280 // There is a reward for a transition that does not exist in the transition matrix.
282 STORM_TEST_RESOURCES_DIR "/rew/mdp_rewardForNonExTrans.trans.rew", transitionResult),
283 storm::exceptions::WrongFormatException);
284}
TEST(NondeterministicSparseTransitionParserTest, NonExistingFile)
A class providing the functionality to parse the transitions of a nondeterministic model.
static storm::storage::SparseMatrix< ValueType > parseNondeterministicTransitionRewards(std::string const &filename, storm::storage::SparseMatrix< MatrixValueType > const &modelInformation)
Load a nondeterministic transition system from file and create a sparse adjacency matrix whose entrie...
static storm::storage::SparseMatrix< ValueType > parseNondeterministicTransitions(std::string const &filename)
Load a nondeterministic transition system from file and create a sparse adjacency matrix whose entrie...
std::unique_ptr< storm::settings::SettingMemento > overrideDontFixDeadlocksSet(bool stateToSet)
Overrides the option to not fix deadlocks by setting it to the specified value.
A class that holds a possibly non-square matrix in the compressed row storage format.
index_type getEntryCount() const
Returns the number of entries in the matrix.
const_iterator begin(index_type row) const
Retrieves an iterator that points to the beginning of the given row.
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
index_type getColumnCount() const
Returns the number of columns of the matrix.
std::vector< MatrixEntry< index_type, value_type > >::const_iterator const_iterator
std::size_t hash() const
Calculates a hash value over all values contained in the matrix.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
index_type getRowCount() const
Returns the number of rows of the matrix.
storm::settings::modules::BuildSettings & mutableBuildSettings()
Retrieves the build settings in a mutable form.
#define STORM_SILENT_ASSERT_THROW(statement, expected_exception)
Definition storm_gtest.h:26