@@ -19,6 +19,9 @@ mutable struct _CBFDataStructure
19
19
bcoord:: Vector{Tuple{Int,Float64}}
20
20
hcoord:: Vector{Tuple{Int,Int,Int,Int,Float64}}
21
21
dcoord:: Vector{Tuple{Int,Int,Int,Float64}}
22
+ variables_with_domain:: Set{MOI.VariableIndex}
23
+ variable_cones:: Vector{Tuple{Vector{MOI.VariableIndex},String}}
24
+
22
25
function _CBFDataStructure ()
23
26
return new (
24
27
0 ,
@@ -30,6 +33,8 @@ mutable struct _CBFDataStructure
30
33
Tuple{Int,Float64}[],
31
34
Tuple{Int,Int,Int,Int,Float64}[],
32
35
Tuple{Int,Int,Int,Float64}[],
36
+ Set {MOI.VariableIndex} (),
37
+ Tuple{Vector{MOI. VariableIndex},String}[],
33
38
)
34
39
end
35
40
end
@@ -125,6 +130,57 @@ function _add_cones(
125
130
return
126
131
end
127
132
133
+ function _add_cones (
134
+ data:: _CBFDataStructure ,
135
+ model:: Model ,
136
+ :: Type{F} ,
137
+ :: Type{S} ,
138
+ ) where {F<: MOI.VectorOfVariables ,S}
139
+ for ci in MOI. get (model, MOI. ListOfConstraintIndices {F,S} ())
140
+ f = MOI. get (model, MOI. ConstraintFunction (), ci)
141
+ is_variable_cone = true
142
+ for (i, xi) in enumerate (f. variables)
143
+ if xi in data. variables_with_domain
144
+ is_variable_cone = false
145
+ break
146
+ elseif xi. value != f. variables[1 ]. value + i - 1
147
+ is_variable_cone = false
148
+ break
149
+ end
150
+ push! (data. variables_with_domain, xi)
151
+ end
152
+ str = _cone_string (data, S)
153
+ if ! is_variable_cone
154
+ _add_function (data, f, S)
155
+ set = MOI. get (model, MOI. ConstraintSet (), ci)
156
+ push! (data. cones, (str, MOI. dimension (set)))
157
+ else
158
+ push! (data. variable_cones, (f. variables, str))
159
+ end
160
+ end
161
+ return
162
+ end
163
+
164
+ function _add_cones (
165
+ data:: _CBFDataStructure ,
166
+ model:: Model ,
167
+ :: Type{F} ,
168
+ :: Type{S} ,
169
+ ) where {
170
+ F<: MOI.VectorOfVariables ,
171
+ S<: Union{MOI.ExponentialCone,MOI.DualExponentialCone} ,
172
+ }
173
+ # The Exponential cone in MOI and CBF are reversed. Instead of dealing with
174
+ # this complexity, just write them out as `Ax + b in K` constraints.
175
+ # TODO (odow): we should support this at some point. See #2478
176
+ for ci in MOI. get (model, MOI. ListOfConstraintIndices {F,S} ())
177
+ f = MOI. get (model, MOI. ConstraintFunction (), ci)
178
+ _add_function (data, f, S)
179
+ push! (data. cones, (_cone_string (data, S), 3 ))
180
+ end
181
+ return
182
+ end
183
+
128
184
function _add_cones (
129
185
data:: _CBFDataStructure ,
130
186
model:: Model ,
@@ -252,11 +308,26 @@ function _write_POWCONES(io::IO, model::Model, S, keyword)
252
308
return
253
309
end
254
310
255
- function _write_VAR (io:: IO , model:: Model )
311
+ function _write_VAR (io:: IO , model:: Model , data )
256
312
num_var = MOI. get (model, MOI. NumberOfVariables ())
313
+ cones = Tuple{String,Int}[]
314
+ current_variable = 0
315
+ for (f, str) in sort! (data. variable_cones; by = x -> first (x[1 ]). value)
316
+ offset = first (f). value - current_variable - 1
317
+ if offset > 0
318
+ push! (cones, (" F" , offset))
319
+ end
320
+ push! (cones, (str, length (f)))
321
+ current_variable = last (f). value
322
+ end
323
+ if current_variable < num_var
324
+ push! (cones, (" F" , num_var - current_variable))
325
+ end
257
326
println (io, " VAR" )
258
- println (io, num_var, " 1" )
259
- println (io, " F " , num_var)
327
+ println (io, num_var, " " , length (cones))
328
+ for (K, n) in cones
329
+ println (io, K, " " , n)
330
+ end
260
331
println (io)
261
332
return
262
333
end
@@ -417,7 +488,7 @@ function Base.write(io::IO, model::Model)
417
488
# ##
418
489
_write_OBJSENSE (io, model)
419
490
# _write_PSDVAR
420
- _write_VAR (io, model)
491
+ _write_VAR (io, model, data )
421
492
_write_INT (io, model)
422
493
_write_PSDCON (io, data)
423
494
_write_CON (io, data)
0 commit comments