Skip to content

Commit

Permalink
[Bridges] fix querying result attributes with result_index != 1
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 28, 2024
1 parent 02dc52c commit 353eacf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/bridges/det.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function MOI.get(
bridge::LogDetBridge,
)
d = length(bridge.lcindex)
Δ = MOI.get(model, MOI.VariablePrimal(), bridge.Δ)
Δ = MOI.get(model, MOI.VariablePrimal(attr.result_index), bridge.Δ)

Check warning on line 235 in src/Bridges/Constraint/bridges/det.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/det.jl#L235

Added line #L235 was not covered by tests
t =
MOI.get(model, attr, bridge.tlindex) +
sum(MOI.get(model, attr, ci)[1] for ci in bridge.lcindex)
Expand Down
10 changes: 5 additions & 5 deletions src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ end
# constraint is (tr(U) + tr(V), 2X) in NormNuclearCone.
function MOI.get(
model::MOI.ModelLike,
::MOI.ConstraintDual,
attr::MOI.ConstraintDual,
bridge::NormSpectralBridge,
)
dual = MOI.get(model, MOI.ConstraintDual(), bridge.psd_index)
dual = MOI.get(model, attr, bridge.psd_index)

Check warning on line 206 in src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl#L206

Added line #L206 was not covered by tests
column_dim = bridge.column_dim
side_dim = bridge.row_dim + column_dim
t = sum(dual[MOI.Utilities.trimap(i, i)] for i in 1:side_dim)
Expand Down Expand Up @@ -450,11 +450,11 @@ end

function MOI.get(
model::MOI.ModelLike,
::MOI.ConstraintPrimal,
attr::MOI.ConstraintPrimal,
bridge::NormNuclearBridge,
)
ge_primal = MOI.get(model, MOI.ConstraintPrimal(), bridge.ge_index)
psd_primal = MOI.get(model, MOI.ConstraintPrimal(), bridge.psd_index)
ge_primal = MOI.get(model, attr, bridge.ge_index)
psd_primal = MOI.get(model, attr, bridge.psd_index)

Check warning on line 457 in src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl#L456-L457

Added lines #L456 - L457 were not covered by tests
side_dim = bridge.row_dim + bridge.column_dim
t =
ge_primal +
Expand Down
7 changes: 5 additions & 2 deletions src/Bridges/Objective/bridges/slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ function MOI.get(
# value of `bridge.slack`. Since `bridge.constraint` is `g - slack`, we can
# get the value of the original objective by summing the value of `slack`
# with the `ConstraintPrimal` of the constraint.
obj_slack_constant =
MOI.get(model, MOI.ConstraintPrimal(), bridge.constraint)
obj_slack_constant = MOI.get(

Check warning on line 158 in src/Bridges/Objective/bridges/slack.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Objective/bridges/slack.jl#L158

Added line #L158 was not covered by tests
model,
MOI.ConstraintPrimal(attr.result_index),
bridge.constraint,
)
return obj_slack_constant + slack + bridge.constant
end

Expand Down
6 changes: 5 additions & 1 deletion src/Bridges/Objective/bridges/vector_slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ function MOI.get(
N = attr_g.result_index
attr_f = MOI.Bridges.ObjectiveFunctionValue{MOI.VectorOfVariables}(N)
objective_value = MOI.get(model, attr_f)
con_primal = MOI.get(model, MOI.ConstraintPrimal(), bridge.constraint)
con_primal = MOI.get(

Check warning on line 162 in src/Bridges/Objective/bridges/vector_slack.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Objective/bridges/vector_slack.jl#L162

Added line #L162 was not covered by tests
model,
MOI.ConstraintPrimal(attr_g.result_index),
bridge.constraint,
)
sense = MOI.get(model, MOI.ObjectiveSense())
if sense == MOI.MIN_SENSE
# con_primal = objective_value - f(x)
Expand Down

0 comments on commit 353eacf

Please sign in to comment.