15template<
typename ValueType,
typename StateType>
17 : markovian(markovian), actionIndex(actionIndex), distribution(), totalMass(
storm::utility::zero<ValueType>()), rewards(), labels() {
21template<
typename ValueType,
typename StateType>
23 STORM_LOG_THROW(this->markovian == other.markovian, storm::exceptions::InvalidOperationException,
"Type of choices do not match.");
24 STORM_LOG_THROW(this->actionIndex == other.actionIndex, storm::exceptions::InvalidOperationException,
"Action index of choices do not match.");
25 STORM_LOG_THROW(this->rewards.size() == other.rewards.size(), storm::exceptions::InvalidOperationException,
"Reward value sizes of choices do not match.");
28 this->distribution.add(other.distribution);
31 this->totalMass += other.totalMass;
34 auto otherRewIt = other.rewards.begin();
35 for (
auto& rewardValue : this->rewards) {
36 rewardValue += *otherRewIt;
41 this->addLabels(other.labels.get());
43 if (other.originData) {
44 this->addOriginData(other.originData.get());
48template<
typename ValueType,
typename StateType>
50 return distribution.sampleFromDistribution(quantile);
53template<
typename ValueType,
typename StateType>
55 return distribution.begin();
58template<
typename ValueType,
typename StateType>
60 return distribution.cbegin();
63template<
typename ValueType,
typename StateType>
65 return distribution.end();
68template<
typename ValueType,
typename StateType>
70 return distribution.cend();
73template<
typename ValueType,
typename StateType>
76 labels = std::set<std::string>();
78 labels->insert(newLabel);
81template<
typename ValueType,
typename StateType>
84 labels->insert(newLabels.begin(), newLabels.end());
90template<
typename ValueType,
typename StateType>
92 return labels.is_initialized();
95template<
typename ValueType,
typename StateType>
100template<
typename ValueType,
typename StateType>
102 this->playerIndex = playerIndex;
105template<
typename ValueType,
typename StateType>
107 return playerIndex.is_initialized();
110template<
typename ValueType,
typename StateType>
112 return playerIndex.get();
115template<
typename ValueType,
typename StateType>
117 if (!this->originData || this->originData->empty()) {
118 this->originData = data;
123 auto existingDataAsIndexSet = boost::any_cast<storm::storage::FlatSet<uint_fast64_t>>(&this->originData.get());
124 if (existingDataAsIndexSet !=
nullptr) {
125 auto givenDataAsIndexSet = boost::any_cast<storm::storage::FlatSet<uint_fast64_t>>(&data);
126 STORM_LOG_THROW(givenDataAsIndexSet !=
nullptr, storm::exceptions::InvalidOperationException,
127 "Types of existing and given choice origin data do not match.");
128 existingDataAsIndexSet->insert(givenDataAsIndexSet->begin(), givenDataAsIndexSet->end());
131 "Type of choice origin data (aka " << data.type().name() <<
") is not implemented.");
137template<
typename ValueType,
typename StateType>
139 return originData.is_initialized();
142template<
typename ValueType,
typename StateType>
144 return originData.get();
147template<
typename ValueType,
typename StateType>
152template<
typename ValueType,
typename StateType>
157template<
typename ValueType,
typename StateType>
160 distribution.addProbability(state, value);
163template<
typename ValueType,
typename StateType>
165 rewards.push_back(value);
168template<
typename ValueType,
typename StateType>
170 this->rewards = std::move(values);
173template<
typename ValueType,
typename StateType>
178template<
typename ValueType,
typename StateType>
183template<
typename ValueType,
typename StateType>
185 return distribution.size();
188template<
typename ValueType,
typename StateType>
190 distribution.reserve(size);
193template<
typename ValueType,
typename StateType>
196 for (
auto const& stateProbabilityPair : choice) {
197 out << stateProbabilityPair.first <<
" : " << stateProbabilityPair.second <<
", ";
203template struct Choice<double>;
205#ifdef STORM_HAVE_CARL
206template struct Choice<storm::RationalNumber>;
207template struct Choice<storm::RationalFunction>;
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 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.