Browse Source
Minor improvements everywhere. Also implemented some tests
Minor improvements everywhere. Also implemented some tests
Former-commit-id: be74e5f459
tempestpy_adaptions
TimQu
10 years ago
16 changed files with 832 additions and 82 deletions
-
7examples/pdtmc/brp_rewards/brp256-5.sh
-
150examples/pdtmc/brp_rewards/brp_16_2.pm
-
8src/modelchecker/region/ApproximationModel.cpp
-
45src/modelchecker/region/ParameterRegion.cpp
-
14src/modelchecker/region/ParameterRegion.h
-
8src/modelchecker/region/SamplingModel.cpp
-
78src/modelchecker/region/SparseDtmcRegionModelChecker.cpp
-
35src/modelchecker/region/SparseDtmcRegionModelChecker.h
-
4src/settings/SettingsManager.cpp
-
8src/settings/SettingsManager.h
-
32src/settings/modules/RegionSettings.cpp
-
20src/settings/modules/RegionSettings.h
-
25src/utility/regions.cpp
-
9src/utility/regions.h
-
468test/functional/modelchecker/SparseDtmcRegionModelCheckerTest.cpp
-
3test/functional/storm-functional-tests.cpp
@ -0,0 +1,7 @@ |
|||
#!/bin/bash |
|||
|
|||
smtcommand=$(cat smtcommand.txt) |
|||
|
|||
/home/tim/git/storm/build/storm -s "/home/tim/git/paramagic/benchmarkfiles/pdtmc/brp/brp_256-5.pm" --prop 'P<0.5 [F "target"]' --parametric --parametricRegion --smt2:exportscript "/home/tim/Desktop/smtlibcommand.smt2" --smt2:solvercommand "$smtcommand" --region:regionfile /home/tim/Desktop/brpRegions.txt $1 |
|||
|
|||
|
@ -0,0 +1,150 @@ |
|||
// bounded retransmission protocol [D'AJJL01] |
|||
// gxn/dxp 23/05/2001 |
|||
|
|||
dtmc |
|||
|
|||
// number of chunks |
|||
const int N = 16; |
|||
// maximum number of retransmissions |
|||
const int MAX = 2; |
|||
|
|||
// reliability of channels |
|||
const double pL; |
|||
const double pK; |
|||
|
|||
// timeouts |
|||
const double TOMsg; |
|||
const double TOAck; |
|||
|
|||
module sender |
|||
|
|||
s : [0..6]; |
|||
// 0 idle |
|||
// 1 next_frame |
|||
// 2 wait_ack |
|||
// 3 retransmit |
|||
// 4 success |
|||
// 5 error |
|||
// 6 wait sync |
|||
srep : [0..3]; |
|||
// 0 bottom |
|||
// 1 not ok (nok) |
|||
// 2 do not know (dk) |
|||
// 3 ok (ok) |
|||
nrtr : [0..MAX]; |
|||
i : [0..N]; |
|||
bs : bool; |
|||
s_ab : bool; |
|||
fs : bool; |
|||
ls : bool; |
|||
|
|||
// idle |
|||
[NewFile] (s=0) -> (s'=1) & (i'=1) & (srep'=0); |
|||
// next_frame |
|||
[aF] (s=1) -> (s'=2) & (fs'=(i=1)) & (ls'=(i=N)) & (bs'=s_ab) & (nrtr'=0); |
|||
// wait_ack |
|||
[aB] (s=2) -> (s'=4) & (s_ab'=!s_ab); |
|||
[TO_Msg] (s=2) -> (s'=3); |
|||
[TO_Ack] (s=2) -> (s'=3); |
|||
// retransmit |
|||
[aF] (s=3) & (nrtr<MAX) -> (s'=2) & (fs'=(i=1)) & (ls'=(i=N)) & (bs'=s_ab) & (nrtr'=nrtr+1); |
|||
[] (s=3) & (nrtr=MAX) & (i<N) -> (s'=5) & (srep'=1); |
|||
[] (s=3) & (nrtr=MAX) & (i=N) -> (s'=5) & (srep'=2); |
|||
// success |
|||
[] (s=4) & (i<N) -> (s'=1) & (i'=i+1); |
|||
[] (s=4) & (i=N) -> (s'=0) & (srep'=3); |
|||
// error |
|||
[SyncWait] (s=5) -> (s'=6); |
|||
// wait sync |
|||
[SyncWait] (s=6) -> (s'=0) & (s_ab'=false); |
|||
|
|||
endmodule |
|||
|
|||
module receiver |
|||
|
|||
r : [0..5]; |
|||
// 0 new_file |
|||
// 1 fst_safe |
|||
// 2 frame_received |
|||
// 3 frame_reported |
|||
// 4 idle |
|||
// 5 resync |
|||
rrep : [0..4]; |
|||
// 0 bottom |
|||
// 1 fst |
|||
// 2 inc |
|||
// 3 ok |
|||
// 4 nok |
|||
fr : bool; |
|||
lr : bool; |
|||
br : bool; |
|||
r_ab : bool; |
|||
recv : bool; |
|||
|
|||
|
|||
// new_file |
|||
[SyncWait] (r=0) -> (r'=0); |
|||
[aG] (r=0) -> (r'=1) & (fr'=fs) & (lr'=ls) & (br'=bs) & (recv'=T); |
|||
// fst_safe_frame |
|||
[] (r=1) -> (r'=2) & (r_ab'=br); |
|||
// frame_received |
|||
[] (r=2) & (r_ab=br) & (fr=true) & (lr=false) -> (r'=3) & (rrep'=1); |
|||
[] (r=2) & (r_ab=br) & (fr=false) & (lr=false) -> (r'=3) & (rrep'=2); |
|||
[] (r=2) & (r_ab=br) & (fr=false) & (lr=true) -> (r'=3) & (rrep'=3); |
|||
[aA] (r=2) & !(r_ab=br) -> (r'=4); |
|||
// frame_reported |
|||
[aA] (r=3) -> (r'=4) & (r_ab'=!r_ab); |
|||
// idle |
|||
[aG] (r=4) -> (r'=2) & (fr'=fs) & (lr'=ls) & (br'=bs) & (recv'=T); |
|||
[SyncWait] (r=4) & (ls=true) -> (r'=5); |
|||
[SyncWait] (r=4) & (ls=false) -> (r'=5) & (rrep'=4); |
|||
// resync |
|||
[SyncWait] (r=5) -> (r'=0) & (rrep'=0); |
|||
|
|||
endmodule |
|||
|
|||
// prevents more than one file being sent |
|||
module tester |
|||
|
|||
T : bool; |
|||
|
|||
[NewFile] (T=false) -> (T'=true); |
|||
|
|||
endmodule |
|||
|
|||
module channelK |
|||
|
|||
k : [0..2]; |
|||
|
|||
// idle |
|||
[aF] (k=0) -> pK : (k'=1) + 1-pK : (k'=2); |
|||
// sending |
|||
[aG] (k=1) -> (k'=0); |
|||
// lost |
|||
[TO_Msg] (k=2) -> (k'=0); |
|||
|
|||
endmodule |
|||
|
|||
module channelL |
|||
|
|||
l : [0..2]; |
|||
|
|||
// idle |
|||
[aA] (l=0) -> pL : (l'=1) + 1-pL : (l'=2); |
|||
// sending |
|||
[aB] (l=1) -> (l'=0); |
|||
// lost |
|||
[TO_Ack] (l=2) -> (l'=0); |
|||
|
|||
endmodule |
|||
|
|||
rewards |
|||
[TO_Msg] true : TOMsg; |
|||
[TO_Ack] true : TOAck; |
|||
endrewards |
|||
|
|||
label "error" = s=5; |
|||
label "success" = (s=0) & (srep=3); |
|||
label "target" = (s=5) | (s=0 & srep=3); |
|||
|
|||
|
@ -0,0 +1,468 @@ |
|||
#include "gtest/gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#ifdef STORM_HAVE_CARL
|
|||
|
|||
#include "src/adapters/CarlAdapter.h"
|
|||
|
|||
#include "src/settings/SettingsManager.h"
|
|||
#include "src/settings/modules/GeneralSettings.h"
|
|||
#include "src/settings/modules/RegionSettings.h"
|
|||
|
|||
#include "src/models/sparse/Dtmc.h"
|
|||
#include "src/parser/PrismParser.h"
|
|||
#include "src/parser/FormulaParser.h"
|
|||
#include "src/logic/Formulas.h"
|
|||
#include "src/models/ModelBase.h"
|
|||
#include "src/models/sparse/Model.h"
|
|||
#include "src/models/sparse/Dtmc.h"
|
|||
#include "builder/ExplicitPrismModelBuilder.h"
|
|||
#include "modelchecker/region/SparseDtmcRegionModelChecker.h"
|
|||
#include "modelchecker/region/ParameterRegion.h"
|
|||
|
|||
TEST(SparseDtmcRegionModelCheckerTest, Brp_Prob) { |
|||
|
|||
std::string const& programFile = STORM_CPP_BASE_PATH "/examples/pdtmc/brp/brp_16_2.pm"; |
|||
std::string const& formulaAsString = "P<=0.85 [F \"target\" ]"; |
|||
std::string const& constantsAsString = ""; //e.g. pL=0.9,TOACK=0.5
|
|||
bool const buildRewards = false; |
|||
std::string const& rewardModelName = ""; |
|||
|
|||
//Build model, formula, region model checker
|
|||
boost::optional<storm::prism::Program> program=storm::parser::PrismParser::parse(programFile).simplify().simplify(); |
|||
program->checkValidity(); |
|||
storm::parser::FormulaParser formulaParser(program.get().getManager().getSharedPointer()); |
|||
boost::optional<std::shared_ptr<storm::logic::Formula>> formula = formulaParser.parseFromString(formulaAsString); |
|||
typename storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options options=storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options(*formula.get()); |
|||
options.addConstantDefinitionsFromString(program.get(), constantsAsString); |
|||
options.buildRewards = buildRewards; |
|||
if (buildRewards) options.rewardModelName = rewardModelName; |
|||
std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model = storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::translateProgram(program.get(), options)->as<storm::models::sparse::Model<storm::RationalFunction>>(); |
|||
ASSERT_EQ(storm::models::ModelType::Dtmc, model->getType()); |
|||
std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc = model->template as<storm::models::sparse::Dtmc<storm::RationalFunction>>(); |
|||
storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double> modelchecker(*dtmc); |
|||
ASSERT_TRUE(modelchecker.canHandle(*formula.get())); |
|||
modelchecker.specifyFormula(formula.get()); |
|||
|
|||
//start testing
|
|||
auto allSatRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.7<=pL<=0.9,0.75<=pK<=0.95"); |
|||
auto exBothRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.4<=pL<=0.65,0.75<=pK<=0.95"); |
|||
auto allVioRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=pL<=0.9,0.2<=pK<=0.5"); |
|||
|
|||
EXPECT_NEAR(0.8369631407, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(0.8369631407, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.0476784174, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.0476784174, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.9987948367, modelchecker.getReachabilityValue<double>(exBothRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(0.9987948367, modelchecker.getReachabilityValue<double>(exBothRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.6020480995, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.6020480995, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(1.0000000000, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(1.0000000000, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.9456084185, modelchecker.getReachabilityValue<double>(allVioRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.9456084185, modelchecker.getReachabilityValue<double>(allVioRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
|
|||
//test approximative method
|
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::INSTANTIATE, storm::settings::modules::RegionSettings::SmtMode::OFF); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegion.getCheckResult()); |
|||
modelchecker.checkRegion(exBothRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegion.getCheckResult()); |
|||
modelchecker.checkRegion(allVioRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegion.getCheckResult()); |
|||
|
|||
//test smt method (the regions need to be created again, because the old ones have some information stored in their internal state)
|
|||
auto allSatRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.7<=pL<=0.9,0.75<=pK<=0.95"); |
|||
auto exBothRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.4<=pL<=0.65,0.75<=pK<=0.95"); |
|||
auto allVioRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=pL<=0.9,0.2<=pK<=0.5"); |
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::OFF, storm::settings::modules::RegionSettings::SampleMode::EVALUATE, storm::settings::modules::RegionSettings::SmtMode::FUNCTION); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(exBothRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(allVioRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegionSmt.getCheckResult());
|
|||
|
|||
storm::settings::mutableRegionSettings().resetModes(); |
|||
} |
|||
|
|||
TEST(SparseDtmcRegionModelCheckerTest, Brp_Rew) { |
|||
|
|||
std::string const& programFile = STORM_CPP_BASE_PATH "/examples/pdtmc/brp_rewards/brp_16_2.pm"; |
|||
std::string const& formulaAsString = "R>2.5 [F \"target\" ]"; |
|||
std::string const& constantsAsString = "pL=0.9,TOAck=0.5"; |
|||
bool const buildRewards = true; |
|||
std::string const& rewardModelName = ""; |
|||
|
|||
//Build model, formula, region model checker
|
|||
boost::optional<storm::prism::Program> program=storm::parser::PrismParser::parse(programFile).simplify().simplify(); |
|||
program->checkValidity(); |
|||
storm::parser::FormulaParser formulaParser(program.get().getManager().getSharedPointer()); |
|||
boost::optional<std::shared_ptr<storm::logic::Formula>> formula = formulaParser.parseFromString(formulaAsString); |
|||
typename storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options options=storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options(*formula.get()); |
|||
options.addConstantDefinitionsFromString(program.get(), constantsAsString); |
|||
options.buildRewards = buildRewards; |
|||
if (buildRewards) options.rewardModelName = rewardModelName; |
|||
std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model = storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::translateProgram(program.get(), options)->as<storm::models::sparse::Model<storm::RationalFunction>>(); |
|||
ASSERT_EQ(storm::models::ModelType::Dtmc, model->getType()); |
|||
std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc = model->template as<storm::models::sparse::Dtmc<storm::RationalFunction>>(); |
|||
storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double> modelchecker(*dtmc); |
|||
ASSERT_TRUE(modelchecker.canHandle(*formula.get())); |
|||
modelchecker.specifyFormula(formula.get()); |
|||
|
|||
//start testing
|
|||
auto allSatRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.7<=pK<=0.875,0.75<=TOMsg<=0.95"); |
|||
auto exBothRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.6<=pK<=0.9,0.5<=TOMsg<=0.95"); |
|||
auto exBothHardRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.5<=pK<=0.75,0.3<=TOMsg<=0.4"); //this region has a local maximum!
|
|||
auto allVioRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=pK<=0.3,0.2<=TOMsg<=0.3"); |
|||
|
|||
EXPECT_NEAR(4.367791292, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(4.367791292, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(3.044795147, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(3.044795147, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(3.182535759, modelchecker.getReachabilityValue<double>(exBothRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(3.182535759, modelchecker.getReachabilityValue<double>(exBothRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(2.609602197, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(2.609602197, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(1.842551039, modelchecker.getReachabilityValue<double>(exBothHardRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(1.842551039, modelchecker.getReachabilityValue<double>(exBothHardRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(2.453500364, modelchecker.getReachabilityValue<double>(exBothHardRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(2.453500364, modelchecker.getReachabilityValue<double>(exBothHardRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.6721974438, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(0.6721974438, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(1.308324558, modelchecker.getReachabilityValue<double>(allVioRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(1.308324558, modelchecker.getReachabilityValue<double>(allVioRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
|
|||
//test approximative method
|
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::INSTANTIATE, storm::settings::modules::RegionSettings::SmtMode::OFF); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegion.getCheckResult()); |
|||
modelchecker.checkRegion(exBothRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegion.getCheckResult()); |
|||
modelchecker.checkRegion(exBothHardRegion); |
|||
//At this moment, Approximation should not be able to get a result for this region. (However, it is not wrong if it can)
|
|||
EXPECT_TRUE( |
|||
(exBothHardRegion.getCheckResult()==(storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH)) || |
|||
(exBothHardRegion.getCheckResult()==(storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSVIOLATED)) |
|||
); |
|||
modelchecker.checkRegion(allVioRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegion.getCheckResult()); |
|||
|
|||
//test smt method (the regions need to be created again, because the old ones have some information stored in their internal state)
|
|||
auto allSatRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.7<=pK<=0.9,0.75<=TOMsg<=0.95"); |
|||
auto exBothRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.3<=pK<=0.5,0.5<=TOMsg<=0.75"); |
|||
auto exBothHardRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.5<=pK<=0.75,0.3<=TOMsg<=0.4"); //this region has a local maximum!
|
|||
auto allVioRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=pK<=0.3,0.2<=TOMsg<=0.3"); |
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::OFF, storm::settings::modules::RegionSettings::SampleMode::EVALUATE, storm::settings::modules::RegionSettings::SmtMode::FUNCTION); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(exBothRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(exBothHardRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothHardRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(allVioRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegionSmt.getCheckResult());
|
|||
|
|||
//test smt + approx
|
|||
auto exBothHardRegionSmtApp=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.5<=pK<=0.75,0.3<=TOMsg<=0.4"); //this region has a local maximum!
|
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::EVALUATE, storm::settings::modules::RegionSettings::SmtMode::FUNCTION); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(exBothHardRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothHardRegionSmtApp.getCheckResult());
|
|||
|
|||
|
|||
storm::settings::mutableRegionSettings().resetModes(); |
|||
} |
|||
|
|||
TEST(SparseDtmcRegionModelCheckerTest, Brp_Rew_4Par) { |
|||
|
|||
std::string const& programFile = STORM_CPP_BASE_PATH "/examples/pdtmc/brp_rewards/brp_16_2.pm"; |
|||
std::string const& formulaAsString = "R>2.5 [F \"target\" ]"; |
|||
std::string const& constantsAsString = ""; //!! this model will have 4 parameters
|
|||
bool const buildRewards = true; |
|||
std::string const& rewardModelName = ""; |
|||
|
|||
//Build model, formula, region model checker
|
|||
boost::optional<storm::prism::Program> program=storm::parser::PrismParser::parse(programFile).simplify().simplify(); |
|||
program->checkValidity(); |
|||
storm::parser::FormulaParser formulaParser(program.get().getManager().getSharedPointer()); |
|||
boost::optional<std::shared_ptr<storm::logic::Formula>> formula = formulaParser.parseFromString(formulaAsString); |
|||
typename storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options options=storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options(*formula.get()); |
|||
options.addConstantDefinitionsFromString(program.get(), constantsAsString); |
|||
options.buildRewards = buildRewards; |
|||
if (buildRewards) options.rewardModelName = rewardModelName; |
|||
std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model = storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::translateProgram(program.get(), options)->as<storm::models::sparse::Model<storm::RationalFunction>>(); |
|||
ASSERT_EQ(storm::models::ModelType::Dtmc, model->getType()); |
|||
std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc = model->template as<storm::models::sparse::Dtmc<storm::RationalFunction>>(); |
|||
storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double> modelchecker(*dtmc); |
|||
ASSERT_TRUE(modelchecker.canHandle(*formula.get())); |
|||
modelchecker.specifyFormula(formula.get()); |
|||
|
|||
//start testing
|
|||
auto allSatRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.7<=pK<=0.9,0.6<=pL<=0.85,0.9<=TOMsg<=0.95,0.85<=TOAck<=0.9"); |
|||
auto exBothRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=pK<=0.7,0.2<=pL<=0.8,0.15<=TOMsg<=0.65,0.3<=TOAck<=0.9"); |
|||
auto allVioRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=pK<=0.4,0.2<=pL<=0.3,0.15<=TOMsg<=0.3,0.1<=TOAck<=0.2"); |
|||
|
|||
EXPECT_NEAR(4.834779705, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(4.834779705, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(4.674651623, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(4.674651623, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.4467496536, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(0.4467496536, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
|
|||
//test approximative method
|
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::INSTANTIATE, storm::settings::modules::RegionSettings::SmtMode::OFF); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegion.getCheckResult()); |
|||
modelchecker.checkRegion(exBothRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegion.getCheckResult()); |
|||
modelchecker.checkRegion(allVioRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegion.getCheckResult()); |
|||
|
|||
//test smt method (the regions need to be created again, because the old ones have some information stored in their internal state)
|
|||
auto allSatRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.7<=pK<=0.9,0.6<=pL<=0.85,0.9<=TOMsg<=0.95,0.85<=TOAck<=0.9"); |
|||
auto exBothRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=pK<=0.7,0.2<=pL<=0.8,0.15<=TOMsg<=0.65,0.3<=TOAck<=0.9"); |
|||
auto allVioRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=pK<=0.4,0.2<=pL<=0.3,0.15<=TOMsg<=0.3,0.1<=TOAck<=0.2"); |
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::OFF, storm::settings::modules::RegionSettings::SampleMode::EVALUATE, storm::settings::modules::RegionSettings::SmtMode::FUNCTION); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(exBothRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(allVioRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegionSmt.getCheckResult());
|
|||
|
|||
storm::settings::mutableRegionSettings().resetModes(); |
|||
} |
|||
|
|||
TEST(SparseDtmcRegionModelCheckerTest, Crowds_Prob) { |
|||
|
|||
std::string const& programFile = STORM_CPP_BASE_PATH "/examples/pdtmc/crowds/crowds_3-5.pm"; |
|||
std::string const& formulaAsString = "P<0.5 [F \"observe0Greater1\" ]"; |
|||
std::string const& constantsAsString = ""; //e.g. pL=0.9,TOACK=0.5
|
|||
bool const buildRewards = false; |
|||
std::string const& rewardModelName = ""; |
|||
|
|||
//Build model, formula, region model checker
|
|||
boost::optional<storm::prism::Program> program=storm::parser::PrismParser::parse(programFile).simplify().simplify(); |
|||
program->checkValidity(); |
|||
storm::parser::FormulaParser formulaParser(program.get().getManager().getSharedPointer()); |
|||
boost::optional<std::shared_ptr<storm::logic::Formula>> formula = formulaParser.parseFromString(formulaAsString); |
|||
typename storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options options=storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options(*formula.get()); |
|||
options.addConstantDefinitionsFromString(program.get(), constantsAsString); |
|||
options.buildRewards = buildRewards; |
|||
if (buildRewards) options.rewardModelName = rewardModelName; |
|||
std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model = storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::translateProgram(program.get(), options)->as<storm::models::sparse::Model<storm::RationalFunction>>(); |
|||
ASSERT_EQ(storm::models::ModelType::Dtmc, model->getType()); |
|||
std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc = model->template as<storm::models::sparse::Dtmc<storm::RationalFunction>>(); |
|||
storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double> modelchecker(*dtmc); |
|||
ASSERT_TRUE(modelchecker.canHandle(*formula.get())); |
|||
modelchecker.specifyFormula(formula.get()); |
|||
|
|||
//start testing
|
|||
auto allSatRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=PF<=0.75,0.15<=badC<=0.2"); |
|||
auto exBothRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.75<=PF<=0.8,0.2<=badC<=0.3"); |
|||
auto allVioRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.8<=PF<=0.95,0.2<=badC<=0.2"); |
|||
auto allVioHardRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.8<=PF<=0.95,0.2<=badC<=0.9"); |
|||
|
|||
EXPECT_NEAR(0.1734086422, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(0.1734086422, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.47178, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.47178, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.7085157883, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.7085157883, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.5095205203, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(0.5095205203, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.6819701472, modelchecker.getReachabilityValue<double>(allVioRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(0.6819701472, modelchecker.getReachabilityValue<double>(allVioRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.999895897, modelchecker.getReachabilityValue<double>(allVioHardRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.999895897, modelchecker.getReachabilityValue<double>(allVioHardRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
|
|||
//test approximative method
|
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::INSTANTIATE, storm::settings::modules::RegionSettings::SmtMode::OFF); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegion.getCheckResult()); |
|||
modelchecker.checkRegion(exBothRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegion.getCheckResult()); |
|||
modelchecker.checkRegion(allVioRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegion.getCheckResult()); |
|||
modelchecker.checkRegion(allVioHardRegion); |
|||
//At this moment, Approximation should not be able to get a result for this region. (However, it is not wrong if it can)
|
|||
EXPECT_TRUE( |
|||
(allVioHardRegion.getCheckResult()==(storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED)) || |
|||
(allVioHardRegion.getCheckResult()==(storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSVIOLATED)) |
|||
); |
|||
|
|||
//test smt method (the regions need to be created again, because the old ones have some information stored in their internal state)
|
|||
auto allSatRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.1<=PF<=0.75,0.15<=badC<=0.2"); |
|||
auto exBothRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.75<=PF<=0.8,0.2<=badC<=0.3"); |
|||
auto allVioRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.8<=PF<=0.95,0.2<=badC<=0.2"); |
|||
auto allVioHardRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.8<=PF<=0.95,0.2<=badC<=0.9"); |
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::OFF, storm::settings::modules::RegionSettings::SampleMode::EVALUATE, storm::settings::modules::RegionSettings::SmtMode::FUNCTION); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(exBothRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(allVioRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(allVioHardRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioHardRegionSmt.getCheckResult());
|
|||
|
|||
//test smt + approx
|
|||
auto allVioHardRegionSmtApp=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.8<=PF<=0.95,0.2<=badC<=0.9"); |
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::EVALUATE, storm::settings::modules::RegionSettings::SmtMode::FUNCTION); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allVioHardRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioHardRegionSmtApp.getCheckResult());
|
|||
|
|||
storm::settings::mutableRegionSettings().resetModes(); |
|||
} |
|||
|
|||
TEST(SparseDtmcRegionModelCheckerTest, Crowds_Prob_1Par) { |
|||
|
|||
std::string const& programFile = STORM_CPP_BASE_PATH "/examples/pdtmc/crowds/crowds_3-5.pm"; |
|||
std::string const& formulaAsString = "P>0.75 [F \"observe0Greater1\" ]"; |
|||
std::string const& constantsAsString = "badC=0.3"; //e.g. pL=0.9,TOACK=0.5
|
|||
bool const buildRewards = false; |
|||
std::string const& rewardModelName = ""; |
|||
|
|||
//Build model, formula, region model checker
|
|||
boost::optional<storm::prism::Program> program=storm::parser::PrismParser::parse(programFile).simplify().simplify(); |
|||
program->checkValidity(); |
|||
storm::parser::FormulaParser formulaParser(program.get().getManager().getSharedPointer()); |
|||
boost::optional<std::shared_ptr<storm::logic::Formula>> formula = formulaParser.parseFromString(formulaAsString); |
|||
typename storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options options=storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options(*formula.get()); |
|||
options.addConstantDefinitionsFromString(program.get(), constantsAsString); |
|||
options.buildRewards = buildRewards; |
|||
if (buildRewards) options.rewardModelName = rewardModelName; |
|||
std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model = storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::translateProgram(program.get(), options)->as<storm::models::sparse::Model<storm::RationalFunction>>(); |
|||
ASSERT_EQ(storm::models::ModelType::Dtmc, model->getType()); |
|||
std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc = model->template as<storm::models::sparse::Dtmc<storm::RationalFunction>>(); |
|||
storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double> modelchecker(*dtmc); |
|||
ASSERT_TRUE(modelchecker.canHandle(*formula.get())); |
|||
modelchecker.specifyFormula(formula.get()); |
|||
|
|||
//start testing
|
|||
auto allSatRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.9<=PF<=0.99"); |
|||
auto exBothRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.8<=PF<=0.9"); |
|||
auto allVioRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.01<=PF<=0.8"); |
|||
|
|||
EXPECT_NEAR(0.8430128158, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.8430128158, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.7731321947, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.7731321947, modelchecker.getReachabilityValue<double>(exBothRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.4732302663, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(0.4732302663, modelchecker.getReachabilityValue<double>(allVioRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.7085157883, modelchecker.getReachabilityValue<double>(allVioRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //instantiation of sampling model
|
|||
EXPECT_NEAR(0.7085157883, modelchecker.getReachabilityValue<double>(allVioRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
|
|||
//test approximative method
|
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::INSTANTIATE, storm::settings::modules::RegionSettings::SmtMode::OFF); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegion.getCheckResult()); |
|||
modelchecker.checkRegion(exBothRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegion.getCheckResult()); |
|||
modelchecker.checkRegion(allVioRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegion.getCheckResult()); |
|||
|
|||
//test smt method (the regions need to be created again, because the old ones have some information stored in their internal state)
|
|||
auto allSatRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.9<=PF<=0.99"); |
|||
auto exBothRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.8<=PF<=0.9"); |
|||
auto allVioRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion("0.01<=PF<=0.8"); |
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::OFF, storm::settings::modules::RegionSettings::SampleMode::EVALUATE, storm::settings::modules::RegionSettings::SmtMode::FUNCTION); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(exBothRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::EXISTSBOTH), exBothRegionSmt.getCheckResult());
|
|||
modelchecker.checkRegion(allVioRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLVIOLATED), allVioRegionSmt.getCheckResult());
|
|||
|
|||
storm::settings::mutableRegionSettings().resetModes(); |
|||
} |
|||
|
|||
TEST(SparseDtmcRegionModelCheckerTest, Crowds_Prob_Const) { |
|||
|
|||
std::string const& programFile = STORM_CPP_BASE_PATH "/examples/pdtmc/crowds/crowds_3-5.pm"; |
|||
std::string const& formulaAsString = "P>0.6 [F \"observe0Greater1\" ]"; |
|||
std::string const& constantsAsString = "PF=0.9,badC=0.2"; |
|||
bool const buildRewards = false; |
|||
std::string const& rewardModelName = ""; |
|||
|
|||
//Build model, formula, region model checker
|
|||
boost::optional<storm::prism::Program> program=storm::parser::PrismParser::parse(programFile).simplify().simplify(); |
|||
program->checkValidity(); |
|||
storm::parser::FormulaParser formulaParser(program.get().getManager().getSharedPointer()); |
|||
boost::optional<std::shared_ptr<storm::logic::Formula>> formula = formulaParser.parseFromString(formulaAsString); |
|||
typename storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options options=storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::Options(*formula.get()); |
|||
options.addConstantDefinitionsFromString(program.get(), constantsAsString); |
|||
options.buildRewards = buildRewards; |
|||
if (buildRewards) options.rewardModelName = rewardModelName; |
|||
std::shared_ptr<storm::models::sparse::Model<storm::RationalFunction>> model = storm::builder::ExplicitPrismModelBuilder<storm::RationalFunction>::translateProgram(program.get(), options)->as<storm::models::sparse::Model<storm::RationalFunction>>(); |
|||
ASSERT_EQ(storm::models::ModelType::Dtmc, model->getType()); |
|||
std::shared_ptr<storm::models::sparse::Dtmc<storm::RationalFunction>> dtmc = model->template as<storm::models::sparse::Dtmc<storm::RationalFunction>>(); |
|||
storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double> modelchecker(*dtmc); |
|||
ASSERT_TRUE(modelchecker.canHandle(*formula.get())); |
|||
modelchecker.specifyFormula(formula.get()); |
|||
|
|||
//start testing
|
|||
auto allSatRegion=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion(""); |
|||
|
|||
EXPECT_NEAR(0.6119660237, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.6119660237, modelchecker.getReachabilityValue<double>(allSatRegion.getUpperBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.6119660237, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), false), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
EXPECT_NEAR(0.6119660237, modelchecker.getReachabilityValue<double>(allSatRegion.getLowerBounds(), true), storm::settings::generalSettings().getPrecision()); //evaluation of function
|
|||
|
|||
//test approximative method
|
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::TESTFIRST, storm::settings::modules::RegionSettings::SampleMode::INSTANTIATE, storm::settings::modules::RegionSettings::SmtMode::OFF); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegion); |
|||
EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegion.getCheckResult()); |
|||
|
|||
//test smt method (the regions need to be created again, because the old ones have some information stored in their internal state)
|
|||
auto allSatRegionSmt=storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::ParameterRegion::parseRegion(""); |
|||
storm::settings::mutableRegionSettings().modifyModes(storm::settings::modules::RegionSettings::ApproxMode::OFF, storm::settings::modules::RegionSettings::SampleMode::EVALUATE, storm::settings::modules::RegionSettings::SmtMode::FUNCTION); |
|||
ASSERT_FALSE(storm::settings::regionSettings().doApprox()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSample()); |
|||
ASSERT_TRUE(storm::settings::regionSettings().doSmt()); |
|||
modelchecker.checkRegion(allSatRegionSmt); |
|||
//smt EXPECT_EQ((storm::modelchecker::SparseDtmcRegionModelChecker<storm::RationalFunction, double>::RegionCheckResult::ALLSAT), allSatRegionSmt.getCheckResult());
|
|||
|
|||
storm::settings::mutableRegionSettings().resetModes(); |
|||
} |
|||
|
|||
#endif
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue