Skip to content

Commit 2888ce2

Browse files
Refactor constraint handling: streamline reason parameter usage in set_lb and set_ub calls for improved clarity and consistency.
1 parent 38f396e commit 2888ce2

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/linspire.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ namespace linspire
6868
assert(c != 0);
6969
const utils::inf_rational c_right = utils::inf_rational(-expr.known_term) / c; // the right-hand side of the constraint is the division of the negation of the known term by the coefficient..
7070
// we can set both the lower and upper bound of the variable to the right-hand side of the constraint..
71-
return reason ? set_lb(x, c_right, reason.value()) && set_ub(x, c_right, reason.value()) : set_lb(x, c_right) && set_ub(x, c_right);
71+
return set_lb(x, c_right, reason) && set_ub(x, c_right, reason);
7272
}
7373
default: // the expression is still a general linear expression..
7474
const utils::inf_rational c_right = utils::inf_rational(-expr.known_term);
7575
expr.known_term = utils::rational::zero;
7676
// we add the expression to the tableau, associating it with a new (slack) variable
7777
utils::var slack = new_var(std::move(expr));
78-
return reason ? set_lb(slack, c_right, reason.value()) && set_ub(slack, c_right, reason.value()) : set_lb(slack, c_right) && set_ub(slack, c_right);
78+
return set_lb(slack, c_right, reason) && set_ub(slack, c_right, reason);
7979
}
8080
}
8181
bool solver::new_lt(const utils::lin &lhs, const utils::lin &rhs, bool strict, std::optional<std::reference_wrapper<constraint>> reason) noexcept
@@ -105,16 +105,16 @@ namespace linspire
105105
assert(c != 0);
106106
const utils::inf_rational c_right = utils::inf_rational(-expr.known_term, strict ? -1 : 0) / c; // the right-hand side of the constraint is the division of the negation of the known term minus an infinitesimal by the coefficient..
107107
if (is_positive(c))
108-
return reason ? set_ub(x, c_right, reason.value()) : set_ub(x, c_right); // we are in the case `c * v < c_right`..
108+
return set_ub(x, c_right, reason); // we are in the case `c * v < c_right`..
109109
else
110-
return reason ? set_lb(x, c_right, reason.value()) : set_lb(x, c_right); // we are in the case `c * v > c_right`..
110+
return set_lb(x, c_right, reason); // we are in the case `c * v > c_right`..
111111
}
112112
default: // the expression is still a general linear expression..
113113
const utils::inf_rational c_right = utils::inf_rational(-expr.known_term, strict ? -1 : 0);
114114
expr.known_term = utils::rational::zero;
115115
// we add the expression to the tableau, associating it with a new (slack) variable
116116
utils::var slack = new_var(std::move(expr));
117-
return reason ? set_ub(slack, c_right, reason.value()) : set_ub(slack, c_right); // we are in the case `expr < c_right`..
117+
return set_ub(slack, c_right, reason); // we are in the case `expr < c_right`..
118118
}
119119
}
120120
bool solver::new_gt(const utils::lin &lhs, const utils::lin &rhs, bool strict, std::optional<std::reference_wrapper<constraint>> reason) noexcept { return new_lt(rhs, lhs, strict, reason); }

0 commit comments

Comments
 (0)