Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
MultiObjectiveSchedRestModelCheckerTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
5#include "storm/api/storm.h"
15
16#ifdef STORM_HAVE_Z3_OPTIMIZE
17
18namespace {
19
20class FlowBigMEnvironment {
21 public:
22 static storm::Environment getEnv() {
26 env.modelchecker().multi().setUseBsccOrderEncoding(false); // not relevant for Flow
27 env.modelchecker().multi().setUseRedundantBsccConstraints(false); // not relevant for Flow
28 return env;
29 }
30};
31
32class FlowIndicatorEnvironment {
33 public:
34 static storm::Environment getEnv() {
38 env.modelchecker().multi().setUseBsccOrderEncoding(false); // not relevant for Flow
39 env.modelchecker().multi().setUseRedundantBsccConstraints(false); // not relevant for Flow
40 return env;
41 }
42};
43
44class BigMEnvironment {
45 public:
46 static storm::Environment getEnv() {
52 return env;
53 }
54};
55
56class IndicatorEnvironment {
57 public:
58 static storm::Environment getEnv() {
64 return env;
65 }
66};
67
68class BigMOrderEnvironment {
69 public:
70 static storm::Environment getEnv() {
76 return env;
77 }
78};
79
80class IndicatorOrderEnvironment {
81 public:
82 static storm::Environment getEnv() {
88 return env;
89 }
90};
91
92class RedundantEnvironment {
93 public:
94 static storm::Environment getEnv() {
100 return env;
101 }
102};
103
104class RedundantOrderEnvironment {
105 public:
106 static storm::Environment getEnv() {
112 return env;
113 }
114};
115
116template<typename TestType>
117class MultiObjectiveSchedRestModelCheckerTest : public ::testing::Test {
118 public:
119 typedef storm::RationalNumber ValueType;
120
121 bool isFlowEncoding() const {
122 return TestType::getEnv().modelchecker().multi().getEncodingType() == storm::MultiObjectiveModelCheckerEnvironment::EncodingType::Flow;
123 }
124
125 storm::Environment getPositionalDeterministicEnvironment() {
126 auto env = TestType::getEnv();
127 env.modelchecker().multi().setSchedulerRestriction(storm::storage::SchedulerClass().setPositional().setIsDeterministic());
128 return env;
129 }
130
131 storm::Environment getGoalDeterministicEnvironment() {
132 auto env = TestType::getEnv();
135 return env;
136 }
137
138 typedef std::vector<storm::RationalNumber> Point;
139
140 ValueType parseNumber(std::string const& input) const {
141 return storm::utility::convertNumber<ValueType>(input);
142 }
143
144 std::vector<Point> parsePoints(std::vector<std::string> const& input) {
145 std::vector<Point> result;
146 for (auto const& i : input) {
147 Point currPoint;
148 std::size_t pos1 = 0;
149 std::size_t pos2 = i.find(",");
150 while (pos2 != std::string::npos) {
151 currPoint.push_back(parseNumber(i.substr(pos1, pos2 - pos1)));
152 pos1 = pos2 + 1;
153 pos2 = i.find(",", pos1);
154 }
155 currPoint.push_back(parseNumber(i.substr(pos1)));
156 result.push_back(currPoint);
157 }
158 return result;
159 }
160
161 std::set<Point> setMinus(std::vector<Point> const& lhs, std::vector<Point> const& rhs) {
162 std::set<Point> result(lhs.begin(), lhs.end());
163 for (auto const& r : rhs) {
164 for (auto lIt = result.begin(); lIt != result.end(); ++lIt) {
165 if (*lIt == r) {
166 result.erase(lIt);
167 break;
168 }
169 }
170 }
171 return result;
172 }
173
174 std::string toString(Point point, bool asDouble) {
175 std::stringstream s;
176 s << "[";
177 bool first = true;
178 for (auto const& pi : point) {
179 if (first) {
180 first = false;
181 } else {
182 s << ", ";
183 }
184 if (asDouble) {
185 s << storm::utility::convertNumber<double>(pi);
186 } else {
187 s << pi;
188 }
189 }
190 s << "]";
191 return s.str();
192 }
193
194 std::string getDiffString(std::vector<Point> const& expected, std::vector<Point> const& actual) {
195 std::stringstream stream;
196 stream << "Unexpected set of Points:\n";
197 stream << " Expected | Actual | Point\n";
198 for (auto const& p : expected) {
199 if (std::find(actual.begin(), actual.end(), p) != actual.end()) {
200 stream << " yes | yes | " << toString(p, true) << "\n";
201 } else {
202 stream << " --> yes | no | " << toString(p, true) << "\n";
203 }
204 }
205 for (auto const& p : actual) {
206 if (std::find(expected.begin(), expected.end(), p) == expected.end()) {
207 stream << " --> no | yes | " << toString(p, true) << "\n";
208 }
209 }
210 return stream.str();
211 }
212
213 bool isSame(std::vector<Point> const& expected, std::vector<Point> const& actual, std::string& diffString) {
214 if (expected.size() != actual.size()) {
215 diffString = getDiffString(expected, actual);
216 return false;
217 }
218 for (auto const& p : expected) {
219 if (std::find(actual.begin(), actual.end(), p) == actual.end()) {
220 diffString = getDiffString(expected, actual);
221 return false;
222 }
223 }
224 diffString = "";
225 return true;
226 }
227
228 template<typename SparseModelType>
229 bool testParetoFormula(storm::Environment const& env, SparseModelType const& model, storm::logic::Formula const& formula,
230 std::vector<Point> const& expected, std::string& errorString) {
232 if (!result->isParetoCurveCheckResult()) {
233 errorString = "Not a ParetoCurveCheckResult";
234 return false;
235 }
236 return isSame(expected, result->template asExplicitParetoCurveCheckResult<ValueType>().getPoints(), errorString);
237 }
238};
239
240typedef ::testing::Types<FlowBigMEnvironment, FlowIndicatorEnvironment, BigMEnvironment, IndicatorEnvironment, BigMOrderEnvironment, IndicatorOrderEnvironment,
241 RedundantEnvironment, RedundantOrderEnvironment>
243
244TYPED_TEST_SUITE(MultiObjectiveSchedRestModelCheckerTest, TestingTypes, );
245
246TYPED_TEST(MultiObjectiveSchedRestModelCheckerTest, steps) {
247 typedef typename TestFixture::ValueType ValueType;
248 typedef typename TestFixture::Point Point;
249
250 std::string programFile = STORM_TEST_RESOURCES_DIR "/mdp/multiobj_stairs.nm";
251 std::string constantsString = "N=3";
252 std::string formulasAsString = "multi(Pmax=? [ F y=1], Pmax=? [ F y=2 ]);";
253 formulasAsString += "multi(P>=0.375 [ F y=1], Pmax>=0.5 [ F y=2 ]);";
254 formulasAsString += "multi(P>=0.4 [ F y=1], Pmax>=0.4 [ F y=2 ]);";
255 formulasAsString += "multi(Pmax=? [ F y=1], Pmax>=0.4 [ F y=2 ]);";
256 formulasAsString += "multi(Pmax=? [ F y=1], Pmax>=0.9 [ F y=2 ]);";
257
258 // programm, model, formula
259 storm::prism::Program program = storm::api::parseProgram(programFile);
260 program = storm::utility::prism::preprocess(program, constantsString);
261 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
263 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp =
264 storm::api::buildSparseModel<ValueType>(program, formulas)->template as<storm::models::sparse::Mdp<ValueType>>();
265 std::string errorString; // storage for error reporting
266
267 storm::Environment env = this->getPositionalDeterministicEnvironment();
268 uint64_t formulaIndex = 0;
269 {
270 auto expected = this->parsePoints({"0.875,0", "0,0.875", "0.125,0.75", "0.25,0.625", "0.375,0.5", "0.5,0.375", "0.625,0.25", "0.75,0.125"});
271 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
272 }
273 ++formulaIndex;
274 {
275 auto result = storm::modelchecker::multiobjective::performMultiObjectiveModelChecking(env, *mdp, formulas[formulaIndex]->asMultiObjectiveFormula());
276 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
277 EXPECT_TRUE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
278 }
279 ++formulaIndex;
280 {
281 auto result = storm::modelchecker::multiobjective::performMultiObjectiveModelChecking(env, *mdp, formulas[formulaIndex]->asMultiObjectiveFormula());
282 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
283 EXPECT_FALSE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
284 }
285 ++formulaIndex;
286 {
287 auto result = storm::modelchecker::multiobjective::performMultiObjectiveModelChecking(env, *mdp, formulas[formulaIndex]->asMultiObjectiveFormula());
288 ASSERT_TRUE(result->isExplicitQuantitativeCheckResult());
289 auto expected = storm::utility::convertNumber<ValueType, std::string>("0.375");
290 EXPECT_EQ(result->template asExplicitQuantitativeCheckResult<ValueType>()[*mdp->getInitialStates().begin()], expected);
291 }
292 ++formulaIndex;
293 {
294 auto result = storm::modelchecker::multiobjective::performMultiObjectiveModelChecking(env, *mdp, formulas[formulaIndex]->asMultiObjectiveFormula());
295 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
296 EXPECT_FALSE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
297 }
298}
299
300TYPED_TEST(MultiObjectiveSchedRestModelCheckerTest, mecs) {
301 typedef typename TestFixture::ValueType ValueType;
302 typedef typename TestFixture::Point Point;
303 std::string programFile = STORM_TEST_RESOURCES_DIR "/mdp/multiobj_mecs.nm";
304 std::string constantsString = "";
305 std::string formulasAsString = "multi(Pmin=? [ F x=3], Pmax=? [ F x=4 ]);";
306 formulasAsString += "\nmulti(R{\"test\"}min=? [C], Pmin=? [F \"t1\"]);";
307 formulasAsString += "\nmulti(R{\"test\"}min=? [C], Pmin=? [F \"t2\"]);";
308 formulasAsString += "\nmulti(R{\"test\"}min=? [C], Pmin=? [F \"t2\"], Pmax=? [F \"t1\"]);";
309 formulasAsString += "\nmulti(R{\"test\"}<=0 [C], P<=1 [F \"t2\"], P>=0 [F \"t1\"]);";
310 formulasAsString += "\nmulti(R{\"test\"}<=1 [C], P<=1 [F \"t2\"], P>=0.1 [F \"t1\"]);";
311 // programm, model, formula
312 storm::prism::Program program = storm::api::parseProgram(programFile);
313 program = storm::utility::prism::preprocess(program, constantsString);
314 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
316 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp =
317 storm::api::buildSparseModel<ValueType>(program, formulas)->template as<storm::models::sparse::Mdp<ValueType>>();
318 std::string errorString; // storage for error reporting
319 std::vector<Point> expected;
320
321 storm::Environment env = this->getPositionalDeterministicEnvironment();
322
323 uint64_t formulaIndex = 0;
324 expected = this->parsePoints({"0.5,0.5", "1,1"});
325 if (this->isFlowEncoding()) {
326 STORM_SILENT_EXPECT_THROW(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString),
327 storm::exceptions::InvalidOperationException);
328 } else {
329 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
330 }
331
332 ++formulaIndex;
333 expected = this->parsePoints({"0,0"});
334 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
335
336 ++formulaIndex;
337 expected = this->parsePoints({"0,1"});
338 if (this->isFlowEncoding()) {
339 STORM_SILENT_EXPECT_THROW(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString),
340 storm::exceptions::InvalidOperationException);
341 } else {
342 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
343 }
344
345 ++formulaIndex;
346 expected = this->parsePoints({"0,1,0", "2,1,1"});
347 if (this->isFlowEncoding()) {
348 STORM_SILENT_EXPECT_THROW(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString),
349 storm::exceptions::InvalidOperationException);
350 } else {
351 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
352 }
353 ++formulaIndex;
354 {
355 if (this->isFlowEncoding()) {
357 storm::modelchecker::multiobjective::performMultiObjectiveModelChecking(env, *mdp, formulas[formulaIndex]->asMultiObjectiveFormula()),
358 storm::exceptions::InvalidOperationException);
359 } else {
360 auto result = storm::modelchecker::multiobjective::performMultiObjectiveModelChecking(env, *mdp, formulas[formulaIndex]->asMultiObjectiveFormula());
361 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
362 EXPECT_TRUE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
363 }
364 }
365 ++formulaIndex;
366 {
367 if (this->isFlowEncoding()) {
369 storm::modelchecker::multiobjective::performMultiObjectiveModelChecking(env, *mdp, formulas[formulaIndex]->asMultiObjectiveFormula()),
370 storm::exceptions::InvalidOperationException);
371 } else {
372 auto result = storm::modelchecker::multiobjective::performMultiObjectiveModelChecking(env, *mdp, formulas[formulaIndex]->asMultiObjectiveFormula());
373 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
374 EXPECT_FALSE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
375 }
376 }
377}
378
379TYPED_TEST(MultiObjectiveSchedRestModelCheckerTest, compromise) {
380 typedef typename TestFixture::ValueType ValueType;
381 typedef typename TestFixture::Point Point;
382 std::string programFile = STORM_TEST_RESOURCES_DIR "/mdp/multiobj_compromise.nm";
383 std::string constantsString = "";
384 std::string formulasAsString = "multi(Pmax=? [ F x=1], Pmax=? [ F x=2 ]);";
385 formulasAsString += "\nmulti(R{\"test\"}min=? [F x=1], Pmax=? [F x=1 ]);";
386 formulasAsString += "\nmulti(Pmax=? [F x=1], Pmax=? [F x=2 ], Pmax=? [F x=3 ]);";
387 formulasAsString += "\nmulti(R{\"test\"}min=? [C], Pmin=? [F x=2 ], Pmin=? [F x=3]);";
388 // programm, model, formula
389 storm::prism::Program program = storm::api::parseProgram(programFile);
390 program = storm::utility::prism::preprocess(program, constantsString);
391 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
393 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp =
394 storm::api::buildSparseModel<ValueType>(program, formulas)->template as<storm::models::sparse::Mdp<ValueType>>();
395 std::string errorString; // storage for error reporting
396 std::vector<Point> expected;
397
398 storm::Environment env = this->getPositionalDeterministicEnvironment();
399
400 uint64_t formulaIndex = 0;
401 expected = this->parsePoints({"1,0", "0,1", "0.3,3/7"});
402 if (this->isFlowEncoding()) {
403 STORM_SILENT_EXPECT_THROW(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString),
404 storm::exceptions::InvalidOperationException);
405 } else {
406 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
407 }
408
409 ++formulaIndex;
410 expected = this->parsePoints({"0,0.3", "2,1"});
411 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
412
413 ++formulaIndex;
414 expected = this->parsePoints({"1,0,0", "0,1,0", "0.3,3/7,4/7"});
415 if (this->isFlowEncoding()) {
416 STORM_SILENT_EXPECT_THROW(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString),
417 storm::exceptions::InvalidOperationException);
418 } else {
419 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
420 }
421
422 ++formulaIndex;
423 expected = this->parsePoints({"0,1,0", "0,3/7,4/7"});
424 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
425
426 env = this->getGoalDeterministicEnvironment();
427
428 formulaIndex = 0;
429 expected = this->parsePoints({"1,1"});
430 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
431
432 ++formulaIndex;
433 expected = this->parsePoints({"0,0.3", "2,1"});
434 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
435
436 ++formulaIndex;
437 expected = this->parsePoints({"1,1,0", "1,3/7,4/7"});
438 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
439
440 ++formulaIndex;
441 expected = this->parsePoints({"0,1,0", "0,3/7,4/7"});
442 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
443}
444
445TYPED_TEST(MultiObjectiveSchedRestModelCheckerTest, infrew) {
446 typedef typename TestFixture::ValueType ValueType;
447 typedef typename TestFixture::Point Point;
448 std::string programFile = STORM_TEST_RESOURCES_DIR "/mdp/multiobj_infrew.nm";
449 std::string constantsString = "";
450 std::string formulasAsString = "multi(R{\"one\"}min=? [ F x=2], R{\"two\"}min=? [ C ]);";
451 // programm, model, formula
452 storm::prism::Program program = storm::api::parseProgram(programFile);
453 program = storm::utility::prism::preprocess(program, constantsString);
454 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
456 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp =
457 storm::api::buildSparseModel<ValueType>(program, formulas)->template as<storm::models::sparse::Mdp<ValueType>>();
458 std::string errorString; // storage for error reporting
459 std::vector<Point> expected;
460
461 storm::Environment env = this->getPositionalDeterministicEnvironment();
462
463 uint64_t formulaIndex = 0;
464 expected = this->parsePoints({"10,1"});
465 if (this->isFlowEncoding()) {
466 STORM_SILENT_EXPECT_THROW(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString),
467 storm::exceptions::InvalidOperationException);
468 } else {
469 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
470 }
471
472 env = this->getGoalDeterministicEnvironment();
473
474 formulaIndex = 0;
475 expected = this->parsePoints({"0,1"});
476 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
477}
478
479} // namespace
480
481#endif /* defined STORM_HAVE_Z3_OPTIMIZE */
ModelCheckerEnvironment & modelchecker()
MultiObjectiveModelCheckerEnvironment & multi()
void setSchedulerRestriction(storm::storage::SchedulerClass const &value)
MultiObjectiveFormula & asMultiObjectiveFormula()
Definition Formula.cpp:229
std::vector< storm::jani::Property > parsePropertiesForPrismProgram(std::string const &inputString, storm::prism::Program const &program, boost::optional< std::set< std::string > > const &propertyFilter)
storm::prism::Program parseProgram(std::string const &filename, bool prismCompatibility, bool simplify)
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
SFTBDDChecker::ValueType ValueType
std::string toString(DFTElementType const &type)
std::unique_ptr< CheckResult > performMultiObjectiveModelChecking(Environment const &env, SparseModelType const &model, storm::logic::MultiObjectiveFormula const &formula)
NumberType parseNumber(std::string const &value)
Parse number from string.
storm::prism::Program preprocess(storm::prism::Program const &program, std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantDefinitions)
Definition prism.cpp:19
TYPED_TEST(GraphTestAR, SymbolicProb01StochasticGameDieSmall)
Definition GraphTest.cpp:49
TYPED_TEST_SUITE(GraphTestAR, TestingTypes,)
::testing::Types< Cudd, Sylvan > TestingTypes
Definition GraphTest.cpp:46
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)