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.

97 lines
6.4 KiB

  1. #ifndef STORM_SOLVER_TOPOLOGICALVALUEITERATIONNONDETERMINISTICLINEAREQUATIONSOLVER_H_
  2. #define STORM_SOLVER_TOPOLOGICALVALUEITERATIONNONDETERMINISTICLINEAREQUATIONSOLVER_H_
  3. #include "src/solver/NativeNondeterministicLinearEquationSolver.h"
  4. #include "src/storage/StronglyConnectedComponentDecomposition.h"
  5. #include "src/storage/SparseMatrix.h"
  6. #include <utility>
  7. #include <vector>
  8. #include "storm-config.h"
  9. #ifdef STORM_HAVE_CUDAFORSTORM
  10. # include "cudaForStorm.h"
  11. #endif
  12. namespace storm {
  13. namespace solver {
  14. /*!
  15. * A class that uses SCC Decompositions to solve a linear equation system
  16. */
  17. template<class ValueType>
  18. class TopologicalValueIterationNondeterministicLinearEquationSolver : public NativeNondeterministicLinearEquationSolver<ValueType> {
  19. public:
  20. /*!
  21. * Constructs a nondeterministic linear equation solver with parameters being set according to the settings
  22. * object.
  23. */
  24. TopologicalValueIterationNondeterministicLinearEquationSolver();
  25. /*!
  26. * Constructs a nondeterminstic linear equation solver with the given parameters.
  27. *
  28. * @param precision The precision to use for convergence detection.
  29. * @param maximalNumberOfIterations The maximal number of iterations do perform before iteration is aborted.
  30. * @param relative If set, the relative error rather than the absolute error is considered for convergence
  31. * detection.
  32. */
  33. TopologicalValueIterationNondeterministicLinearEquationSolver(double precision, uint_fast64_t maximalNumberOfIterations, bool relative = true);
  34. virtual NondeterministicLinearEquationSolver<ValueType>* clone() const override;
  35. virtual void solveEquationSystem(bool minimize, storm::storage::SparseMatrix<ValueType> const& A, std::vector<ValueType>& x, std::vector<ValueType> const& b, std::vector<ValueType>* multiplyResult = nullptr, std::vector<ValueType>* newX = nullptr) const override;
  36. private:
  37. /*!
  38. * 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.
  39. */
  40. 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;
  41. };
  42. template <typename ValueType>
  43. bool __basicValueIteration_mvReduce_uint64_minimize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<ValueType>> const& columnIndicesAndValues, std::vector<ValueType>& x, std::vector<ValueType> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  44. //
  45. throw;
  46. }
  47. template <>
  48. inline bool __basicValueIteration_mvReduce_uint64_minimize<double>(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<double>> const& columnIndicesAndValues, std::vector<double>& x, std::vector<double> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  49. #ifdef STORM_HAVE_CUDAFORSTORM
  50. return basicValueIteration_mvReduce_uint64_double_minimize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount);
  51. #else
  52. throw;
  53. #endif
  54. }
  55. template <>
  56. inline bool __basicValueIteration_mvReduce_uint64_minimize<float>(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<float>> const& columnIndicesAndValues, std::vector<float>& x, std::vector<float> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  57. #ifdef STORM_HAVE_CUDAFORSTORM
  58. return basicValueIteration_mvReduce_uint64_float_minimize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount);
  59. #else
  60. throw;
  61. #endif
  62. }
  63. template <typename ValueType>
  64. bool __basicValueIteration_mvReduce_uint64_maximize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<ValueType>> const& columnIndicesAndValues, std::vector<ValueType>& x, std::vector<ValueType> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  65. //
  66. throw;
  67. }
  68. template <>
  69. inline bool __basicValueIteration_mvReduce_uint64_maximize<double>(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<double>> const& columnIndicesAndValues, std::vector<double>& x, std::vector<double> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  70. #ifdef STORM_HAVE_CUDAFORSTORM
  71. return basicValueIteration_mvReduce_uint64_double_maximize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount);
  72. #else
  73. throw;
  74. #endif
  75. }
  76. template <>
  77. inline bool __basicValueIteration_mvReduce_uint64_maximize<float>(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector<uint_fast64_t> const& matrixRowIndices, std::vector<storm::storage::MatrixEntry<float>> const& columnIndicesAndValues, std::vector<float>& x, std::vector<float> const& b, std::vector<uint_fast64_t> const& nondeterministicChoiceIndices, size_t& iterationCount) {
  78. #ifdef STORM_HAVE_CUDAFORSTORM
  79. return basicValueIteration_mvReduce_uint64_float_maximize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount);
  80. #else
  81. throw;
  82. #endif
  83. }
  84. } // namespace solver
  85. } // namespace storm
  86. #endif /* STORM_SOLVER_NATIVENONDETERMINISTICLINEAREQUATIONSOLVER_H_ */