Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Distribution.h
Go to the documentation of this file.
1#ifndef STORM_STORAGE_DISTRIBUTION_H_
2#define STORM_STORAGE_DISTRIBUTION_H_
3
4#include <boost/container/flat_map.hpp>
5#include <iosfwd>
6#include <vector>
7
10
11namespace storm {
12
13namespace storage {
14
15template<typename ValueType, typename StateType = uint32_t>
17 public:
18 typedef boost::container::flat_map<StateType, ValueType> container_type;
19 typedef typename container_type::iterator iterator;
20 typedef typename container_type::const_iterator const_iterator;
21
26
27 Distribution(Distribution const& other) = default;
28 Distribution& operator=(Distribution const& other) = default;
29 Distribution(Distribution&& other) = default;
30 Distribution& operator=(Distribution&& other) = default;
31
32 /*
33 * If the size of this distribution is known before adding probabilities,, this method can be used to reserve enough space.
34 */
35 void reserve(uint64_t size);
36
40 void add(Distribution const& other);
41
49
56 void addProbability(StateType const& state, ValueType const& probability);
57
66 void removeProbability(StateType const& state, ValueType const& probability, storm::utility::ConstantsComparator<ValueType> const& comparator);
67
77 void shiftProbability(StateType const& fromState, StateType const& toState, ValueType const& probability,
79
86
92 const_iterator begin() const;
93
99 const_iterator cbegin() const;
100
106 iterator end();
107
113 const_iterator end() const;
114
120 const_iterator cend() const;
121
129 void scale(StateType const& state);
130
134 std::size_t size() const;
135
137
143 ValueType getProbability(StateType const& state) const;
144
148 void normalize();
149
159 StateType sampleFromDistribution(ValueType const& quantile) const;
160
161 private:
162 // A list of states and the probabilities that are assigned to them.
163 container_type distribution;
164};
165
166template<typename ValueType, typename StateType = uint32_t>
167std::ostream& operator<<(std::ostream& out, Distribution<ValueType, StateType> const& distribution);
168} // namespace storage
169} // namespace storm
170
171namespace std {
172
173template<typename ValueType>
174struct hash<storm::storage::Distribution<ValueType>> {
175 std::size_t operator()(storm::storage::Distribution<ValueType> const& distribution) const {
176 return (distribution.getHash());
177 }
178};
179
180} // namespace std
181
182#endif /* STORM_STORAGE_DISTRIBUTION_H_ */
void shiftProbability(StateType const &fromState, StateType const &toState, ValueType const &probability, storm::utility::ConstantsComparator< ValueType > const &comparator)
Removes the probability mass from one state and adds it to another.
iterator end()
Retrieves an iterator past the elements in this distribution.
void reserve(uint64_t size)
void addProbability(StateType const &state, ValueType const &probability)
Assigns the given state the given probability under this distribution.
Distribution & operator=(Distribution &&other)=default
boost::container::flat_map< StateType, ValueType > container_type
void removeProbability(StateType const &state, ValueType const &probability, storm::utility::ConstantsComparator< ValueType > const &comparator)
Removes the given probability mass of going to the given state.
const_iterator cend() const
Retrieves an iterator past the elements in this distribution.
bool less(Distribution< ValueType, StateType > const &other, storm::utility::ConstantsComparator< ValueType > const &comparator) const
Distribution(Distribution const &other)=default
void normalize()
Normalizes the distribution such that the values sum up to one.
Distribution(Distribution &&other)=default
container_type::const_iterator const_iterator
const_iterator cbegin() const
Retrieves an iterator to the elements in this distribution.
std::size_t size() const
Retrieves the size of the distribution, i.e.
bool equals(Distribution< ValueType, StateType > const &other, storm::utility::ConstantsComparator< ValueType > const &comparator) const
Checks whether the two distributions specify the same probabilities to go to the same states.
StateType sampleFromDistribution(ValueType const &quantile) const
Given a value q, find the event in the ordered distribution that corresponds to this prob.
iterator begin()
Retrieves an iterator to the elements in this distribution.
ValueType getProbability(StateType const &state) const
Returns the probability of the given state.
Distribution()
Creates an empty distribution.
container_type::iterator iterator
void add(Distribution const &other)
Adds the given distribution to the current one.
void scale(StateType const &state)
Scales the distribution by multiplying all the probabilities with 1/p where p is the probability of m...
Distribution & operator=(Distribution const &other)=default