1#include "storm-config.h"
16#ifdef STORM_HAVE_Z3_OPTIMIZE
20class FlowBigMEnvironment {
32class FlowIndicatorEnvironment {
44class BigMEnvironment {
56class IndicatorEnvironment {
68class BigMOrderEnvironment {
80class IndicatorOrderEnvironment {
92class RedundantEnvironment {
104class RedundantOrderEnvironment {
116template<
typename TestType>
117class MultiObjectiveSchedRestModelCheckerTest :
public ::testing::Test {
121 bool isFlowEncoding()
const {
126 auto env = TestType::getEnv();
132 auto env = TestType::getEnv();
138 typedef std::vector<storm::RationalNumber> Point;
141 return storm::utility::convertNumber<ValueType>(input);
144 std::vector<Point> parsePoints(std::vector<std::string>
const& input) {
145 std::vector<Point> result;
146 for (
auto const& i : input) {
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)));
153 pos2 =
i.find(
",", pos1);
156 result.push_back(currPoint);
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) {
174 std::string
toString(Point point,
bool asDouble) {
178 for (
auto const& pi : point) {
185 s << storm::utility::convertNumber<double>(pi);
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";
202 stream <<
" --> yes | no | " <<
toString(p,
true) <<
"\n";
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";
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);
218 for (
auto const& p : expected) {
219 if (std::find(actual.begin(), actual.end(), p) == actual.end()) {
220 diffString = getDiffString(expected, actual);
228 template<
typename SparseModelType>
230 std::vector<Point>
const& expected, std::string& errorString) {
232 if (!result->isParetoCurveCheckResult()) {
233 errorString =
"Not a ParetoCurveCheckResult";
236 return isSame(expected, result->template asExplicitParetoCurveCheckResult<ValueType>().getPoints(), errorString);
240typedef ::testing::Types<FlowBigMEnvironment, FlowIndicatorEnvironment, BigMEnvironment, IndicatorEnvironment, BigMOrderEnvironment, IndicatorOrderEnvironment,
241 RedundantEnvironment, RedundantOrderEnvironment>
246TYPED_TEST(MultiObjectiveSchedRestModelCheckerTest, steps) {
247 typedef typename TestFixture::ValueType
ValueType;
249 std::string programFile = STORM_TEST_RESOURCES_DIR
"/mdp/multiobj_stairs.nm";
250 std::string constantsString =
"N=3";
251 std::string formulasAsString =
"multi(Pmax=? [ F y=1], Pmax=? [ F y=2 ]);";
252 formulasAsString +=
"multi(P>=0.375 [ F y=1], Pmax>=0.5 [ F y=2 ]);";
253 formulasAsString +=
"multi(P>=0.4 [ F y=1], Pmax>=0.4 [ F y=2 ]);";
254 formulasAsString +=
"multi(Pmax=? [ F y=1], Pmax>=0.4 [ F y=2 ]);";
255 formulasAsString +=
"multi(Pmax=? [ F y=1], Pmax>=0.9 [ F y=2 ]);";
260 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
262 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp =
263 storm::api::buildSparseModel<ValueType>(program, formulas)->template as<storm::models::sparse::Mdp<ValueType>>();
264 std::string errorString;
267 uint64_t formulaIndex = 0;
269 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"});
270 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
275 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
276 EXPECT_TRUE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
281 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
282 EXPECT_FALSE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
287 ASSERT_TRUE(result->isExplicitQuantitativeCheckResult());
288 auto expected = storm::utility::convertNumber<ValueType, std::string>(
"0.375");
289 EXPECT_EQ(result->template asExplicitQuantitativeCheckResult<ValueType>()[*mdp->getInitialStates().begin()], expected);
294 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
295 EXPECT_FALSE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
299TYPED_TEST(MultiObjectiveSchedRestModelCheckerTest, mecs) {
300 typedef typename TestFixture::ValueType
ValueType;
301 typedef typename TestFixture::Point Point;
302 std::string programFile = STORM_TEST_RESOURCES_DIR
"/mdp/multiobj_mecs.nm";
303 std::string constantsString =
"";
304 std::string formulasAsString =
"multi(Pmin=? [ F x=3], Pmax=? [ F x=4 ]);";
305 formulasAsString +=
"\nmulti(R{\"test\"}min=? [C], Pmin=? [F \"t1\"]);";
306 formulasAsString +=
"\nmulti(R{\"test\"}min=? [C], Pmin=? [F \"t2\"]);";
307 formulasAsString +=
"\nmulti(R{\"test\"}min=? [C], Pmin=? [F \"t2\"], Pmax=? [F \"t1\"]);";
308 formulasAsString +=
"\nmulti(R{\"test\"}<=0 [C], P<=1 [F \"t2\"], P>=0 [F \"t1\"]);";
309 formulasAsString +=
"\nmulti(R{\"test\"}<=1 [C], P<=1 [F \"t2\"], P>=0.1 [F \"t1\"]);";
313 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
315 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp =
316 storm::api::buildSparseModel<ValueType>(program, formulas)->template as<storm::models::sparse::Mdp<ValueType>>();
317 std::string errorString;
318 std::vector<Point> expected;
322 uint64_t formulaIndex = 0;
323 expected = this->parsePoints({
"0.5,0.5",
"1,1"});
324 if (this->isFlowEncoding()) {
326 storm::exceptions::InvalidOperationException);
328 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
332 expected = this->parsePoints({
"0,0"});
333 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
336 expected = this->parsePoints({
"0,1"});
337 if (this->isFlowEncoding()) {
339 storm::exceptions::InvalidOperationException);
341 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
345 expected = this->parsePoints({
"0,1,0",
"2,1,1"});
346 if (this->isFlowEncoding()) {
348 storm::exceptions::InvalidOperationException);
350 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
354 if (this->isFlowEncoding()) {
357 storm::exceptions::InvalidOperationException);
360 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
361 EXPECT_TRUE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
366 if (this->isFlowEncoding()) {
369 storm::exceptions::InvalidOperationException);
372 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
373 EXPECT_FALSE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
378TYPED_TEST(MultiObjectiveSchedRestModelCheckerTest, compromise) {
379 typedef typename TestFixture::ValueType
ValueType;
380 typedef typename TestFixture::Point Point;
381 std::string programFile = STORM_TEST_RESOURCES_DIR
"/mdp/multiobj_compromise.nm";
382 std::string constantsString =
"";
383 std::string formulasAsString =
"multi(Pmax=? [ F x=1], Pmax=? [ F x=2 ]);";
384 formulasAsString +=
"\nmulti(R{\"test\"}min=? [F x=1], Pmax=? [F x=1 ]);";
385 formulasAsString +=
"\nmulti(Pmax=? [F x=1], Pmax=? [F x=2 ], Pmax=? [F x=3 ]);";
386 formulasAsString +=
"\nmulti(R{\"test\"}min=? [C], Pmin=? [F x=2 ], Pmin=? [F x=3]);";
390 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
392 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp =
393 storm::api::buildSparseModel<ValueType>(program, formulas)->template as<storm::models::sparse::Mdp<ValueType>>();
394 std::string errorString;
395 std::vector<Point> expected;
399 uint64_t formulaIndex = 0;
400 expected = this->parsePoints({
"1,0",
"0,1",
"0.3,3/7"});
401 if (this->isFlowEncoding()) {
403 storm::exceptions::InvalidOperationException);
405 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
409 expected = this->parsePoints({
"0,0.3",
"2,1"});
410 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
413 expected = this->parsePoints({
"1,0,0",
"0,1,0",
"0.3,3/7,4/7"});
414 if (this->isFlowEncoding()) {
416 storm::exceptions::InvalidOperationException);
418 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
422 expected = this->parsePoints({
"0,1,0",
"0,3/7,4/7"});
423 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
425 env = this->getGoalDeterministicEnvironment();
428 expected = this->parsePoints({
"1,1"});
429 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
432 expected = this->parsePoints({
"0,0.3",
"2,1"});
433 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
436 expected = this->parsePoints({
"1,1,0",
"1,3/7,4/7"});
437 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
440 expected = this->parsePoints({
"0,1,0",
"0,3/7,4/7"});
441 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
444TYPED_TEST(MultiObjectiveSchedRestModelCheckerTest, infrew) {
445 typedef typename TestFixture::ValueType
ValueType;
446 typedef typename TestFixture::Point Point;
447 std::string programFile = STORM_TEST_RESOURCES_DIR
"/mdp/multiobj_infrew.nm";
448 std::string constantsString =
"";
449 std::string formulasAsString =
"multi(R{\"one\"}min=? [ F x=2], R{\"two\"}min=? [ C ]);";
453 std::vector<std::shared_ptr<storm::logic::Formula const>> formulas =
455 std::shared_ptr<storm::models::sparse::Mdp<ValueType>> mdp =
456 storm::api::buildSparseModel<ValueType>(program, formulas)->template as<storm::models::sparse::Mdp<ValueType>>();
457 std::string errorString;
458 std::vector<Point> expected;
462 uint64_t formulaIndex = 0;
463 expected = this->parsePoints({
"10,1"});
464 if (this->isFlowEncoding()) {
466 storm::exceptions::InvalidOperationException);
468 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
471 env = this->getGoalDeterministicEnvironment();
474 expected = this->parsePoints({
"0,1"});
475 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
ModelCheckerEnvironment & modelchecker()
MultiObjectiveModelCheckerEnvironment & multi()
@ Classic
Pick automatically.
@ Flow
The classic backwards encoding.
void setUseBsccOrderEncoding(bool value)
void setUseRedundantBsccConstraints(bool value)
void setEncodingType(EncodingType const &value)
void setSchedulerRestriction(storm::storage::SchedulerClass const &value)
void setUseIndicatorConstraints(bool value)
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, bool produceScheduler)
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)
TYPED_TEST(GraphTestAR, SymbolicProb01StochasticGameDieSmall)
TYPED_TEST_SUITE(GraphTestAR, TestingTypes,)
::testing::Types< Cudd, Sylvan > TestingTypes
#define STORM_SILENT_EXPECT_THROW(statement, expected_exception)