Storm 1.13.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
NativeMultiplier.cpp
Go to the documentation of this file.
1#include "NativeMultiplier.h"
2
11
12namespace storm {
13namespace solver {
14
15template<typename ValueType>
19
20template<typename ValueType>
21void NativeMultiplier<ValueType>::multiply(Environment const& env, std::vector<ValueType> const& x, std::vector<ValueType> const* b,
22 std::vector<ValueType>& result) const {
23 std::vector<ValueType>* target = &result;
24 if (&x == &result) {
25 target = &this->provideCachedVector(x.size());
26 }
27 multAdd(x, b, *target);
28 if (&x == &result) {
29 std::swap(result, *target);
30 }
31}
32
33template<typename ValueType>
34void NativeMultiplier<ValueType>::multiplyGaussSeidel(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b,
35 bool backwards) const {
36 if (backwards) {
37 this->matrix.multiplyWithVectorBackward(x, x, b);
38 } else {
39 this->matrix.multiplyWithVectorForward(x, x, b);
40 }
41}
42
43template<typename ValueType>
44void NativeMultiplier<ValueType>::multiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices,
45 std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result,
46 UncertaintyResolutionMode const& uncertaintyResolutionMode, std::vector<uint_fast64_t>* choices) const {
47 STORM_LOG_THROW(uncertaintyResolutionMode == UncertaintyResolutionMode::Unset, storm::exceptions::NotSupportedException,
48 "Uncertainty resolution modes other than 'Unset' are not supported by the native multiplier.");
49
50 std::vector<ValueType>* target = &result;
51 if (&x == &result) {
52 target = &this->provideCachedVector(x.size());
53 }
54 multAddReduce(dir, rowGroupIndices, x, b, *target, choices);
55 if (&x == &result) {
56 std::swap(result, *target);
57 }
58}
59
60template<typename ValueType>
62 std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType>& x,
63 std::vector<ValueType> const* b, std::vector<uint_fast64_t>* choices, bool backwards) const {
64 if (backwards) {
65 this->matrix.multiplyAndReduceBackward(dir, rowGroupIndices, x, b, x, choices);
66 } else {
67 this->matrix.multiplyAndReduceForward(dir, rowGroupIndices, x, b, x, choices);
68 }
69}
70
71template<typename ValueType>
72void NativeMultiplier<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType& value) const {
73 for (auto const& entry : this->matrix.getRow(rowIndex)) {
74 value += entry.getValue() * x[entry.getColumn()];
75 }
76}
77
78template<typename ValueType>
79void NativeMultiplier<ValueType>::multiplyRow2(uint64_t const& rowIndex, std::vector<ValueType> const& x1, ValueType& val1, std::vector<ValueType> const& x2,
80 ValueType& val2) const {
81 for (auto const& entry : this->matrix.getRow(rowIndex)) {
82 val1 += entry.getValue() * x1[entry.getColumn()];
83 val2 += entry.getValue() * x2[entry.getColumn()];
84 }
85}
86
87template<typename ValueType>
88void NativeMultiplier<ValueType>::multAdd(std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result) const {
89 this->matrix.multiplyWithVector(x, result, b);
90}
91
92template<typename ValueType>
93void NativeMultiplier<ValueType>::multAddReduce(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices,
94 std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result,
95 std::vector<uint64_t>* choices) const {
96 this->matrix.multiplyAndReduce(dir, rowGroupIndices, x, b, result, choices);
97}
98
99template class NativeMultiplier<double>;
100template class NativeMultiplier<storm::RationalNumber>;
101template class NativeMultiplier<storm::RationalFunction>;
102template class NativeMultiplier<storm::Interval>;
103
104} // namespace solver
105} // namespace storm
Multiplier(storm::storage::SparseMatrix< ValueType > const &matrix)
std::vector< SolutionType > & provideCachedVector(uint64_t size) const
storm::storage::SparseMatrix< ValueType > const & matrix
Definition Multiplier.h:168
virtual void multiplyAndReduceGaussSeidel(Environment const &env, OptimizationDirection const &dir, std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > &x, std::vector< ValueType > const *b, std::vector< uint_fast64_t > *choices=nullptr, bool backwards=true) const override
void multiplyRow(uint64_t const &rowIndex, std::vector< ValueType > const &x, ValueType &value) const
Multiplies the row with the given index with x and adds the result to the provided value.
NativeMultiplier(storm::storage::SparseMatrix< ValueType > const &matrix)
void multiplyRow2(uint64_t const &rowIndex, std::vector< ValueType > const &x1, ValueType &val1, std::vector< ValueType > const &x2, ValueType &val2) const
Multiplies the row with the given index with x1 and x2 and adds the given offset o1 and o2,...
virtual void multiplyAndReduce(Environment const &env, OptimizationDirection const &dir, std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > const &x, std::vector< ValueType > const *b, std::vector< ValueType > &result, UncertaintyResolutionMode const &uncertaintyResolutionMode=UncertaintyResolutionMode::Unset, std::vector< uint_fast64_t > *choices=nullptr) const override
virtual void multiplyGaussSeidel(Environment const &env, std::vector< ValueType > &x, std::vector< ValueType > const *b, bool backwards=true) const override
virtual void multiply(Environment const &env, std::vector< ValueType > const &x, std::vector< ValueType > const *b, std::vector< ValueType > &result) const override
A class that holds a possibly non-square matrix in the compressed row storage format.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30