Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseAccumulator.cpp
Go to the documentation of this file.
2
3#include <utility>
4
9
10namespace storm::bisimulation {
11
12template<typename ValueType>
13SparseAccumulator<ValueType>::SparseAccumulator(uint64_t const numStates) : values(numStates, defaultValue()) {}
14
15template<typename ValueType>
16std::vector<ValueType> const& SparseAccumulator<ValueType>::getValues() const {
17 return values;
18}
19
20template<typename ValueType>
21std::vector<uint64_t> const& SparseAccumulator<ValueType>::getNonDefaultStates() const {
22 return nonDefaultStates;
23}
24
25template<typename ValueType>
26void SparseAccumulator<ValueType>::addValue(uint64_t const state, ValueType value) {
27 if constexpr (std::is_same_v<ValueType, uint64_t>) { // WrappingSetAccumulator case
28 // We only store the value modulo 64, namely as a bit of the mask of the given state.
29 if (values[state] == 0ull) {
30 nonDefaultStates.push_back(state);
31 }
32 values[state] |= 1ull << (value % 64ull);
33 } else {
34 STORM_LOG_ASSERT(!storm::utility::isZero(value), "Did not expect adding 0 probability");
35 if (storm::utility::isZero(values[state])) {
36 nonDefaultStates.push_back(state);
37 values[state] = std::move(value);
38 } else {
39 values[state] += std::move(value);
40 }
41 }
42}
43
44template<typename ValueType>
46 for (auto const& state : nonDefaultStates) {
47 values[state] = defaultValue();
48 }
49 nonDefaultStates.clear();
50}
51
52template<typename ValueType>
53ValueType SparseAccumulator<ValueType>::defaultValue() {
55}
56
57template class SparseAccumulator<double>;
58template class SparseAccumulator<storm::RationalNumber>;
59template class SparseAccumulator<storm::RationalFunction>;
60template class SparseAccumulator<uint64_t>; // WrappingSetAccumulator
61
62} // namespace storm::bisimulation
void clear()
Clears the set, i.e., writes the default value for all states.
std::vector< ValueType > const & getValues() const
SparseAccumulator(uint64_t const numStates)
std::vector< uint64_t > const & getNonDefaultStates() const
void addValue(uint64_t const state, ValueType value)
Adds value to the currently mapped value of the given state, i.e., inserts it into the set of that st...
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
bool isZero(ValueType const &a)
Definition constants.cpp:44
ValueType zero()
Definition constants.cpp:26