Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Multiplier.cpp
Go to the documentation of this file.
2
16
17namespace storm {
18namespace solver {
19
20template<typename ValueType>
22 // Intentionally left empty.
23}
24
25template<typename ValueType>
27 cachedVector.reset();
28}
29
30template<typename ValueType>
31void Multiplier<ValueType>::multiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType> const& x,
32 std::vector<ValueType> const* b, std::vector<ValueType>& result, std::vector<uint_fast64_t>* choices) const {
33 multiplyAndReduce(env, dir, this->matrix.getRowGroupIndices(), x, b, result, choices);
34}
35
36template<typename ValueType>
37void Multiplier<ValueType>::multiplyAndReduceGaussSeidel(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType>& x,
38 std::vector<ValueType> const* b, std::vector<uint_fast64_t>* choices, bool backwards) const {
39 multiplyAndReduceGaussSeidel(env, dir, this->matrix.getRowGroupIndices(), x, b, choices, backwards);
40}
41
42template<typename ValueType>
43void Multiplier<ValueType>::repeatedMultiply(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b, uint64_t n) const {
44 storm::utility::ProgressMeasurement progress("multiplications");
45 progress.setMaxCount(n);
46 progress.startNewMeasurement(0);
47 for (uint64_t i = 0; i < n; ++i) {
48 progress.updateProgress(i);
49 multiply(env, x, b, x);
51 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications.");
52 break;
53 }
54 }
55}
56
57template<typename ValueType>
58void Multiplier<ValueType>::repeatedMultiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType>& x,
59 std::vector<ValueType> const* b, uint64_t n) const {
60 storm::utility::ProgressMeasurement progress("multiplications");
61 progress.setMaxCount(n);
62 progress.startNewMeasurement(0);
63 for (uint64_t i = 0; i < n; ++i) {
64 progress.updateProgress(i);
65 multiplyAndReduce(env, dir, x, b, x);
67 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications");
68 break;
69 }
70 }
71}
72
73template<typename ValueType>
75 std::vector<ValueType> const* b, uint64_t n, ValueType factor) const {
76 storm::utility::ProgressMeasurement progress("multiplications");
77 progress.setMaxCount(n);
78 progress.startNewMeasurement(0);
79 for (uint64_t i = 0; i < n; ++i) {
80 progress.updateProgress(i);
81 std::transform(x.begin(), x.end(), x.begin(), [factor](ValueType& c) { return c * factor; });
82 multiplyAndReduce(env, dir, x, b, x);
84 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications");
85 break;
86 }
87 }
88}
89
90template<typename ValueType>
91void Multiplier<ValueType>::repeatedMultiplyWithFactor(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b, uint64_t n,
92 ValueType factor) const {
93 storm::utility::ProgressMeasurement progress("multiplications");
94 progress.setMaxCount(n);
95 progress.startNewMeasurement(0);
96 for (uint64_t i = 0; i < n; ++i) {
97 progress.updateProgress(i);
98 std::transform(x.begin(), x.end(), x.begin(), [factor](ValueType& c) { return c * factor; });
99 multiply(env, x, b, x);
101 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications");
102 break;
103 }
104 }
105}
106
107template<typename ValueType>
108
109std::vector<ValueType>& Multiplier<ValueType>::provideCachedVector(uint64_t size) const {
110 if (this->cachedVector) {
111 this->cachedVector->resize(size);
112 } else {
113 this->cachedVector = std::make_unique<std::vector<ValueType>>(size);
114 }
115 return *this->cachedVector;
116}
117
118template<typename ValueType>
119std::unique_ptr<Multiplier<ValueType>> MultiplierFactory<ValueType>::create(Environment const& env, storm::storage::SparseMatrix<ValueType> const& matrix) {
120 auto type = env.solver().multiplier().getType();
121
122 // Adjust the type if the ValueType is not supported
123 if (type == MultiplierType::ViOperator && (std::is_same_v<ValueType, storm::RationalFunction> || std::is_same_v<ValueType, storm::Interval>)) {
124 STORM_LOG_INFO("Switching multiplier type from 'vioperator' to 'native' because the given ValueType is not supported by the VI Operator multiplier.");
125 type = MultiplierType::Native;
126 }
127
128 switch (type) {
129 case MultiplierType::ViOperator:
130 if constexpr (std::is_same_v<ValueType, storm::RationalFunction> || std::is_same_v<ValueType, storm::Interval>) {
131 throw storm::exceptions::NotImplementedException() << "VI Operator multiplier not supported with given value type.";
132 }
133 if (matrix.hasTrivialRowGrouping()) {
134 return std::make_unique<ViOperatorMultiplier<ValueType, true>>(matrix);
135 } else {
136 return std::make_unique<ViOperatorMultiplier<ValueType, false>>(matrix);
137 }
138 case MultiplierType::Native:
139 return std::make_unique<NativeMultiplier<ValueType>>(matrix);
140 }
141 STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentException, "Unknown MultiplierType");
142}
143
144template class Multiplier<double>;
145template class MultiplierFactory<double>;
150template class Multiplier<storm::Interval>;
152
153} // namespace solver
154} // 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).