-
-
Notifications
You must be signed in to change notification settings - Fork 427
Closed
Description
Details for the issue
When using lpSum to define a sum constraint and applying both Min and Max constraints to the resulting variable, PuLP generates the constraints incorrectly. Specifically, the Min_Constraint is overwritten or altered when the Max_Constraint is added. This issue occurs when multiple constraints are applied sequentially to the sum of variables. See example below.
import sys
import pulp
print(f"Python version: {sys.version}")
print(f"pulp version: {pulp.__version__}")
# Create a minimization problem
model = pulp.LpProblem("Sum_Constraint_Example", pulp.LpMinimize)
# Define individual variables x[i] for i in range(3)
x_vars = {i: pulp.LpVariable(f"x{i}", lowBound=0, cat=pulp.LpContinuous) for i in range(3)}
# Define x as the sum of all x[i]
x = pulp.lpSum(x_vars[i] for i in range(3))
# Add min and max constraints on x
model += (x >= 2, "Min_Constraint")
model += (x <= 5, "Max_Constraint")
# Print model
print(model)
What Pulp generated
Python version: 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]
pulp version: 3.0.0
Sum_Constraint_Example:
MINIMIZE
None
SUBJECT TO
Min_Constraint: x0 + x1 + x2 >= 7Max_Constraint: x0 + x1 + x2 <= 7
VARIABLES
x0 Continuous
x1 Continuous
x2 Continuous
Useful extra information
The info below often helps, please fill it out if you're able to. :)
What operating system are you using?
- Windows: ( version: ___ )
- Linux: ( distro: ___ )
- Mac OS: ( version: ___ )
- Other: ___
I'm using python version:
- 3.7
- 3.8
- 3.9
- 3.10
- 3.11
- Other: ___
I installed PuLP via:
- pypi (python -m pip install pulp)
- github (python -m pip install -U git+https://github.com/coin-or/pulp)
- Other: ___ (conda?)
Did you also
- Tried out the latest github version: https://github.com/coin-or/pulp
- Searched for an existing similar issue: https://github.com/coin-or/pulp/issues?utf8=%E2%9C%93&q=is%3Aissue%20
Metadata
Metadata
Assignees
Labels
No labels