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 clear();
40
44 void add(Distribution const& other);
45
53
60 void addProbability(StateType const& state, ValueType const& probability);
61
70 void removeProbability(StateType const& state, ValueType const& probability, storm::utility::ConstantsComparator<ValueType> const& comparator);
71
81 void shiftProbability(StateType const& fromState, StateType const& toState, ValueType const& probability,
83
90
96 const_iterator begin() const;
97
103 const_iterator cbegin() const;
104
110 iterator end();
111
117 const_iterator end() const;
118
124 const_iterator cend() const;
125
133 void scale(StateType const& state);
134
138 std::size_t size() const;
139
141
147 ValueType getProbability(StateType const& state) const;
148
152 void normalize();
153
163 StateType sampleFromDistribution(ValueType const& quantile) const;
164
165 private:
166 // A list of states and the probabilities that are assigned to them.
167 container_type distribution;
168};
169
170template<typename ValueType, typename StateType = uint32_t>
171std::ostream& operator<<(std::ostream& out, Distribution<ValueType, StateType> const& distribution);
172} // namespace storage
173} // namespace storm
174
175namespace std {
176
177template<typename ValueType>
178struct hash<storm::storage::Distribution<ValueType>> {
179 std::size_t operator()(storm::storage::Distribution<ValueType> const& distribution) const {
180 return (distribution.getHash());
181 }
182};
183
184} // 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
void clear()
Removes all entries from this distribution.
std::ostream & operator<<(std::ostream &out, ParameterRegion< ParametricType > const &region)
std::size_t operator()(storm::storage::Distribution< ValueType > const &distribution) const