Storm
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
10#include "NativeMultiplier.h"
14
20
21namespace storm {
22namespace solver {
23
24template<typename ValueType>
26 // Intentionally left empty.
27}
28
29template<typename ValueType>
31 cachedVector.reset();
32}
33
34template<typename ValueType>
35void Multiplier<ValueType>::multiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType> const& x,
36 std::vector<ValueType> const* b, std::vector<ValueType>& result, std::vector<uint_fast64_t>* choices) const {
37 multiplyAndReduce(env, dir, this->matrix.getRowGroupIndices(), x, b, result, choices);
38}
39
40template<typename ValueType>
41void Multiplier<ValueType>::multiplyAndReduceGaussSeidel(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType>& x,
42 std::vector<ValueType> const* b, std::vector<uint_fast64_t>* choices, bool backwards) const {
43 multiplyAndReduceGaussSeidel(env, dir, this->matrix.getRowGroupIndices(), x, b, choices, backwards);
44}
45
46template<typename ValueType>
47void Multiplier<ValueType>::repeatedMultiply(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b, uint64_t n) const {
48 storm::utility::ProgressMeasurement progress("multiplications");
49 progress.setMaxCount(n);
50 progress.startNewMeasurement(0);
51 for (uint64_t i = 0; i < n; ++i) {
52 progress.updateProgress(i);
53 multiply(env, x, b, x);
55 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications.");
56 break;
57 }
58 }
59}
60
61template<typename ValueType>
62void Multiplier<ValueType>::repeatedMultiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType>& x,
63 std::vector<ValueType> const* b, uint64_t n) const {
64 storm::utility::ProgressMeasurement progress("multiplications");
65 progress.setMaxCount(n);
66 progress.startNewMeasurement(0);
67 for (uint64_t i = 0; i < n; ++i) {
68 multiplyAndReduce(env, dir, x, b, x);
70 STORM_LOG_WARN("Aborting after " << i << " of " << n << " multiplications");
71 break;
72 }
73 }
74}
75
76template<typename ValueType>
77void Multiplier<ValueType>::multiplyRow2(uint64_t const& rowIndex, std::vector<ValueType> const& x1, ValueType& val1, std::vector<ValueType> const& x2,
78 ValueType& val2) const {
79 multiplyRow(rowIndex, x1, val1);
80 multiplyRow(rowIndex, x2, val2);
81}
82
83template<typename ValueType>
84std::unique_ptr<Multiplier<ValueType>> MultiplierFactory<ValueType>::create(Environment const& env, storm::storage::SparseMatrix<ValueType> const& matrix) {
85 auto type = env.solver().multiplier().getType();
86
87 // Adjust the multiplier type if an eqsolver was specified but not a multiplier
89 bool changed = false;
90 if (env.solver().getLinearEquationSolverType() == EquationSolverType::Gmmxx && type != MultiplierType::Gmmxx) {
91 type = MultiplierType::Gmmxx;
92 changed = true;
93 } else if (env.solver().getLinearEquationSolverType() == EquationSolverType::Native && type != MultiplierType::Native) {
94 type = MultiplierType::Native;
95 changed = true;
96 }
97 STORM_LOG_INFO_COND(!changed, "Selecting '" + toString(type) +
98 "' as the multiplier type to match the selected equation solver. If you want to override this, please explicitly "
99 "specify a different multiplier type.");
100 }
101
102 switch (type) {
103 case MultiplierType::Gmmxx:
104 if constexpr (std::is_same_v<ValueType, storm::Interval>) {
105 throw storm::exceptions::NotImplementedException() << "Gmm not supported with intervals.";
106 }
107 return std::make_unique<GmmxxMultiplier<ValueType>>(matrix);
108 case MultiplierType::Native:
109 return std::make_unique<NativeMultiplier<ValueType>>(matrix);
110 }
111 STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentException, "Unknown MultiplierType");
112}
113
114template class Multiplier<double>;
115template class MultiplierFactory<double>;
120template class Multiplier<storm::Interval>;
122
123} // namespace solver
124} // namespace storm
SolverEnvironment & solver()
bool const & isTypeSetFromDefault() const
storm::solver::MultiplierType const & getType() const
MultiplierEnvironment & multiplier()
storm::solver::EquationSolverType const & getLinearEquationSolverType() const
bool isLinearEquationSolverTypeSetFromDefaultValue() const
std::unique_ptr< Multiplier< ValueType > > create(Environment const &env, storm::storage::SparseMatrix< ValueType > const &matrix)
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...
virtual 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,...
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.
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.
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_WARN(message)
Definition logging.h:30
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
#define STORM_LOG_INFO_COND(cond, message)
Definition macros.h:45
std::string toString(GurobiSolverMethod const &method)
Yields a string representation of the GurobiSolverMethod.
bool isTerminate()
Check whether the program should terminate (due to some abort signal).
LabParser.cpp.
Definition cli.cpp:18