Skip to content

Print a constraint with Name #2335

@WalterMadelim

Description

@WalterMadelim

While building a model with Gurobi.jl and MOI, variable names is visiable from print(model), but constraint names are not. I think this is inconsistent.

julia> import MathOptInterface as MOI
julia> import Gurobi
julia> o = Gurobi.Optimizer();
julia> x = MOI.add_variable(o);
julia> ci = MOI.add_constraint(o, 1. * x, MOI.LessThan(0.))
MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.LessThan{Float64}}(1)

julia> print(o) ### model_print_1
Feasibility

Subject to:

ScalarAffineFunction{Float64}-in-LessThan{Float64}
 0.0 + 1.0 v[1] <= 0.0

julia> MOI.set(o,MOI.VariableName(),x,"x") ### set Variable Name

julia> print(o) ### model_print_2
Feasibility

Subject to:

ScalarAffineFunction{Float64}-in-LessThan{Float64}
 0.0 + 1.0 x <= 0.0 ### Variable Name updated from "v[1]" to "x", compared with model_print_1

julia> MOI.set(o,MOI.ConstraintName(),ci,"x_le_0") ### set Constraint Name

julia> print(o) ### model_print_3, which is the same as model_print_2
Feasibility

Subject to:

ScalarAffineFunction{Float64}-in-LessThan{Float64}
 0.0 + 1.0 x <= 0.0

julia> 

I think an ideal case in model_print_3 should be something like

julia> print(o)
Feasibility

Subject to:

ScalarAffineFunction{Float64}-in-LessThan{Float64}
x_le_0: 0.0 + 1.0 x <= 0.0

Do you think this is a good proposal, because when users model physical problems, they need to label constraints of different types (e.g., ramp_up rates, demand_balance,...)
It will be convenient to check them in the prints.

Or maybe this is a question with MOI, generally?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions