Skip to content

Commit 010f846

Browse files
authored
[Bridges] refactor SDPAModel to separate file (#2364)
1 parent b057d7e commit 010f846

File tree

2 files changed

+108
-100
lines changed

2 files changed

+108
-100
lines changed

test/Bridges/lazy_bridge_optimizer.jl

+1-100
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function runtests()
2222
end
2323

2424
include("utilities.jl")
25+
include("sdpa_models.jl")
2526

2627
function test_add_remove_has_bridges()
2728
T = Int
@@ -309,106 +310,6 @@ function test_MOI_runtests_LPModel()
309310
return
310311
end
311312

312-
# Model similar to SDPA format, it gives a good example because it does not
313-
# support a lot hence need a lot of bridges
314-
MOI.Utilities.@model(
315-
StandardSDPAModel,
316-
(),
317-
(MOI.EqualTo,),
318-
(MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle),
319-
(),
320-
(),
321-
(MOI.ScalarAffineFunction,),
322-
(MOI.VectorOfVariables,),
323-
()
324-
)
325-
326-
function MOI.supports_constraint(
327-
::StandardSDPAModel{T},
328-
::Type{MOI.VariableIndex},
329-
::Type{
330-
<:Union{
331-
MOI.GreaterThan{T},
332-
MOI.LessThan{T},
333-
MOI.EqualTo{T},
334-
MOI.Interval{T},
335-
MOI.ZeroOne,
336-
MOI.Integer,
337-
},
338-
},
339-
) where {T}
340-
return false
341-
end
342-
343-
function MOI.supports_constraint(
344-
::StandardSDPAModel{T},
345-
::Type{MOI.VectorOfVariables},
346-
::Type{MOI.Reals},
347-
) where {T}
348-
return false
349-
end
350-
351-
function MOI.supports_add_constrained_variables(
352-
::StandardSDPAModel,
353-
::Type{<:Union{MOI.Nonnegatives,MOI.PositiveSemidefiniteConeTriangle}},
354-
)
355-
return true
356-
end
357-
358-
function MOI.supports_add_constrained_variables(
359-
::StandardSDPAModel,
360-
::Type{MOI.Reals},
361-
)
362-
return false
363-
end
364-
365-
function MOI.supports(
366-
::StandardSDPAModel{T},
367-
::MOI.ObjectiveFunction{
368-
<:Union{MOI.VariableIndex,MOI.ScalarQuadraticFunction{T}},
369-
},
370-
) where {T}
371-
return false
372-
end
373-
374-
MOI.Utilities.@model(
375-
GeometricSDPAModel,
376-
(),
377-
(),
378-
(MOI.Zeros, MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle),
379-
(),
380-
(),
381-
(),
382-
(),
383-
(MOI.VectorAffineFunction,)
384-
)
385-
386-
function MOI.supports_constraint(
387-
::GeometricSDPAModel{T},
388-
::Type{MOI.VariableIndex},
389-
::Type{
390-
<:Union{
391-
MOI.GreaterThan{T},
392-
MOI.LessThan{T},
393-
MOI.EqualTo{T},
394-
MOI.Interval{T},
395-
MOI.ZeroOne,
396-
MOI.Integer,
397-
},
398-
},
399-
) where {T}
400-
return false
401-
end
402-
403-
function MOI.supports(
404-
::GeometricSDPAModel{T},
405-
::MOI.ObjectiveFunction{
406-
<:Union{MOI.VariableIndex,MOI.ScalarQuadraticFunction{T}},
407-
},
408-
) where {T}
409-
return false
410-
end
411-
412313
function test_MOI_runtests_StandardSDPAModel()
413314
model = StandardSDPAModel{Float64}()
414315
bridged = MOI.Bridges.full_bridge_optimizer(model, Float64)

test/Bridges/sdpa_models.jl

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Copyright (c) 2017: Miles Lubin and contributors
2+
# Copyright (c) 2017: Google Inc.
3+
#
4+
# Use of this source code is governed by an MIT-style license that can be found
5+
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
6+
7+
# This file implements models similar to the SDPA format. It gives a good
8+
# example because it does not support a lot of functions, hence the need for
9+
# a lot of bridges.
10+
11+
MOI.Utilities.@model(
12+
StandardSDPAModel,
13+
(),
14+
(MOI.EqualTo,),
15+
(MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle),
16+
(),
17+
(),
18+
(MOI.ScalarAffineFunction,),
19+
(MOI.VectorOfVariables,),
20+
()
21+
)
22+
23+
function MOI.supports_constraint(
24+
::StandardSDPAModel{T},
25+
::Type{MOI.VariableIndex},
26+
::Type{
27+
<:Union{
28+
MOI.GreaterThan{T},
29+
MOI.LessThan{T},
30+
MOI.EqualTo{T},
31+
MOI.Interval{T},
32+
MOI.ZeroOne,
33+
MOI.Integer,
34+
},
35+
},
36+
) where {T}
37+
return false
38+
end
39+
40+
function MOI.supports_constraint(
41+
::StandardSDPAModel{T},
42+
::Type{MOI.VectorOfVariables},
43+
::Type{MOI.Reals},
44+
) where {T}
45+
return false
46+
end
47+
48+
function MOI.supports_add_constrained_variables(
49+
::StandardSDPAModel,
50+
::Type{<:Union{MOI.Nonnegatives,MOI.PositiveSemidefiniteConeTriangle}},
51+
)
52+
return true
53+
end
54+
55+
function MOI.supports_add_constrained_variables(
56+
::StandardSDPAModel,
57+
::Type{MOI.Reals},
58+
)
59+
return false
60+
end
61+
62+
function MOI.supports(
63+
::StandardSDPAModel{T},
64+
::MOI.ObjectiveFunction{
65+
<:Union{MOI.VariableIndex,MOI.ScalarQuadraticFunction{T}},
66+
},
67+
) where {T}
68+
return false
69+
end
70+
71+
MOI.Utilities.@model(
72+
GeometricSDPAModel,
73+
(),
74+
(),
75+
(MOI.Zeros, MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle),
76+
(),
77+
(),
78+
(),
79+
(),
80+
(MOI.VectorAffineFunction,)
81+
)
82+
83+
function MOI.supports_constraint(
84+
::GeometricSDPAModel{T},
85+
::Type{MOI.VariableIndex},
86+
::Type{
87+
<:Union{
88+
MOI.GreaterThan{T},
89+
MOI.LessThan{T},
90+
MOI.EqualTo{T},
91+
MOI.Interval{T},
92+
MOI.ZeroOne,
93+
MOI.Integer,
94+
},
95+
},
96+
) where {T}
97+
return false
98+
end
99+
100+
function MOI.supports(
101+
::GeometricSDPAModel{T},
102+
::MOI.ObjectiveFunction{
103+
<:Union{MOI.VariableIndex,MOI.ScalarQuadraticFunction{T}},
104+
},
105+
) where {T}
106+
return false
107+
end

0 commit comments

Comments
 (0)