1

I've been using the code below for some time now and it's always been able to find the max/min except for now.

I get one corner point to this: x=168, y=192, objective=3288

But there is a corner point that is the true max: x=0, y=304, objective=3344

What am I doing wrong that makes this code unable to find the x,y that truly maximizes the objective?

from pulp import LpVariable, LpProblem, LpMaximize, LpStatus, value, LpMinimize

# declare your variables
x = LpVariable("y1", 0, None)
y = LpVariable("y2", 0, None)

# defines the problem
prob = LpProblem("problem", LpMaximize)

# defines the constraints
prob += 1/2*x+3/4*y == 228
prob += 1/2*x+1/4*y == 132

# defines the objective function to maximize
prob += 7*x+11*y

# solve the problem
status = prob.solve()
LpStatus[status]
# print the results
print('x={0},y={1}.'.format(round(value(x)),round(value(y))))
print("The objective is ${}.".format(round(value(prob.objective))))
1
  • 1
    I think you probably want the left-hand side of each constraint to be less than or equal to the corresponding right-hand side. If so, then the corner point you report is indeed optimal. If you force equalities in the constraints, you have two variables and two equations, and the feasible space is only one point, the solution of the corresponding linear system of equalities. Commented Nov 3, 2018 at 14:50

1 Answer 1

2

Consider the constraint prob += 1/2*x+1/4*y == 132.
If you set x=0 and y=304 this constraint would be violated ( 76 ≠ 132).
To test a solution you can just add the constraints:

prob+= x == 0
prob+= y == 304

status = prob.solve()
print(LpStatus[status])

which outputs Infeasible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.