How Do I Change The Bounds Of A Lpvariable In Pulp Dynamically?
I've initialised my LpVariable like so: x = LpVariable('x', None, None) At this point, my variable has upper and lower bounds as float('inf') and float('-inf'). Now based on som
Solution 1:
Turns out both ways work. So for the example:
y = LpProblem("min", LpMinimize)
y += x +10 # Objective Function
x = LpVariable('x', None, None) # setto bounds=[float("-inf"),float("inf")]
We can change the lower bound on x
from the default float("-inf")
to 20
in one of the following ways:
Option 1:
Modifying the constraints on the LpProblem. So, for instance, if you wanted to change the lowBound of x to 20
, you would need to use:
y += x > 20, "changing lower bound of x"
Option 2: Modifying the lowBound attribute on the LpVariable object:
x.lowBound = 20
Both these changes should give us the solution of y = 30
Post a Comment for "How Do I Change The Bounds Of A Lpvariable In Pulp Dynamically?"