-
Notifications
You must be signed in to change notification settings - Fork 94
Description
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.