Skip to content

Commit 8da1a5b

Browse files
authored
Merge pull request #66 from JuliaOpt/bl/moi0.3
Updates for MOI v0.3
2 parents 993453d + 15fd6c2 commit 8da1a5b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
julia 0.6
22
BinDeps
33
MathProgBase 0.5 0.8
4-
MathOptInterface 0.2 0.3
4+
MathOptInterface 0.3 0.4
55
@osx Homebrew
66
Compat 0.63

src/MOIWrapper.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ end
127127
# Build constraint matrix
128128
scalecoef(rows, coef, minus, s) = minus ? -coef : coef
129129
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)
131135
constrrows(::MOI.AbstractScalarSet) = 1
132136
constrrows(s::MOI.AbstractVectorSet) = 1:MOI.dimension(s)
133137
constrrows(instance::ECOSOptimizer, ci::CI{<:MOI.AbstractScalarFunction, <:MOI.AbstractScalarSet}) = 1
@@ -139,7 +143,7 @@ matrix(instance::ECOSOptimizer, s) = matrix(instance.data, s)
139143
MOIU.canloadconstraint(::ECOSOptimizer, ::Type{<:SF}, ::Type{<:SS}) = true
140144
MOIU.loadconstraint!(instance::ECOSOptimizer, ci, f::MOI.SingleVariable, s) = MOIU.loadconstraint!(instance, ci, MOI.ScalarAffineFunction{Float64}(f), s)
141145
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))
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)
173177
end
174178
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))
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
224228
function MOIU.load!(::ECOSOptimizer, ::MOI.ObjectiveSense, ::MOI.OptimizationSense) end
225229
MOIU.canload(::ECOSOptimizer, ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}) = true
226230
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))
228232
instance.data.objconstant = f.constant
229233
instance.data.c = instance.maxsense ? -c0 : c0
230234
end

0 commit comments

Comments
 (0)