#ifndef STORM_SOLVER_ABSTRACTEQUATIONSOLVER_H_ #define STORM_SOLVER_ABSTRACTEQUATIONSOLVER_H_ #include #include #include #include "storm/solver/TerminationCondition.h" namespace storm { namespace solver { template class AbstractEquationSolver { public: AbstractEquationSolver(); /*! * Sets a custom termination condition that is used together with the regular termination condition of the * solver. * * @param terminationCondition An object that can be queried whether to terminate early or not. */ void setTerminationCondition(std::unique_ptr> terminationCondition); /*! * Removes a previously set custom termination condition. */ void resetTerminationCondition(); /*! * Retrieves whether a custom termination condition has been set. */ bool hasCustomTerminationCondition() const; /*! * Checks whether the solver can terminate wrt. to its termination condition. If no termination condition, * this will yield false. */ bool terminateNow(std::vector const& values, SolverGuarantee const& guarantee) const; /*! * Retrieves whether this solver has particularly relevant values. */ bool hasRelevantValues() const; /*! * Retrieves the relevant values (if there are any). */ storm::storage::BitVector const& getRelevantValues() const; /*! * Sets the relevant values. */ void setRelevantValues(storm::storage::BitVector&& valuesOfInterest); /*! * Removes the values of interest (if there were any). */ void clearRelevantValues(); enum class BoundType { Global, Local, Any }; /*! * Retrieves whether this solver has a lower bound. */ bool hasLowerBound(BoundType const& type = BoundType::Any) const; /*! * Retrieves whether this solver has an upper bound. */ bool hasUpperBound(BoundType const& type = BoundType::Any) const; /*! * Sets a lower bound for the solution that can potentially be used by the solver. */ void setLowerBound(ValueType const& value); /*! * Sets an upper bound for the solution that can potentially be used by the solver. */ void setUpperBound(ValueType const& value); /*! * Sets bounds for the solution that can potentially be used by the solver. */ void setBounds(ValueType const& lower, ValueType const& upper); /*! * Retrieves the lower bound (if there is any). */ ValueType const& getLowerBound() const; /*! * Retrieves the upper bound (if there is any). */ ValueType const& getUpperBound() const; /*! * Retrieves a vector containing the lower bounds (if there are any). */ std::vector const& getLowerBounds() const; /*! * Retrieves a vector containing the upper bounds (if there are any). */ std::vector const& getUpperBounds() const; /*! * Sets lower bounds for the solution that can potentially be used by the solver. */ void setLowerBounds(std::vector const& values); /*! * Sets upper bounds for the solution that can potentially be used by the solver. */ void setUpperBounds(std::vector const& values); /*! * Sets upper bounds for the solution that can potentially be used by the solver. */ void setUpperBounds(std::vector&& values); /*! * Sets bounds for the solution that can potentially be used by the solver. */ void setBounds(std::vector const& lower, std::vector const& upper); /*! * Removes all specified solution bounds */ void clearBounds(); /*! * Retrieves whether progress is to be shown. */ bool isShowProgressSet() const; /*! * Retrieves the delay between progress emissions. */ uint64_t getShowProgressDelay() const; /*! * Starts to measure progress. */ void startMeasureProgress(uint64_t startingIteration = 0) const; /*! * Shows progress if this solver is asked to do so. */ void showProgressIterative(uint64_t iterations, boost::optional const& bound = boost::none) const; virtual void setPrecision(ValueType const& precision); protected: /*! * Retrieves the custom termination condition (if any was set). * * @return The custom termination condition. */ TerminationCondition const& getTerminationCondition() const; std::unique_ptr> const& getTerminationConditionPointer() const; void createUpperBoundsVector(std::vector& upperBoundsVector) const; void createUpperBoundsVector(std::unique_ptr>& upperBoundsVector, uint64_t length) const; void createLowerBoundsVector(std::vector& lowerBoundsVector) const; // A termination condition to be used (can be unset). std::unique_ptr> terminationCondition; // A bit vector containing the indices of the relevant values if they were set. boost::optional relevantValues; // A lower bound if one was set. boost::optional lowerBound; // An upper bound if one was set. boost::optional upperBound; // Lower bounds if they were set. boost::optional> lowerBounds; // Lower bounds if they were set. boost::optional> upperBounds; private: // A flag that indicates whether progress is to be shown. bool showProgressFlag; // The delay between progress emission. uint64_t showProgressDelay; // Time points that are used when showing progress. mutable uint64_t iterationOfLastMessage; mutable std::chrono::high_resolution_clock::time_point timeOfStart; mutable std::chrono::high_resolution_clock::time_point timeOfLastMessage; }; } } #endif /* STORM_SOLVER_ABSTRACTEQUATIONSOLVER_H_ */