diff --git a/src/storm/solver/EigenLinearEquationSolver.cpp b/src/storm/solver/EigenLinearEquationSolver.cpp index 874d6f4c4..bcba06888 100644 --- a/src/storm/solver/EigenLinearEquationSolver.cpp +++ b/src/storm/solver/EigenLinearEquationSolver.cpp @@ -268,6 +268,13 @@ namespace storm { } } + template + ValueType EigenLinearEquationSolver::multiplyRow(uint64_t const& rowIndex, std::vector const& x) const { + auto eigenX = StormEigen::Matrix::Map(x.data(), x.size()); + return (eigenA->row(rowIndex) * eigenX)(0); + } + + template LinearEquationSolverProblemFormat EigenLinearEquationSolver::getEquationProblemFormat(Environment const& env) const { return LinearEquationSolverProblemFormat::EquationSystem; diff --git a/src/storm/solver/EigenLinearEquationSolver.h b/src/storm/solver/EigenLinearEquationSolver.h index a6bbae91a..0bdeabba1 100644 --- a/src/storm/solver/EigenLinearEquationSolver.h +++ b/src/storm/solver/EigenLinearEquationSolver.h @@ -21,6 +21,8 @@ namespace storm { virtual void setMatrix(storm::storage::SparseMatrix&& A) override; virtual void multiply(std::vector& x, std::vector const* b, std::vector& result) const override; + virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector const& x) const override; + virtual LinearEquationSolverProblemFormat getEquationProblemFormat(Environment const& env) const override; diff --git a/src/storm/solver/EliminationLinearEquationSolver.cpp b/src/storm/solver/EliminationLinearEquationSolver.cpp index 3e84b7f0c..2e67119d6 100644 --- a/src/storm/solver/EliminationLinearEquationSolver.cpp +++ b/src/storm/solver/EliminationLinearEquationSolver.cpp @@ -109,6 +109,11 @@ namespace storm { } } } + + template + ValueType EliminationLinearEquationSolver::multiplyRow(uint64_t const& rowIndex, std::vector const& x) const { + return A->multiplyRowWithVector(rowIndex, x); + } template LinearEquationSolverProblemFormat EliminationLinearEquationSolver::getEquationProblemFormat(Environment const& env) const { diff --git a/src/storm/solver/EliminationLinearEquationSolver.h b/src/storm/solver/EliminationLinearEquationSolver.h index 60403336e..57da6bbaa 100644 --- a/src/storm/solver/EliminationLinearEquationSolver.h +++ b/src/storm/solver/EliminationLinearEquationSolver.h @@ -22,6 +22,8 @@ namespace storm { virtual void setMatrix(storm::storage::SparseMatrix&& A) override; virtual void multiply(std::vector& x, std::vector const* b, std::vector& result) const override; + virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector const& x) const override; + virtual LinearEquationSolverProblemFormat getEquationProblemFormat(Environment const& env) const override; diff --git a/src/storm/solver/GmmxxLinearEquationSolver.cpp b/src/storm/solver/GmmxxLinearEquationSolver.cpp index 0f517d5a9..f87a02a96 100644 --- a/src/storm/solver/GmmxxLinearEquationSolver.cpp +++ b/src/storm/solver/GmmxxLinearEquationSolver.cpp @@ -145,6 +145,12 @@ namespace storm { multiplier.multAddReduceGaussSeidel(dir, rowGroupIndices, *gmmxxA, x, b, choices); } + template + ValueType GmmxxLinearEquationSolver::multiplyRow(uint64_t const& rowIndex, std::vector const& x) const { + return multiplier.multiplyRow(*gmmxxA, rowIndex, x); + } + + template LinearEquationSolverProblemFormat GmmxxLinearEquationSolver::getEquationProblemFormat(Environment const& env) const { return LinearEquationSolverProblemFormat::EquationSystem; diff --git a/src/storm/solver/GmmxxLinearEquationSolver.h b/src/storm/solver/GmmxxLinearEquationSolver.h index bb08cf007..434d5688a 100644 --- a/src/storm/solver/GmmxxLinearEquationSolver.h +++ b/src/storm/solver/GmmxxLinearEquationSolver.h @@ -32,6 +32,7 @@ namespace storm { virtual bool supportsGaussSeidelMultiplication() const override; virtual void multiplyGaussSeidel(std::vector& x, std::vector const* b) const override; virtual void multiplyAndReduceGaussSeidel(OptimizationDirection const& dir, std::vector const& rowGroupIndices, std::vector& x, std::vector const* b, std::vector* choices = nullptr) const override; + virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector const& x) const override; virtual LinearEquationSolverProblemFormat getEquationProblemFormat(Environment const& env) const override; diff --git a/src/storm/solver/GmmxxMultiplier.cpp b/src/storm/solver/GmmxxMultiplier.cpp index b05ef8bcc..5158d03fb 100644 --- a/src/storm/solver/GmmxxMultiplier.cpp +++ b/src/storm/solver/GmmxxMultiplier.cpp @@ -231,6 +231,14 @@ namespace storm { STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "This operation is not supported."); } + template + T GmmxxMultiplier::multiplyRow(gmm::csr_matrix const& matrix, uint64_t const& rowIndex, std::vector const& x) const { + return vect_sp(gmm::mat_const_row(matrix, rowIndex), x, typename gmm::linalg_traits>::storage_type(), typename gmm::linalg_traits>::storage_type()); + } + + + + template class GmmxxMultiplier; #ifdef STORM_HAVE_CARL diff --git a/src/storm/solver/GmmxxMultiplier.h b/src/storm/solver/GmmxxMultiplier.h index 237f56b63..aebdb069d 100644 --- a/src/storm/solver/GmmxxMultiplier.h +++ b/src/storm/solver/GmmxxMultiplier.h @@ -23,6 +23,8 @@ namespace storm { void multAddParallel(gmm::csr_matrix const& matrix, std::vector const& x, std::vector const* b, std::vector& result) const; void multAddReduceParallel(storm::solver::OptimizationDirection const& dir, std::vector const& rowGroupIndices, gmm::csr_matrix const& matrix, std::vector const& x, std::vector const* b, std::vector& result, std::vector* choices = nullptr) const; + T multiplyRow(gmm::csr_matrix const& matrix, uint64_t const& rowIndex, std::vector const& x) const; + private: void multAddReduceHelper(storm::solver::OptimizationDirection const& dir, std::vector const& rowGroupIndices, gmm::csr_matrix const& matrix, std::vector const& x, std::vector const* b, std::vector& result, std::vector* choices = nullptr) const; }; diff --git a/src/storm/solver/LinearEquationSolver.h b/src/storm/solver/LinearEquationSolver.h index b4b49d627..cc2f73a7a 100644 --- a/src/storm/solver/LinearEquationSolver.h +++ b/src/storm/solver/LinearEquationSolver.h @@ -109,6 +109,14 @@ namespace storm { */ virtual void multiplyAndReduceGaussSeidel(OptimizationDirection const& dir, std::vector const& rowGroupIndices, std::vector& x, std::vector const* b, std::vector* choices = nullptr) const; + /*! + * Multiplies the row with the given index with x and adds the given offset + * @param rowIndex The index of the considered row + * @param x The input vector with which the row is multiplied + * @param offset A value that is added to the matrix-vector multiplication result + */ + virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector const& x) const = 0; + /*! * Performs repeated matrix-vector multiplication, using x[0] = x and x[i + 1] = A*x[i] + b. After * performing the necessary multiplications, the result is written to the input vector x. Note that the diff --git a/src/storm/solver/NativeLinearEquationSolver.cpp b/src/storm/solver/NativeLinearEquationSolver.cpp index c140dcf3f..0199857d1 100644 --- a/src/storm/solver/NativeLinearEquationSolver.cpp +++ b/src/storm/solver/NativeLinearEquationSolver.cpp @@ -1081,6 +1081,12 @@ namespace storm { multiplier.multAddReduceGaussSeidelBackward(dir, rowGroupIndices, *A, x, b, choices); } + template + ValueType NativeLinearEquationSolver::multiplyRow(uint64_t const& rowIndex, std::vector const& x) const { + return multiplier.multiplyRow(*A, rowIndex, x); + } + + template LinearEquationSolverProblemFormat NativeLinearEquationSolver::getEquationProblemFormat(Environment const& env) const { auto method = getMethod(env, storm::NumberTraits::IsExact); diff --git a/src/storm/solver/NativeLinearEquationSolver.h b/src/storm/solver/NativeLinearEquationSolver.h index 34ff42bf7..fbb5d4357 100644 --- a/src/storm/solver/NativeLinearEquationSolver.h +++ b/src/storm/solver/NativeLinearEquationSolver.h @@ -35,7 +35,8 @@ namespace storm { virtual bool supportsGaussSeidelMultiplication() const override; virtual void multiplyGaussSeidel(std::vector& x, std::vector const* b) const override; virtual void multiplyAndReduceGaussSeidel(OptimizationDirection const& dir, std::vector const& rowGroupIndices, std::vector& x, std::vector const* b, std::vector* choices = nullptr) const override; - + virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector const& x) const override; + virtual LinearEquationSolverProblemFormat getEquationProblemFormat(storm::Environment const& env) const override; virtual LinearEquationSolverRequirements getRequirements(Environment const& env, LinearEquationSolverTask const& task = LinearEquationSolverTask::Unspecified) const override; diff --git a/src/storm/solver/NativeMultiplier.cpp b/src/storm/solver/NativeMultiplier.cpp index f5fc1d903..ddbeb235f 100644 --- a/src/storm/solver/NativeMultiplier.cpp +++ b/src/storm/solver/NativeMultiplier.cpp @@ -89,6 +89,10 @@ namespace storm { #endif } + template + ValueType NativeMultiplier::multiplyRow(storm::storage::SparseMatrix const& matrix, uint64_t const& rowIndex, std::vector const& x) const { + return matrix.multiplyRowWithVector(rowIndex, x); + } template class NativeMultiplier; diff --git a/src/storm/solver/NativeMultiplier.h b/src/storm/solver/NativeMultiplier.h index 01233b1ba..ea8f543d4 100644 --- a/src/storm/solver/NativeMultiplier.h +++ b/src/storm/solver/NativeMultiplier.h @@ -25,6 +25,8 @@ namespace storm { void multAddParallel(storm::storage::SparseMatrix const& matrix, std::vector const& x, std::vector const* b, std::vector& result) const; void multAddReduceParallel(storm::solver::OptimizationDirection const& dir, std::vector const& rowGroupIndices, storm::storage::SparseMatrix const& matrix, std::vector const& x, std::vector const* b, std::vector& result, std::vector* choices = nullptr) const; + + ValueType multiplyRow(storm::storage::SparseMatrix const& matrix, uint64_t const& rowIndex, std::vector const& x) const; }; } diff --git a/src/storm/solver/TopologicalLinearEquationSolver.cpp b/src/storm/solver/TopologicalLinearEquationSolver.cpp index 69a3efe18..9f6dcdebf 100644 --- a/src/storm/solver/TopologicalLinearEquationSolver.cpp +++ b/src/storm/solver/TopologicalLinearEquationSolver.cpp @@ -354,6 +354,11 @@ namespace storm { multiplier.multAddReduceGaussSeidelBackward(dir, rowGroupIndices, *A, x, b, choices); } + template + ValueType TopologicalLinearEquationSolver::multiplyRow(uint64_t const& rowIndex, std::vector const& x) const { + return multiplier.multiplyRow(*A, rowIndex, x); + } + template LinearEquationSolverProblemFormat TopologicalLinearEquationSolver::getEquationProblemFormat(Environment const& env) const { return LinearEquationSolverProblemFormat::FixedPointSystem; diff --git a/src/storm/solver/TopologicalLinearEquationSolver.h b/src/storm/solver/TopologicalLinearEquationSolver.h index bb888b52b..7403423b7 100644 --- a/src/storm/solver/TopologicalLinearEquationSolver.h +++ b/src/storm/solver/TopologicalLinearEquationSolver.h @@ -27,7 +27,8 @@ namespace storm { virtual bool supportsGaussSeidelMultiplication() const override; virtual void multiplyGaussSeidel(std::vector& x, std::vector const* b) const override; virtual void multiplyAndReduceGaussSeidel(OptimizationDirection const& dir, std::vector const& rowGroupIndices, std::vector& x, std::vector const* b, std::vector* choices = nullptr) const override; - + virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector const& x) const override; + virtual LinearEquationSolverProblemFormat getEquationProblemFormat(storm::Environment const& env) const override; virtual LinearEquationSolverRequirements getRequirements(Environment const& env, LinearEquationSolverTask const& task = LinearEquationSolverTask::Unspecified) const override;