Skip to content

Commit

Permalink
Merge pull request #133 from jump-dev/gb/improve-dual-names
Browse files Browse the repository at this point in the history
Add dual names to constrained variables
  • Loading branch information
guilhermebodin authored Mar 30, 2022
2 parents 39a4f2d + 650bd74 commit 7fdfb40
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Dualization"
uuid = "191a621a-6537-11e9-281d-650236a99e60"
authors = ["guilhermebodin <[email protected]>"]
version = "0.5.1"
version = "0.5.2"

[deps]
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
Expand Down
20 changes: 19 additions & 1 deletion src/dual_equality_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function add_dual_equality_constraints(
scalar_terms,
sense_change,
T,
dual_names,
)
end

Expand All @@ -66,7 +67,7 @@ function add_dual_equality_constraints(
MOI.ScalarAffineFunction(scalar_affine_terms[primal_vi], zero(T)),
MOI.EqualTo(sense_change * get(scalar_terms, primal_vi, zero(T))),
)
#Set constraint name with the name of the associated priaml variable
# Set constraint name with the name of the associated priaml variable
if !is_empty(dual_names)
set_dual_constraint_name(
dual_model,
Expand Down Expand Up @@ -116,6 +117,7 @@ function _add_constrained_variable_constraint(
scalar_terms,
sense_change,
::Type{T},
dual_names::DualNames,
) where {T}
set_primal = MOI.get(primal_model, MOI.ConstraintSet(), ci)
set_dual = MOI.dual_set(set_primal)
Expand All @@ -133,6 +135,11 @@ function _add_constrained_variable_constraint(
) for (i, primal_vi) in enumerate(func_primal.variables)
])
ci_map[ci] = MOI.add_constraint(dual_model, func_dual, set_dual)
if !is_empty(dual_names)
@warn(
"dual names for constrained vector of variables not supported yet."
)
end
return
end

Expand All @@ -146,6 +153,7 @@ function _add_constrained_variable_constraint(
scalar_terms,
sense_change,
::Type{T},
dual_names::DualNames,
) where {T}
# Nothing to add as the set is `EqualTo`.
func_primal = MOI.get(primal_model, MOI.ConstraintFunction(), ci)
Expand All @@ -165,6 +173,7 @@ function _add_constrained_variable_constraint(
scalar_terms,
sense_change,
::Type{T},
dual_names::DualNames,
) where {T}
func_primal = MOI.get(primal_model, MOI.ConstraintFunction(), ci)
primal_vi = func_primal
Expand All @@ -176,6 +185,15 @@ function _add_constrained_variable_constraint(
set_dual = _dual_set(set_primal)
ci_map[ci] =
MOIU.normalize_and_add_constraint(dual_model, func_dual, set_dual)
if !is_empty(dual_names)
set_dual_constraint_name(
dual_model,
primal_model,
primal_vi,
ci_map[ci],
dual_names.dual_constraint_name_prefix,
)
end
return
end

Expand Down
1 change: 1 addition & 0 deletions src/dual_model_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ function set_dual_variable_name(
ci_name::String,
prefix::String,
)
isempty(ci_name) && return
MOI.set(dual_model, MOI.VariableName(), vi, prefix * ci_name * "_$i")
return
end
Expand Down
1 change: 1 addition & 0 deletions test/Tests/test_dualize_conic_linear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
list_of_cons = MOI.get(dual_model, MOI.ListOfConstraintTypesPresent())
@test Set(list_of_cons) == Set(
[
(VAF{Float64}, MOI.Reals)
(VAF{Float64}, MOI.Nonpositives)
(VAF{Float64}, MOI.Nonnegatives)
(SAF{Float64}, MOI.EqualTo{Float64})
Expand Down

2 comments on commit 7fdfb40

@guilhermebodin
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/57626

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.2 -m "<description of version>" 7fdfb40f065ef48f8e74288906d8c079a0b23167
git push origin v0.5.2

Please sign in to comment.