Skip to content

Commit 58afc13

Browse files
committed
Add test with multiple PSD variable on same constraint
1 parent e4ce984 commit 58afc13

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/Test/test_conic.jl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5770,6 +5770,78 @@ function setup_test(
57705770
return
57715771
end
57725772

5773+
function test_conic_PositiveSemidefiniteConeTriangle_4(
5774+
model::MOI.ModelLike,
5775+
config::Config{T},
5776+
) where {T<:Real}
5777+
atol = config.atol
5778+
rtol = config.rtol
5779+
@requires MOI.supports_incremental_interface(model)
5780+
@requires MOI.supports(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}())
5781+
@requires MOI.supports(model, MOI.ObjectiveSense())
5782+
@requires MOI.supports_constraint(
5783+
model,
5784+
MOI.VectorOfVariables,
5785+
MOI.PositiveSemidefiniteConeTriangle,
5786+
)
5787+
@requires MOI.supports_constraint(
5788+
model,
5789+
MOI.ScalarAffineFunction{T},
5790+
MOI.EqualTo{T},
5791+
)
5792+
@requires MOI.supports_constraint(
5793+
model,
5794+
MOI.ScalarAffineFunction{T},
5795+
MOI.GreaterThan{T},
5796+
)
5797+
5798+
x, cx = MOI.add_constrained_variables(model, MOI.PositiveSemidefiniteConeTriangle(2))
5799+
y, cy = MOI.add_constrained_variables(model, MOI.PositiveSemidefiniteConeTriangle(2))
5800+
c1 = MOI.add_constraint(model, sum(1.0 .* x) - sum(1.0 .* y), MOI.EqualTo(0.0))
5801+
c2 = MOI.add_constraint(model, 1.0 * y[1] + 1.0 * y[3], MOI.GreaterThan(1.0))
5802+
obj = 1.0 * x[1] + 1.0 * x[3]
5803+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
5804+
MOI.set(model, MOI.ObjectiveFunction{typeof(obj)}(), obj)
5805+
if _supports(config, MOI.optimize!)
5806+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED
5807+
MOI.optimize!(model)
5808+
@test MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
5809+
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT
5810+
if _supports(config, MOI.ConstraintDual)
5811+
@test MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
5812+
end
5813+
@test MOI.get.(model, MOI.VariablePrimal(), x) ones(3) ./ T(6) atol = atol rtol = rtol
5814+
@test MOI.get.(model, MOI.VariablePrimal(), y) [1, -1, 1] ./ T(2) atol = atol rtol = rtol
5815+
if _supports(config, MOI.ConstraintDual)
5816+
@test MOI.get(model, MOI.ConstraintDual(), cx) [1, -1, 1] ./ T(3) atol = atol rtol = rtol
5817+
@test MOI.get(model, MOI.ConstraintDual(), cy) ones(3) ./ T(3) atol = atol rtol = rtol
5818+
@test MOI.get(model, MOI.ConstraintDual(), c1) T(2)/T(3) atol = atol rtol = rtol
5819+
@test MOI.get(model, MOI.ConstraintDual(), c2) T(1)/T(3) atol = atol rtol = rtol
5820+
end
5821+
end
5822+
return
5823+
end
5824+
5825+
# Test with multiple PSD variable on the same constraint in order to catch
5826+
# https://github.com/jump-dev/MosekTools.jl/issues/139
5827+
function setup_test(
5828+
::typeof(test_conic_PositiveSemidefiniteConeTriangle_4),
5829+
model::MOIU.MockOptimizer,
5830+
::Config{T},
5831+
) where {T<:Real}
5832+
MOIU.set_mock_optimize!(
5833+
model,
5834+
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(
5835+
mock,
5836+
[[1, 1, 1] / T(6); [1, -1, 1] / T(2)],
5837+
(MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeTriangle) => [[1, -1, 1] ./ T(3), ones(3) ./ T(3)],
5838+
(MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}) => [T(2)/T(3)],
5839+
(MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}) => [T(1)/T(3)],
5840+
),
5841+
)
5842+
return
5843+
end
5844+
57735845
"""
57745846
_test_det_cone_helper_ellipsoid(
57755847
model::MOI.ModelLike,

0 commit comments

Comments
 (0)