How To Add Logical Constraints In Pulp
Solution 1:
Three points:
(1) Your first constraint forces the lpsum to be equal to 2, so f will always be 1 in your example - are you sure your formulation is correct?
(2) If statements can't be used in combination with the lpSum - you should formulate it as an actual constraint.
For example, you could define f as a binary variable and add this constraint:
prob += lpSum(c[i]for i inrange(len(c)))-1<= M*f
where M is a sufficiently large number. Then, if f==0 we have that "lpsum() <= 1" and if f==1 we have that lpsum can be anything. Play around with that type of constraints to get f to behave the way you want.
(3) The constraint "prob += lpSum(c[i] for i in range (len(c)) + f )" does nothing unless it's supposed to be the objective of your MILP? If so, you should add it immediately after prob = LpProblem("The MILP problem", LpMinimize)
Good luck
Post a Comment for "How To Add Logical Constraints In Pulp"