You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
7.3 KiB

  1. #ifndef STORM_SOLVER_TOPOLOGICALVALUEITERATIONMINMAXLINEAREQUATIONSOLVER_H_
  2. #define STORM_SOLVER_TOPOLOGICALVALUEITERATIONMINMAXLINEAREQUATIONSOLVER_H_
  3. #include "src/solver/NativeMinMaxLinearEquationSolver.h"
  4. #include "src/storage/StronglyConnectedComponentDecomposition.h"
  5. #include "src/storage/SparseMatrix.h"
  6. #include "src/exceptions/NotImplementedException.h"
  7. #include "src/exceptions/NotSupportedException.h"
  8. #include <utility>
  9. #include <vector>
  10. #include "storm-config.h"
  11. #ifdef STORM_HAVE_CUDA
  12. #include "cudaForStorm.h"
  13. #endif
  14. namespace storm {
  15. namespace solver {
  16. /*!
  17. * A class that uses SCC Decompositions to solve a min/max linear equation system.
  18. */
  19. template<class ValueType>
  20. class TopologicalMinMaxLinearEquationSolver : public NativeMinMaxLinearEquationSolver<ValueType> {
  21. public:
  22. /*!
  23. * Constructs a min-max linear equation solver with parameters being set according to the settings
  24. * object.
  25. *
  26. * @param A The matrix defining the coefficients of the linear equation system.
  27. */
  28. TopologicalMinMaxLinearEquationSolver(storm::storage::SparseMatrix<ValueType> const& A);
  29. /*!
  30. * Constructs a min/max linear equation solver with the given parameters.
  31. *
  32. * @param A The matrix defining the coefficients of the linear equation system.
  33. * @param precision The precision to use for convergence detection.
  34. * @param maximalNumberOfIterations The maximal number of iterations do perform before iteration is aborted.
  35. * @param relative If set, the relative error rather than the absolute error is considered for convergence
  36. * detection.
  37. */
  38. TopologicalMinMaxLinearEquationSolver(storm::storage::SparseMatrix<ValueType> const& A, double precision, uint_fast64_t maximalNumberOfIterations, bool relative = true);
  39. virtual void solveEquationSystem(OptimizationDirection dir, std::vector<ValueType>& x, std::vector<ValueType> const& b, std::vector<ValueType>* multiplyResult = nullptr, std::vector<ValueType>* newX = nullptr) const override;
  40. private:
  41. bool enableCuda;
  42. /*!
  43. * Given a topological sort of a SCC Decomposition, this will calculate the optimal grouping of SCCs with respect to the size of the GPU memory.
  44. */
  45. std::vector<std::pair<bool, storm::storage::StateBlock>> getOptimalGroupingFromTopologicalSccDecomposition(storm::storage::StronglyConnectedComponentDecomposition<ValueType> const& sccDecomposition, std::vector<uint_fast64_t> const& topologicalSort, storm::storage::SparseMatrix<ValueType> const& matrix) const;
  46. };
  47. template <typename IndexType, typename ValueType>
  48. bool __basicValueIteration_mvReduce_minimize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<IndexType, ValueType>> const& columnIndicesAndValues, std::vector<ValueType>& x, std::vector<ValueType> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  49. //
  50. STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Unsupported template arguments.");
  51. }
  52. template <>
  53. inline bool __basicValueIteration_mvReduce_minimize<uint_fast64_t, double>(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<uint_fast64_t, double>> const& columnIndicesAndValues, std::vector<double>& x, std::vector<double> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  54. #ifdef STORM_HAVE_CUDA
  55. return basicValueIteration_mvReduce_uint64_double_minimize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount);
  56. #else
  57. STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "StoRM is compiled without CUDA support.");
  58. #endif
  59. }
  60. template <>
  61. inline bool __basicValueIteration_mvReduce_minimize<uint_fast64_t, float>(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<uint_fast64_t, float>> const& columnIndicesAndValues, std::vector<float>& x, std::vector<float> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  62. #ifdef STORM_HAVE_CUDA
  63. return basicValueIteration_mvReduce_uint64_float_minimize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount);
  64. #else
  65. STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "StoRM is compiled without CUDA support.");
  66. #endif
  67. }
  68. template <typename IndexType, typename ValueType>
  69. bool __basicValueIteration_mvReduce_maximize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<IndexType, ValueType>> const& columnIndicesAndValues, std::vector<ValueType>& x, std::vector<ValueType> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  70. //
  71. STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Unsupported template arguments.");
  72. }
  73. template <>
  74. inline bool __basicValueIteration_mvReduce_maximize<uint_fast64_t, double>(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<uint_fast64_t, double>> const& columnIndicesAndValues, std::vector<double>& x, std::vector<double> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  75. #ifdef STORM_HAVE_CUDA
  76. return basicValueIteration_mvReduce_uint64_double_maximize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount);
  77. #else
  78. STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "StoRM is compiled without CUDA support.");
  79. #endif
  80. }
  81. template <>
  82. inline bool __basicValueIteration_mvReduce_maximize<uint_fast64_t, float>(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<uint_fast64_t, float>> const& columnIndicesAndValues, std::vector<float>& x, std::vector<float> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  83. #ifdef STORM_HAVE_CUDA
  84. return basicValueIteration_mvReduce_uint64_float_maximize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount);
  85. #else
  86. STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "StoRM is compiled without CUDA support.");
  87. #endif
  88. }
  89. } // namespace solver
  90. } // namespace storm
  91. #endif /* STORM_SOLVER_TOPOLOGICALVALUEITERATIONMINMAXLINEAREQUATIONSOLVER_H_ */