Browse Source

Added multiplication of a single matrix row with a vector to the linear equation solver interface

tempestpy_adaptions
TimQu 7 years ago
parent
commit
8260455a55
  1. 7
      src/storm/solver/EigenLinearEquationSolver.cpp
  2. 2
      src/storm/solver/EigenLinearEquationSolver.h
  3. 5
      src/storm/solver/EliminationLinearEquationSolver.cpp
  4. 2
      src/storm/solver/EliminationLinearEquationSolver.h
  5. 6
      src/storm/solver/GmmxxLinearEquationSolver.cpp
  6. 1
      src/storm/solver/GmmxxLinearEquationSolver.h
  7. 8
      src/storm/solver/GmmxxMultiplier.cpp
  8. 2
      src/storm/solver/GmmxxMultiplier.h
  9. 8
      src/storm/solver/LinearEquationSolver.h
  10. 6
      src/storm/solver/NativeLinearEquationSolver.cpp
  11. 3
      src/storm/solver/NativeLinearEquationSolver.h
  12. 4
      src/storm/solver/NativeMultiplier.cpp
  13. 2
      src/storm/solver/NativeMultiplier.h
  14. 5
      src/storm/solver/TopologicalLinearEquationSolver.cpp
  15. 3
      src/storm/solver/TopologicalLinearEquationSolver.h

7
src/storm/solver/EigenLinearEquationSolver.cpp

@ -268,6 +268,13 @@ namespace storm {
}
}
template<typename ValueType>
ValueType EigenLinearEquationSolver<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x) const {
auto eigenX = StormEigen::Matrix<ValueType, StormEigen::Dynamic, 1>::Map(x.data(), x.size());
return (eigenA->row(rowIndex) * eigenX)(0);
}
template<typename ValueType>
LinearEquationSolverProblemFormat EigenLinearEquationSolver<ValueType>::getEquationProblemFormat(Environment const& env) const {
return LinearEquationSolverProblemFormat::EquationSystem;

2
src/storm/solver/EigenLinearEquationSolver.h

@ -21,6 +21,8 @@ namespace storm {
virtual void setMatrix(storm::storage::SparseMatrix<ValueType>&& A) override;
virtual void multiply(std::vector<ValueType>& x, std::vector<ValueType> const* b, std::vector<ValueType>& result) const override;
virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x) const override;
virtual LinearEquationSolverProblemFormat getEquationProblemFormat(Environment const& env) const override;

5
src/storm/solver/EliminationLinearEquationSolver.cpp

@ -109,6 +109,11 @@ namespace storm {
}
}
}
template<typename ValueType>
ValueType EliminationLinearEquationSolver<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x) const {
return A->multiplyRowWithVector(rowIndex, x);
}
template<typename ValueType>
LinearEquationSolverProblemFormat EliminationLinearEquationSolver<ValueType>::getEquationProblemFormat(Environment const& env) const {

2
src/storm/solver/EliminationLinearEquationSolver.h

@ -22,6 +22,8 @@ namespace storm {
virtual void setMatrix(storm::storage::SparseMatrix<ValueType>&& A) override;
virtual void multiply(std::vector<ValueType>& x, std::vector<ValueType> const* b, std::vector<ValueType>& result) const override;
virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x) const override;
virtual LinearEquationSolverProblemFormat getEquationProblemFormat(Environment const& env) const override;

6
src/storm/solver/GmmxxLinearEquationSolver.cpp

@ -145,6 +145,12 @@ namespace storm {
multiplier.multAddReduceGaussSeidel(dir, rowGroupIndices, *gmmxxA, x, b, choices);
}
template<typename ValueType>
ValueType GmmxxLinearEquationSolver<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x) const {
return multiplier.multiplyRow(*gmmxxA, rowIndex, x);
}
template<typename ValueType>
LinearEquationSolverProblemFormat GmmxxLinearEquationSolver<ValueType>::getEquationProblemFormat(Environment const& env) const {
return LinearEquationSolverProblemFormat::EquationSystem;

1
src/storm/solver/GmmxxLinearEquationSolver.h

@ -32,6 +32,7 @@ namespace storm {
virtual bool supportsGaussSeidelMultiplication() const override;
virtual void multiplyGaussSeidel(std::vector<ValueType>& x, std::vector<ValueType> const* b) const override;
virtual void multiplyAndReduceGaussSeidel(OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType>& x, std::vector<ValueType> const* b, std::vector<uint_fast64_t>* choices = nullptr) const override;
virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x) const override;
virtual LinearEquationSolverProblemFormat getEquationProblemFormat(Environment const& env) const override;

8
src/storm/solver/GmmxxMultiplier.cpp

@ -231,6 +231,14 @@ namespace storm {
STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "This operation is not supported.");
}
template<typename T>
T GmmxxMultiplier<T>::multiplyRow(gmm::csr_matrix<T> const& matrix, uint64_t const& rowIndex, std::vector<T> const& x) const {
return vect_sp(gmm::mat_const_row(matrix, rowIndex), x, typename gmm::linalg_traits<gmm::csr_matrix<T>>::storage_type(), typename gmm::linalg_traits<std::vector<T>>::storage_type());
}
template class GmmxxMultiplier<double>;
#ifdef STORM_HAVE_CARL

2
src/storm/solver/GmmxxMultiplier.h

@ -23,6 +23,8 @@ namespace storm {
void multAddParallel(gmm::csr_matrix<T> const& matrix, std::vector<T> const& x, std::vector<T> const* b, std::vector<T>& result) const;
void multAddReduceParallel(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices, gmm::csr_matrix<T> const& matrix, std::vector<T> const& x, std::vector<T> const* b, std::vector<T>& result, std::vector<uint64_t>* choices = nullptr) const;
T multiplyRow(gmm::csr_matrix<T> const& matrix, uint64_t const& rowIndex, std::vector<T> const& x) const;
private:
void multAddReduceHelper(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices, gmm::csr_matrix<T> const& matrix, std::vector<T> const& x, std::vector<T> const* b, std::vector<T>& result, std::vector<uint64_t>* choices = nullptr) const;
};

8
src/storm/solver/LinearEquationSolver.h

@ -109,6 +109,14 @@ namespace storm {
*/
virtual void multiplyAndReduceGaussSeidel(OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType>& x, std::vector<ValueType> const* b, std::vector<uint_fast64_t>* 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<ValueType> 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

6
src/storm/solver/NativeLinearEquationSolver.cpp

@ -1081,6 +1081,12 @@ namespace storm {
multiplier.multAddReduceGaussSeidelBackward(dir, rowGroupIndices, *A, x, b, choices);
}
template<typename ValueType>
ValueType NativeLinearEquationSolver<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x) const {
return multiplier.multiplyRow(*A, rowIndex, x);
}
template<typename ValueType>
LinearEquationSolverProblemFormat NativeLinearEquationSolver<ValueType>::getEquationProblemFormat(Environment const& env) const {
auto method = getMethod(env, storm::NumberTraits<ValueType>::IsExact);

3
src/storm/solver/NativeLinearEquationSolver.h

@ -35,7 +35,8 @@ namespace storm {
virtual bool supportsGaussSeidelMultiplication() const override;
virtual void multiplyGaussSeidel(std::vector<ValueType>& x, std::vector<ValueType> const* b) const override;
virtual void multiplyAndReduceGaussSeidel(OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType>& x, std::vector<ValueType> const* b, std::vector<uint_fast64_t>* choices = nullptr) const override;
virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> 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;

4
src/storm/solver/NativeMultiplier.cpp

@ -89,6 +89,10 @@ namespace storm {
#endif
}
template<typename ValueType>
ValueType NativeMultiplier<ValueType>::multiplyRow(storm::storage::SparseMatrix<ValueType> const& matrix, uint64_t const& rowIndex, std::vector<ValueType> const& x) const {
return matrix.multiplyRowWithVector(rowIndex, x);
}
template class NativeMultiplier<double>;

2
src/storm/solver/NativeMultiplier.h

@ -25,6 +25,8 @@ namespace storm {
void multAddParallel(storm::storage::SparseMatrix<ValueType> const& matrix, std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result) const;
void multAddReduceParallel(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices, storm::storage::SparseMatrix<ValueType> const& matrix, std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result, std::vector<uint64_t>* choices = nullptr) const;
ValueType multiplyRow(storm::storage::SparseMatrix<ValueType> const& matrix, uint64_t const& rowIndex, std::vector<ValueType> const& x) const;
};
}

5
src/storm/solver/TopologicalLinearEquationSolver.cpp

@ -354,6 +354,11 @@ namespace storm {
multiplier.multAddReduceGaussSeidelBackward(dir, rowGroupIndices, *A, x, b, choices);
}
template<typename ValueType>
ValueType TopologicalLinearEquationSolver<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x) const {
return multiplier.multiplyRow(*A, rowIndex, x);
}
template<typename ValueType>
LinearEquationSolverProblemFormat TopologicalLinearEquationSolver<ValueType>::getEquationProblemFormat(Environment const& env) const {
return LinearEquationSolverProblemFormat::FixedPointSystem;

3
src/storm/solver/TopologicalLinearEquationSolver.h

@ -27,7 +27,8 @@ namespace storm {
virtual bool supportsGaussSeidelMultiplication() const override;
virtual void multiplyGaussSeidel(std::vector<ValueType>& x, std::vector<ValueType> const* b) const override;
virtual void multiplyAndReduceGaussSeidel(OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType>& x, std::vector<ValueType> const* b, std::vector<uint_fast64_t>* choices = nullptr) const override;
virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> 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;

Loading…
Cancel
Save