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>
77
78std::vector<ValueType>& Multiplier<ValueType>::provideCachedVector(uint64_t size) const {
79 if (this->cachedVector) {
80 this->cachedVector->resize(size);
81 } else {
82 this->cachedVector = std::make_unique<std::vector<ValueType>>(size);
83 }
84 return *this->cachedVector;
85}
86
87template<typename ValueType>
88std::unique_ptr<Multiplier<ValueType>> MultiplierFactory<ValueType>::create(Environment const& env, storm::storage::SparseMatrix<ValueType> const& matrix) {
89 auto type = env.solver().multiplier().getType();
90
91 // Adjust the type if the ValueType is not supported
92 if (type == MultiplierType::ViOperator && (std::is_same_v<ValueType, storm::RationalFunction> || std::is_same_v<ValueType, storm::Interval>)) {
93 STORM_LOG_INFO("Switching multiplier type from 'vioperator' to 'native' because the given ValueType is not supported by the VI Operator multiplier.");
94 type = MultiplierType::Native;
95 }
96
97 switch (type) {
98 case MultiplierType::ViOperator:
99 if constexpr (std::is_same_v<ValueType, storm::RationalFunction> || std::is_same_v<ValueType, storm::Interval>) {
100 throw storm::exceptions::NotImplementedException() << "VI Operator multiplier not supported with given value type.";
101 }
102 if (matrix.hasTrivialRowGrouping()) {
103 return std::make_unique<ViOperatorMultiplier<ValueType, true>>(matrix);
104 } else {
105 return std::make_unique<ViOperatorMultiplier<ValueType, false>>(matrix);
106 }
107 case MultiplierType::Native:
108 return std::make_unique<NativeMultiplier<ValueType>>(matrix);
109 }
110 STORM_LOG_THROW(false, storm::exceptions::IllegalArgumentException, "Unknown MultiplierType");
111}
112
113template class Multiplier<double>;
114template class MultiplierFactory<double>;
119template class Multiplier<storm::Interval>;
121
122} // namespace solver
123} // 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 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.
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:29
#define STORM_LOG_WARN(message)
Definition logging.h:30
#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.
Definition cli.cpp:18