#ifndef STORM_SOLVER_SYMBOLICMINMAXLINEAREQUATIONSOLVER_H_ #define STORM_SOLVER_SYMBOLICMINMAXLINEAREQUATIONSOLVER_H_ #include #include #include #include #include "storm/solver/SymbolicLinearEquationSolver.h" #include "storm/storage/expressions/Variable.h" #include "storm/storage/dd/DdType.h" namespace storm { namespace dd { template class Add; template class Bdd; } namespace solver { template class SymbolicMinMaxLinearEquationSolverSettings { public: SymbolicMinMaxLinearEquationSolverSettings(); enum class SolutionMethod { ValueIteration, PolicyIteration }; void setSolutionMethod(SolutionMethod const& solutionMethod); void setMaximalNumberOfIterations(uint64_t maximalNumberOfIterations); void setRelativeTerminationCriterion(bool value); void setPrecision(ValueType precision); SolutionMethod const& getSolutionMethod() const; uint64_t getMaximalNumberOfIterations() const; ValueType getPrecision() const; bool getRelativeTerminationCriterion() const; private: SolutionMethod solutionMethod; uint64_t maximalNumberOfIterations; ValueType precision; bool relative; }; /*! * An interface that represents an abstract symbolic linear equation solver. In addition to solving a system of * linear equations, the functionality to repeatedly multiply a matrix with a given vector is provided. */ template class SymbolicMinMaxLinearEquationSolver { public: /*! * Constructs a symbolic min/max linear equation solver with the given meta variable sets and pairs. * * @param A The matrix defining the coefficients of the linear equation system. * @param diagonal An ADD characterizing the elements on the diagonal of the matrix. * @param allRows A BDD characterizing all rows of the equation system. * @param illegalMask A mask that characterizes all illegal choices (that are therefore not to be taken). * @param rowMetaVariables The meta variables used to encode the rows of the matrix. * @param columnMetaVariables The meta variables used to encode the columns of the matrix. * @param choiceVariables The variables encoding the choices of each row group. * @param rowColumnMetaVariablePairs The pairs of row meta variables and the corresponding column meta * variables. * @param settings The settings to use. */ SymbolicMinMaxLinearEquationSolver(storm::dd::Add const& A, storm::dd::Bdd const& allRows, storm::dd::Bdd const& illegalMask, std::set const& rowMetaVariables, std::set const& columnMetaVariables, std::set const& choiceVariables, std::vector> const& rowColumnMetaVariablePairs, std::unique_ptr>&& linearEquationSolverFactory, SymbolicMinMaxLinearEquationSolverSettings const& settings = SymbolicMinMaxLinearEquationSolverSettings()); /*! * Solves the equation system A*x = b. The matrix A is required to be square and have a unique solution. * The solution of the set of linear equations will be written to the vector x. Note that the matrix A has * to be given upon construction time of the solver object. * * @param minimize If set, all the value of a group of rows is the taken as the minimum over all rows and as * the maximum otherwise. * @param x The initual guess for the solution vector. Its length must be equal to the number of row * groups of A. * @param b The right-hand side of the equation system. Its length must be equal to the number of row groups * of A. * @return The solution of the equation system. */ virtual storm::dd::Add solveEquations(bool minimize, storm::dd::Add const& x, storm::dd::Add const& b) const; /*! * 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 * matrix A has to be given upon construction time of the solver object. * * @param minimize If set, all the value of a group of rows is the taken as the minimum over all rows and as * the maximum otherwise. * @param x The initial vector with which to perform matrix-vector multiplication. Its length must be equal * to the number of row groups of A. * @param b If non-null, this vector is added after each multiplication. If given, its length must be equal * to the number of row groups of A. * @return The solution of the equation system. */ virtual storm::dd::Add multiply(bool minimize, storm::dd::Add const& x, storm::dd::Add const* b = nullptr, uint_fast64_t n = 1) const; SymbolicMinMaxLinearEquationSolverSettings const& getSettings() const; private: storm::dd::Add solveEquationsValueIteration(bool minimize, storm::dd::Add const& x, storm::dd::Add const& b) const; storm::dd::Add solveEquationsPolicyIteration(bool minimize, storm::dd::Add const& x, storm::dd::Add const& b) const; protected: // The matrix defining the coefficients of the linear equation system. storm::dd::Add A; // A BDD characterizing all rows of the equation system. storm::dd::Bdd allRows; // An ADD characterizing the illegal choices. storm::dd::Add illegalMaskAdd; // The row variables. std::set rowMetaVariables; // The column variables. std::set columnMetaVariables; // The choice variables. std::set choiceVariables; // The pairs of meta variables used for renaming. std::vector> rowColumnMetaVariablePairs; // A factory for creating linear equation solvers when needed. std::unique_ptr> linearEquationSolverFactory; // The settings to use. SymbolicMinMaxLinearEquationSolverSettings settings; }; template class SymbolicMinMaxLinearEquationSolverFactory { public: virtual std::unique_ptr> create(storm::dd::Add const& A, storm::dd::Bdd const& allRows, storm::dd::Bdd const& illegalMask, std::set const& rowMetaVariables, std::set const& columnMetaVariables, std::set const& choiceVariables, std::vector> const& rowColumnMetaVariablePairs) const = 0; }; template class SymbolicGeneralMinMaxLinearEquationSolverFactory : public SymbolicMinMaxLinearEquationSolverFactory { public: virtual std::unique_ptr> create(storm::dd::Add const& A, storm::dd::Bdd const& allRows, storm::dd::Bdd const& illegalMask, std::set const& rowMetaVariables, std::set const& columnMetaVariables, std::set const& choiceVariables, std::vector> const& rowColumnMetaVariablePairs) const; SymbolicMinMaxLinearEquationSolverSettings& getSettings(); SymbolicMinMaxLinearEquationSolverSettings const& getSettings() const; private: SymbolicMinMaxLinearEquationSolverSettings settings; }; } // namespace solver } // namespace storm #endif /* STORM_SOLVER_SYMBOLICMINMAXLINEAREQUATIONSOLVER_H_ */