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;
248 typedef typename TestFixture::Point Point;
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 ]);";
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;
268 uint64_t formulaIndex = 0;
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;
276 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
277 EXPECT_TRUE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
282 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
283 EXPECT_FALSE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
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);
295 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
296 EXPECT_FALSE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
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\"]);";
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;
319 std::vector<Point> expected;
323 uint64_t formulaIndex = 0;
324 expected = this->parsePoints({
"0.5,0.5",
"1,1"});
325 if (this->isFlowEncoding()) {
327 storm::exceptions::InvalidOperationException);
329 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
333 expected = this->parsePoints({
"0,0"});
334 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
337 expected = this->parsePoints({
"0,1"});
338 if (this->isFlowEncoding()) {
340 storm::exceptions::InvalidOperationException);
342 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
346 expected = this->parsePoints({
"0,1,0",
"2,1,1"});
347 if (this->isFlowEncoding()) {
349 storm::exceptions::InvalidOperationException);
351 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
355 if (this->isFlowEncoding()) {
358 storm::exceptions::InvalidOperationException);
361 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
362 EXPECT_TRUE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
367 if (this->isFlowEncoding()) {
370 storm::exceptions::InvalidOperationException);
373 ASSERT_TRUE(result->isExplicitQualitativeCheckResult());
374 EXPECT_FALSE(result->asExplicitQualitativeCheckResult()[*mdp->getInitialStates().begin()]);
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]);";
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;
396 std::vector<Point> expected;
400 uint64_t formulaIndex = 0;
401 expected = this->parsePoints({
"1,0",
"0,1",
"0.3,3/7"});
402 if (this->isFlowEncoding()) {
404 storm::exceptions::InvalidOperationException);
406 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
410 expected = this->parsePoints({
"0,0.3",
"2,1"});
411 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
414 expected = this->parsePoints({
"1,0,0",
"0,1,0",
"0.3,3/7,4/7"});
415 if (this->isFlowEncoding()) {
417 storm::exceptions::InvalidOperationException);
419 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
423 expected = this->parsePoints({
"0,1,0",
"0,3/7,4/7"});
424 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
426 env = this->getGoalDeterministicEnvironment();
429 expected = this->parsePoints({
"1,1"});
430 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
433 expected = this->parsePoints({
"0,0.3",
"2,1"});
434 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
437 expected = this->parsePoints({
"1,1,0",
"1,3/7,4/7"});
438 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
441 expected = this->parsePoints({
"0,1,0",
"0,3/7,4/7"});
442 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
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 ]);";
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;
459 std::vector<Point> expected;
463 uint64_t formulaIndex = 0;
464 expected = this->parsePoints({
"10,1"});
465 if (this->isFlowEncoding()) {
467 storm::exceptions::InvalidOperationException);
469 EXPECT_TRUE(this->testParetoFormula(env, mdp, *formulas[formulaIndex], expected, errorString)) << errorString;
472 env = this->getGoalDeterministicEnvironment();
475 expected = this->parsePoints({
"0,1"});
476 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)
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)