Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Distribution.cpp
Go to the documentation of this file.
2
7
8namespace storm::generator {
9
10template<typename IndexType, typename ValueType>
12 // Intentionally left empty.
13}
14
15template<typename IndexType, typename ValueType>
17 this->storage = other.storage;
18 this->compressed = other.compressed;
19}
20
21template<typename IndexType, typename ValueType>
23 this->storage = std::move(other.storage);
24 this->compressed = other.compressed;
25 other.compressed = true;
26}
27
28template<typename IndexType, typename ValueType>
30 if (this != &other) {
31 this->storage = other.storage;
32 this->compressed = other.compressed;
33 }
34 return *this;
35}
36
37template<typename IndexType, typename ValueType>
39 if (this != &other) {
40 this->storage = std::move(other.storage);
41 this->compressed = other.compressed;
42 other.compressed = true;
43 }
44 return *this;
45}
46
47template<typename IndexType, typename ValueType>
49 storage.push_back(entry);
50 compressed &= storage.back().getState() < entry.getState();
51}
52
53template<typename IndexType, typename ValueType>
54void Distribution<IndexType, ValueType>::add(IndexType const& index, ValueType const& value) {
55 storage.emplace_back(index, value);
56 compressed &= storage.back().getState() < index;
57}
58
59template<typename IndexType, typename ValueType>
61 storage.insert(storage.end(), std::make_move_iterator(distribution.begin()), std::make_move_iterator(distribution.end()));
62 compressed = false;
63}
64
65template<typename IndexType, typename ValueType>
67 if (!compressed) {
68 std::sort(storage.begin(), storage.end(), [](DistributionEntry<IndexType, ValueType> const& a, DistributionEntry<IndexType, ValueType> const& b) {
69 return a.getState() < b.getState();
70 });
71
72 // Code taken from std::unique and modified to fit needs.
73 auto first = storage.begin();
74 auto last = storage.end();
75
76 if (first != last) {
77 auto result = first;
78 while (++first != last) {
79 if (!(result->getState() == first->getState())) {
80 if (++result != first) {
81 *result = std::move(*first);
82 }
83 } else {
84 result->addToValue(first->getValue());
85 }
86 }
87 ++result;
88
89 storage.resize(std::distance(storage.begin(), result));
90 }
91 compressed = true;
92 }
93}
94
95template<typename IndexType, typename ValueType>
96void Distribution<IndexType, ValueType>::divide(ValueType const& value) {
97 for (auto& entry : storage) {
98 entry.divide(value);
99 }
100}
101
102template<typename IndexType, typename ValueType>
104 this->storage.clear();
105 this->compressed = true;
106}
107
108template<typename IndexType, typename ValueType>
112
113template<typename IndexType, typename ValueType>
117
118template<typename IndexType, typename ValueType>
122
123template<typename IndexType, typename ValueType>
127
128template class Distribution<uint32_t, double>;
132
137
138} // 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.