Skip to content

Commit

Permalink
fix division by zero error in linear presolve
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbynum committed Feb 24, 2024
1 parent 4cceaa9 commit 58996fa
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pyomo/repn/plugins/nl_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1829,15 +1829,6 @@ def _linear_presolve(self, comp_by_linear_var, lcon_by_linear_nnz, var_bounds):
if expr_info.linear[x] == 0:
nnz -= 1
coef = expr_info.linear.pop(x)
if not nnz:
if abs(expr_info.const) > TOL:
# constraint is trivially infeasible
raise InfeasibleConstraintException(
"model contains a trivially infeasible constraint "
f"{expr_info.const} == {coef}*{var_map[x]}"
)
# constraint is trivially feasible
eliminated_cons.add(con_id)
elif a:
expr_info.linear[x] = c * a
# replacing _id with x... NNZ is not changing,
Expand All @@ -1847,6 +1838,15 @@ def _linear_presolve(self, comp_by_linear_var, lcon_by_linear_nnz, var_bounds):
continue
_old = lcon_by_linear_nnz[old_nnz]
if con_id in _old:
if not nnz:
if abs(expr_info.const) > TOL:
# constraint is trivially infeasible
raise InfeasibleConstraintException(
"model contains a trivially infeasible constraint "
f"{expr_info.const} == {coef}*{var_map[x]}"
)
# constraint is trivially feasible
eliminated_cons.add(con_id)
lcon_by_linear_nnz[nnz][con_id] = _old.pop(con_id)
# If variables were replaced by the variable that
# we are currently eliminating, then we need to update
Expand Down

0 comments on commit 58996fa

Please sign in to comment.