Storm 1.14.0.1
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
11
12// NOTE: The KSPs / distances of these tests were generated by the
13// KSP-Generator itself and checked for gross implausibility, but no
14// more than that.
15// An independent verification of the values would be really nice ...
16
17class KSPTest : public ::testing::Test {
18 protected:
19 void SetUp() override {
20#ifndef STORM_HAVE_Z3
21 GTEST_SKIP() << "Z3 not available.";
22#endif
23 }
24};
25
26std::shared_ptr<storm::models::sparse::Model<double>> buildExampleModel() {
27 std::string prismModelPath = STORM_TEST_RESOURCES_DIR "/dtmc/brp-16-2.pm";
29 storm::prism::Program program = modelDescription.preprocess().asPrismProgram();
31}
32
33// NOTE: these are hardcoded (obviously), but the model's state indices might change
34// (e.g., when the parser or model builder are changed)
35// [state 296 seems to be the new index of the old state 300 (checked a few ksps' probs)]
38
39TEST_F(KSPTest, dijkstra) {
40 auto model = buildExampleModel();
42
43 double dist = spg.getDistance(1);
44 EXPECT_NEAR(0.015859334652581887, dist, 1e-12);
45}
46
47TEST_F(KSPTest, singleTarget) {
48 auto model = buildExampleModel();
50
51 double dist = spg.getDistance(100);
52 EXPECT_NEAR(1.5231305000339662e-06, dist, 1e-12);
53}
54
55TEST_F(KSPTest, reentry) {
56 auto model = buildExampleModel();
58
59 double dist = spg.getDistance(100);
60 EXPECT_NEAR(1.5231305000339662e-06, dist, 1e-12);
61
62 // get another distance to ensure re-entry is no problem
63 double dist2 = spg.getDistance(500);
64 EXPECT_NEAR(3.0462610000679315e-08, dist2, 1e-12);
65}
66
67TEST_F(KSPTest, groupTarget) {
68 auto model = buildExampleModel();
69 auto groupTarget = std::vector<storm::utility::ksp::state_t>{50, 90};
70 auto spg = storm::utility::ksp::ShortestPathsGenerator<double>(*model, groupTarget);
71
72 double dist1 = spg.getDistance(8);
73 EXPECT_NEAR(0.00018449245583999996, dist1, 1e-12);
74
75 double dist2 = spg.getDistance(9);
76 EXPECT_NEAR(0.00018449245583999996, dist2, 1e-12);
77
78 double dist3 = spg.getDistance(12);
79 EXPECT_NEAR(7.5303043199999984e-06, dist3, 1e-12);
80}
81
82TEST_F(KSPTest, kTooLargeException) {
83 auto model = buildExampleModel();
85
86 STORM_SILENT_ASSERT_THROW(spg.getDistance(2), storm::exceptions::InvalidArgumentException);
87}
88
89TEST_F(KSPTest, kspStateSet) {
90 auto model = buildExampleModel();
92
93 auto bv = spg.getStates(7);
94 EXPECT_EQ(50ull, bv.getNumberOfSetBits());
95
96 // The result may sadly depend on the compiler/system, so checking a particular outcome is not feasible.
97 // storm::storage::BitVector referenceBV(model->getNumberOfStates(), false);
98 // 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,
99 // 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}) {
100 // referenceBV.set(s, true);
101 // }
102 //
103 // EXPECT_EQ(referenceBV, bv);
104}
105
106TEST_F(KSPTest, kspPathAsList) {
107 auto model = buildExampleModel();
109
110 auto list = spg.getPathAsList(7);
111 EXPECT_EQ(50ull, list.size());
112
113 // TODO: use path that actually has a loop or something to make this more interesting
114 // 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,
115 // 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,
116 // list);
117}
const storm::utility::ksp::state_t testState
Definition KSPTest.cpp:36
TEST_F(KSPTest, dijkstra)
Definition KSPTest.cpp:39
const storm::utility::ksp::state_t stateWithOnlyOnePath
Definition KSPTest.cpp:37
std::shared_ptr< storm::models::sparse::Model< double > > buildExampleModel()
Definition KSPTest.cpp:26
void SetUp() override
Definition KSPTest.cpp:19
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:14