1#include "storm-config.h"
23 builder.addNextValue(0, 1, 0.6);
24 builder.addNextValue(0, 2, 0.4);
25 builder.addNextValue(1, 1, 1.0);
26 builder.addNextValue(2, 2, 1.0);
27 auto matrix = builder.build();
30 labeling.addLabel(
"init");
31 labeling.addLabelToState(
"init", 0);
32 labeling.addLabel(
"a");
33 labeling.addLabelToState(
"a", 1);
34 labeling.addLabel(
"b");
35 labeling.addLabelToState(
"b", 2);
36 labeling.addLabel(
"good");
37 labeling.addLabelToState(
"good", 1);
52 builder.newRowGroup(0);
53 builder.addNextValue(0, 1, 1.0);
54 builder.addNextValue(1, 1, 1.0);
55 builder.newRowGroup(2);
56 builder.addNextValue(2, 2, 1.0);
57 builder.addNextValue(3, 2, 1.0);
58 builder.newRowGroup(4);
59 builder.addNextValue(4, 2, 1.0);
60 auto matrix = builder.build();
63 labeling.addLabel(
"init");
64 labeling.addLabelToState(
"init", 0);
65 labeling.addLabel(
"step0");
66 labeling.addLabelToState(
"step0", 0);
67 labeling.addLabel(
"step1");
68 labeling.addLabelToState(
"step1", 1);
69 labeling.addLabel(
"accepting");
70 labeling.addLabelToState(
"accepting", 1);
71 labeling.addLabel(
"step2");
72 labeling.addLabelToState(
"step2", 2);
73 labeling.addLabel(
"horizon");
74 labeling.addLabelToState(
"horizon", 2);
83 choiceLabeling.addLabel(
"a", aChoices);
87 choiceLabeling.addLabel(
"b", bChoices);
90 components.choiceLabeling = std::move(choiceLabeling);
98 std::vector<double> risk = {0.0, 1.0, 0.0}) {
99 auto exprManager = std::make_shared<storm::expressions::ExpressionManager>();
102 return gen.createProduct();
105TEST(MonitorVerifier, ProductHasExpectedLabels) {
106 auto mc = buildSimpleMC();
107 auto monitor = buildSimpleMonitor();
112 auto mv = makeProduct(mc, monitor, options);
113 const auto& product = mv->getProduct();
114 const auto& labeling = product.getStateLabeling();
116 EXPECT_TRUE(labeling.containsLabel(
"init"));
117 EXPECT_TRUE(labeling.containsLabel(
"goal"));
118 EXPECT_TRUE(labeling.containsLabel(
"stop"));
119 EXPECT_TRUE(labeling.containsLabel(
"condition"));
120 EXPECT_TRUE(labeling.containsLabel(
"sink"));
122 EXPECT_EQ(1ul, labeling.getStates(
"goal").getNumberOfSetBits());
123 EXPECT_EQ(1ul, labeling.getStates(
"stop").getNumberOfSetBits());
124 EXPECT_EQ(1ul, labeling.getStates(
"sink").getNumberOfSetBits());
125 EXPECT_GE(labeling.getStates(
"init").getNumberOfSetBits(), 1ul);
128 EXPECT_EQ(2ul, labeling.getStates(
"condition").getNumberOfSetBits());
129 EXPECT_EQ(labeling.getStates(
"goal") | labeling.getStates(
"stop"), labeling.getStates(
"condition"));
132 EXPECT_TRUE(product.hasChoiceLabeling());
135TEST(MonitorVerifier, ObservationMapEntries) {
136 auto mc = buildSimpleMC();
137 auto monitor = buildSimpleMonitor();
142 auto mv = makeProduct(mc, monitor, options);
143 const auto& obsMap = mv->getObservationMap();
146 EXPECT_TRUE(obsMap.contains(std::make_pair(0u,
false)));
147 EXPECT_TRUE(obsMap.contains(std::make_pair(1u,
true)));
148 EXPECT_TRUE(obsMap.contains(std::make_pair(2u,
false)));
151 std::set<uint32_t> obsValues;
152 for (
const auto& [key, val] : obsMap) {
153 obsValues.insert(val);
155 EXPECT_EQ(obsMap.size(), obsValues.size());
158TEST(MonitorVerifier, RestartSemanticsHasNoSink) {
159 auto mc = buildSimpleMC();
160 auto monitor = buildSimpleMonitor();
165 auto mv = makeProduct(mc, monitor, options);
166 const auto& labeling = mv->getProduct().getStateLabeling();
169 EXPECT_FALSE(labeling.containsLabel(
"sink"));
172 EXPECT_TRUE(labeling.containsLabel(
"goal"));
173 EXPECT_TRUE(labeling.containsLabel(
"stop"));
174 EXPECT_TRUE(labeling.containsLabel(
"init"));
177TEST(MonitorVerifier, WithRiskAlmostOneGoesToGoal) {
178 auto mc = buildSimpleMC();
179 auto monitor = buildSimpleMonitor();
184 auto exprManager = std::make_shared<storm::expressions::ExpressionManager>();
188 gen.setRisk({0.0, 1.0, 0.0});
189 auto mv = gen.createProduct();
191 const auto& product = mv->getProduct();
192 const auto& labeling = product.getStateLabeling();
193 const auto& transMatrix = product.getTransitionMatrix();
195 uint64_t goalState = *labeling.getStates(
"goal").begin();
196 uint64_t stopState = *labeling.getStates(
"stop").begin();
197 uint32_t acceptingObs = mv->getObservationMap().at(std::make_pair(1u,
true));
199 bool foundGoalOnly =
false;
200 bool foundStopOnly =
false;
202 for (uint64_t state = 0; state < product.getNumberOfStates(); ++state) {
203 if (product.getObservation(state) != acceptingObs)
205 for (uint64_t row = transMatrix.getRowGroupIndices()[state]; row < transMatrix.getRowGroupIndices()[state + 1]; ++row) {
206 if (product.getChoiceLabeling().getLabelsOfChoice(row).count(
"end") == 0)
208 bool toGoal =
false, toStop =
false;
209 for (
const auto& entry : transMatrix.getRow(row)) {
210 if (entry.getColumn() == goalState)
212 if (entry.getColumn() == stopState)
215 if (toGoal && !toStop)
216 foundGoalOnly =
true;
217 if (!toGoal && toStop)
218 foundStopOnly =
true;
222 EXPECT_TRUE(foundGoalOnly) <<
"Expected an accepting state with risk=1 to route entirely to goal";
223 EXPECT_TRUE(foundStopOnly) <<
"Expected an accepting state with risk=0 to route entirely to stop";
226TEST(MonitorVerifier, WithRiskIntermediateSplitsGoalStop) {
227 auto mc = buildSimpleMC();
228 auto monitor = buildSimpleMonitor();
233 auto exprManager = std::make_shared<storm::expressions::ExpressionManager>();
237 gen.setRisk({0.0, 0.5, 0.0});
238 auto mv = gen.createProduct();
240 const auto& product = mv->getProduct();
241 const auto& labeling = product.getStateLabeling();
242 const auto& transMatrix = product.getTransitionMatrix();
244 uint64_t goalState = *labeling.getStates(
"goal").begin();
245 uint64_t stopState = *labeling.getStates(
"stop").begin();
246 uint32_t acceptingObs = mv->getObservationMap().at(std::make_pair(1u,
true));
248 bool foundSplit =
false;
250 for (uint64_t state = 0; state < product.getNumberOfStates(); ++state) {
251 if (product.getObservation(state) != acceptingObs)
253 for (uint64_t row = transMatrix.getRowGroupIndices()[state]; row < transMatrix.getRowGroupIndices()[state + 1]; ++row) {
254 if (product.getChoiceLabeling().getLabelsOfChoice(row).count(
"end") == 0)
256 bool toGoal =
false, toStop =
false;
257 for (
const auto& entry : transMatrix.getRow(row)) {
258 if (entry.getColumn() == goalState)
260 if (entry.getColumn() == stopState)
263 if (toGoal && toStop) {
269 EXPECT_TRUE(foundSplit) <<
"Expected an accepting state with risk=0.5 to split between goal and stop";
This class manages the labeling of the choice space with a number of (atomic) labels.
This class represents a discrete-time Markov chain.
This class represents a (discrete-time) Markov decision process.
This class manages the labeling of the state space with a number of (atomic) labels.
A bit vector that is internally represented as a vector of 64-bit values.
A class that can be used to build a sparse matrix by adding value by value.