#ifndef STORM_SOLVER_TOPOLOGICALVALUEITERATIONMINMAXLINEAREQUATIONSOLVER_H_ #define STORM_SOLVER_TOPOLOGICALVALUEITERATIONMINMAXLINEAREQUATIONSOLVER_H_ #include "storm/solver/MinMaxLinearEquationSolver.h" #include "storm/storage/StronglyConnectedComponentDecomposition.h" #include "storm/storage/SparseMatrix.h" #include "storm/exceptions/NotImplementedException.h" #include "storm/exceptions/NotSupportedException.h" #include #include #include "storm-config.h" #ifdef STORM_HAVE_CUDA #include "cudaForStorm.h" #endif namespace storm { namespace solver { /*! * A class that uses SCC Decompositions to solve a min/max linear equation system. */ template class TopologicalMinMaxLinearEquationSolver : public MinMaxLinearEquationSolver { public: /*! * Constructs a min-max linear equation solver with parameters being set according to the settings * object. * * @param A The matrix defining the coefficients of the linear equation system. */ TopologicalMinMaxLinearEquationSolver(storm::storage::SparseMatrix const& A, double precision = 1e-6, uint_fast64_t maximalNumberOfIterations = 20000, bool relative = true); virtual bool solveEquations(OptimizationDirection dir, std::vector& x, std::vector const& b) const override; virtual void repeatedMultiply(OptimizationDirection dir, std::vector& x, std::vector* b, uint_fast64_t n) const override; virtual ValueType getPrecision() const override; virtual bool getRelative() const override; private: storm::storage::SparseMatrix const& A; double precision; uint_fast64_t maximalNumberOfIterations; bool relative; bool enableCuda; /*! * 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. */ std::vector> getOptimalGroupingFromTopologicalSccDecomposition(storm::storage::StronglyConnectedComponentDecomposition const& sccDecomposition, std::vector const& topologicalSort, storm::storage::SparseMatrix const& matrix) const; }; template bool __basicValueIteration_mvReduce_minimize(uint_fast64_t const, double const, bool const, std::vector const&, std::vector> const&, std::vector& x, std::vector const&, std::vector const&, size_t&) { // STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Unsupported template arguments."); } template <> inline bool __basicValueIteration_mvReduce_minimize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector const& matrixRowIndices, std::vector> const& columnIndicesAndValues, std::vector& x, std::vector const& b, std::vector const& nondeterministicChoiceIndices, size_t& iterationCount) { (void)maxIterationCount; (void)precision; (void)relativePrecisionCheck; (void)matrixRowIndices; (void)columnIndicesAndValues; (void)x; (void)b; (void)nondeterministicChoiceIndices; (void)iterationCount; #ifdef STORM_HAVE_CUDA return basicValueIteration_mvReduce_uint64_double_minimize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "storm is compiled without CUDA support."); #endif } template <> inline bool __basicValueIteration_mvReduce_minimize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector const& matrixRowIndices, std::vector> const& columnIndicesAndValues, std::vector& x, std::vector const& b, std::vector const& nondeterministicChoiceIndices, size_t& iterationCount) { (void)maxIterationCount; (void)precision; (void)relativePrecisionCheck; (void)matrixRowIndices; (void)columnIndicesAndValues; (void)x; (void)b; (void)nondeterministicChoiceIndices; (void)iterationCount; #ifdef STORM_HAVE_CUDA return basicValueIteration_mvReduce_uint64_float_minimize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "storm is compiled without CUDA support."); #endif } template bool __basicValueIteration_mvReduce_maximize(uint_fast64_t const, double const, bool const, std::vector const&, std::vector> const&, std::vector&, std::vector const&, std::vector const&, size_t&) { STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Unsupported template arguments."); } template <> inline bool __basicValueIteration_mvReduce_maximize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector const& matrixRowIndices, std::vector> const& columnIndicesAndValues, std::vector& x, std::vector const& b, std::vector const& nondeterministicChoiceIndices, size_t& iterationCount) { (void)maxIterationCount; (void)precision; (void)relativePrecisionCheck; (void)matrixRowIndices; (void)columnIndicesAndValues; (void)x; (void)b; (void)nondeterministicChoiceIndices; (void)iterationCount; #ifdef STORM_HAVE_CUDA return basicValueIteration_mvReduce_uint64_double_maximize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "storm is compiled without CUDA support."); #endif } template <> inline bool __basicValueIteration_mvReduce_maximize(uint_fast64_t const maxIterationCount, double const precision, bool const relativePrecisionCheck, std::vector const& matrixRowIndices, std::vector> const& columnIndicesAndValues, std::vector& x, std::vector const& b, std::vector const& nondeterministicChoiceIndices, size_t& iterationCount) { (void)maxIterationCount; (void)precision; (void)relativePrecisionCheck; (void)matrixRowIndices; (void)columnIndicesAndValues; (void)x; (void)b; (void)nondeterministicChoiceIndices; (void)iterationCount; #ifdef STORM_HAVE_CUDA return basicValueIteration_mvReduce_uint64_float_maximize(maxIterationCount, precision, relativePrecisionCheck, matrixRowIndices, columnIndicesAndValues, x, b, nondeterministicChoiceIndices, iterationCount); #else STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "storm is compiled without CUDA support."); #endif } template class TopologicalMinMaxLinearEquationSolverFactory : public MinMaxLinearEquationSolverFactory { public: TopologicalMinMaxLinearEquationSolverFactory(bool trackScheduler = false); virtual std::unique_ptr> create(storm::storage::SparseMatrix const& matrix) const override; virtual std::unique_ptr> create(storm::storage::SparseMatrix&& matrix) const override; }; } // namespace solver } // namespace storm #endif /* STORM_SOLVER_TOPOLOGICALVALUEITERATIONMINMAXLINEAREQUATIONSOLVER_H_ */