Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DiscreteTimeSparseModelSimulatorTest.cpp
Go to the documentation of this file.
1#include "storm-config.h"
2#include "test/storm_gtest.h"
3
8
9TEST(DiscreteTimeSparseModelSimulatorTest, TransitionRewards) {
10 // 0 --0.5--> 1, 0 --0.5--> 2, 1 -> 1, 2 -> 2
12 builder.addNextValue(0, 1, 0.5);
13 builder.addNextValue(0, 2, 0.5);
14 builder.addNextValue(1, 1, 1.0);
15 builder.addNextValue(2, 2, 1.0);
16 auto matrix = builder.build();
17
18 // Transition rewards: 0->1 yields 3, 0->2 yields 7 and the self loops yield nothing (entries omitted).
20 rewBuilder.addNextValue(0, 1, 3.0);
21 rewBuilder.addNextValue(0, 2, 7.0);
22 auto rewMatrix = rewBuilder.build();
23
25 labeling.addLabel("init");
26 labeling.addLabelToState("init", 0);
27 std::unordered_map<std::string, storm::models::sparse::StandardRewardModel<double>> rewardModels;
28 rewardModels.emplace("r", storm::models::sparse::StandardRewardModel<double>(std::nullopt, std::nullopt, std::move(rewMatrix)));
29 storm::models::sparse::Dtmc<double> dtmc(std::move(matrix), std::move(labeling), std::move(rewardModels));
30
32 sim.setSeed(1);
33 bool seen1 = false, seen2 = false;
34 for (int i = 0; i < 50; ++i) {
35 sim.resetToInitial();
36 EXPECT_EQ(0.0, sim.getLastRewards()[0]);
37 ASSERT_TRUE(sim.randomStep());
38 if (sim.getCurrentState() == 1) {
39 EXPECT_EQ(3.0, sim.getLastRewards()[0]);
40 seen1 = true;
41 } else {
42 ASSERT_EQ(2ul, sim.getCurrentState());
43 EXPECT_EQ(7.0, sim.getLastRewards()[0]);
44 seen2 = true;
45 }
46 ASSERT_TRUE(sim.randomStep());
47 EXPECT_EQ(0.0, sim.getLastRewards()[0]);
48 }
49 EXPECT_TRUE(seen1);
50 EXPECT_TRUE(seen2);
51}
TEST(DiscreteTimeSparseModelSimulatorTest, TransitionRewards)
This class represents a discrete-time Markov chain.
Definition Dtmc.h:16
void addLabel(std::string const &label)
Adds a new label to the labelings.
This class manages the labeling of the state space with a number of (atomic) labels.
void addLabelToState(std::string const &label, storm::storage::sparse::state_type state)
Adds a label to a given state.
This class is a low-level interface to quickly sample from Discrete-Time Models stored explicitly as ...
A class that can be used to build a sparse matrix by adding value by value.
void addNextValue(index_type row, index_type column, value_type const &value)
Sets the matrix entry at the given row and column to the given value.
SparseMatrix< value_type > build(index_type overriddenRowCount=0, index_type overriddenColumnCount=0, index_type overriddenRowGroupCount=0)