15template<
typename ValueType,
typename StateType>
17 : markovian(markovian), actionIndex(actionIndex), distribution(), totalMass(
storm::
utility::zero<ValueType>()), rewards(), labels() {
21template<
typename ValueType,
typename StateType>
23 markovian = newMarkovian;
24 actionIndex = newActionIndex;
28 originData = boost::none;
30 playerIndex = boost::none;
33template<
typename ValueType,
typename StateType>
35 STORM_LOG_THROW(this->markovian == other.markovian, storm::exceptions::InvalidOperationException,
"Type of choices do not match.");
36 STORM_LOG_THROW(this->actionIndex == other.actionIndex, storm::exceptions::InvalidOperationException,
"Action index of choices do not match.");
37 STORM_LOG_THROW(this->rewards.size() == other.rewards.size(), storm::exceptions::InvalidOperationException,
"Reward value sizes of choices do not match.");
40 this->distribution.add(other.distribution);
43 this->totalMass += other.totalMass;
46 auto otherRewIt = other.rewards.begin();
47 for (
auto& rewardValue : this->rewards) {
48 rewardValue += *otherRewIt;
56 if (other.originData) {
61template<
typename ValueType,
typename StateType>
63 return distribution.sampleFromDistribution(quantile);
66template<
typename ValueType,
typename StateType>
68 return distribution.begin();
71template<
typename ValueType,
typename StateType>
73 return distribution.cbegin();
76template<
typename ValueType,
typename StateType>
78 return distribution.end();
81template<
typename ValueType,
typename StateType>
83 return distribution.cend();
86template<
typename ValueType,
typename StateType>
89 labels = std::set<std::string>();
91 labels->insert(newLabel);
94template<
typename ValueType,
typename StateType>
97 labels->insert(newLabels.begin(), newLabels.end());
103template<
typename ValueType,
typename StateType>
105 return labels.is_initialized();
108template<
typename ValueType,
typename StateType>
113template<
typename ValueType,
typename StateType>
115 this->playerIndex = playerIndex;
118template<
typename ValueType,
typename StateType>
120 return playerIndex.is_initialized();
123template<
typename ValueType,
typename StateType>
125 return playerIndex.get();
128template<
typename ValueType,
typename StateType>
130 if (!this->originData || this->originData->empty()) {
131 this->originData = data;
136 auto existingDataAsIndexSet = boost::any_cast<storm::storage::FlatSet<uint_fast64_t>>(&this->originData.get());
137 if (existingDataAsIndexSet !=
nullptr) {
138 auto givenDataAsIndexSet = boost::any_cast<storm::storage::FlatSet<uint_fast64_t>>(&data);
139 STORM_LOG_THROW(givenDataAsIndexSet !=
nullptr, storm::exceptions::InvalidOperationException,
140 "Types of existing and given choice origin data do not match.");
141 existingDataAsIndexSet->insert(givenDataAsIndexSet->begin(), givenDataAsIndexSet->end());
144 "Type of choice origin data (aka " << data.type().name() <<
") is not implemented.");
150template<
typename ValueType,
typename StateType>
152 return originData.is_initialized();
155template<
typename ValueType,
typename StateType>
157 return originData.get();
160template<
typename ValueType,
typename StateType>
165template<
typename ValueType,
typename StateType>
170template<
typename ValueType,
typename StateType>
173 distribution.addProbability(state, value);
176template<
typename ValueType,
typename StateType>
178 rewards.push_back(value);
181template<
typename ValueType,
typename StateType>
183 this->rewards = std::move(values);
186template<
typename ValueType,
typename StateType>
191template<
typename ValueType,
typename StateType>
196template<
typename ValueType,
typename StateType>
201template<
typename ValueType,
typename StateType>
203 return distribution.size();
206template<
typename ValueType,
typename StateType>
208 distribution.reserve(
size);
211template<
typename ValueType,
typename StateType>
214 for (
auto const& stateProbabilityPair : choice) {
215 out << stateProbabilityPair.first <<
" : " << stateProbabilityPair.second <<
", ";
221template struct Choice<double>;
223template struct Choice<storm::RationalNumber>;
224template struct Choice<storm::RationalFunction>;
225template struct Choice<storm::Interval>;
226template struct Choice<storm::RationalInterval>;
container_type::const_iterator const_iterator
container_type::iterator iterator
#define STORM_LOG_THROW(cond, exception, message)
std::ostream & operator<<(std::ostream &out, Choice< ValueType, StateType > const &choice)
bool hasLabels() const
Returns whether there are labels defined for this choice.
bool isMarkovian() const
Retrieves whether the choice is Markovian.
boost::any const & getOriginData() const
Returns the origin data associated with this choice.
void addLabel(std::string const &label)
Adds the given label to the labels associated with this choice.
uint_fast64_t getActionIndex() const
Retrieves the index of the action of this choice.
storm::storage::Distribution< ValueType, StateType >::iterator end()
Returns an iterator past the end of the distribution associated with this choice.
std::vector< ValueType > const & getRewards() const
Retrieves the rewards for this choice under selected reward models.
std::set< std::string > const & getLabels() const
Retrieves the set of labels associated with this choice.
void add(Choice const &other)
Adds the given choice to the current one.
ValueType getTotalMass() const
Retrieves the total mass of this choice.
void addOriginData(boost::any const &data)
Adds the given data that specifies the origin of this choice w.r.t.
void setPlayerIndex(storm::storage::PlayerIndex const &playerIndex)
Sets the players index.
storm::storage::PlayerIndex const & getPlayerIndex() const
Retrieves the players index associated with this choice.
Choice(uint_fast64_t actionIndex=0, bool markovian=false)
void addLabels(std::set< std::string > const &labels)
Adds the given label set to the labels associated with this choice.
bool hasOriginData() const
Returns whether there is origin data defined for this choice.
void addRewards(std::vector< ValueType > &&values)
Adds the given choices rewards to this choice.
StateType sampleFromDistribution(ValueType const &quantile) const
Given a value q, find the event in the ordered distribution that corresponds to this prob.
storm::storage::Distribution< ValueType, StateType >::iterator begin()
Returns an iterator to the distribution associated with this choice.
void reset(uint_fast64_t actionIndex=0, bool markovian=false)
Resets this choice to an empty choice with the given action index (i.e., as if it was newly construct...
void reserve(std::size_t const &size)
If the size is already known, reserves space in the underlying distribution.
bool hasPlayerIndex() const
Returns whether there is an index for the player defined for this choice.
std::size_t size() const
Retrieves the size of the distribution associated with this choice.
void addProbability(StateType const &state, ValueType const &value)
Adds the given probability value to the given state in the underlying distribution.
void addReward(ValueType const &value)
Adds the given value to the reward associated with this choice.