Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
KSPTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
10
11// NOTE: The KSPs / distances of these tests were generated by the
12// KSP-Generator itself and checked for gross implausibility, but no
13// more than that.
14// An independent verification of the values would be really nice ...
15
16class KSPTest : public ::testing::Test {
17 protected:
18 void SetUp() override {
19#ifndef STORM_HAVE_Z3
20 GTEST_SKIP() << "Z3 not available.";
21#endif
22 }
23};
24
25std::shared_ptr<storm::models::sparse::Model<double>> buildExampleModel() {
26 std::string prismModelPath = STORM_TEST_RESOURCES_DIR "/dtmc/brp-16-2.pm";
28 storm::prism::Program program = modelDescription.preprocess().asPrismProgram();
30}
31
32// NOTE: these are hardcoded (obviously), but the model's state indices might change
33// (e.g., when the parser or model builder are changed)
34// [state 296 seems to be the new index of the old state 300 (checked a few ksps' probs)]
37
38TEST_F(KSPTest, dijkstra) {
39 auto model = buildExampleModel();
41
42 double dist = spg.getDistance(1);
43 EXPECT_NEAR(0.015859334652581887, dist, 1e-12);
44}
45
46TEST_F(KSPTest, singleTarget) {
47 auto model = buildExampleModel();
49
50 double dist = spg.getDistance(100);
51 EXPECT_NEAR(1.5231305000339662e-06, dist, 1e-12);
52}
53
54TEST_F(KSPTest, reentry) {
55 auto model = buildExampleModel();
57
58 double dist = spg.getDistance(100);
59 EXPECT_NEAR(1.5231305000339662e-06, dist, 1e-12);
60
61 // get another distance to ensure re-entry is no problem
62 double dist2 = spg.getDistance(500);
63 EXPECT_NEAR(3.0462610000679315e-08, dist2, 1e-12);
64}
65
66TEST_F(KSPTest, groupTarget) {
67 auto model = buildExampleModel();
68 auto groupTarget = std::vector<storm::utility::ksp::state_t>{50, 90};
69 auto spg = storm::utility::ksp::ShortestPathsGenerator<double>(*model, groupTarget);
70
71 double dist1 = spg.getDistance(8);
72 EXPECT_NEAR(0.00018449245583999996, dist1, 1e-12);
73
74 double dist2 = spg.getDistance(9);
75 EXPECT_NEAR(0.00018449245583999996, dist2, 1e-12);
76
77 double dist3 = spg.getDistance(12);
78 EXPECT_NEAR(7.5303043199999984e-06, dist3, 1e-12);
79}
80
81TEST_F(KSPTest, kTooLargeException) {
82 auto model = buildExampleModel();
84
85 STORM_SILENT_ASSERT_THROW(spg.getDistance(2), std::invalid_argument);
86}
87
88TEST_F(KSPTest, kspStateSet) {
89 auto model = buildExampleModel();
91
92 auto bv = spg.getStates(7);
93 EXPECT_EQ(50ull, bv.getNumberOfSetBits());
94
95 // The result may sadly depend on the compiler/system, so checking a particular outcome is not feasible.
96 // storm::storage::BitVector referenceBV(model->getNumberOfStates(), false);
97 // for (auto s : std::vector<storm::utility::ksp::state_t>{0, 1, 2, 4, 6, 9, 12, 17, 22, 30, 37, 45, 52, 58, 65, 70, 74, 77, 81, 85, 92, 98, 104, 112,
98 // 119, 127, 134, 140, 146, 154, 161, 169, 176, 182, 188, 196, 203, 211, 218, 224, 230, 238, 245, 253, 260, 266, 272, 281, 288, 296}) {
99 // referenceBV.set(s, true);
100 // }
101 //
102 // EXPECT_EQ(referenceBV, bv);
103}
104
105TEST_F(KSPTest, kspPathAsList) {
106 auto model = buildExampleModel();
108
109 auto list = spg.getPathAsList(7);
110 EXPECT_EQ(50ull, list.size());
111
112 // TODO: use path that actually has a loop or something to make this more interesting
113 // auto reference = storm::utility::ksp::OrderedStateList{296, 288, 281, 272, 266, 260, 253, 245, 238, 230, 224, 218, 211, 203, 196, 188, 182, 176, 169,
114 // 161, 154, 146, 140, 134, 127, 119, 112, 104, 98, 92, 85, 77, 70, 81, 74, 65, 58, 52, 45, 37, 30, 22, 17, 12, 9, 6, 4, 2, 1, 0}; EXPECT_EQ(reference,
115 // list);
116}
const storm::utility::ksp::state_t testState
Definition KSPTest.cpp:35
TEST_F(KSPTest, dijkstra)
Definition KSPTest.cpp:38
const storm::utility::ksp::state_t stateWithOnlyOnePath
Definition KSPTest.cpp:36
std::shared_ptr< storm::models::sparse::Model< double > > buildExampleModel()
Definition KSPTest.cpp:25
void SetUp() override
Definition KSPTest.cpp:18
std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > build()
Convert the program given at construction time to an abstract model.
static storm::prism::Program parse(std::string const &filename, bool prismCompatability=false)
Parses the given file into the PRISM storage classes assuming it complies with the PRISM syntax.
storm::prism::Program const & asPrismProgram() const
SymbolicModelDescription preprocess(std::string const &constantDefinitionString="") const
storage::BitVector getStates(unsigned long k)
Returns the states that occur in the KSP.
T getDistance(unsigned long k)
Returns distance (i.e., probability) of the KSP.
OrderedStateList getPathAsList(unsigned long k)
Returns the states of the KSP as back-to-front traversal.
storage::sparse::state_type state_t
#define STORM_SILENT_ASSERT_THROW(statement, expected_exception)
Definition storm_gtest.h:99