Gurobi AddGenConstrPoly() in JuMP

Hi All,
Can we code GRBModel.AddGenConstrPoly()
constraint available in gurobi directly in JuMP.

The MINLP is solved using Juniper. we want to try Gurobi for this.

You’ll need to use the C API https://www.gurobi.com/documentation/11.0/refman/c_agc_poly.html

Something like:

using JuMP, Gurobi
column(x::VariableRef) = Gurobi.c_column(backend(owner_model(x)), index(x))
model = direct_model(Gurobi.Optimizer())
@variable(model, x)
@variable(model, y)
p = [3.0, 0.0, 0.0, 7.0, 3.0]
GRBaddgenconstrPoly(backend(model), C_NULL, column(x), column(y), 5, p, "")
optimize!(model)

See also: Can't solve a problem with nonlinear terms like x^0.7 or x^3 using JuMP with Gurobi 11 - #8 by odow

1 Like

See also GitHub - jump-dev/Gurobi.jl: Julia interface for Gurobi Optimizer

1 Like

Dear Odow
with [2e9cd046] Gurobi v1.2.0 on julia 1.6

julia> column(x::VariableRef) = Gurobi.c_column(backend(owner_model(x)), index(x))
column (generic function with 1 method)
julia> model = direct_model(Gurobi.Optimizer())
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: DIRECT
Solver name: Gurobi

julia> @variable(model, x[i in 1:2])
2-element Vector{VariableRef}:
 x[1]
 x[2]

julia> @variable(model, y[1:2])
2-element Vector{VariableRef}:
 y[1]
 y[2]

julia> GRBaddgenconstrPow(backend(model), "x1^0.7", column(x[1]), column(y[1]), 0.7, "")
ERROR: UndefVarError: c_column not defined
Stacktrace:
 [1] column(x::VariableRef)
   @ Main .\REPL[32]:1
 [2] top-level scope
   @ REPL[36]:1

julia> GRBaddgenconstrPow(backend(model), "x2^3", column(x[2]), column(y[2]), 3.0, "")
ERROR: UndefVarError: c_column not defined
Stacktrace:
 [1] column(x::VariableRef)
   @ Main .\REPL[32]:1
 [2] top-level scope
   @ REPL[37]:1

julia> @objective(model, Min, y[1] + y[2])
y[1] + y[2]

julia> optimize!(model)

Are you sure you typed exactly:

using JuMP, Gurobi
column(x::VariableRef) = Gurobi.c_column(backend(owner_model(x)), index(x))

What did you type before the code you posted?

Note that you need Gurobi.c_column not just c_column.

1 Like

yes it was typo. Thanks for the reply.

1 Like

Hi
can do the same for JUMP expressions?

You cannot.

Define an additional variable and use an equality constraint to make the additional variable equal to the expression.

1 Like