Skip to content

Commit adb2580

Browse files
committed
Fix qcp1 and add ConstraintPrimal to qcp tests
1 parent 6a51dfc commit adb2580

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Test/contquadratic.jl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,12 @@ function qcp1test(model::MOI.ModelLike, config::TestConfig)
261261
rtol = config.rtol
262262
@testset "qcp1" begin
263263
# quadratic constraint
264-
# Max x + y
265-
# st - x + y >= 0 (c1[1])
266-
# x + y >= 0 (c1[2])
267-
# 0.5x^2 + y <= 2 (c2)
264+
# Max x + y
265+
# st -x + y >= 0 (c1[1])
266+
# x + y >= 0 (c1[2])
267+
# x² + y <= 2 (c2)
268+
# Optimal solution
269+
# x = 1/2, y = 7/4
268270

269271
@test MOI.supports(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}())
270272
@test MOI.supportsconstraint(model, MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives)
@@ -283,7 +285,7 @@ function qcp1test(model::MOI.ModelLike, config::TestConfig)
283285
c1 = MOI.addconstraint!(model, MOI.VectorAffineFunction([1,1,2,2], [x,y,x,y], [-1.0,1.0,1.0,1.0], [0.0,0.0]), MOI.Nonnegatives(2))
284286
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives}()) == 1
285287

286-
c2f = MOI.ScalarQuadraticFunction([y],[1.0],[x],[x],[1.0], 0.0)
288+
c2f = MOI.ScalarQuadraticFunction([y],[1.0],[x],[x],[2.0], 0.0)
287289
@test MOI.canaddconstraint(model, typeof(c2f), MOI.LessThan{Float64})
288290
c2 = MOI.addconstraint!(model, c2f, MOI.LessThan(2.0))
289291
@test MOI.get(model, MOI.NumberOfConstraints{MOI.ScalarQuadraticFunction{Float64}, MOI.LessThan{Float64}}()) == 1
@@ -313,6 +315,11 @@ function qcp1test(model::MOI.ModelLike, config::TestConfig)
313315

314316
@test MOI.canget(model, MOI.VariablePrimal(), MOI.VariableIndex)
315317
@test MOI.get(model, MOI.VariablePrimal(), [x,y]) [0.5,1.75] atol=atol rtol=rtol
318+
319+
@test MOI.canget(model, MOI.ConstraintPrimal(), typeof(c1))
320+
@test MOI.get(model, MOI.ConstraintPrimal(), c1) [5/4, 9/4] atol=atol rtol=rtol
321+
@test MOI.canget(model, MOI.ConstraintPrimal(), typeof(c2))
322+
@test MOI.get(model, MOI.ConstraintPrimal(), c2) 2 atol=atol rtol=rtol
316323
end
317324

318325
# try delete quadratic constraint and go back to linear
@@ -386,6 +393,9 @@ function qcp2test(model::MOI.ModelLike, config::TestConfig)
386393
@test MOI.canget(model, MOI.VariablePrimal(), MOI.VariableIndex)
387394
@test MOI.get(model, MOI.VariablePrimal(), x) sqrt(2) atol=atol rtol=rtol
388395

396+
@test MOI.canget(model, MOI.ConstraintPrimal(), typeof(c))
397+
@test MOI.get(model, MOI.ConstraintPrimal(), c) 2 atol=atol rtol=rtol
398+
389399
# TODO - duals
390400
# @test MOI.canget(model, MOI.ConstraintDual(), typeof(c))
391401
# @test MOI.get(model, MOI.ConstraintDual(), c) ≈ 0.5/sqrt(2) atol=atol rtol=rtol
@@ -446,6 +456,9 @@ function qcp3test(model::MOI.ModelLike, config::TestConfig)
446456
@test MOI.canget(model, MOI.VariablePrimal(), MOI.VariableIndex)
447457
@test MOI.get(model, MOI.VariablePrimal(), x) sqrt(2) atol=atol rtol=rtol
448458

459+
@test MOI.canget(model, MOI.ConstraintPrimal(), typeof(c))
460+
@test MOI.get(model, MOI.ConstraintPrimal(), c) 2 atol=atol rtol=rtol
461+
449462
# TODO - duals
450463
# @test MOI.canget(model, MOI.ConstraintDual(), typeof(c))
451464
# @test MOI.get(model, MOI.ConstraintDual(), c) ≈ -0.5/sqrt(2) atol=atol rtol=rtol

0 commit comments

Comments
 (0)