127
127
# Build constraint matrix
128
128
scalecoef (rows, coef, minus, s) = minus ? - coef : coef
129
129
scalecoef (rows, coef, minus, s:: Union{MOI.LessThan, Type{<:MOI.LessThan}, MOI.Nonpositives, Type{MOI.Nonpositives}} ) = minus ? coef : - coef
130
- _varmap (f) = map (vi -> vi. value, f. variables)
130
+ output_index (t:: MOI.VectorAffineTerm ) = t. output_index
131
+ variable_index_value (t:: MOI.ScalarAffineTerm ) = t. variable_index. value
132
+ variable_index_value (t:: MOI.VectorAffineTerm ) = variable_index_value (t. scalar_term)
133
+ coefficient (t:: MOI.ScalarAffineTerm ) = t. coefficient
134
+ coefficient (t:: MOI.VectorAffineTerm ) = coefficient (t. scalar_term)
131
135
constrrows (:: MOI.AbstractScalarSet ) = 1
132
136
constrrows (s:: MOI.AbstractVectorSet ) = 1 : MOI. dimension (s)
133
137
constrrows (instance:: ECOSOptimizer , ci:: CI{<:MOI.AbstractScalarFunction, <:MOI.AbstractScalarSet} ) = 1
@@ -139,7 +143,7 @@ matrix(instance::ECOSOptimizer, s) = matrix(instance.data, s)
139
143
MOIU. canloadconstraint (:: ECOSOptimizer , :: Type{<:SF} , :: Type{<:SS} ) = true
140
144
MOIU. loadconstraint! (instance:: ECOSOptimizer , ci, f:: MOI.SingleVariable , s) = MOIU. loadconstraint! (instance, ci, MOI. ScalarAffineFunction {Float64} (f), s)
141
145
function MOIU. loadconstraint! (instance:: ECOSOptimizer , ci, f:: MOI.ScalarAffineFunction , s:: MOI.AbstractScalarSet )
142
- a = sparsevec (_varmap (f ), f . coefficients )
146
+ a = sparsevec (variable_index_value .(f . terms ), coefficient .(f . terms) )
143
147
# sparsevec combines duplicates with + but does not remove zeros created so we call dropzeros!
144
148
dropzeros! (a)
145
149
offset = constroffset (instance, ci)
@@ -172,7 +176,7 @@ function orderidx(idx, s::MOI.ExponentialCone)
172
176
expmap .(idx)
173
177
end
174
178
function MOIU. loadconstraint! (instance:: ECOSOptimizer , ci, f:: MOI.VectorAffineFunction , s:: MOI.AbstractVectorSet )
175
- A = sparse (f . outputindex, _varmap (f ), f . coefficients )
179
+ A = sparse (output_index .(f . terms), variable_index_value .(f . terms ), coefficient .(f . terms) )
176
180
# sparse combines duplicates with + but does not remove zeros created so we call dropzeros!
177
181
dropzeros! (A)
178
182
I, J, V = findnz (A)
@@ -187,7 +191,7 @@ function MOIU.loadconstraint!(instance::ECOSOptimizer, ci, f::MOI.VectorAffineFu
187
191
# The ECOS format is b - Ax ∈ cone
188
192
# so minus=false for b and minus=true for A
189
193
b, Is, Js, Vs = matrix (instance, s)
190
- b[i] = scalecoef (rows, orderval (f. constant , s), false , s)
194
+ b[i] = scalecoef (rows, orderval (f. constants , s), false , s)
191
195
append! (Is, offset + orderidx (I, s))
192
196
append! (Js, J)
193
197
append! (Vs, scalecoef (I, V, true , s))
@@ -224,7 +228,7 @@ MOIU.canload(::ECOSOptimizer, ::MOI.ObjectiveSense) = true
224
228
function MOIU. load! (:: ECOSOptimizer , :: MOI.ObjectiveSense , :: MOI.OptimizationSense ) end
225
229
MOIU. canload (:: ECOSOptimizer , :: MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}} ) = true
226
230
function MOIU. load! (instance:: ECOSOptimizer , :: MOI.ObjectiveFunction , f:: MOI.ScalarAffineFunction )
227
- c0 = full (sparsevec (_varmap (f ), f . coefficients , instance. data. n))
231
+ c0 = Vector (sparsevec (variable_index_value .(f . terms ), coefficient .(f . terms) , instance. data. n))
228
232
instance. data. objconstant = f. constant
229
233
instance. data. c = instance. maxsense ? - c0 : c0
230
234
end
0 commit comments