You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
8.4 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #ifdef STORM_HAVE_CARL
  4. #include "src/adapters/CarlAdapter.h"
  5. #include "src/settings/SettingsManager.h"
  6. #include "src/settings/modules/GeneralSettings.h"
  7. #include "src/settings/modules/RegionSettings.h"
  8. #include "utility/storm.h"
  9. #include "src/models/sparse/Model.h"
  10. #include "modelchecker/region/AbstractSparseRegionModelChecker.h"
  11. #include "modelchecker/region/ParameterRegion.h"
  12. TEST(SparseMdpRegionModelCheckerTest, two_dice_Prob) {
  13. std::string const& programFile = STORM_CPP_BASE_PATH "/examples/pmdp/two_dice/two_dice.nm";
  14. std::string const& formulaFile = STORM_CPP_BASE_PATH "/examples/pmdp/two_dice/two_dice.prctl"; //P<=0.17 [F \"doubles\" ]";
  15. std::string const& constantsAsString = ""; //e.g. pL=0.9,TOACK=0.5
  16. std::shared_ptr<storm::modelchecker::region::AbstractSparseRegionModelChecker<storm::models::sparse::Model<storm::RationalFunction>, double>> modelchecker;
  17. ASSERT_TRUE(storm::initializeRegionModelChecker(modelchecker, programFile, formulaFile, constantsAsString));
  18. auto allSatRegion=storm::modelchecker::region::ParameterRegion<storm::RationalFunction>::parseRegion("0.495<=p1<=0.5,0.5<=p2<=0.505");
  19. auto exBothRegion=storm::modelchecker::region::ParameterRegion<storm::RationalFunction>::parseRegion("0.45<=p1<=0.55,0.45<=p2<=0.55");
  20. auto allVioRegion=storm::modelchecker::region::ParameterRegion<storm::RationalFunction>::parseRegion("0.6<=p1<=0.7,0.6<=p2<=0.6");
  21. EXPECT_TRUE(modelchecker->checkFormulaOnSamplingPoint(allSatRegion.getSomePoint()));
  22. EXPECT_FALSE(modelchecker->checkFormulaOnSamplingPoint(allVioRegion.getSomePoint()));
  23. //Test the methods provided in storm.h
  24. EXPECT_TRUE(storm::checkSamplingPoint(modelchecker,allSatRegion.getLowerBoundaries()));
  25. EXPECT_TRUE(storm::checkSamplingPoint(modelchecker,allSatRegion.getUpperBoundaries()));
  26. EXPECT_FALSE(storm::checkSamplingPoint(modelchecker,exBothRegion.getLowerBoundaries()));
  27. EXPECT_FALSE(storm::checkSamplingPoint(modelchecker,exBothRegion.getUpperBoundaries()));
  28. EXPECT_TRUE(storm::checkSamplingPoint(modelchecker,exBothRegion.getVerticesOfRegion(exBothRegion.getVariables())[1]));
  29. EXPECT_TRUE(storm::checkSamplingPoint(modelchecker,exBothRegion.getVerticesOfRegion(exBothRegion.getVariables())[2]));
  30. EXPECT_FALSE(storm::checkSamplingPoint(modelchecker,exBothRegion.getUpperBoundaries()));
  31. EXPECT_FALSE(storm::checkSamplingPoint(modelchecker,allVioRegion.getLowerBoundaries()));
  32. EXPECT_FALSE(storm::checkSamplingPoint(modelchecker,allVioRegion.getUpperBoundaries()));
  33. EXPECT_TRUE(storm::checkRegionApproximation(modelchecker, allSatRegion.getLowerBoundaries(), allSatRegion.getUpperBoundaries(), true));
  34. EXPECT_FALSE(storm::checkRegionApproximation(modelchecker, allSatRegion.getLowerBoundaries(), allSatRegion.getUpperBoundaries(), false));
  35. EXPECT_FALSE(storm::checkRegionApproximation(modelchecker, exBothRegion.getLowerBoundaries(), exBothRegion.getUpperBoundaries(), true));
  36. EXPECT_FALSE(storm::checkRegionApproximation(modelchecker, exBothRegion.getLowerBoundaries(), exBothRegion.getUpperBoundaries(), false));
  37. EXPECT_FALSE(storm::checkRegionApproximation(modelchecker, allVioRegion.getLowerBoundaries(), allVioRegion.getUpperBoundaries(), true));
  38. EXPECT_TRUE(storm::checkRegionApproximation(modelchecker, allVioRegion.getLowerBoundaries(), allVioRegion.getUpperBoundaries(), false));
  39. //Remaining tests..
  40. EXPECT_NEAR(0.1666665285, modelchecker->getReachabilityValue(allSatRegion.getLowerBoundaries()), storm::settings::generalSettings().getPrecision());
  41. EXPECT_NEAR(0.1666665529, modelchecker->getReachabilityValue(allSatRegion.getUpperBoundaries()), storm::settings::generalSettings().getPrecision());
  42. EXPECT_NEAR(0.1716553235, modelchecker->getReachabilityValue(exBothRegion.getLowerBoundaries()), storm::settings::generalSettings().getPrecision());
  43. EXPECT_NEAR(0.1709666953, modelchecker->getReachabilityValue(exBothRegion.getUpperBoundaries()), storm::settings::generalSettings().getPrecision());
  44. EXPECT_NEAR(0.1826972576, modelchecker->getReachabilityValue(allVioRegion.getLowerBoundaries()), storm::settings::generalSettings().getPrecision());
  45. EXPECT_NEAR(0.1964429282, modelchecker->getReachabilityValue(allVioRegion.getUpperBoundaries()), storm::settings::generalSettings().getPrecision());
  46. //test approximative method
  47. storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::INSTANTIATE, storm::settings::modules::RegionSettings::SmtMode::OFF);
  48. ASSERT_TRUE(storm::settings::regionSettings().doApprox());
  49. ASSERT_TRUE(storm::settings::regionSettings().doSample());
  50. ASSERT_FALSE(storm::settings::regionSettings().doSmt());
  51. modelchecker->checkRegion(allSatRegion);
  52. EXPECT_EQ((storm::modelchecker::region::RegionCheckResult::ALLSAT), allSatRegion.getCheckResult());
  53. modelchecker->checkRegion(exBothRegion);
  54. EXPECT_EQ((storm::modelchecker::region::RegionCheckResult::EXISTSBOTH), exBothRegion.getCheckResult());
  55. modelchecker->checkRegion(allVioRegion);
  56. EXPECT_EQ((storm::modelchecker::region::RegionCheckResult::ALLVIOLATED), allVioRegion.getCheckResult());
  57. storm::settings::mutableRegionSettings().resetModes();
  58. carl::VariablePool::getInstance().clear();
  59. }
  60. TEST(SparseMdpRegionModelCheckerTest, coin_Prob) {
  61. std::string const& programFile = STORM_CPP_BASE_PATH "/examples/pmdp/coin2/coin2_2.pm";
  62. std::string const& formulaAsString = "P>0.25 [F \"finished\"&\"all_coins_equal_1\" ]";
  63. std::string const& constantsAsString = ""; //e.g. pL=0.9,TOACK=0.5
  64. std::shared_ptr<storm::modelchecker::region::AbstractSparseRegionModelChecker<storm::models::sparse::Model<storm::RationalFunction>, double>> modelchecker;
  65. ASSERT_TRUE(storm::initializeRegionModelChecker(modelchecker, programFile, formulaAsString, constantsAsString));
  66. //start testing
  67. auto allSatRegion=storm::modelchecker::region::ParameterRegion<storm::RationalFunction>::parseRegion("0.3<=p1<=0.45,0.2<=p2<=0.54");
  68. auto exBothRegion=storm::modelchecker::region::ParameterRegion<storm::RationalFunction>::parseRegion("0.4<=p1<=0.65,0.5<=p2<=0.7");
  69. auto allVioRegion=storm::modelchecker::region::ParameterRegion<storm::RationalFunction>::parseRegion("0.4<=p1<=0.7,0.55<=p2<=0.6");
  70. EXPECT_TRUE(modelchecker->checkFormulaOnSamplingPoint(allSatRegion.getSomePoint()));
  71. EXPECT_FALSE(modelchecker->checkFormulaOnSamplingPoint(allVioRegion.getSomePoint()));
  72. EXPECT_NEAR(0.95128124239, modelchecker->getReachabilityValue(allSatRegion.getLowerBoundaries()), storm::settings::generalSettings().getPrecision());
  73. EXPECT_NEAR(0.26787251126, modelchecker->getReachabilityValue(allSatRegion.getUpperBoundaries()), storm::settings::generalSettings().getPrecision());
  74. EXPECT_NEAR(0.41880006098, modelchecker->getReachabilityValue(exBothRegion.getLowerBoundaries()), storm::settings::generalSettings().getPrecision());
  75. EXPECT_NEAR(0.01535089684, modelchecker->getReachabilityValue(exBothRegion.getUpperBoundaries()), storm::settings::generalSettings().getPrecision());
  76. EXPECT_NEAR(0.24952791523, modelchecker->getReachabilityValue(allVioRegion.getLowerBoundaries()), storm::settings::generalSettings().getPrecision());
  77. EXPECT_NEAR(0.01711494956, modelchecker->getReachabilityValue(allVioRegion.getUpperBoundaries()), storm::settings::generalSettings().getPrecision());
  78. //test approximative method
  79. storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::INSTANTIATE, storm::settings::modules::RegionSettings::SmtMode::OFF);
  80. ASSERT_TRUE(storm::settings::regionSettings().doApprox());
  81. ASSERT_TRUE(storm::settings::regionSettings().doSample());
  82. ASSERT_FALSE(storm::settings::regionSettings().doSmt());
  83. modelchecker->checkRegion(allSatRegion);
  84. EXPECT_EQ((storm::modelchecker::region::RegionCheckResult::ALLSAT), allSatRegion.getCheckResult());
  85. modelchecker->checkRegion(exBothRegion);
  86. EXPECT_EQ((storm::modelchecker::region::RegionCheckResult::EXISTSBOTH), exBothRegion.getCheckResult());
  87. modelchecker->checkRegion(allVioRegion);
  88. EXPECT_EQ((storm::modelchecker::region::RegionCheckResult::ALLVIOLATED), allVioRegion.getCheckResult());
  89. storm::settings::mutableRegionSettings().resetModes();
  90. carl::VariablePool::getInstance().clear();
  91. }
  92. #endif