1#include "storm-config.h"
6TEST(StateBehaviorTest, StartNewChoiceAndClear) {
8 EXPECT_TRUE(behavior.
empty());
12 c0.addProbability(1, 0.25);
13 c0.addProbability(2, 0.75);
14 c0.getRewards().push_back(5.0);
16 c1.addProbability(0, 1.0);
22 EXPECT_EQ(3u, behavior.
getChoices()[0].getActionIndex());
23 EXPECT_TRUE(behavior.
getChoices()[0].isMarkovian());
24 EXPECT_EQ(2u, behavior.
getChoices()[0].size());
25 EXPECT_EQ(4u, behavior.
getChoices()[1].getActionIndex());
26 EXPECT_EQ(2, std::distance(behavior.
begin(), behavior.
end()));
29 EXPECT_TRUE(behavior.
empty());
32 EXPECT_EQ(0, std::distance(behavior.
begin(), behavior.
end()));
37 EXPECT_EQ(7u, reused.getActionIndex());
38 EXPECT_FALSE(reused.isMarkovian());
39 EXPECT_EQ(0u, reused.size());
40 EXPECT_TRUE(reused.getRewards().empty());
41 EXPECT_FALSE(reused.hasLabels());
42 EXPECT_FALSE(reused.hasOriginData());
43 EXPECT_DOUBLE_EQ(0.0, reused.getTotalMass());
47TEST(StateBehaviorTest, AddChoiceAndRemove) {
49 for (uint64_t i = 0; i < 4; ++i) {
57 EXPECT_EQ(1u, behavior.
getChoices().back().getActionIndex());
62 EXPECT_EQ(9u, behavior.
getChoices().back().getActionIndex());
64 EXPECT_TRUE(behavior.
empty());
67TEST(StateBehaviorTest, CopyOnlyContainsActiveChoices) {
78 EXPECT_EQ(1, std::distance(copy.
begin(), copy.
end()));
87 EXPECT_EQ(1u, assigned.
getChoices()[0].getActionIndex());
90TEST(StateBehaviorTest, Move) {
100 EXPECT_EQ(2, std::distance(moved.
begin(), moved.
end()));
106 EXPECT_TRUE(behavior.
empty());
109 EXPECT_EQ(0, std::distance(behavior.
begin(), behavior.
end()));
118 assigned = std::move(moved);
120 EXPECT_EQ(2u, assigned.
getChoices()[1].getActionIndex());
122 EXPECT_TRUE(moved.
empty());
123 EXPECT_EQ(0, std::distance(moved.
begin(), moved.
end()));
127TEST(StateBehaviorTest, AddChoicesSumsAllRewards) {
142TEST(StateBehaviorTest, CopyAssignmentReusesAndGrows) {
144 for (uint64_t i = 0; i < 3; ++i) {
146 choice.addProbability(i, 0.5);
147 choice.addProbability(i + 10, 0.5);
148 choice.getRewards() = {
static_cast<double>(i)};
158 for (uint64_t i = 0; i < 3; ++i) {
159 EXPECT_EQ(i + 1, small.
getChoices()[i].getActionIndex());
160 EXPECT_EQ(i == 1, small.
getChoices()[i].isMarkovian());
162 EXPECT_DOUBLE_EQ(
static_cast<double>(i), small.
getChoices()[i].getRewards().at(0));
169 for (uint64_t i = 0; i < 5; ++i) {
177 EXPECT_EQ(2, std::distance(large.
begin(), large.
end()));
178 EXPECT_EQ(1u, large.
getChoices()[0].getActionIndex());
179 EXPECT_EQ(2u, large.
getChoices()[1].getActionIndex());
TEST(StateBehaviorTest, StartNewChoiceAndClear)
void addChoice(Choice< ValueType, StateType > &&choice)
Adds the given choice to the behavior of the state.
void addStateReward(ValueType const &stateReward)
Adds the given state reward to the behavior of the state.
void removeLastChoices(std::size_t numberOfChoices)
Removes the last given number of choices.
bool empty() const
Retrieves whether the behavior is empty in the sense that there are no available choices.
std::vector< Choice< ValueType, StateType > >::const_iterator end() const
Retrieves an iterator past the choices available in the behavior.
std::span< Choice< ValueType, StateType > const > getChoices() const
Retrieves the choices.
std::vector< Choice< ValueType, StateType > >::const_iterator begin() const
Retrieves an iterator to the choices available in the behavior.
bool wasExpanded() const
Retrieves whether the state was expanded.
void clearChoices()
Removes all choices (but keeps the state rewards and the allocated memory of the choices for reuse).
std::vector< ValueType > const & getStateRewards() const
Retrieves the list of state rewards under selected reward models.
void clear()
Resets this to an empty behavior, i.e.
std::size_t getNumberOfChoices() const
Retrieves the number of choices in the behavior.
void setExpanded(bool newValue=true)
Sets whether the state was expanded.
Choice< ValueType, StateType > & startNewChoice(uint_fast64_t actionIndex=0, bool markovian=false)
Adds a new empty choice with the given action index and returns a reference to it.
std::vector< ValueType > const & getRewards() const
Retrieves the rewards for this choice under selected reward models.
void add(Choice const &other)
Adds the given choice to the current one.
ValueType getTotalMass() const
Retrieves the total mass of this choice.
void addProbability(StateType const &state, ValueType const &value)
Adds the given probability value to the given state in the underlying distribution.