Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

Commit a07b27c

Browse files
authored
Merge pull request #46 from JuliaOpt/bl/sdp2
Clean up sdp2
2 parents 57db7ea + d731cf4 commit a07b27c

File tree

1 file changed

+19
-46
lines changed

1 file changed

+19
-46
lines changed

src/contconic.jl

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,20 +1312,18 @@ function sdp2test(solver::Function, config::TestConfig)
13121312
x = MOI.addvariables!(instance, 7)
13131313
@test MOI.get(instance, MOI.NumberOfVariables()) == 7
13141314

1315-
c = [0.0,0.0,0.0,0.0,0.0,0.0,1.0]
1316-
b = [10.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
1317-
I = [1, 2, 8, 9, 10, 11, 1, 3, 8, 9, 10, 11, 1, 4, 8, 9, 10, 11, 1, 5, 8, 1, 6, 8, 9, 10, 11, 1, 7, 8, 9, 10, 11, 8, 10]
1318-
J = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7]
1319-
V = -[1.0,1.0,-0.45,0.45/sqrt(2),-0.45,0.0,1.0,1.0,-0.7681980515339464,0.225,-0.13180194846605373,0.0,1.0,1.0,-0.9,0.0,0.0,0.0,1.0,1.0,-0.225,1.0,1.0,-0.1125,0.1125/sqrt(2),-0.1125,0.0,1.0,1.0,0.0,0.0,-0.225,0.0,1.0,1.0]
1320-
1321-
A = sparse(I, J, V, length(b), length(c))
1322-
1323-
f = MOI.VectorAffineFunction(I, x[J], V, b)
1324-
1325-
c1 = MOI.addconstraint!(instance, MOIU.eachscalar(f)[1], MOI.GreaterThan(0.0))
1326-
c2 = MOI.addconstraint!(instance, MOIU.eachscalar(f)[2:7], MOI.Nonpositives(6))
1327-
c3 = MOI.addconstraint!(instance, MOIU.eachscalar(f)[8:10], MOI.PositiveSemidefiniteConeTriangle(2))
1328-
c4 = MOI.addconstraint!(instance, MOIU.eachscalar(f)[11], MOI.EqualTo(0.))
1315+
η = 10.0
1316+
c1 = MOI.addconstraint!(instance, MOI.ScalarAffineFunction(x[1:6], -ones(6), η), MOI.GreaterThan(0.0))
1317+
c2 = MOI.addconstraint!(instance, MOI.VectorAffineFunction(collect(1:6), x[1:6], -ones(6), zeros(6)), MOI.Nonpositives(6))
1318+
α = 0.8
1319+
δ = 0.9
1320+
c3 = MOI.addconstraint!(instance, MOI.VectorAffineFunction([fill(1, 7); fill(2, 5); fill(3, 6)],
1321+
[x[1:7]; x[1:3]; x[5:6]; x[1:3]; x[5:7]],
1322+
[ δ/2, α, δ, δ/4, δ/8, 0.0, -1.0,
1323+
-δ/(2*√2), -δ/4, 0, -δ/(8*√2), 0.0,
1324+
δ/2, δ-α, 0, δ/8, δ/4, -1.0],
1325+
zeros(3)), MOI.PositiveSemidefiniteConeTriangle(2))
1326+
c4 = MOI.addconstraint!(instance, MOI.ScalarAffineFunction([x[1:3]; x[5:6]], zeros(5), 0.0), MOI.EqualTo(0.))
13291327

13301328
@test MOI.get(instance, MOI.NumberOfConstraints{MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}}()) == 1
13311329
@test MOI.get(instance, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64}, MOI.Nonpositives}()) == 1
@@ -1348,50 +1346,25 @@ function sdp2test(solver::Function, config::TestConfig)
13481346
end
13491347

13501348
@test MOI.canget(instance, MOI.VariablePrimal(), MOI.VariableIndex)
1351-
xv = MOI.get(instance, MOI.VariablePrimal(), x)
1352-
@test all(xv[1:6] .> -atol)
1353-
1354-
con = A * xv + b
1349+
@test MOI.get(instance, MOI.VariablePrimal(), x) [2η/3, 0, η/3, 0, 0, 0, η*δ*(1 - 1/√3)/2] atol=atol rtol=rtol
13551350

13561351
@test MOI.canget(instance, MOI.ConstraintPrimal(), typeof(c1))
1357-
@test MOI.get(instance, MOI.ConstraintPrimal(), c1) con[1] atol=atol rtol=rtol
13581352
@test MOI.get(instance, MOI.ConstraintPrimal(), c1) 0.0 atol=atol rtol=rtol
13591353
@test MOI.canget(instance, MOI.ConstraintPrimal(), typeof(c2))
1360-
@test MOI.get(instance, MOI.ConstraintPrimal(), c2) con[2:7] atol=atol rtol=rtol
1361-
@test all(MOI.get(instance, MOI.ConstraintPrimal(), c2) .< atol)
1354+
@test MOI.get(instance, MOI.ConstraintPrimal(), c2) [-2η/3, 0, -η/3, 0, 0, 0] atol=atol rtol=rtol
13621355
@test MOI.canget(instance, MOI.ConstraintPrimal(), typeof(c3))
1363-
Xv = MOI.get(instance, MOI.ConstraintPrimal(), c3)
1364-
@test Xv con[8:10] atol=atol rtol=rtol
1365-
s2 = sqrt(2)
1366-
Xm = [Xv[1] Xv[2]/s2
1367-
Xv[2]/s2 Xv[3]]
1368-
@test eigmin(Xm) > -atol
1356+
@test MOI.get(instance, MOI.ConstraintPrimal(), c3) *δ*(1/√3+1/3)/2, -η*δ/(3*√2), η*δ*(1/√3-1/3)/2] atol=atol rtol=rtol
13691357
@test MOI.canget(instance, MOI.ConstraintPrimal(), typeof(c4))
1370-
@test MOI.get(instance, MOI.ConstraintPrimal(), c4) con[11] atol=atol rtol=rtol
13711358
@test MOI.get(instance, MOI.ConstraintPrimal(), c4) 0.0 atol=atol rtol=rtol
13721359

13731360
if config.duals
13741361
@test MOI.canget(instance, MOI.ConstraintDual(), typeof(c1))
1375-
y1 = MOI.get(instance, MOI.ConstraintDual(), c1)
1376-
@test y1 > -atol
1362+
@test MOI.get(instance, MOI.ConstraintDual(), c1) δ*(1-1/√3)/2 atol=atol rtol=rtol
13771363
@test MOI.canget(instance, MOI.ConstraintDual(), typeof(c2))
1378-
y2 = MOI.get(instance, MOI.ConstraintDual(), c2)
1379-
@test all(MOI.get(instance, MOI.ConstraintDual(), c2) .< atol)
1380-
1364+
@test MOI.get(instance, MOI.ConstraintDual(), c2) [0, -α/√3+δ/(2*√6)*(2*√2-1), 0, -3δ*(1-1/√3)/8, -3δ*(1-1/√3)/8, -δ*(3 - 2*√3 + 1/√3)/8] atol=atol rtol=rtol
13811365
@test MOI.canget(instance, MOI.ConstraintDual(), typeof(c3))
1382-
y3 = MOI.get(instance, MOI.ConstraintDual(), c3)
1383-
s2 = sqrt(2)
1384-
Ym = [y3[1] y3[2]/s2
1385-
y3[2]/s2 y3[3]]
1386-
@test eigmin(Ym) > -atol
1387-
1388-
@test MOI.canget(instance, MOI.ConstraintDual(), typeof(c4))
1389-
y4 = MOI.get(instance, MOI.ConstraintDual(), c4)
1390-
1391-
y = [y1; y2; y3; y4]
1392-
@test dot(c, xv) dot(b, y) atol=atol rtol=rtol
1393-
A[9,:] *= 2 # See duality note for PositiveSemidefiniteConeTriangle, 9 correspond to a off-diagonal entry
1394-
@test A' * y -c atol=atol rtol=rtol
1366+
@test MOI.get(instance, MOI.ConstraintDual(), c3) [(1-1/√3)/2, 1/√6, (1+1/√3)/2] atol=atol rtol=rtol
1367+
# Dual of c4 could be anything
13951368
end
13961369
end
13971370
end

0 commit comments

Comments
 (0)