Can't solve a problem with nonlinear terms like x^0.7 or x^3 using JuMP with Gurobi 11

I have installed Gurobi 11 and Gurobi 1.2.0.jl, and it’s believed that Gurobi now supports solving general nonlinear programming like x^0.7 or x^3, but I cannot solve it with JuMP using Gurobi, if I switch the solve to Ipopt, it works.

using JuMP, Gurobi

m = Model()

@variable(m, 0 <= x1 <= 40, start=23.564546)

@variable(m, 0 <= x2 <= 40, start=33.235712480000004)

@variable(m, 0 <= x3 <= 40, start=9.232629520000001)

@objective(m, Min, 0.1 * (16800 * (x71)^0.7 + 9500 * (x72)^

0.7 + 12600 * (x73)^0.7) + 8000 * x71 + 320 * x72 + 53.6 * x73 +

8000 * x70)

@objective(m, Min, 0.1 * (16800 * (x1)^3 + 9500 * (x2)^

3 + 12600 * (x3)^3) + 8000 * x1 + 320 * x2 + 53.6 * x3)

set_optimizer(m, Gurobi.Optimizer)

optimize!(m)

Just a heads up: you can wrap the code section of your post with backticks and it will display here as an actual code-block with formatting that makes it easier for everyone here to read. See point 2 of Please read: make it easier to help you - Meta Discussion - Julia Programming Language (julialang.org) for more details.

The phrase “cannot solve it” can mean a number of different things. Do you get an error when trying to run this code? If so, it would also be helpful to post the resultant stack trace. If not, what happens when you run it?

1 Like

Thank you, I will make the problem clear and easy to understand.

No problem. I’m not specifically familiar with Gurobi and don’t have a license to use it, but I’ll try to help where I can.

It sounds like Gurobi.jl is a JuMP interface that runs problems in your locally-installed copy of the Gurobi solver software from within Julia. Are you able to run this problem directly in Gurobi without Julia in between? That might help us troubleshoot where the issue is happening: within Gurobi, within the JuMP interface, etc.

From a quick search, I turned up this related article: What types of models can Gurobi solve? – Gurobi Help Center. It sounds to me like they support some non-linear constraints, but the canonical objective function forms seem pretty limited/specific.

I’m attempting to solve a nonconvex optimization problem using Gurobi 11 as the solver through JuMP in Julia. The objective function involves nonconvex terms, such as higher-order polynomials, exponents, and logarithms.

using JuMP, Gurobi

m = Model(Gurobi.Optimizer)

@variable(m, 0 <= x1 <= 40, start=23.564546)
@variable(m, 0 <= x2 <= 40, start=33.235712480000004)

@objective(m, Min, x1^0.7 + x2^3)

optimize!(m)

However, when attempting to use Gurobi 11 as the solver within JuMP, I encounter the following error:

bashCopy code

ERROR: The solver does not support an objective function of type MathOptInterface.ScalarNonlinearFunction.

It seems that although Gurobi itself supports global optimization for certain nonconvex problems, the interface between Gurobi and JuMP might not yet have the capability to handle these specific types of nonconvex objective functions.

I’d appreciate any insights or suggestions on how to effectively handle nonconvex optimization problems involving such objective functions using Gurobi through JuMP.

Good work! This was a really helpful update.

Can you post the full error stack trace? From just the one-line error it sounds like the optimization model is being constructed properly but the Gurobi.jl wrapper doesn’t currently have a way to pass that problem into the software itself.

Someone else here on Discourse with more Gurobi experience might be able to add on, but otherwise I’d suggest filing an Issue on their repo ( GitHub - jump-dev/Gurobi.jl: Julia interface for Gurobi Optimizer) with this example.

1 Like

The nonlinear support in Gurobi 11 is still very limited. You need to use the C API (I haven’t tested this, but it should work):

using JuMP, Gurobi
model = direct_model(Gurobi.Optimizer())
start = [23.564546, 33.235712480000004]
@variable(model, 0 <= x[i in 1:2] <= 40, start = start[i])
@variable(model, y[1:2])
column(x::VariableRef) = Gurobi.c_column(backend(owner_model(x)), index(x))
GRBaddgenconstrPow(backend(model), "x1^0.7", column(x[1]), column(y[1]), 0.7, "")
GRBaddgenconstrPow(backend(model), "x2^3", column(x[2]), column(y[2]), 3.0, "")
@objective(model, Min, y[1] + y[2])
optimize!(model)

A future version of Gurobi will introduce a first-class nonlinear API that we can connect to the nonlinear JuMP interface.

2 Likes

For future readers, see GitHub - jump-dev/Gurobi.jl: Julia interface for Gurobi Optimizer.

1 Like

Thanks, Odow. By the way, It seems that Gurobi 11 now supprot solving bilnear problems directly without the need to set attribute “NonConvex” to 2

1 Like