Skip to content

Commit ee07c24

Browse files
authored
Update test_conic.jl
1 parent ec2b976 commit ee07c24

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

src/Test/test_conic.jl

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5770,13 +5770,14 @@ 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
57735775
function test_conic_PositiveSemidefiniteConeTriangle_4(
57745776
model::MOI.ModelLike,
57755777
config::Config{T},
57765778
) where {T<:Real}
5777-
atol = config.atol
5778-
rtol = config.rtol
57795779
@requires MOI.supports_incremental_interface(model)
5780+
@requires _supports(config, MOI.optimize!)
57805781
@requires MOI.supports(
57815782
model,
57825783
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
@@ -5797,7 +5798,6 @@ function test_conic_PositiveSemidefiniteConeTriangle_4(
57975798
MOI.ScalarAffineFunction{T},
57985799
MOI.GreaterThan{T},
57995800
)
5800-
58015801
x, cx = MOI.add_constrained_variables(
58025802
model,
58035803
MOI.PositiveSemidefiniteConeTriangle(2),
@@ -5808,42 +5808,37 @@ function test_conic_PositiveSemidefiniteConeTriangle_4(
58085808
)
58095809
c1 = MOI.add_constraint(
58105810
model,
5811-
sum(1.0 .* x) - sum(1.0 .* y),
5812-
MOI.EqualTo(0.0),
5811+
sum(one(T) .* x) - sum(one(T) .* y),
5812+
MOI.EqualTo(zero(T)),
58135813
)
5814-
c2 =
5815-
MOI.add_constraint(model, 1.0 * y[1] + 1.0 * y[3], MOI.GreaterThan(1.0))
5816-
obj = 1.0 * x[1] + 1.0 * x[3]
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]
58175820
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
58185821
MOI.set(model, MOI.ObjectiveFunction{typeof(obj)}(), obj)
5819-
if _supports(config, MOI.optimize!)
5820-
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED
5821-
MOI.optimize!(model)
5822-
@test MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
5823-
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT
5824-
if _supports(config, MOI.ConstraintDual)
5825-
@test MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
5826-
end
5827-
@test MOI.get.(model, MOI.VariablePrimal(), x) ones(3) ./ T(6) atol =
5828-
atol rtol = rtol
5829-
@test MOI.get.(model, MOI.VariablePrimal(), y) [1, -1, 1] ./ T(2) atol =
5830-
atol rtol = rtol
5831-
if _supports(config, MOI.ConstraintDual)
5832-
@test MOI.get(model, MOI.ConstraintDual(), cx) [1, -1, 1] ./ T(3) atol =
5833-
atol rtol = rtol
5834-
@test MOI.get(model, MOI.ConstraintDual(), cy) ones(3) ./ T(3) atol =
5835-
atol rtol = rtol
5836-
@test MOI.get(model, MOI.ConstraintDual(), c1) T(2) / T(3) atol =
5837-
atol rtol = rtol
5838-
@test MOI.get(model, MOI.ConstraintDual(), c2) T(1) / T(3) atol =
5839-
atol rtol = rtol
5840-
end
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)
58415838
end
58425839
return
58435840
end
58445841

5845-
# Test with multiple PSD variable on the same constraint in order to catch
5846-
# https://github.com/jump-dev/MosekTools.jl/issues/139
58475842
function setup_test(
58485843
::typeof(test_conic_PositiveSemidefiniteConeTriangle_4),
58495844
model::MOIU.MockOptimizer,
@@ -5853,9 +5848,9 @@ function setup_test(
58535848
model,
58545849
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(
58555850
mock,
5856-
[[1, 1, 1] / T(6); [1, -1, 1] / T(2)],
5851+
T[[1, 1, 1] / T(6); [1, -1, 1] / T(2)],
58575852
(MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeTriangle) =>
5858-
[[1, -1, 1] ./ T(3), ones(3) ./ T(3)],
5853+
T[[1, -1, 1] ./ T(3), ones(T, 3) ./ T(3)],
58595854
(MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}) => [T(2) / T(3)],
58605855
(MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}) =>
58615856
[T(1) / T(3)],

0 commit comments

Comments
 (0)