@@ -261,10 +261,12 @@ function qcp1test(model::MOI.ModelLike, config::TestConfig)
261
261
rtol = config. rtol
262
262
@testset " qcp1" begin
263
263
# 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
268
270
269
271
@test MOI. supports (model, MOI. ObjectiveFunction {MOI.ScalarAffineFunction{Float64}} ())
270
272
@test MOI. supportsconstraint (model, MOI. VectorAffineFunction{Float64}, MOI. Nonnegatives)
@@ -283,7 +285,7 @@ function qcp1test(model::MOI.ModelLike, config::TestConfig)
283
285
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 ))
284
286
@test MOI. get (model, MOI. NumberOfConstraints {MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives} ()) == 1
285
287
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 )
287
289
@test MOI. canaddconstraint (model, typeof (c2f), MOI. LessThan{Float64})
288
290
c2 = MOI. addconstraint! (model, c2f, MOI. LessThan (2.0 ))
289
291
@test MOI. get (model, MOI. NumberOfConstraints {MOI.ScalarQuadraticFunction{Float64}, MOI.LessThan{Float64}} ()) == 1
@@ -313,6 +315,11 @@ function qcp1test(model::MOI.ModelLike, config::TestConfig)
313
315
314
316
@test MOI. canget (model, MOI. VariablePrimal (), MOI. VariableIndex)
315
317
@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
316
323
end
317
324
318
325
# try delete quadratic constraint and go back to linear
@@ -386,6 +393,9 @@ function qcp2test(model::MOI.ModelLike, config::TestConfig)
386
393
@test MOI. canget (model, MOI. VariablePrimal (), MOI. VariableIndex)
387
394
@test MOI. get (model, MOI. VariablePrimal (), x) ≈ sqrt (2 ) atol= atol rtol= rtol
388
395
396
+ @test MOI. canget (model, MOI. ConstraintPrimal (), typeof (c))
397
+ @test MOI. get (model, MOI. ConstraintPrimal (), c) ≈ 2 atol= atol rtol= rtol
398
+
389
399
# TODO - duals
390
400
# @test MOI.canget(model, MOI.ConstraintDual(), typeof(c))
391
401
# @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)
446
456
@test MOI. canget (model, MOI. VariablePrimal (), MOI. VariableIndex)
447
457
@test MOI. get (model, MOI. VariablePrimal (), x) ≈ sqrt (2 ) atol= atol rtol= rtol
448
458
459
+ @test MOI. canget (model, MOI. ConstraintPrimal (), typeof (c))
460
+ @test MOI. get (model, MOI. ConstraintPrimal (), c) ≈ 2 atol= atol rtol= rtol
461
+
449
462
# TODO - duals
450
463
# @test MOI.canget(model, MOI.ConstraintDual(), typeof(c))
451
464
# @test MOI.get(model, MOI.ConstraintDual(), c) ≈ -0.5/sqrt(2) atol=atol rtol=rtol
0 commit comments