Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Distribution.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/container/flat_map.hpp>
4#include <iosfwd>
5#include <vector>
6
9
10namespace storm {
11
12namespace storage {
13
14template<typename ValueType, typename StateType = uint32_t>
16 public:
17 typedef boost::container::flat_map<StateType, ValueType> container_type;
18 typedef typename container_type::iterator iterator;
19 typedef typename container_type::const_iterator const_iterator;
20
25
26 Distribution(Distribution const& other) = default;
27 Distribution& operator=(Distribution const& other) = default;
28 Distribution(Distribution&& other) = default;
29 Distribution& operator=(Distribution&& other) = default;
30
31 /*
32 * If the size of this distribution is known before adding probabilities,, this method can be used to reserve enough space.
33 */
34 void reserve(uint64_t size);
35
39 void add(Distribution const& other);
40
48
55 void addProbability(StateType const& state, ValueType const& probability);
56
65 void removeProbability(StateType const& state, ValueType const& probability, storm::utility::ConstantsComparator<ValueType> const& comparator);
66
76 void shiftProbability(StateType const& fromState, StateType const& toState, ValueType const& probability,
78
85
91 const_iterator begin() const;
92
98 const_iterator cbegin() const;
99
105 iterator end();
106
112 const_iterator end() const;
113
119 const_iterator cend() const;
120
128 void scale(StateType const& state);
129
133 std::size_t size() const;
134
136
142 ValueType getProbability(StateType const& state) const;
143
147 void normalize();
148
158 StateType sampleFromDistribution(ValueType const& quantile) const;
159
160 private:
161 // A list of states and the probabilities that are assigned to them.
162 container_type distribution;
163};
164
165template<typename ValueType, typename StateType = uint32_t>
166std::ostream& operator<<(std::ostream& out, Distribution<ValueType, StateType> const& distribution);
167} // namespace storage
168} // namespace storm
169
170namespace std {
171
172template<typename ValueType>
173struct hash<storm::storage::Distribution<ValueType>> {
174 std::size_t operator()(storm::storage::Distribution<ValueType> const& distribution) const {
175 return (distribution.getHash());
176 }
177};
178
179} // namespace std
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
std::ostream & operator<<(std::ostream &out, ParameterRegion< ParametricType > const &region)
std::size_t operator()(storm::storage::Distribution< ValueType > const &distribution) const