Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nonlinear variables #756

Closed
Aliebc opened this issue Jun 23, 2024 · 2 comments
Closed

Add support for nonlinear variables #756

Aliebc opened this issue Jun 23, 2024 · 2 comments

Comments

@Aliebc
Copy link

Aliebc commented Jun 23, 2024

Add support for nonlinear variable expressions

Currently, Pulp does not support nonlinear variable expressions, and it will raise an error for such expressions.
`
import pulp as pl

x1 = pl.LpVariable("x1", lowBound=0, upBound=5)
x2 = pl.LpVariable("x2", lowBound=0, upBound=5)

problem = pl.LpProblem("MILP", pl.LpMaximize)

problem += x1 * x1 + x2 * x2

problem += x1 + x2 <= 10

problem.solve()

for v in problem.variables():
print(v.name, v.varValue)

print("Obj: ", pl.value(problem.objective))
`

It gives the following error:
TypeError: Non-constant expressions cannot be multiplied

However, GUROBI supports such expressions.

`
from gurobipy import Model, GRB

model = Model("MILP")

x1 = model.addVar(vtype=GRB.CONTINUOUS, name="x1")
x2 = model.addVar(vtype=GRB.CONTINUOUS, name="x2")

model.addConstr(x1 >= 0)
model.addConstr(x1 <= 5)
model.addConstr(x2 >= 0)
model.addConstr(x2 <= 5)

model.setObjective(x1 * x1 + x2 * x2, GRB.MAXIMIZE)

model.addConstr(x1 + x2 <= 10, "c0")

model.optimize()

for v in model.getVars():
print('%s %g' % (v.varName, v.x))

print('Obj: %g' % model.objVal)
`

Can Pulp support such nonlinear variable expressions with GUROBI?

@pchtsp
Copy link
Collaborator

pchtsp commented Jun 27, 2024 via email

@Aliebc
Copy link
Author

Aliebc commented Jun 30, 2024

OK. Thank you very much!

@Aliebc Aliebc closed this as completed Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants