Skip to content

set VariableName doesn't get called #1225

@Wikunia

Description

@Wikunia

I'm interested in getting the name of a variable by its variable index in my solver. See Wikunia/ConstraintSolver.jl#235

I've implemented

# Naming variables
MOI.supports(::Optimizer, ::MOI.VariableName, ::Type{MOI.VariableIndex}) = true

function MOI.get(model::Optimizer, ::MOI.VariableName, v::MOI.VariableIndex)
    return model.inner.search_space[v.value].name
end

function MOI.set(
    model::Optimizer, ::MOI.VariableName, v::MOI.VariableIndex, name::String
)
    println("Doesn't get called")
    model.inner.search_space[v.value].name = name
    return
end

and set MOIU.supports_default_copy_to(model::Optimizer, copy_names::Bool) = true

but a simple model like:

model = Model(optimizer_with_attributes(ConstraintSolver.Optimizer))
@variable(model, b, Bin)
@constraint(model, b <= 0.5)
optimize!(model)

doesn't call the set function and therefore using the get function returns the empty string.

The problem seems to be that copy_names is always set to false in various places like:

Setting it to true there calls the set function just fine.

It mentions that it doesn't have to be set to true as it's handled by model_cache but I don't find any information about that.

Seems like the set function doesn't get called for GLPK either which seems to implement the same methods as Gurobi.

Thanks for any hints in what I'm doing wrong.

My understanding of the variants of different optimizers like CachingOptimizer, BridgeOptimizer etc is very limited so any explanation about it is also highly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions