Skip to content

Commit e2318c7

Browse files
authored
remove ordering of CONES (#10)
1 parent eda206c commit e2318c7

File tree

2 files changed

+4
-69
lines changed

2 files changed

+4
-69
lines changed

src/conic_form.jl

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,15 @@ mutable struct ConicForm{T, AT, VT, C} <: MOI.ModelLike
2222
end
2323
end
2424

25-
# The ordering of CONES matches SCS
26-
const CONES = Dict(
27-
MOI.Zeros => 1,
28-
MOI.Nonnegatives => 2,
29-
MOI.SecondOrderCone => 3,
30-
MOI.PositiveSemidefiniteConeTriangle => 4,
31-
MOI.ExponentialCone => 5,
32-
MOI.DualExponentialCone => 6
33-
)
34-
3525
_set_type(::MOI.ConstraintIndex{F,S}) where {F,S} = S
3626
cons_offset(conic::MOI.Zeros) = conic.dimension
3727
cons_offset(conic::MOI.Nonnegatives) = conic.dimension
3828
cons_offset(conic::MOI.SecondOrderCone) = conic.dimension
3929
cons_offset(conic::MOI.PositiveSemidefiniteConeTriangle) = Int64((conic.side_dimension*(conic.side_dimension+1))/2)
4030

4131
function get_conic_form(::Type{T}, model::M, con_idx) where {T, M <: MOI.AbstractOptimizer}
42-
# reorder constraints
43-
cis = sort(
44-
con_idx,
45-
by = x->CONES[_set_type(x)]
46-
)
47-
4832
# extract cones
49-
cones = _set_type.(cis)
33+
cones = _set_type.(con_idx)
5034
cones = unique(cones)
5135

5236
conic = ConicForm{T, SparseMatrixCSRtoCSC{Int64}, Array{T, 1}}(Tuple(cones))

test/conic_form.jl

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,8 @@ CONIC_OPTIMIZERS = [SCS.Optimizer, ProxSDP.Optimizer, COSMO.Optimizer]
5757
MatModel = MatOI.get_conic_form(Float64, model, [cX; cx; c1; c2])
5858

5959
@test MatModel.c' [2. 2. 2. 0. 2. 2. 1. 0. 0.]
60-
@test MatModel.b' [-1. -0.5 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
61-
@test MatModel.A.nzval [-1.0, -1.0, -1.0, -2.0, -1.0, -1.0, -1.0, -1.0, -2.0, -1.0, -2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0] atol=ATOL rtol=RTOL
62-
# note below matrix is in SCS format (scaled)
63-
# @test A[1, 1] ≈ -1.0
64-
# @test A[2, 1] ≈ -1.0
65-
# @test A[6, 1] ≈ -1.0
66-
# @test A[2, 2] ≈ -2.0
67-
# @test A[7, 2] ≈ -1.41421 atol=ATOL rtol=RTOL
68-
# @test A[1, 3] ≈ -1.0
69-
# @test A[2, 3] ≈ -1.0
70-
# @test A[9, 3] ≈ -1.0
71-
# @test A[2, 4] ≈ -2.0
72-
# @test A[8, 4] ≈ -1.41421 atol=ATOL rtol=RTOL
73-
# @test A[2, 5] ≈ -2.0
74-
# @test A[10, 5] ≈ -1.41421 atol=ATOL rtol=RTOL
75-
# @test A[1, 6] ≈ -1.0
76-
# @test A[2, 6] ≈ -1.0
77-
# @test A[11, 6] ≈ -1.0
78-
# @test A[1, 7] ≈ -1.0
79-
# @test A[3, 7] ≈ -1.0
80-
# @test A[2, 8] ≈ -1.0
81-
# @test A[4, 8] ≈ -1.0
82-
# @test A[2, 9] ≈ -1.0
83-
# @test A[5, 9] ≈ -1.0
60+
@test MatModel.b' [0. 0. 0. 0. 0. 0. 0. 0. 0. -1. -0.5 ]
61+
@test MatModel.A.nzval [-1.0, -1.0, -1.0, -1.0, -2.0, -1.0, -1.0, -1.0, -1.0, -2.0, -1.0, -2.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0] atol=ATOL rtol=RTOL
8462
end
8563
end
8664

@@ -128,35 +106,8 @@ end
128106
MatModel = MatOI.get_conic_form(Float64, model, [c1; c2; c3; c4])
129107

130108
@test MatModel.c [-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -1.0]
131-
@test MatModel.b [0.0, 10.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, 0.0, 0.0, 0.0]
109+
@test MatModel.b [10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
132110
@test MatModel.A.nzval [1.0, -1.0, -0.45, 0.318198, -0.45, 1.0, -1.0, -0.8, 0.225, -0.1, 1.0, -1.0, -0.9, 1.0, -1.0, -0.225, 1.0, -1.0, -0.1125, 0.0795495, -0.1125, 1.0, -1.0, -0.225, 1.0, 1.0] atol=ATOL rtol=RTOL
133-
# note below matrix is in SCS format (scaled)
134-
# @test A[2 , 1] ≈ 1.0
135-
# @test A[3 , 1] ≈ -1.0
136-
# @test A[9 , 1] ≈ -0.45
137-
# @test A[10, 1] ≈ 0.45
138-
# @test A[11, 1] ≈ -0.45
139-
# @test A[2 , 2] ≈ 1.0
140-
# @test A[4 , 2] ≈ -1.0
141-
# @test A[9 , 2] ≈ -0.8
142-
# @test A[10, 2] ≈ 0.318198 atol=ATOL rtol=RTOL
143-
# @test A[11, 2] ≈ -0.1
144-
# @test A[2 , 3] ≈ 1.0
145-
# @test A[5 , 3] ≈ -1.0
146-
# @test A[9 , 3] ≈ -0.9
147-
# @test A[2 , 4] ≈ 1.0
148-
# @test A[6 , 4] ≈ -1.0
149-
# @test A[9 , 4] ≈ -0.225
150-
# @test A[2 , 5] ≈ 1.0
151-
# @test A[7 , 5] ≈ -1.0
152-
# @test A[9 , 5] ≈ -0.1125
153-
# @test A[10, 5] ≈ 0.1125
154-
# @test A[11, 5] ≈ -0.1125
155-
# @test A[2 , 6] ≈ 1.0
156-
# @test A[8 , 6] ≈ -1.0
157-
# @test A[11, 6] ≈ -0.225
158-
# @test A[9 , 7] ≈ 1.0
159-
# @test A[11, 7] ≈ 1.0
160111
end
161112
end
162113

0 commit comments

Comments
 (0)