pulp icon indicating copy to clipboard operation
pulp copied to clipboard

pulp.lpDot update

Open nariaki3551 opened this issue 3 years ago • 7 comments

to address issue #483

With this change, the following lpDot operation behaves as expected.

import pandas as pd
import numpy as np
import pulp as pl

x = pd.Series(pl.LpVariable.dicts("x", range(3)), index=range(3))  # Series of LpVariable
y = 2 * x  # Series of LpAffineExpression [2*x_0, 2*x_1, 2*x_2]
a = np.arange(3) + 1  # [1, 2, 3]

print(pl.lpDot(y, a))
>>> 2*x_0 + 4*x_1 + 6*x_2   # but, current version is x_0 + 2*x_1 + 3*x_2

nariaki3551 avatar Aug 22 '22 01:08 nariaki3551

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Aug 22 '22 01:08 CLAassistant

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Aug 22 '22 01:08 CLAassistant

could you add a unit test to show what did not work and how it works now? thanks.

pchtsp avatar Aug 24 '22 15:08 pchtsp

Thanks for your comment! I added a test for this change. With this change, lpDot outputs the correct LpAffineExpression even when an LpAffineExpression is given to lpDot.

current version

x = LpVariable("x")
y = LpVariable("y")
z = LpVariable("z")
a = [1, 2, 3]

dict(lpDot([2*x, 2*y, 2*z], a))
>>> {x: 1, y: 2, z: 3}

with this change

x = LpVariable("x")
y = LpVariable("y")
z = LpVariable("z")
a = [1, 2, 3]

dict(lpDot([2*x, 2*y, 2*z], a))
>>> {x: 2, y: 4, z: 6}

nariaki3551 avatar Aug 25 '22 01:08 nariaki3551

thanks and sorry for the late reply. Could you take out PSCIP_CMD from this PR? so I can add only the lpDot use? thanks. You can add a new PR with the new solver.

pchtsp avatar Oct 02 '23 11:10 pchtsp

I have completed the requested changes. The PSCIP_CMD addition has been removed from this pull request, focusing solely on the lpDot updating as you suggested.

I apologize for my delayed response. Thanks.

nariaki3551 avatar Nov 22 '23 03:11 nariaki3551