#ifndef STORM_SOLVER_NATIVELINEAREQUATIONSOLVER_H_ #define STORM_SOLVER_NATIVELINEAREQUATIONSOLVER_H_ #include #include "LinearEquationSolver.h" namespace storm { namespace solver { template class NativeLinearEquationSolverSettings { public: enum class SolutionMethod { Jacobi, GaussSeidel, SOR }; NativeLinearEquationSolverSettings(); void setSolutionMethod(SolutionMethod const& method); void setPrecision(ValueType precision); void setMaximalNumberOfIterations(uint64_t maximalNumberOfIterations); void setRelativeTerminationCriterion(bool value); void setOmega(ValueType omega); SolutionMethod getSolutionMethod() const; ValueType getPrecision() const; uint64_t getMaximalNumberOfIterations() const; uint64_t getRelativeTerminationCriterion() const; ValueType getOmega() const; private: SolutionMethod method; double precision; bool relative; uint_fast64_t maximalNumberOfIterations; ValueType omega; }; /*! * A class that uses storm's native matrix operations to implement the LinearEquationSolver interface. */ template class NativeLinearEquationSolver : public LinearEquationSolver { public: NativeLinearEquationSolver(storm::storage::SparseMatrix const& A, NativeLinearEquationSolverSettings const& settings = NativeLinearEquationSolverSettings()); NativeLinearEquationSolver(storm::storage::SparseMatrix&& A, NativeLinearEquationSolverSettings const& settings = NativeLinearEquationSolverSettings()); virtual void setMatrix(storm::storage::SparseMatrix const& A) override; virtual void setMatrix(storm::storage::SparseMatrix&& A) override; virtual bool solveEquations(std::vector& x, std::vector const& b) const override; virtual void multiply(std::vector& x, std::vector const* b, std::vector& result) const override; void setSettings(NativeLinearEquationSolverSettings const& newSettings); NativeLinearEquationSolverSettings const& getSettings() const; virtual void clearCache() const override; private: virtual uint64_t getMatrixRowCount() const override; virtual uint64_t getMatrixColumnCount() const override; // If the solver takes posession of the matrix, we store the moved matrix in this member, so it gets deleted // when the solver is destructed. std::unique_ptr> localA; // A pointer to the original sparse matrix given to this solver. If the solver takes posession of the matrix // the pointer refers to localA. storm::storage::SparseMatrix const* A; // The settings used by the solver. NativeLinearEquationSolverSettings settings; // cached auxiliary data mutable std::unique_ptr, std::vector>> jacobiDecomposition; }; template class NativeLinearEquationSolverFactory : public LinearEquationSolverFactory { public: virtual std::unique_ptr> create(storm::storage::SparseMatrix const& matrix) const override; virtual std::unique_ptr> create(storm::storage::SparseMatrix&& matrix) const override; NativeLinearEquationSolverSettings& getSettings(); NativeLinearEquationSolverSettings const& getSettings() const; virtual std::unique_ptr> clone() const override; private: NativeLinearEquationSolverSettings settings; }; } } #endif /* STORM_SOLVER_NATIVELINEAREQUATIONSOLVER_H_ */