diff --git a/src/Bridges/Constraint/bridges/det.jl b/src/Bridges/Constraint/bridges/det.jl index d74036028d..c35a643395 100644 --- a/src/Bridges/Constraint/bridges/det.jl +++ b/src/Bridges/Constraint/bridges/det.jl @@ -231,8 +231,6 @@ function MOI.get( attr::Union{MOI.ConstraintPrimal,MOI.ConstraintPrimalStart}, bridge::LogDetBridge, ) - d = length(bridge.lcindex) - Δ = 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/test/Bridges/Objective/slack.jl b/test/Bridges/Objective/slack.jl index b52891c56f..68fb70e2e7 100644 --- a/test/Bridges/Objective/slack.jl +++ b/test/Bridges/Objective/slack.jl @@ -208,6 +208,34 @@ function test_SlackBridge_ObjectiveFunctionValue() return end +function test_SlackBridge_ObjectiveFunctionValue_2() + inner = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()) + model = MOI.Bridges.Objective.Slack{Float64}(inner) + x = MOI.add_variable(model) + MOI.add_constraint(model, x, MOI.GreaterThan(1.0)) + f = 1.1 * x - 1.2 + MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) + MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) + MOI.Utilities.set_mock_optimize!( + inner, + mock -> begin + MOI.set(mock, MOI.ResultCount(), 2) + MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL) + MOI.set(mock, MOI.PrimalStatus(1), MOI.FEASIBLE_POINT) + MOI.set(mock, MOI.PrimalStatus(2), MOI.FEASIBLE_POINT) + y = MOI.get(mock, MOI.ListOfVariableIndices()) + MOI.set.(mock, MOI.VariablePrimal(1), y, [1.0, -0.1]) + MOI.set.(mock, MOI.VariablePrimal(2), y, [2.0, 1.0]) + end, + ) + MOI.optimize!(model) + @test MOI.get(model, MOI.ObjectiveValue(1)) ≈ -0.1 + @test MOI.get(model, MOI.VariablePrimal(1), x) ≈ 1.0 + @test MOI.get(model, MOI.ObjectiveValue(2)) ≈ 1.0 + @test MOI.get(model, MOI.VariablePrimal(2), x) ≈ 2.0 + return +end + function test_original() mock = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()) bridged_mock = MOI.Bridges.Objective.Slack{Float64}(mock) diff --git a/test/Bridges/Objective/vector_slack.jl b/test/Bridges/Objective/vector_slack.jl index 14320162d0..142007c4fa 100644 --- a/test/Bridges/Objective/vector_slack.jl +++ b/test/Bridges/Objective/vector_slack.jl @@ -166,6 +166,34 @@ function test_modify_vector_constant_change() return end +function test_SlackBridge_ObjectiveFunctionValue_2() + inner = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()) + model = MOI.Bridges.Objective.VectorSlack{Float64}(inner) + x = MOI.add_variable(model) + MOI.add_constraint(model, x, MOI.GreaterThan(1.0)) + f = MOI.Utilities.operate(vcat, Float64, 1.1 * x - 1.2) + MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) + MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) + MOI.Utilities.set_mock_optimize!( + inner, + mock -> begin + MOI.set(mock, MOI.ResultCount(), 2) + MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL) + MOI.set(mock, MOI.PrimalStatus(1), MOI.FEASIBLE_POINT) + MOI.set(mock, MOI.PrimalStatus(2), MOI.FEASIBLE_POINT) + y = MOI.get(mock, MOI.ListOfVariableIndices()) + MOI.set.(mock, MOI.VariablePrimal(1), y, [1.0, -0.1]) + MOI.set.(mock, MOI.VariablePrimal(2), y, [2.0, 1.0]) + end, + ) + MOI.optimize!(model) + @test MOI.get(model, MOI.ObjectiveValue(1)) ≈ [-0.1] + @test MOI.get(model, MOI.VariablePrimal(1), x) ≈ 1.0 + @test MOI.get(model, MOI.ObjectiveValue(2)) ≈ [1.0] + @test MOI.get(model, MOI.VariablePrimal(2), x) ≈ 2.0 + return +end + end # module TestObjectiveVectorSlack.runtests()