coin-or / pulp

A python Linear Programming API
http://coin-or.github.io/pulp/
Other
2.04k stars 381 forks source link

Give an obvious wrong result for a very simple problem #686

Closed kmeng closed 11 months ago

kmeng commented 11 months ago

Details for the issue

What did you do?

Write a very simple program for learning:

def solve_by_pulp(): model = pulp.LpProblem('Sample3_1', LpMaximize)

# define decision variables
x1 = pulp.LpVariable('x1', lowBound=0)
x2 = pulp.LpVariable('x2', lowBound=0)
x3 = pulp.LpVariable('x3', lowBound=0)

# set objective
model += 2*x1 + 3*x2 - 5+x3

# set constraint
model += x1 + x2 + x3 == 7
# 下面的两个约束条件没有起作用
model += 2*x1 - 5*x2 + x3 >= 10
model += x1 + 3*x2 + x3 >= 12

model.solve()

print('x1 = {}'.format(x1.varValue))
print('x2 = {}'.format(x2.varValue))
print('x3 = {}'.format(x3.varValue))
print('max z= ', value(model.objective))

What did you expect to see?

It should be no result.

What did you see instead?

x1 = 6.4285714 x2 = 0.57142857 x3 = 0.0 max z= 9.57142851

Useful extra information

The info below often helps, please fill it out if you're able to. :)

What operating system are you using?

I'm using python version:

I installed PuLP via:

Did you also

kmeng commented 11 months ago

if the third constraint is changed to:

model += x1 + 3*x2 + x3 <= 12

The objective value was wrong either. it should be 9.57142851

stumitchell commented 11 months ago

Did you check the solution status?

I answered this on my phone. Please excuse any typos and brevity

On Wed, 27 Sep 2023, 10:26 pm Kangjian Meng, @.***> wrote:

if the third constraint is changed to:

model += x1 + 3*x2 + x3 <= 12

The objective value was wrong either. it should be 9.57142851

— Reply to this email directly, view it on GitHub https://github.com/coin-or/pulp/issues/686#issuecomment-1737036427, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFUIWNGJS3BOZYZI7IQ5M3X4PWLDANCNFSM6AAAAAA5JA5ZBE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

kmeng commented 11 months ago

Thanks. It seems I got a wrong sample