Skip to content

set_normalized_rhs changes LessEqual constraint sense to equality in HiGHS model #104

Description

@AllisterFrazier

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions