Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DftApproximationTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
5#include "storm-dft/api/io.h"
14
15namespace {
16
17// Configurations for DFT approximation
18class ApproxDepthConfig {
19 public:
20 typedef double ValueType;
21
22 static storm::dft::DftEnvironment createEnvironment() {
23 storm::dft::DftEnvironment env;
26 env.analysis().setUseModularisation(false);
29 return env;
30 }
31};
32
33class ApproxProbabilityConfig {
34 public:
35 typedef double ValueType;
36
37 static storm::dft::DftEnvironment createEnvironment() {
38 storm::dft::DftEnvironment env;
41 env.analysis().setUseModularisation(false);
44 return env;
45 }
46};
47
48class ApproxBoundDifferenceConfig {
49 public:
50 typedef double ValueType;
51
52 static storm::dft::DftEnvironment createEnvironment() {
53 storm::dft::DftEnvironment env;
56 env.analysis().setUseModularisation(false);
59 return env;
60 }
61};
62
63// General base class for testing of DFT approximation
64template<typename TestType>
65class DftApproximationTest : public ::testing::Test {
66 public:
67 typedef typename TestType::ValueType ValueType;
68
69 DftApproximationTest() : _environment(TestType::createEnvironment()) {}
70
71 std::pair<double, double> analyzeMTTF(std::string const& file, double errorBound) const {
72 std::shared_ptr<storm::dft::storage::DFT<double>> dft =
74 EXPECT_TRUE(storm::dft::api::isWellFormed(*dft).first);
75 std::string property = "T=? [F \"failed\"]";
76 std::vector<std::shared_ptr<storm::logic::Formula const>> properties = storm::api::extractFormulasFromProperties(storm::api::parseProperties(property));
77 storm::dft::DftEnvironment env = this->env();
78 env.analysis().setApproximationError(errorBound);
80 storm::dft::api::analyzeDFT<double>(env, *dft, properties, storm::dft::utility::RelevantEvents());
81 return boost::get<storm::dft::modelchecker::DFTModelChecker<double>::approximation_result>(results[0]);
82 }
83
84 std::pair<double, double> analyzeTimebound(std::string const& file, double timeBound, double errorBound) const {
85 std::shared_ptr<storm::dft::storage::DFT<double>> dft =
87 EXPECT_TRUE(storm::dft::api::isWellFormed(*dft).first);
88 std::stringstream propertyStream;
89 propertyStream << "P=? [F<=" << timeBound << " \"failed\"]";
90 std::vector<std::shared_ptr<storm::logic::Formula const>> properties =
92 storm::dft::DftEnvironment env = this->env();
93 env.analysis().setApproximationError(errorBound);
95 storm::dft::api::analyzeDFT<double>(env, *dft, properties, storm::dft::utility::RelevantEvents());
96 return boost::get<storm::dft::modelchecker::DFTModelChecker<double>::approximation_result>(results[0]);
97 }
98
99 storm::dft::DftEnvironment const& env() const {
100 return _environment;
101 }
102
103 private:
104 storm::dft::DftEnvironment _environment;
105};
106
107typedef ::testing::Types<ApproxDepthConfig, ApproxProbabilityConfig, ApproxBoundDifferenceConfig> TestingTypes;
108
109TYPED_TEST_SUITE(DftApproximationTest, TestingTypes, );
110
111TYPED_TEST(DftApproximationTest, HecsMTTF) {
112 double errorBound = 2;
113 std::pair<double, double> approxResult = this->analyzeMTTF(STORM_TEST_RESOURCES_DIR "/dft/hecs_3_2_2_np.dft", errorBound);
114 EXPECT_LE(approxResult.first, 417.9436693);
115 EXPECT_GE(approxResult.second, 417.9436693);
116 EXPECT_LE(2 * (approxResult.second - approxResult.first) / (approxResult.first + approxResult.second), errorBound);
117 // Ensure results are not equal -> not exact values were computed
118 EXPECT_GE(approxResult.second - approxResult.first, errorBound * approxResult.first / 10);
119}
120
121TYPED_TEST(DftApproximationTest, HecsTimebound) {
122 // double errorBound = 0.01;
123 double errorBound = 0.1;
124 double timeBound = 100;
125 std::pair<double, double> approxResult = this->analyzeTimebound(STORM_TEST_RESOURCES_DIR "/dft/hecs_3_2_2_np.dft", timeBound, errorBound);
126 EXPECT_LE(approxResult.first, 0.0410018417);
127 EXPECT_GE(approxResult.second, 0.0410018417);
128 EXPECT_LE(approxResult.second - approxResult.first, errorBound);
129 // Ensure results are not equal -> not exact values were computed
130 EXPECT_GE(approxResult.second - approxResult.first, errorBound / 10);
131}
132
133} // namespace
void setApproximationHeuristic(storm::dft::builder::ApproximationHeuristic value)
AnalysisEnvironment & analysis()
ModelBuilderEnvironment & modelBuilder()
TransformationEnvironment & transformation()
std::vector< boost::variant< ExtendedValueType, approximation_result > > dft_results
std::vector< std::shared_ptr< storm::logic::Formula const > > extractFormulasFromProperties(std::vector< storm::jani::Property > const &properties)
std::vector< storm::jani::Property > parseProperties(storm::parser::FormulaParser &formulaParser, std::string const &inputString, boost::optional< std::set< std::string > > const &propertyFilter)
std::shared_ptr< storm::dft::storage::DFT< ValueType > > prepareForMarkovAnalysis(storm::dft::storage::DFT< ValueType > const &dft)
Apply transformations to make DFT feasible for Markovian analysis.
std::shared_ptr< storm::dft::storage::DFT< ValueType > > loadDFTGalileoFile(std::string const &file)
Load DFT from Galileo file.
Definition io.cpp:14
std::pair< bool, std::string > isWellFormed(storm::dft::storage::DFT< ValueType > const &dft, bool validForMarkovianAnalysis)
Check whether the DFT is well-formed.
storm::dft::modelchecker::DFTModelChecker< ValueType >::dft_results analyzeDFT(storm::dft::DftEnvironment const &env, storm::dft::storage::DFT< ValueType > const &dft, std::vector< std::shared_ptr< storm::logic::Formula const > > const &properties, storm::dft::utility::RelevantEvents const &relevantEvents, bool printOutput, typename storm::dft::modelchecker::DFTModelChecker< ValueType >::ModelExportCallback const &exportCallback)
Compute the exact or approximate analysis result of the given DFT according to the given properties.
Definition analysis.cpp:27
TYPED_TEST(GraphTestAR, SymbolicProb01StochasticGameDieSmall)
Definition GraphTest.cpp:64
TYPED_TEST_SUITE(GraphTestAR, TestingTypes,)
::testing::Types< Cudd, Sylvan > TestingTypes
Definition GraphTest.cpp:61