Skip to content

Commit 1be26a6

Browse files
authored
[Test] Add test with multiple PSD variables on same constraint (#2594)
1 parent e4ce984 commit 1be26a6

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

src/Test/test_conic.jl

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

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

0 commit comments

Comments
 (0)