Cannot modify constraints after adding to problem
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 433
- PR merge metrics
- No merged PRs in 30d
Description
Before the rust rewrite, this code modified the constraint within the problem:
```py
>>> import pulp as lp
>>> prob = lp.LpProblem()
>>> x = lp.LpVariable('x')
>>> constr = x <= 2
>>> prob += constr
>>> constr[x] = 2
>>> constr
2*x + -2 <= 0
>>> prob.constraints
OrderedDict({'_C1': 2*x + -2 <= 0}
```
In the new version, the constraint doesn't get updated:
```py
>>> import pulp as lp
>>> prob = lp.LpProblem()
>>> x = prob.add_variable('x')
>>> constr = x <= 2
>>> prob += constr
>>> constr[x] = 2
>>> constr
2.0*x + -2.0 <= 0
>>> prob.constraints()
[1.0*x + -2.0 <= 0]
```
It is because the constraints are no longer stored as the given Python objects, but are copied into inmutable proxies instead:
```py
# Before
>>> prob.constraints['_C1'] is constr
True
# After
>>> prob.constraints()[0] is constr
False
```
Contributor guide
Research direction
Start by running the reported Python reproduction through LpProblem, add_variable, prob +=, and constraint mutation, then inspect how constraints are stored and returned after the Rust rewrite. Done means mutating the original constraint after adding it updates the problem's stored constraint, with a regression test covering that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100