17template<
typename ValueType>
24template<
typename ValueType>
26 this->terminationCondition = std::move(terminationCondition);
29template<
typename ValueType>
31 this->terminationCondition =
nullptr;
34template<
typename ValueType>
36 return static_cast<bool>(this->terminationCondition);
39template<
typename ValueType>
41 return *terminationCondition;
44template<
typename ValueType>
46 return terminationCondition;
49template<
typename ValueType>
51 if (!this->hasCustomTerminationCondition()) {
55 return this->getTerminationCondition().
terminateNow(values, guarantee);
58template<
typename ValueType>
60 return static_cast<bool>(relevantValues);
63template<
typename ValueType>
65 return relevantValues.
get();
68template<
typename ValueType>
70 return relevantValues;
73template<
typename ValueType>
75 this->relevantValues = std::move(relevantValues);
78template<
typename ValueType>
80 this->relevantValues = relevantValues;
83template<
typename ValueType>
85 relevantValues = boost::none;
88template<
typename ValueType>
90 if (type == BoundType::Any) {
91 return static_cast<bool>(lowerBound) ||
static_cast<bool>(lowerBounds);
92 }
else if (type == BoundType::Global) {
93 return static_cast<bool>(lowerBound);
94 }
else if (type == BoundType::Local) {
95 return static_cast<bool>(lowerBounds);
100template<
typename ValueType>
102 if (type == BoundType::Any) {
103 return static_cast<bool>(upperBound) ||
static_cast<bool>(upperBounds);
104 }
else if (type == BoundType::Global) {
105 return static_cast<bool>(upperBound);
106 }
else if (type == BoundType::Local) {
107 return static_cast<bool>(upperBounds);
112template<
typename ValueType>
117template<
typename ValueType>
122template<
typename ValueType>
124 setLowerBound(lower);
125 setUpperBound(upper);
128template<
typename ValueType>
130 return lowerBound.get();
133template<
typename ValueType>
136 STORM_LOG_ASSERT(index < lowerBounds->size(),
"Invalid row index " << index <<
" for vector of size " << lowerBounds->size());
138 return std::max(lowerBound.get(), lowerBounds.get()[index]);
140 return lowerBounds.get()[index];
143 STORM_LOG_ASSERT(lowerBound,
"Lower bound requested but was not specified before.");
144 return lowerBound.get();
148template<
typename ValueType>
151 return lowerBound.get();
152 }
else if (convertLocalBounds) {
153 return *std::min_element(lowerBounds->begin(), lowerBounds->end());
155 STORM_LOG_THROW(
false, storm::exceptions::InvalidOperationException,
"No lower bound available but some was requested.");
159template<
typename ValueType>
161 return upperBound.get();
164template<
typename ValueType>
167 STORM_LOG_ASSERT(index < upperBounds->size(),
"Invalid row index " << index <<
" for vector of size " << upperBounds->size());
169 return std::min(upperBound.get(), upperBounds.get()[index]);
171 return upperBounds.get()[index];
174 STORM_LOG_ASSERT(upperBound,
"Upper bound requested but was not specified before.");
175 return upperBound.get();
179template<
typename ValueType>
182 return upperBound.get();
183 }
else if (convertLocalBounds) {
184 return *std::max_element(upperBounds->begin(), upperBounds->end());
186 STORM_LOG_THROW(
false, storm::exceptions::InvalidOperationException,
"No upper bound available but some was requested.");
190template<
typename ValueType>
192 return lowerBounds.get();
195template<
typename ValueType>
197 return upperBounds.get();
200template<
typename ValueType>
202 lowerBounds = values;
205template<
typename ValueType>
207 lowerBounds = std::move(values);
210template<
typename ValueType>
212 upperBounds = values;
215template<
typename ValueType>
217 upperBounds = std::move(values);
220template<
typename ValueType>
222 setLowerBounds(lower);
223 setUpperBounds(upper);
226template<
typename ValueType>
242template<
typename ValueType>
244 lowerBound = boost::none;
245 upperBound = boost::none;
246 lowerBounds = boost::none;
247 upperBounds = boost::none;
250template<
typename ValueType>
252 if (this->hasLowerBound(BoundType::Local)) {
253 lowerBoundsVector = this->getLowerBounds();
255 ValueType lowerBound = this->hasLowerBound(BoundType::Global) ? this->getLowerBound() : storm::utility::zero<ValueType>();
256 for (
auto& e : lowerBoundsVector) {
262template<
typename ValueType>
265 if (this->hasUpperBound(BoundType::Global)) {
266 upperBoundsVector.assign(upperBoundsVector.size(), this->getUpperBound());
268 upperBoundsVector.assign(this->getUpperBounds().begin(), this->getUpperBounds().end());
272template<
typename ValueType>
275 if (!upperBoundsVector) {
276 if (this->hasUpperBound(BoundType::Local)) {
277 STORM_LOG_ASSERT(length == this->getUpperBounds().size(),
"Mismatching sizes.");
278 upperBoundsVector = std::make_unique<std::vector<ValueType>>(this->getUpperBounds());
280 upperBoundsVector = std::make_unique<std::vector<ValueType>>(length, this->getUpperBound());
283 createUpperBoundsVector(*upperBoundsVector);
287template<
typename ValueType>
289 return this->progressMeasurement.is_initialized();
292template<
typename ValueType>
294 STORM_LOG_ASSERT(this->isShowProgressSet(),
"Tried to get the progress message delay but progress is not shown.");
295 return this->progressMeasurement->getShowProgressDelay();
298template<
typename ValueType>
300 if (this->isShowProgressSet()) {
301 this->progressMeasurement->startNewMeasurement(startingIteration);
305template<
typename ValueType>
307 if (this->isShowProgressSet()) {
309 this->progressMeasurement->setMaxCount(bound.get());
311 this->progressMeasurement->updateProgress(iteration);
315template<
typename ValueType>
320 STORM_LOG_TRACE(
"Iterative solver converged after " << iterations.get() <<
" iterations.");
323 STORM_LOG_TRACE(
"Iterative solver terminated early after " << iterations.get() <<
" iterations.");
326 STORM_LOG_WARN(
"Iterative solver did not converge after " << iterations.get() <<
" iterations.");
329 STORM_LOG_WARN(
"Iterative solver was aborted after " << iterations.get() <<
" iterations.");
332 STORM_LOG_THROW(
false, storm::exceptions::InvalidStateException,
"Iterative solver terminated unexpectedly.");
343 STORM_LOG_ASSERT(
false,
"Non-iterative solver should not exceed maximal number of iterations.");
350 STORM_LOG_THROW(
false, storm::exceptions::InvalidStateException,
"Solver terminated unexpectedly.");
355template<
typename ValueType>
357 uint64_t maximalNumberOfIterations)
const {
359 if (earlyTermination) {
361 }
else if (iterations >= maximalNumberOfIterations) {
370template<
typename ValueType>
372 uint64_t iterations, uint64_t maximalNumberOfIterations)
const {
373 return this->updateStatus(status, this->hasCustomTerminationCondition() && this->getTerminationCondition().terminateNow(x, guarantee), iterations,
374 maximalNumberOfIterations);
379#ifdef STORM_HAVE_CARL
uint64_t getShowProgressDelay() const
Retrieves the delay between progress emissions.
void clearRelevantValues()
Removes the values of interest (if there were any).
void setUpperBound(ValueType const &value)
Sets an upper bound for the solution that can potentially be used by the solver.
void createLowerBoundsVector(std::vector< ValueType > &lowerBoundsVector) const
std::vector< ValueType > const & getLowerBounds() const
Retrieves a vector containing the lower bounds (if there are any).
bool hasUpperBound(BoundType const &type=BoundType::Any) const
Retrieves whether this solver has an upper bound.
bool hasLowerBound(BoundType const &type=BoundType::Any) const
Retrieves whether this solver has a lower bound.
void showProgressIterative(uint64_t iterations, boost::optional< uint64_t > const &bound=boost::none) const
Shows progress if this solver is asked to do so.
storm::storage::BitVector const & getRelevantValues() const
Retrieves the relevant values (if there are any).
std::unique_ptr< TerminationCondition< ValueType > > const & getTerminationConditionPointer() const
void setLowerBound(ValueType const &value)
Sets a lower bound for the solution that can potentially be used by the solver.
ValueType const & getUpperBound() const
Retrieves the upper bound (if there is any).
void setUpperBounds(std::vector< ValueType > const &values)
Sets upper bounds for the solution that can potentially be used by the solver.
void setRelevantValues(storm::storage::BitVector &&valuesOfInterest)
Sets the relevant values.
bool terminateNow(std::vector< ValueType > const &values, SolverGuarantee const &guarantee) const
Checks whether the solver can terminate wrt.
void setBounds(ValueType const &lower, ValueType const &upper)
Sets bounds for the solution that can potentially be used by the solver.
void startMeasureProgress(uint64_t startingIteration=0) const
Starts to measure progress.
void createUpperBoundsVector(std::vector< ValueType > &upperBoundsVector) const
void setBoundsFromOtherSolver(AbstractEquationSolver< ValueType > const &other)
void resetTerminationCondition()
Removes a previously set custom termination condition.
std::vector< ValueType > const & getUpperBounds() const
Retrieves a vector containing the upper bounds (if there are any).
bool isShowProgressSet() const
Retrieves whether progress is to be shown.
void clearBounds()
Removes all specified solution bounds.
TerminationCondition< ValueType > const & getTerminationCondition() const
Retrieves the custom termination condition (if any was set).
bool hasRelevantValues() const
Retrieves whether this solver has particularly relevant values.
bool hasCustomTerminationCondition() const
Retrieves whether a custom termination condition has been set.
boost::optional< storm::storage::BitVector > const & getOptionalRelevantValues() const
ValueType const & getLowerBound() const
Retrieves the lower bound (if there is any).
void setTerminationCondition(std::unique_ptr< TerminationCondition< ValueType > > terminationCondition)
Sets a custom termination condition that is used together with the regular termination condition of t...
SolverStatus updateStatus(SolverStatus status, std::vector< ValueType > 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,...
void reportStatus(SolverStatus status, boost::optional< uint64_t > const &iterations=boost::none) const
Report the current status of the solver.
void setLowerBounds(std::vector< ValueType > const &values)
Sets lower bounds for the solution that can potentially be used by the solver.
virtual bool terminateNow(std::vector< ValueType > const ¤tValues, SolverGuarantee const &guarantee=SolverGuarantee::None) const
Retrieves whether the guarantee provided by the solver for the current result is sufficient to termin...
A bit vector that is internally represented as a vector of 64-bit values.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
A class that provides convenience operations to display run times.
#define STORM_LOG_WARN(message)
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
SettingsType const & getModule()
Get module.
@ MaximalIterationsExceeded
bool isTerminate()
Check whether the program should terminate (due to some abort signal).