Hi, thanks for maintaining PyOptInterface.
I may be misunderstanding the intended semantics of set_normalized_rhs, but I found a case where calling it on a LessEqual linear constraint appears to change the constraint into an equality constraint.
Environment
- pyoptinterface: 0.6.1
- solver: HiGHS
- Python: 3.13
- OS: Windows
Minimal reproducer
from pathlib import Path
import pyoptinterface as poi
from pyoptinterface import highs
before = Path("rhs_before.lp")
after = Path("rhs_after.lp")
m = highs.Model()
x = m.add_variable(name="x", lb=0, ub=10)
m.set_obj_sense(poi.ObjectiveSense.Minimize)
m.set_objective_coefficient(x, 1.0)
expr = poi.ScalarAffineFunction()
expr.add_term(x, 1.0)
c = m.add_linear_constraint(
expr,
sense=poi.ConstraintSense.LessEqual,
rhs=5.0,
name="limit",
)
m.write(str(before))
m.optimize()
print("before RHS change:", m.get_variable_attribute(x, poi.VariableAttribute.Value))
m.set_normalized_rhs(c, 4.0)
m.write(str(after))
m.optimize()
print("after RHS change:", m.get_variable_attribute(x, poi.VariableAttribute.Value))
print("before LP row:")
print(next(line.strip() for line in before.read_text().splitlines() if line.strip().startswith("limit:")))
print("after LP row:")
print(next(line.strip() for line in after.read_text().splitlines() if line.strip().startswith("limit:")))
Observed Behavior
before RHS change: 0.0
after RHS change: 4.0
before LP row:
limit: +1 x <= +5
after LP row:
limit: +1 x = +4
The constraint in the written LP file changes from inequality to equality. The solve result also changes: since this is a minimization model with x >= 0, a preserved x <= 4 constraint should still allow x = 0. Instead, the model behaves like x = 4.
Expected behavior
I expected set_normalized_rhs(c, 4.0) to preserve the original constraint sense and update only the RHS, resulting in:
limit: +1 x <= +4
If this behavior is intentional because set_normalized_rhs operates on some canonical equality representation, is there a recommended API for changing the RHS of an existing inequality constraint while preserving its sense?
Hi, thanks for maintaining PyOptInterface.
I may be misunderstanding the intended semantics of
set_normalized_rhs, but I found a case where calling it on aLessEquallinear constraint appears to change the constraint into an equality constraint.Environment
Minimal reproducer
Observed Behavior
before RHS change: 0.0
after RHS change: 4.0
before LP row:
limit: +1 x <= +5
after LP row:
limit: +1 x = +4
The constraint in the written LP file changes from inequality to equality. The solve result also changes: since this is a minimization model with x >= 0, a preserved x <= 4 constraint should still allow x = 0. Instead, the model behaves like x = 4.
Expected behavior
I expected set_normalized_rhs(c, 4.0) to preserve the original constraint sense and update only the RHS, resulting in:
limit: +1 x <= +4If this behavior is intentional because
set_normalized_rhsoperates on some canonical equality representation, is there a recommended API for changing the RHS of an existing inequality constraint while preserving its sense?