Skip to content

Commit 852c11a

Browse files
committed
Fixes
1 parent 529042d commit 852c11a

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/Bridges/Bridges.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,12 @@ function _test_dual(
307307
Bridge::Type{<:AbstractBridge},
308308
input_fn::Function;
309309
dual,
310+
eltype,
310311
model_eltype,
311312
)
312313
inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{model_eltype}())
313314
mock = MOI.Utilities.MockOptimizer(inner)
314-
model = _bridged_model(Bridge{model_eltype}, mock)
315+
model = _bridged_model(Bridge{eltype}, mock)
315316
input_fn(model)
316317
final_touch(model)
317318
# Should be able to call final_touch multiple times.
@@ -331,13 +332,10 @@ function _test_dual(
331332
MOI.set(model, MOI.ConstraintDual(), ci, _fake_start(dual, set))
332333
end
333334
end
334-
model_dual = MOI.Utilities.get_fallback(
335-
model,
336-
MOI.DualObjectiveValue(),
337-
model_eltype,
338-
)
335+
model_dual =
336+
MOI.Utilities.get_fallback(model, MOI.DualObjectiveValue(), eltype)
339337
mock_dual =
340-
MOI.Utilities.get_fallback(mock, MOI.DualObjectiveValue(), model_eltype)
338+
MOI.Utilities.get_fallback(mock, MOI.DualObjectiveValue(), eltype)
341339
# Need `atol` in case one of them is zero and the other one almost zero
342340
Test.@test model_dual mock_dual atol = 1e-6
343341
end
@@ -455,7 +453,7 @@ function _runtests(
455453
end
456454
if !isnothing(dual)
457455
Test.@testset "Test ConstraintDual" begin
458-
_test_dual(Bridge, input_fn; dual, model_eltype)
456+
_test_dual(Bridge, input_fn; dual, eltype, model_eltype)
459457
end
460458
end
461459
return

src/Utilities/results.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@ function _dual_objective_value(
8888
)
8989
end
9090

91+
_lower(set::MOI.Interval, ::Type) = set.lower
92+
_upper(set::MOI.Interval, ::Type) = set.upper
93+
_lower(::MOI.ZeroOne, ::Type{T}) where {T} = zero(T)
94+
_upper(::MOI.ZeroOne, ::Type{T}) where {T} = one(T)
95+
9196
function _dual_objective_value(
9297
model::MOI.ModelLike,
93-
ci::MOI.ConstraintIndex{<:MOI.AbstractScalarFunction,<:MOI.Interval},
98+
ci::MOI.ConstraintIndex{<:MOI.AbstractScalarFunction,<:Union{MOI.ZeroOne,MOI.Interval}},
9499
::Type{T},
95100
result_index::Integer,
96101
) where {T}
@@ -100,10 +105,10 @@ function _dual_objective_value(
100105
if dual < zero(dual)
101106
# The dual is negative so it is in the dual of the MOI.LessThan cone
102107
# hence the upper bound of the Interval set is tight
103-
constant -= set.upper
108+
constant -= _upper(set, T)
104109
else
105110
# the lower bound is tight
106-
constant -= set.lower
111+
constant -= _lower(set, T)
107112
end
108113
return set_dot(constant, dual, set)
109114
end

test/Bridges/Constraint/ScalarFunctionizeBridge.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ function test_FunctionConversionBridge()
317317
variables: x, y
318318
ScalarNonlinearFunction(1.0 * x * x + 2.0 * x * y + 3.0 * y + 4.0) >= 1.0
319319
""",
320+
dual = nothing, # `get_fallback` ignores the constant `4.0` of the function
320321
)
321322
# VectorAffineFunction -> VectorQuadraticFunction
322323
MOI.Bridges.runtests(

0 commit comments

Comments
 (0)