Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
StateBehavior.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <utility>
5
10
11namespace storm {
12namespace generator {
13
14template<typename ValueType, typename StateType>
15StateBehavior<ValueType, StateType>::StateBehavior() : numberOfChoices(0), expanded(false) {
16 // Intentionally left empty.
18
19template<typename ValueType, typename StateType>
21 : choices(other.choices.begin(), other.choices.begin() + other.numberOfChoices),
22 numberOfChoices(other.numberOfChoices),
23 stateRewards(other.stateRewards),
24 expanded(other.expanded) {
25 // Intentionally left empty. Note that we only copy the choices that are actually part of the behavior.
26}
27
28template<typename ValueType, typename StateType>
30 : choices(std::move(other.choices)),
31 numberOfChoices(std::exchange(other.numberOfChoices, 0)),
32 stateRewards(std::move(other.stateRewards)),
33 expanded(std::exchange(other.expanded, false)) {
34 // Make sure that other is in a well-defined (empty) state.
35 other.choices.clear();
36 other.stateRewards.clear();
37}
38
39template<typename ValueType, typename StateType>
41 if (this != &other) {
42 choices = std::move(other.choices);
43 numberOfChoices = std::exchange(other.numberOfChoices, 0);
44 stateRewards = std::move(other.stateRewards);
45 expanded = std::exchange(other.expanded, false);
46 other.choices.clear();
47 other.stateRewards.clear();
48 }
49 return *this;
50}
51
52template<typename ValueType, typename StateType>
54 if (this != &other) {
55 // Copy the active choices into the already existing choices (this reuses their memory)
56 if (choices.size() < other.numberOfChoices) {
57 choices.resize(other.numberOfChoices);
58 }
59 std::copy(other.choices.begin(), other.choices.begin() + other.numberOfChoices, choices.begin());
60 numberOfChoices = other.numberOfChoices;
61 stateRewards = other.stateRewards;
62 expanded = other.expanded;
63 }
64 return *this;
65}
66
67template<typename ValueType, typename StateType>
70 stateRewards.clear();
71 expanded = false;
72}
74template<typename ValueType, typename StateType>
76 numberOfChoices = 0;
77}
79template<typename ValueType, typename StateType>
81 if (numberOfChoices < choices.size()) {
82 choices[numberOfChoices] = std::move(choice);
83 } else {
84 choices.push_back(std::move(choice));
85 }
86 ++numberOfChoices;
87}
89template<typename ValueType, typename StateType>
91 if (numberOfChoices < choices.size()) {
92 choices[numberOfChoices].reset(actionIndex, markovian);
93 } else {
94 choices.emplace_back(actionIndex, markovian);
95 }
96 return choices[numberOfChoices++];
97}
98
99template<typename ValueType, typename StateType>
100void StateBehavior<ValueType, StateType>::removeLastChoices(std::size_t numberOfChoicesToRemove) {
101 STORM_LOG_ASSERT(numberOfChoicesToRemove <= numberOfChoices, "Cannot remove more choices than available.");
102 numberOfChoices -= numberOfChoicesToRemove;
104
105template<typename ValueType, typename StateType>
106void StateBehavior<ValueType, StateType>::addStateReward(ValueType const& stateReward) {
107 stateRewards.push_back(stateReward);
108}
109
110template<typename ValueType, typename StateType>
111void StateBehavior<ValueType, StateType>::addStateRewards(std::vector<ValueType>&& stateRewards) {
112 this->stateRewards = std::move(stateRewards);
114
115template<typename ValueType, typename StateType>
117 this->expanded = newValue;
118}
119
120template<typename ValueType, typename StateType>
122 return expanded;
123}
124
125template<typename ValueType, typename StateType>
127 return numberOfChoices == 0;
128}
129
130template<typename ValueType, typename StateType>
131typename std::vector<Choice<ValueType, StateType>>::const_iterator StateBehavior<ValueType, StateType>::begin() const {
132 return choices.begin();
133}
134
135template<typename ValueType, typename StateType>
136typename std::vector<Choice<ValueType, StateType>>::const_iterator StateBehavior<ValueType, StateType>::end() const {
137 return choices.begin() + numberOfChoices;
138}
139
140template<typename ValueType, typename StateType>
141std::span<Choice<ValueType, StateType> const> StateBehavior<ValueType, StateType>::getChoices() const {
142 return std::span<Choice<ValueType, StateType> const>(choices.data(), numberOfChoices);
143}
144
145template<typename ValueType, typename StateType>
146std::span<Choice<ValueType, StateType>> StateBehavior<ValueType, StateType>::getChoices() {
147 return std::span<Choice<ValueType, StateType>>(choices.data(), numberOfChoices);
148}
149
150template<typename ValueType, typename StateType>
151std::vector<ValueType> const& StateBehavior<ValueType, StateType>::getStateRewards() const {
152 return stateRewards;
153}
154
155template<typename ValueType, typename StateType>
157 return stateRewards;
158}
159
160template<typename ValueType, typename StateType>
162 return numberOfChoices;
163}
164
165template class StateBehavior<double>;
168template class StateBehavior<storm::Interval>;
170} // namespace generator
171} // namespace storm
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.
StateBehavior & operator=(StateBehavior const &other)
std::vector< Choice< ValueType, StateType > >::const_iterator end() const
Retrieves an iterator past the choices available in the behavior.
StateBehavior()
Creates an empty behavior, i.e.
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).
void addStateRewards(std::vector< ValueType > &&stateRewards)
Adds the given state rewards to the behavior of the state.
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.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9