Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
AbstractEquationSolver.h
Go to the documentation of this file.
1#pragma once
2
3#include <boost/optional.hpp>
4#include <chrono>
5#include <iostream>
6#include <memory>
7
12
13namespace storm {
14namespace solver {
15
16template<typename SolutionType>
18 public:
20
27 void setShowProgress(bool verbose, uint64_t delay = 5);
28
36
41
46
51 bool terminateNow(std::vector<SolutionType> const& values, SolverGuarantee const& guarantee) const;
52
56 bool hasRelevantValues() const;
57
62 boost::optional<storm::storage::BitVector> const& getOptionalRelevantValues() const;
63
67 void setRelevantValues(storm::storage::BitVector&& valuesOfInterest);
68
72 void setRelevantValues(storm::storage::BitVector const& valuesOfInterest);
73
78
79 enum class BoundType { Global, Local, Any };
80
84 bool hasLowerBound(BoundType const& type = BoundType::Any) const;
85
89 bool hasUpperBound(BoundType const& type = BoundType::Any) const;
90
94 void setLowerBound(SolutionType const& value);
95
99 void setUpperBound(SolutionType const& value);
100
104 void setBounds(SolutionType const& lower, SolutionType const& upper);
105
109 SolutionType const& getLowerBound() const;
110
116 SolutionType const& getLowerBound(uint64_t const& index) const;
117
123 SolutionType getLowerBound(bool convertLocalBounds) const;
124
128 SolutionType const& getUpperBound() const;
129
135 SolutionType const& getUpperBound(uint64_t const& index) const;
136
142 SolutionType getUpperBound(bool convertLocalBounds) const;
143
147 std::vector<SolutionType> const& getLowerBounds() const;
148
152 std::vector<SolutionType> const& getUpperBounds() const;
153
157 void setLowerBounds(std::vector<SolutionType> const& values);
158
162 void setLowerBounds(std::vector<SolutionType>&& values);
163
167 void setUpperBounds(std::vector<SolutionType> const& values);
168
172 void setUpperBounds(std::vector<SolutionType>&& values);
173
177 void setBounds(std::vector<SolutionType> const& lower, std::vector<SolutionType> const& upper);
178
180
184 void clearBounds();
185
190 bool hasSolutionLowerBounds() const;
191 bool hasSolutionUpperBounds() const;
192
196 bool hasExactSolutionBounds() const;
197
202 std::vector<SolutionType> const& getSolutionLowerBounds() const;
203 std::vector<SolutionType> const& getSolutionUpperBounds() const;
204
209
213 bool isShowProgressSet() const;
214
218 uint64_t getShowProgressDelay() const;
219
223 void startMeasureProgress(uint64_t startingIteration = 0) const;
224
228 void showProgressIterative(uint64_t iterations, boost::optional<uint64_t> const& bound = boost::none) const;
229
230 protected:
237 std::unique_ptr<TerminationCondition<SolutionType>> const& getTerminationConditionPointer() const;
238
244
250 void setSolutionBoundsExact(std::vector<SolutionType> const& x) const;
251
258 void finalizeSolutionBounds(std::vector<SolutionType> const& x) const;
259
264 void clearSolutionBounds() const;
265
275 void setSolutionBoundsFromPrecision(std::vector<SolutionType> const& x, SolutionType const& precision, bool relative) const;
276
277 void createUpperBoundsVector(std::vector<SolutionType>& upperBoundsVector) const;
278 void createUpperBoundsVector(std::unique_ptr<std::vector<SolutionType>>& upperBoundsVector, uint64_t length) const;
279 void createLowerBoundsVector(std::vector<SolutionType>& lowerBoundsVector) const;
280
286 void reportStatus(SolverStatus status, boost::optional<uint64_t> const& iterations = boost::none) const;
287
297 SolverStatus updateStatus(SolverStatus status, std::vector<SolutionType> const& x, SolverGuarantee const& guarantee, uint64_t iterations,
298 uint64_t maximalNumberOfIterations) const;
299
308 SolverStatus updateStatus(SolverStatus status, bool earlyTermination, uint64_t iterations, uint64_t maximalNumberOfIterations) const;
309
310 // A termination condition to be used (can be unset).
311 std::unique_ptr<TerminationCondition<SolutionType>> terminationCondition;
312
313 // A bit vector containing the indices of the relevant values if they were set.
314 boost::optional<storm::storage::BitVector> relevantValues;
315
316 // A lower bound if one was set.
317 boost::optional<SolutionType> lowerBound;
318
319 // An upper bound if one was set.
320 boost::optional<SolutionType> upperBound;
321
322 // Lower bounds if they were set.
323 boost::optional<std::vector<SolutionType>> lowerBounds;
324
325 // Lower bounds if they were set.
326 boost::optional<std::vector<SolutionType>> upperBounds;
327
328 private:
329 // Sound bounds on the solution, if the last call to this solver produced any.
330 mutable SolutionBounds<SolutionType> solutionBounds;
331
332 // Indicates the progress of this solver.
333 mutable boost::optional<storm::utility::ProgressMeasurement> progressMeasurement;
334};
335
336} // namespace solver
337} // namespace storm
bool hasLowerBound(BoundType const &type=BoundType::Any) const
Retrieves whether this solver has a lower bound.
void setSolutionBoundsExact(std::vector< SolutionType > const &x) const
Reports the given solution as an exact one, i.e.
void setRelevantValues(storm::storage::BitVector &&valuesOfInterest)
Sets the relevant values.
void setSolutionBounds(SolutionBounds< SolutionType > bounds) const
Stores sound bounds on the solution that were obtained while solving.
bool hasCustomTerminationCondition() const
Retrieves whether a custom termination condition has been set.
std::unique_ptr< TerminationCondition< SolutionType > > const & getTerminationConditionPointer() const
void showProgressIterative(uint64_t iterations, boost::optional< uint64_t > const &bound=boost::none) const
Shows progress if this solver is asked to do so.
void setTerminationCondition(std::unique_ptr< TerminationCondition< SolutionType > > terminationCondition)
Sets a custom termination condition that is used together with the regular termination condition of t...
void setBounds(SolutionType const &lower, SolutionType const &upper)
Sets bounds for the solution that can potentially be used by the solver.
boost::optional< storm::storage::BitVector > const & getOptionalRelevantValues() const
boost::optional< SolutionType > lowerBound
std::vector< SolutionType > const & getSolutionUpperBounds() const
storm::storage::BitVector const & getRelevantValues() const
Retrieves the relevant values (if there are any).
bool hasUpperBound(BoundType const &type=BoundType::Any) const
Retrieves whether this solver has an upper bound.
std::unique_ptr< TerminationCondition< SolutionType > > terminationCondition
bool isShowProgressSet() const
Retrieves whether progress is to be shown.
bool hasExactSolutionBounds() const
Retrieves whether the bounds computed by the last call to this solver coincide.
SolutionType const & getUpperBound() const
Retrieves the upper bound (if there is any).
void setBoundsFromOtherSolver(AbstractEquationSolver< SolutionType > const &other)
void setSolutionBoundsFromPrecision(std::vector< SolutionType > const &x, SolutionType const &precision, bool relative) const
Turns a precision that the solving procedure is known to have achieved into sound bounds on the solut...
SolutionBounds< SolutionType > const & getSolutionBounds() const
Retrieves both bounds at once, either of which may be unset.
std::vector< SolutionType > const & getLowerBounds() const
Retrieves a vector containing the lower bounds (if there are any).
void setShowProgress(bool verbose, uint64_t delay=5)
Configures whether this solver should show progress during iterative solving.
bool hasSolutionLowerBounds() const
Retrieves whether the last call to this solver computed a sound lower resp.
void setUpperBounds(std::vector< SolutionType > const &values)
Sets upper bounds for the solution that can potentially be used by the solver.
SolverStatus updateStatus(SolverStatus status, std::vector< SolutionType > const &x, SolverGuarantee const &guarantee, uint64_t iterations, uint64_t maximalNumberOfIterations) const
Update the status of the solver with respect to convergence, early termination, abortion,...
boost::optional< SolutionType > upperBound
void createUpperBoundsVector(std::vector< SolutionType > &upperBoundsVector) const
void setLowerBound(SolutionType const &value)
Sets a lower bound for the solution that can potentially be used by the solver.
boost::optional< storm::storage::BitVector > relevantValues
void startMeasureProgress(uint64_t startingIteration=0) const
Starts to measure progress.
void resetTerminationCondition()
Removes a previously set custom termination condition.
TerminationCondition< SolutionType > const & getTerminationCondition() const
Retrieves the custom termination condition (if any was set).
SolutionType const & getLowerBound() const
Retrieves the lower bound (if there is any).
bool hasRelevantValues() const
Retrieves whether this solver has particularly relevant values.
void clearRelevantValues()
Removes the values of interest (if there were any).
std::vector< SolutionType > const & getUpperBounds() const
Retrieves a vector containing the upper bounds (if there are any).
bool terminateNow(std::vector< SolutionType > const &values, SolverGuarantee const &guarantee) const
Checks whether the solver can terminate wrt.
void clearSolutionBounds() const
Discards any bounds on the solution obtained by a previous call.
void clearBounds()
Removes all specified solution bounds.
boost::optional< std::vector< SolutionType > > upperBounds
void reportStatus(SolverStatus status, boost::optional< uint64_t > const &iterations=boost::none) const
Report the current status of the solver.
void createLowerBoundsVector(std::vector< SolutionType > &lowerBoundsVector) const
uint64_t getShowProgressDelay() const
Retrieves the delay between progress emissions.
void finalizeSolutionBounds(std::vector< SolutionType > const &x) const
Settles the bounds to report once solving is over: the ones handed to this solver beforehand are fold...
boost::optional< std::vector< SolutionType > > lowerBounds
void setUpperBound(SolutionType const &value)
Sets an upper bound for the solution that can potentially be used by the solver.
void setLowerBounds(std::vector< SolutionType > const &values)
Sets lower bounds for the solution that can potentially be used by the solver.
std::vector< SolutionType > const & getSolutionLowerBounds() const
Retrieves sound bounds on the solution that the last call to this solver computed.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
carl::BoundType BoundType
Type describing the interval bounds.
Sound lower and upper bounds on a solution vector.