coin-or / CyLP

A Python interface to CLP, CBC, and CGL to solve LPs and MIPs.
Other
181 stars 68 forks source link

multiplication of CyLPExpr by constant not commutative #146

Open sdementen opened 2 years ago

sdementen commented 2 years ago

When multiplying by a constant before or after a variable.sum() I get a wrong / good answer

from cylp.cy.CyClpSimplex import CyClpSimplex

s = CyClpSimplex()
x = s.addVariable("x", 2)
y = s.addVariable("y", 2)
s += y >= 0
s += y.sum() - x.sum() * 3 <= -1  # ==> gives wrong solution x=[0,1]
# s += y.sum() - 3 * x.sum() <= -1  # ==> gives correct solution x=[0,0.3333]
s.objective = x.sum()
s.primal()

The two expressions y.sum() - x.sum() * 3 <= -1 and y.sum() - 3 * x.sum() <= -1 should represent the same constraint and give the same results but only the second gives the correct model.

rsemenoff commented 2 years ago

I believe this is a documented limitation.  On Friday, January 28, 2022, 05:08:03 AM PST, sdementen @.***> wrote:

When multiplying by a constant before or after a variable.sum() I get a wrong / good answer from cylp.cy.CyClpSimplex import CyClpSimplex

s = CyClpSimplex() x = s.addVariable("x", 2) y = s.addVariable("y", 2) s += y >= 0 s += y.sum() - x.sum() * 3 <= -1 # ==> gives wrong solution x=[0,1]

s += y.sum() - 3 * x.sum() <= -1 # ==> gives correct solution x=[0,0.3333]

s.objective = x.sum() s.primal() The two expressions y.sum() - x.sum() 3 <= -1 and y.sum() - 3 x.sum() <= -1 should represent the same constraint and give the same results but only the second gives the correct model.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you are subscribed to this thread.Message ID: @.***>