Storm 1.11.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Multiplier.cpp
Go to the documentation of this file.
2
3#include "storm-config.h"
4
6
9
13
15
21
22namespace storm {
23namespace solver {
24
25template<typename ValueType>
27 // Intentionally left empty.
28}
29
30template<typename ValueType>
32 cachedVector.reset();
33}
34
35template<typename ValueType>
36void Multiplier<ValueType>::multiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType> const& x,
37 std::vector<ValueType> const* b, std::vector<ValueType>& result, std::vector<uint_fast64_t>* choices) const {
38 multiplyAndReduce(env, dir, this->matrix.getRowGroupIndices(), x, b, result, choices);
39}
40
41template<typename ValueType>
42void Multiplier<ValueType>::multiplyAndReduceGaussSeidel(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType>& x,
43 std::vector<ValueType> const* b, std::vector<uint_fast64_t>* choices, bool backwards) const {
44 multiplyAndReduceGaussSeidel(env, dir, this->matrix.getRowGroupIndices(), x, b, choices, backwards);
45}
46
47template<typename ValueType>
48void Multiplier<ValueType>::repeatedMultiply(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b, uint64_t n) const {
49 storm::utility::ProgressMeasurement progress("multiplications");
50 progress.setMaxCount(n);
51 progress.startNewMeasurement(0);
52 for (uint64_t i = 0; i < n; ++i) {
53 progress.updateProgress(i);
54 multiply(env, x, b, x);
56 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications.");
57 break;
58 }
59 }
60}
61
62template<typename ValueType>
63void Multiplier<ValueType>::repeatedMultiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType>& x,
64 std::vector<ValueType> const* b, uint64_t n) const {
65 storm::utility::ProgressMeasurement progress("multiplications");
66 progress.setMaxCount(n);
67 progress.startNewMeasurement(0);
68 for (uint64_t i = 0; i < n; ++i) {
69 progress.updateProgress(i);
70 multiplyAndReduce(env, dir, x, b, x);
72 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications");
73 break;
74 }
75 }
76}
77
78template<typename ValueType>
80 std::vector<ValueType> const* b, uint64_t n, ValueType factor) const {
81 storm::utility::ProgressMeasurement progress("multiplications");
82 progress.setMaxCount(n);
83 progress.startNewMeasurement(0);
84 for (uint64_t i = 0; i < n; ++i) {
85 progress.updateProgress(i);
86 std::transform(x.begin(), x.end(), x.begin(), [factor](ValueType& c) { return c * factor; });
87 multiplyAndReduce(env, dir, x, b, x);
89 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications");
90 break;
91 }
92 }
93}
94
95template<typename ValueType>
96void Multiplier<ValueType>::repeatedMultiplyWithFactor(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b, uint64_t n,
97 ValueType factor) const {
98 storm::utility::ProgressMeasurement progress("multiplications");
99 progress.setMaxCount(n);
100 progress.startNewMeasurement(0);
101 for (uint64_t i = 0; i < n; ++i) {
102 progress.updateProgress(i);
103 std::transform(x.begin(), x.end(), x.begin(), [factor](ValueType& c) { return c * factor; });
104 multiply(env, x, b, x);
106 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications");
107 break;
108 }
109 }
110}
111
112template<typename ValueType>
113
114std::vector<ValueType>& Multiplier<ValueType>::provideCachedVector(uint64_t size) const {
115 if (this->cachedVector) {
116 this->cachedVector->resize(size);
117 } else {
118 this->cachedVector = std::make_unique<std::vector<ValueType>>(size);
119 }
120 return *this->cachedVector;
121}
122
123template<typename ValueType>
124std::unique_ptr<Multiplier<ValueType>> MultiplierFactory<ValueType>::create(Environment const& env, storm::storage::SparseMatrix<ValueType> const& matrix) {
125 auto type = env.solver().multiplier().getType();
126
127 // Adjust the type if the ValueType is not supported
128 if (type == MultiplierType::ViOperator && (std::is_same_v<ValueType, storm::RationalFunction> || std::is_same_v<ValueType, storm::Interval>)) {
129 STORM_LOG_INFO("Switching multiplier type from 'vioperator' to 'native' because the given ValueType is not supported by the VI Operator multiplier.");
130 type = MultiplierType::Native;
131 }
132
133 switch (type) {
134 case MultiplierType::ViOperator:
135 if constexpr (std::is_same_v<ValueType, storm::RationalFunction> || std::is_same_v<ValueType, storm::Interval>) {
136 throw storm::exceptions::NotImplementedException() << "VI Operator multiplier not supported with given value type.";
137 }
138 if (matrix.hasTrivialRowGrouping()) {
139 return std::make_unique<ViOperatorMultiplier<ValueType, true>>(matrix);
140 } else {
141 return std::make_unique<ViOperatorMultiplier<ValueType, false>>(matrix);
142 }
143 case MultiplierType::Native:
144 return std::make_unique<NativeMultiplier<ValueType>>(matrix);
145 }
146 STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentException, "Unknown MultiplierType");
147}
148
149template class Multiplier<double>;
150template class MultiplierFactory<double>;
155template class Multiplier<storm::Interval>;
157
158} // namespace solver
159} // namespace storm
SolverEnvironment & solver()
storm::solver::MultiplierType const & getType() const
MultiplierEnvironment & multiplier()
std::unique_ptr< Multiplier< ValueType > > create(Environment const &env, storm::storage::SparseMatrix< ValueType > const &matrix)
std::vector< ValueType > & provideCachedVector(uint64_t size) const
virtual void clearCache() const
void multiplyAndReduceGaussSeidel(Environment const &env, OptimizationDirection const &dir, std::vector< ValueType > &x, std::vector< ValueType > const *b, std::vector< uint_fast64_t > *choices=nullptr, bool backwards=true) const
Performs a matrix-vector multiplication in gauss-seidel style and then minimizes/maximizes over the r...
void multiplyAndReduce(Environment const &env, OptimizationDirection const &dir, std::vector< ValueType > const &x, std::vector< ValueType > const *b, std::vector< ValueType > &result, std::vector< uint_fast64_t > *choices=nullptr) const
Performs a matrix-vector multiplication x' = A*x + b and then minimizes/maximizes over the row groups...
void repeatedMultiplyWithFactor(Environment const &env, std::vector< ValueType > &x, std::vector< ValueType > const *b, uint64_t n, ValueType factor) const
Performs repeated matrix-vector multiplication x' = A*(factor * x) + b.
void repeatedMultiply(Environment const &env, std::vector< ValueType > &x, std::vector< ValueType > const *b, uint64_t n) const
Performs repeated matrix-vector multiplication, using x[0] = x and x[i + 1] = A*x[i] + b.
void repeatedMultiplyAndReduceWithFactor(Environment const &env, OptimizationDirection const &dir, std::vector< ValueType > &x, std::vector< ValueType > const *b, uint64_t n, ValueType factor) const
Performs repeated matrix-vector multiplication x' = A*(factor * x) + b, minimizes/maximizes over the ...
Multiplier(storm::storage::SparseMatrix< ValueType > const &matrix)
void repeatedMultiplyAndReduce(Environment const &env, OptimizationDirection const &dir, std::vector< ValueType > &x, std::vector< ValueType > const *b, uint64_t n) const
Performs repeated matrix-vector multiplication x' = A*x + b and then minimizes/maximizes over the row...
A class that holds a possibly non-square matrix in the compressed row storage format.
bool hasTrivialRowGrouping() const
Retrieves whether the matrix has a trivial row grouping.
A class that provides convenience operations to display run times.
bool updateProgress(uint64_t count)
Updates the progress to the current count and prints it if the delay passed.
void setMaxCount(uint64_t maxCount)
Sets the maximal possible count.
void startNewMeasurement(uint64_t startCount)
Starts a new measurement, dropping all progress information collected so far.
#define STORM_LOG_INFO(message)
Definition logging.h:24
#define STORM_LOG_WARN(message)
Definition logging.h:25
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
bool isTerminate()
Check whether the program should terminate (due to some abort signal).
LabParser.cpp.