Skip to content

[MOI] Set Gurobi-specific attributes #211

@odow

Description

@odow

As raised in this Discourse post, we should implement Gurobi-specific MOI attributes to allow the getting and setting of attributes from JuMP.

A sketch of the idea looks like:

struct ConstraintAttribute{T} <: MOI.AbstractConstraintAttribute
    name::String
end

function MOI.set(
    model::Optimizer, attr::ConstraintAttribute{Int}, 
    con::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64}, T}, val::Int
    ) where {T}
    row = model[con]
    set_intattrelement!(model.inner, attr.name, row, val)    
    return
end

function MOI.get(
    model, attr::ConstraintAttribute{Int}, 
    con::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64}, T}) where {T}
    return get_intattrelement(model.inner, attr.name, model[con])
end

MOI.set(model, ConstraintAttribute{Int}("Lazy"), con, 3)
MOI.get(model, ConstraintAttribute{Int}("Lazy"), con) # --> 3

Here is the list of Gurobi attributes
http://www.gurobi.com/documentation/8.1/refman/attributes.html

Here is the list of Gurobi.jl attribute getters and setters
https://github.com/JuliaOpt/Gurobi.jl/blob/master/src/grb_attrs.jl
Note that different functions need to be called based on the type of the attribute (e.g., get_intattr, get_dblattr, get_strattr).

Here is the list of abstract MOI attributes
https://github.com/JuliaOpt/MathOptInterface.jl/blob/06216dc6907b5ec76390c8380e4655065c83ea22/src/attributes.jl#L16-L35

We should repeat the Julia code above for the other types of attributes listed in the Gurobi documentation, defining new structs as needed.

We probably need to check that the string attribute names match the right int/dbl/str type.

Any code also needs tests and documentation.

For anyone working on this, make some small changes, and then open a pull-request. It doesn't need to be complete. We can workshop the changes before you spend too much time trying to implement everything.

Also, if you have a better idea for how to implement this, say so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions