Gurobi.jl icon indicating copy to clipboard operation
Gurobi.jl copied to clipboard

Modifying MultiObjective Parameters

Open mstriebs opened this issue 3 years ago • 2 comments

Currently the multi-objective implementation uses individual functions to set/get attributes. However, currently only weigth and priority are implemented. Some other important parameters like objnabstol, or objnrelstol cannot be set as the functions are missing. I would suggest something like the following structs and overloads, to have a more universal approach:

struct MultiObjectiveAttr <: MOI.AbstractModelAttribute
    index::Int
    attr::String
end

function MOI.get(model::Gurobi.Optimizer, attr::MultiObjectiveAttr)
    env = GRBgetenv(model)
    ret = GRBsetintparam(env, "ObjNumber", attr.index - 1)
    _check_ret(env, ret)
    val = Ref{Cdouble}()
    ret = GRBgetdblattr(model, attr.attr, val)
    _check_ret(model, ret)
    return val[]
end

function MOI.set(
    model::Gurobi.Optimizer,
    attr::MultiObjectiveAttr,
    value::Float64,
)
    env = GRBgetenv(model)
    ret = GRBsetintparam(env, "ObjNumber", attr.index - 1)
    _check_ret(env, ret)
    ret = GRBsetdblattr(model, attr.attr, value)
    _check_ret(model, ret)
    _require_update(model)
    return
end

mstriebs avatar Mar 22 '22 11:03 mstriebs

I'll review a pull request to add these with tests if you want to make one :)

Source goes here: https://github.com/jump-dev/Gurobi.jl/blob/master/src/MOI_wrapper/MOI_multi_objective.jl

For the tests, write a new function here: https://github.com/jump-dev/Gurobi.jl/blob/master/test/MOI/MOI_multiobjective.jl

odow avatar Mar 22 '22 20:03 odow

Hi guys, a few days ago I had to use GRBsetstrattr to set the objective names for better readability. So it would be nice to include this case as well. 🙂

aartinian avatar Apr 18 '22 20:04 aartinian