-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Comments
Hello! That's a good point. Unfortunately we try to keep pulp valid for
many solvers and sometimes this means not being able to provide the full
functionality of each solver.
As a workaround, you can build most of the problem in pulp and then
manipulate the GUROBI model just before running, as explained here :
https://coin-or.github.io/pulp/guides/how_to_configure_solvers.html#using-solver-specific-functionality
The example uses cplex but it's valid for the GUROBI solver
…---------- Forwarded message ---------
From: AX ***@***.***>
Date: Sun, Jun 23, 2024, 04:37
Subject: [coin-or/pulp] Add support for nonlinear variables (Issue #756)
To: coin-or/pulp ***@***.***>
Cc: Subscribed ***@***.***>
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?
—
Reply to this email directly, view it on GitHub
<#756>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJUZ4YETRSU2I3NQEKGTQ3ZIYYFRAVCNFSM6AAAAABJX6CYESVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3DQMJWGUYDCMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
OK. Thank you very much! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
The text was updated successfully, but these errors were encountered: