Storm
1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Distribution.cpp
Go to the documentation of this file.
1
#include "
storm/generator/Distribution.h
"
2
3
#include "
storm/adapters/IntervalAdapter.h
"
4
#include "
storm/adapters/RationalFunctionAdapter.h
"
5
#include "
storm/adapters/RationalNumberAdapter.h
"
6
#include "
storm/storage/BitVector.h
"
7
8
namespace
storm::generator
{
9
10
template
<
typename
IndexType,
typename
ValueType>
11
Distribution<IndexType, ValueType>::Distribution
() : compressed(true) {
12
// Intentionally left empty.
13
}
14
15
template
<
typename
IndexType,
typename
ValueType>
16
Distribution<IndexType, ValueType>::Distribution
(
Distribution<IndexType, ValueType>
const
& other) {
17
this->storage = other.storage;
18
this->compressed = other.compressed;
19
}
20
21
template
<
typename
IndexType,
typename
ValueType>
22
Distribution<IndexType, ValueType>::Distribution
(
Distribution<IndexType, ValueType>
&& other) {
23
this->storage = std::move(other.storage);
24
this->compressed = other.compressed;
25
other.compressed =
true
;
26
}
27
28
template
<
typename
IndexType,
typename
ValueType>
29
Distribution<IndexType, ValueType>
&
Distribution<IndexType, ValueType>::operator=
(
Distribution<IndexType, ValueType>
const
& other) {
30
if
(
this
!= &other) {
31
this->storage = other.storage;
32
this->compressed = other.compressed;
33
}
34
return
*
this
;
35
}
36
37
template
<
typename
IndexType,
typename
ValueType>
38
Distribution<IndexType, ValueType>
&
Distribution<IndexType, ValueType>::operator=
(
Distribution<IndexType, ValueType>
&& other) {
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
47
template
<
typename
IndexType,
typename
ValueType>
48
void
Distribution<IndexType, ValueType>::add
(
DistributionEntry<IndexType, ValueType>
const
& entry) {
49
storage.push_back(entry);
50
compressed &= storage.back().getState() < entry.
getState
();
51
}
52
53
template
<
typename
IndexType,
typename
ValueType>
54
void
Distribution<IndexType, ValueType>::add
(IndexType
const
& index, ValueType
const
& value) {
55
storage.emplace_back(index, value);
56
compressed &= storage.back().getState() < index;
57
}
58
59
template
<
typename
IndexType,
typename
ValueType>
60
void
Distribution<IndexType, ValueType>::add
(
Distribution
&& distribution) {
61
storage.insert(storage.end(), std::make_move_iterator(distribution.begin()), std::make_move_iterator(distribution.end()));
62
compressed =
false
;
63
}
64
65
template
<
typename
IndexType,
typename
ValueType>
66
void
Distribution<IndexType, ValueType>::compress
() {
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
95
template
<
typename
IndexType,
typename
ValueType>
96
void
Distribution<IndexType, ValueType>::divide
(ValueType
const
& value) {
97
for
(
auto
& entry : storage) {
98
entry.
divide
(value);
99
}
100
}
101
102
template
<
typename
IndexType,
typename
ValueType>
103
void
Distribution<IndexType, ValueType>::clear
() {
104
this->storage.clear();
105
this->compressed =
true
;
106
}
107
108
template
<
typename
IndexType,
typename
ValueType>
109
typename
Distribution<IndexType, ValueType>::ContainerType::iterator
Distribution<IndexType, ValueType>::begin
() {
110
return
storage.begin();
111
}
112
113
template
<
typename
IndexType,
typename
ValueType>
114
typename
Distribution<IndexType, ValueType>::ContainerType::const_iterator
Distribution<IndexType, ValueType>::begin
()
const
{
115
return
storage.begin();
116
}
117
118
template
<
typename
IndexType,
typename
ValueType>
119
typename
Distribution<IndexType, ValueType>::ContainerType::iterator
Distribution<IndexType, ValueType>::end
() {
120
return
storage.end();
121
}
122
123
template
<
typename
IndexType,
typename
ValueType>
124
typename
Distribution<IndexType, ValueType>::ContainerType::const_iterator
Distribution<IndexType, ValueType>::end
()
const
{
125
return
storage.end();
126
}
127
128
template
class
Distribution<uint32_t, double>
;
129
template
class
Distribution<uint32_t, storm::RationalNumber>
;
130
template
class
Distribution<uint32_t, storm::RationalFunction>
;
131
template
class
Distribution<uint32_t, storm::Interval>
;
132
template
class
Distribution<uint32_t, storm::RationalInterval>
;
133
134
template
class
Distribution<storm::storage::BitVector, double>
;
135
template
class
Distribution<storm::storage::BitVector, storm::RationalNumber>
;
136
template
class
Distribution<storm::storage::BitVector, storm::RationalFunction>
;
137
template
class
Distribution<storm::storage::BitVector, storm::Interval>
;
138
template
class
Distribution<storm::storage::BitVector, storm::RationalInterval>
;
139
140
}
// namespace storm::generator
BitVector.h
IntervalAdapter.h
RationalFunctionAdapter.h
RationalNumberAdapter.h
storm::generator::DistributionEntry
Definition
DistributionEntry.h:6
storm::generator::DistributionEntry::divide
void divide(ValueType const &value)
Definition
DistributionEntry.cpp:37
storm::generator::DistributionEntry::getState
StateType const & getState() const
Definition
DistributionEntry.cpp:22
storm::generator::Distribution
Definition
Distribution.h:10
storm::generator::Distribution::clear
void clear()
Clears this distribution.
Definition
Distribution.cpp:103
storm::generator::Distribution::Distribution
Distribution()
Definition
Distribution.cpp:11
storm::generator::Distribution::operator=
Distribution & operator=(Distribution const &)
Definition
Distribution.cpp:29
storm::generator::Distribution::begin
ContainerType::iterator begin()
Access to iterators over the entries of the distribution.
Definition
Distribution.cpp:109
storm::generator::Distribution::divide
void divide(ValueType const &value)
Divides all values in the distribution by the provided value.
Definition
Distribution.cpp:96
storm::generator::Distribution::compress
void compress()
Compresses the internal storage by summing the values of entries which agree on the index.
Definition
Distribution.cpp:66
storm::generator::Distribution::end
ContainerType::iterator end()
Definition
Distribution.cpp:119
storm::generator::Distribution::add
void add(DistributionEntry< IndexType, ValueType > const &entry)
Adds the given entry to the distribution.
Definition
Distribution.cpp:48
Distribution.h
storm::generator
Definition
BeliefSupportTracker.cpp:6
src
storm
generator
Distribution.cpp
Generated by
1.15.0