57bool checkConvergence(std::pair<std::vector<ValueType>, std::vector<ValueType>>
const& xy, uint64_t& convergenceCheckState,
58 std::function<
void()>
const& getNextConvergenceCheckState,
bool relative, ValueType
const& precision) {
60 for (; convergenceCheckState < xy.first.size(); getNextConvergenceCheckState()) {
61 ValueType
const& l = xy.first[convergenceCheckState];
62 ValueType
const& u = xy.second[convergenceCheckState];
63 if (l > storm::utility::zero<ValueType>()) {
64 if ((u - l) > l * precision) {
67 }
else if (u < storm::utility::zero<ValueType>()) {
68 if ((l - u) < u * precision) {
78 for (; convergenceCheckState < xy.first.size(); getNextConvergenceCheckState()) {
79 if (xy.second[convergenceCheckState] - xy.first[convergenceCheckState] > precision) {
90 std::vector<ValueType>
const& offsets, uint64_t& numIterations,
bool relative,
91 ValueType
const& precision,
93 std::optional<storm::storage::BitVector>
const& relevantValues)
const {
96 uint64_t convergenceCheckState = 0;
97 std::function<void()> getNextConvergenceCheckState;
99 convergenceCheckState = relevantValues->getNextSetIndex(0);
100 getNextConvergenceCheckState = [&convergenceCheckState, &relevantValues]() {
101 convergenceCheckState = relevantValues->getNextSetIndex(++convergenceCheckState);
104 getNextConvergenceCheckState = [&convergenceCheckState]() { ++convergenceCheckState; };
108 viOperator->applyInPlace(xy, offsets, backend);
109 if (
checkConvergence(xy, convergenceCheckState, getNextConvergenceCheckState, relative, precision)) {
111 }
else if (iterationCallback) {
120 uint64_t& numIterations,
bool relative, ValueType
const& precision,
121 std::function<
void(std::vector<ValueType>&)>
const& prepareLowerBounds,
122 std::function<
void(std::vector<ValueType>&)>
const& prepareUpperBounds,
123 std::optional<storm::OptimizationDirection>
const& dir,
125 std::optional<storm::storage::BitVector>
const& relevantValues)
const {
127 std::pair<std::vector<ValueType>, std::vector<ValueType>> xy;
128 auto& auxVector = viOperator->allocateAuxiliaryVector(operand.size());
129 xy.first.swap(operand);
130 xy.second.swap(auxVector);
131 prepareLowerBounds(xy.first);
132 prepareUpperBounds(xy.second);
133 auto doublePrec = precision + precision;
134 if constexpr (std::is_same_v<ValueType, double>) {
135 doublePrec -= precision * 1e-6;
138 if (!dir.has_value() ||
maximize(*dir)) {
139 status = II<OptimizationDirection::Maximize>(xy, offsets, numIterations, relative, precision, iterationCallback, relevantValues);
141 status = II<OptimizationDirection::Minimize>(xy, offsets, numIterations, relative, precision, iterationCallback, relevantValues);
143 auto two = storm::utility::convertNumber<ValueType>(2.0);
145 storm::utility::vector::applyPointwise<ValueType, ValueType, ValueType>(
146 xy.first, xy.second, xy.first, [&two](ValueType
const& a, ValueType
const& b) -> ValueType { return (a + b) / two; });
148 xy.first.swap(operand);
149 xy.second.swap(auxVector);
150 viOperator->freeAuxiliaryVector();
156 ValueType
const& precision,
157 std::function<
void(std::vector<ValueType>&)>
const& prepareLowerBounds,
158 std::function<
void(std::vector<ValueType>&)>
const& prepareUpperBounds,
159 std::optional<storm::OptimizationDirection>
const& dir,
161 std::optional<storm::storage::BitVector>
const& relevantValues)
const {
162 uint64_t numIterations = 0;
163 return II(operand, offsets, numIterations, relative, precision, prepareLowerBounds, prepareUpperBounds, dir, iterationCallback, relevantValues);
SolverStatus II(std::pair< std::vector< ValueType >, std::vector< ValueType > > &xy, std::vector< ValueType > const &offsets, uint64_t &numIterations, bool relative, ValueType const &precision, std::function< SolverStatus(IIData< ValueType > const &)> const &iterationCallback={}, std::optional< storm::storage::BitVector > const &relevantValues={}) const
bool checkConvergence(std::pair< std::vector< ValueType >, std::vector< ValueType > > const &xy, uint64_t &convergenceCheckState, std::function< void()> const &getNextConvergenceCheckState, bool relative, ValueType const &precision)