Skip to content

[BUG] Python: Problem.addConstraint accepts the same Constraint twice #2326

Open

Description

@ramakrishnap-nv

In the Python API, Problem.addConstraint accepts the same Constraint object twice. The second call overwrites constr.index and appends the constraint to Problem.constrs again, so the problem has two rows for one Constraint, and both rows map to the second index.

from cuopt.linear_programming.problem import Problem

p = Problem("dup")
x = p.addVariable(lb=0, ub=1, name="x")
c = x <= 1
p.addConstraint(c)
p.addConstraint(c)  # accepted; c.index becomes 1 and p.constrs holds c twice

Expected: ValueError, with p.constrs and c.index left unchanged.

Same bug as the Java one in #2224 (fixed in #2226). The check belongs in Problem.addConstraint, because the native solver only receives a CSR matrix.

🤖 Generated with Claude Code

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions