Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Distribution.cpp
Go to the documentation of this file.
2
4
6
7namespace storm::generator {
8
9template<typename IndexType, typename ValueType>
11 // Intentionally left empty.
12}
13
14template<typename IndexType, typename ValueType>
16 this->storage = other.storage;
17 this->compressed = other.compressed;
18}
19
20template<typename IndexType, typename ValueType>
22 this->storage = std::move(other.storage);
23 this->compressed = other.compressed;
24 other.compressed = true;
25}
26
27template<typename IndexType, typename ValueType>
29 if (this != &other) {
30 this->storage = other.storage;
31 this->compressed = other.compressed;
32 }
33 return *this;
34}
35
36template<typename IndexType, typename ValueType>
38 if (this != &other) {
39 this->storage = std::move(other.storage);
40 this->compressed = other.compressed;
41 other.compressed = true;
42 }
43 return *this;
44}
45
46template<typename IndexType, typename ValueType>
48 storage.push_back(entry);
49 compressed &= storage.back().getState() < entry.getState();
50}
51
52template<typename IndexType, typename ValueType>
53void Distribution<IndexType, ValueType>::add(IndexType const& index, ValueType const& value) {
54 storage.emplace_back(index, value);
55 compressed &= storage.back().getState() < index;
56}
57
58template<typename IndexType, typename ValueType>
60 storage.insert(storage.end(), std::make_move_iterator(distribution.begin()), std::make_move_iterator(distribution.end()));
61 compressed = false;
62}
63
64template<typename IndexType, typename ValueType>
66 if (!compressed) {
67 std::sort(storage.begin(), storage.end(), [](DistributionEntry<IndexType, ValueType> const& a, DistributionEntry<IndexType, ValueType> const& b) {
68 return a.getState() < b.getState();
69 });
70
71 // Code taken from std::unique and modified to fit needs.
72 auto first = storage.begin();
73 auto last = storage.end();
74
75 if (first != last) {
76 auto result = first;
77 while (++first != last) {
78 if (!(result->getState() == first->getState())) {
79 if (++result != first) {
80 *result = std::move(*first);
81 }
82 } else {
83 result->addToValue(first->getValue());
84 }
85 }
86 ++result;
87
88 storage.resize(std::distance(storage.begin(), result));
89 }
90 compressed = true;
91 }
92}
93
94template<typename IndexType, typename ValueType>
95void Distribution<IndexType, ValueType>::divide(ValueType const& value) {
96 for (auto& entry : storage) {
97 entry.divide(value);
98 }
99}
100
101template<typename IndexType, typename ValueType>
103 this->storage.clear();
104 this->compressed = true;
105}
106
107template<typename IndexType, typename ValueType>
111
112template<typename IndexType, typename ValueType>
116
117template<typename IndexType, typename ValueType>
121
122template<typename IndexType, typename ValueType>
126
127template class Distribution<uint32_t, double>;
130
134
135} // namespace storm::generator
StateType const & getState() const
void clear()
Clears this distribution.
Distribution & operator=(Distribution const &)
ContainerType::iterator begin()
Access to iterators over the entries of the distribution.
void divide(ValueType const &value)
Divides all values in the distribution by the provided value.
void compress()
Compresses the internal storage by summing the values of entries which agree on the index.
ContainerType::iterator end()
void add(DistributionEntry< IndexType, ValueType > const &entry)
Adds the given entry to the distribution.