127127# Build constraint matrix
128128scalecoef (rows, coef, minus, s) = minus ? - coef : coef
129129scalecoef (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)
131135constrrows (:: MOI.AbstractScalarSet ) = 1
132136constrrows (s:: MOI.AbstractVectorSet ) = 1 : MOI. dimension (s)
133137constrrows (instance:: ECOSOptimizer , ci:: CI{<:MOI.AbstractScalarFunction, <:MOI.AbstractScalarSet} ) = 1
@@ -139,7 +143,7 @@ matrix(instance::ECOSOptimizer, s) = matrix(instance.data, s)
139143MOIU. canloadconstraint (:: ECOSOptimizer , :: Type{<:SF} , :: Type{<:SS} ) = true
140144MOIU. loadconstraint! (instance:: ECOSOptimizer , ci, f:: MOI.SingleVariable , s) = MOIU. loadconstraint! (instance, ci, MOI. ScalarAffineFunction {Float64} (f), s)
141145function 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) )
143147 # sparsevec combines duplicates with + but does not remove zeros created so we call dropzeros!
144148 dropzeros! (a)
145149 offset = constroffset (instance, ci)
@@ -172,7 +176,7 @@ function orderidx(idx, s::MOI.ExponentialCone)
172176 expmap .(idx)
173177end
174178function 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) )
176180 # sparse combines duplicates with + but does not remove zeros created so we call dropzeros!
177181 dropzeros! (A)
178182 I, J, V = findnz (A)
@@ -187,7 +191,7 @@ function MOIU.loadconstraint!(instance::ECOSOptimizer, ci, f::MOI.VectorAffineFu
187191 # The ECOS format is b - Ax ∈ cone
188192 # so minus=false for b and minus=true for A
189193 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)
191195 append! (Is, offset + orderidx (I, s))
192196 append! (Js, J)
193197 append! (Vs, scalecoef (I, V, true , s))
@@ -224,7 +228,7 @@ MOIU.canload(::ECOSOptimizer, ::MOI.ObjectiveSense) = true
224228function MOIU. load! (:: ECOSOptimizer , :: MOI.ObjectiveSense , :: MOI.OptimizationSense ) end
225229MOIU. canload (:: ECOSOptimizer , :: MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}} ) = true
226230function 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))
228232 instance. data. objconstant = f. constant
229233 instance. data. c = instance. maxsense ? - c0 : c0
230234end
0 commit comments