From 353eacf4eaa1dba2185651de1bfda4171abf63a3 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 29 Nov 2024 12:46:19 +1300 Subject: [PATCH] [Bridges] fix querying result attributes with result_index != 1 --- src/Bridges/Constraint/bridges/det.jl | 2 +- src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl | 10 +++++----- src/Bridges/Objective/bridges/slack.jl | 7 +++++-- src/Bridges/Objective/bridges/vector_slack.jl | 6 +++++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Bridges/Constraint/bridges/det.jl b/src/Bridges/Constraint/bridges/det.jl index 0614cdbcc5..d74036028d 100644 --- a/src/Bridges/Constraint/bridges/det.jl +++ b/src/Bridges/Constraint/bridges/det.jl @@ -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.Δ) t = MOI.get(model, attr, bridge.tlindex) + sum(MOI.get(model, attr, ci)[1] for ci in bridge.lcindex) diff --git a/src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl b/src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl index 42c4027b5e..838b0a67d0 100644 --- a/src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl +++ b/src/Bridges/Constraint/bridges/norm_spec_nuc_to_psd.jl @@ -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) 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) @@ -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) side_dim = bridge.row_dim + bridge.column_dim t = ge_primal + diff --git a/src/Bridges/Objective/bridges/slack.jl b/src/Bridges/Objective/bridges/slack.jl index 1b9a1c56be..9413f65c02 100644 --- a/src/Bridges/Objective/bridges/slack.jl +++ b/src/Bridges/Objective/bridges/slack.jl @@ -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( + model, + MOI.ConstraintPrimal(attr.result_index), + bridge.constraint, + ) return obj_slack_constant + slack + bridge.constant end diff --git a/src/Bridges/Objective/bridges/vector_slack.jl b/src/Bridges/Objective/bridges/vector_slack.jl index 82efe8d7b1..9a8d979e39 100644 --- a/src/Bridges/Objective/bridges/vector_slack.jl +++ b/src/Bridges/Objective/bridges/vector_slack.jl @@ -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( + 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)