Max and min Gurobi constraint in Julia

Hi All,

  • MAX constraint: The constraint ![</span>r = \max\{x_1,\ldots,x_k,c\}<span>
  • MIN constraint: Similar to a MAX constraint, the constraint ![</span>r = \min\{x_1,\ldots,x_k,c\}<span>]

can we code max and min constraint available in gurobi directly in JuMP.

1 Like

There is some support for this, but you need to use the Gurobi C API. Here’s the example from https://www.gurobi.com/documentation/current/refman/c_agc_max.html

using JuMP, Gurobi
model = direct_model(Gurobi.Optimizer())
l = [1, 2, 3, 4, 0]
@variable(model, x[i = 1:5] >= l[I])
@objective(model, Min, sum(x))
# x5 = max(x1, x3, x4, 2.0)
grb = backend(model)
columns = Cint.(Gurobi.column.(grb, index.(x)) .- 1)
ind = columns[[1, 3, 4]]
GRBaddgenconstrMax(grb, "maxconstr", columns[5], 3, ind, 2.0)
optimize!(model)
value.(x) # [1, 2, 3, 4, 4]
1 Like

Thank you very much.

1 Like