Storm
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
50
57 void addProbability(StateType const& state, ValueType const& probability);
58
67 void removeProbability(StateType const& state, ValueType const& probability,
69
79 void shiftProbability(StateType const& fromState, StateType const& toState, ValueType const& probability,
81
88
94 const_iterator begin() const;
95
101 const_iterator cbegin() const;
102
108 iterator end();
109
115 const_iterator end() const;
116
122 const_iterator cend() const;
123
131 void scale(StateType const& state);
132
136 std::size_t size() const;
137
139
145 ValueType getProbability(StateType const& state) const;
146
150 void normalize();
151
161 StateType sampleFromDistribution(ValueType const& quantile) const;
162
163 private:
164 // A list of states and the probabilities that are assigned to them.
165 container_type distribution;
166};
167
168template<typename ValueType, typename StateType = uint32_t>
169std::ostream& operator<<(std::ostream& out, Distribution<ValueType, StateType> const& distribution);
170} // namespace storage
171} // namespace storm
172
173namespace std {
174
175template<typename ValueType>
176struct hash<storm::storage::Distribution<ValueType>> {
177 std::size_t operator()(storm::storage::Distribution<ValueType> const& distribution) const {
178 return (distribution.getHash());
179 }
180};
181
182} // namespace std
183
184#endif /* STORM_STORAGE_DISTRIBUTION_H_ */
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
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
void shiftProbability(StateType const &fromState, StateType const &toState, ValueType const &probability, storm::utility::ConstantsComparator< ValueType > const &comparator=storm::utility::ConstantsComparator< ValueType >())
Removes the probability mass from one state and adds it to another.
Distribution(Distribution const &other)=default
void normalize()
Normalizes the distribution such that the values sum up to one.
Distribution(Distribution &&other)=default
bool equals(Distribution< ValueType, StateType > const &other, storm::utility::ConstantsComparator< ValueType > const &comparator=storm::utility::ConstantsComparator< ValueType >()) const
Checks whether the two distributions specify the same probabilities to go to the same states.
container_type::const_iterator const_iterator
const_iterator cbegin() const
Retrieves an iterator to the elements in this distribution.
void removeProbability(StateType const &state, ValueType const &probability, storm::utility::ConstantsComparator< ValueType > const &comparator=storm::utility::ConstantsComparator< ValueType >())
Removes the given probability mass of going to the given state.
std::size_t size() const
Retrieves the size of the distribution, i.e.
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
std::ostream & operator<<(std::ostream &out, ParameterRegion< ParametricType > const &region)
LabParser.cpp.
Definition cli.cpp:18