Skip to content

Unique names don't require underscores #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/dual_model_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function add_dual_variable(
# Add each vi to the dictionary
func = get_function(primal_model, ci)
set = get_set(primal_model, ci)
is_unique_var = length(vis) == 1
for (i, vi) in enumerate(vis)
push_to_dual_obj_aff_terms!(
primal_model,
Expand All @@ -164,6 +165,7 @@ function add_dual_variable(
i,
ci_name,
dual_names.dual_variable_name_prefix,
ensure_unique = !is_unique_var,
)
end
end
Expand All @@ -175,10 +177,15 @@ function set_dual_variable_name(
vi::MOI.VariableIndex,
i::Int,
ci_name::String,
prefix::String,
prefix::String;
ensure_unique::Bool = true,
)
isempty(ci_name) && return
MOI.set(dual_model, MOI.VariableName(), vi, prefix * ci_name * "_$i")
name = prefix * ci_name
if ensure_unique
name *= "_$i"
end
MOI.set(dual_model, MOI.VariableName(), vi, name)
return
end

Expand Down
2 changes: 1 addition & 1 deletion test/Tests/test_JuMP_dualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end

dual_model = dualize(model; dual_names = DualNames("dual", ""))

@test typeof(dual_model[:dualeqcon_1]) == VariableRef
@test typeof(dual_model[:dualeqcon]) == VariableRef
@test !haskey(dual_model, Symbol(""))
end
@testset "JuMP_dualize_kwargs" begin
Expand Down
9 changes: 9 additions & 0 deletions test/Tests/test_dual_model_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
vi = MOI.VariableIndex(1)
Dualization.set_dual_variable_name(primal_model, vi, 1, "con", "")
@test MOI.get(primal_model, MOI.VariableName(), vi) == "con_1"
Dualization.set_dual_variable_name(
primal_model,
vi,
1,
"con",
"",
ensure_unique = false,
)
@test MOI.get(primal_model, MOI.VariableName(), vi) == "con"
Dualization.set_dual_variable_name(primal_model, vi, 2, "con", "")
@test MOI.get(primal_model, MOI.VariableName(), vi) == "con_2"
Dualization.set_dual_variable_name(primal_model, vi, 2, "con", "oi")
Expand Down
2 changes: 1 addition & 1 deletion test/Tests/test_dual_names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
}(
1,
)][1]
@test MOI.get(dual_model, MOI.VariableName(), vi_2) == "dualvar_lessthan_1"
@test MOI.get(dual_model, MOI.VariableName(), vi_2) == "dualvar_lessthan"
# Query constraint names
ci_1 = primal_dual_map.primal_var_dual_con[MOI.VariableIndex(1)]
ci_2 = primal_dual_map.primal_var_dual_con[MOI.VariableIndex(2)]
Expand Down
5 changes: 1 addition & 4 deletions test/optimize_abstract_models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
Attach an MOI.ModelLike to an optimizer,
solve it and retrieve the termination status and objective value
"""
function solve_abstract_model(
model::MOI.ModelLike,
optimizer_constructor,
) where {T}
function solve_abstract_model(model::MOI.ModelLike, optimizer_constructor)
JuMP_model = JuMP.Model()
MOI.copy_to(JuMP.backend(JuMP_model), model)
set_optimizer(JuMP_model, optimizer_constructor)
Expand Down