Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 29, 2024
1 parent 353eacf commit 782f84b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/Bridges/Constraint/bridges/det.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions test/Bridges/Objective/slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions test/Bridges/Objective/vector_slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 782f84b

Please sign in to comment.