Skip to content

Commit f5c7440

Browse files
authored
Merge pull request #11 from JuliaOpt/bl/moi0.3
Updates for MOI v0.3
2 parents 83aa1dd + 158a46a commit f5c7440

4 files changed

Lines changed: 21 additions & 140 deletions

File tree

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
julia 0.6
2-
MathOptInterface
2+
MathOptInterface 0.3 0.4

src/constraint.jl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626

2727
nconstraints(f::Union{SVF, SAF}, s) = 1
2828
nconstraints(f::VVF, s) = length(f.variables)
29-
nconstraints(f::VAF, s) = length(f.constant)
29+
nconstraints(f::VAF, s) = MOIU.moilength(f)
3030

3131
MOIU.canallocateconstraint(::SOItoMOIBridge{T}, f::Type{<:Union{VF, AF{T}}}, ::Type{<:SupportedSets}) where T = true
3232
function _allocateconstraint!(m::SOItoMOIBridge, f, s)
@@ -55,35 +55,36 @@ function loadslacks!(m::SOItoMOIBridge, cs)
5555
end
5656
end
5757

58-
_row(f::SAF, i) = 1
59-
_row(f::VAF, i) = f.outputindex[i]
58+
output_index(::MOI.ScalarAffineTerm) = 1
59+
output_index(t::MOI.VectorAffineTerm) = t.output_index
60+
scalar_term(t::MOI.ScalarAffineTerm) = t
61+
scalar_term(t::MOI.VectorAffineTerm) = t.scalar_term
6062

6163
_getconstant(m::SOItoMOIBridge, s::MOI.AbstractScalarSet) = MOIU.getconstant(s)
6264
_getconstant(m::SOItoMOIBridge{T}, s::MOI.AbstractSet) where T = zero(T)
6365

6466
function loadcoefficients!(m::SOItoMOIBridge, cs::UnitRange, f::AF, s)
6567
f = MOIU.canonical(f) # sum terms with same variables and same outputindex
6668
if !isempty(cs)
67-
rhs = _getconstant(m, s) - f.constant
68-
for i in 1:length(f.variables)
69-
val = f.coefficients[i]
70-
if !iszero(val)
71-
row = _row(f, i)
72-
c = cs[row]
73-
for (blk, i, j, coef, shift) in varmap(m, f.variables[i])
69+
rhs = _getconstant(m, s) - MOIU._constant(f)
70+
for t in f.terms
71+
st = scalar_term(t)
72+
if !iszero(st.coefficient)
73+
c = cs[output_index(t)]
74+
for (blk, i, j, coef, shift) in varmap(m, st.variable_index)
7475
if !iszero(blk)
7576
@assert !iszero(coef)
76-
setconstraintcoefficient!(m.sdoptimizer, val*coef, c, blk, i, j)
77+
setconstraintcoefficient!(m.sdoptimizer, st.coefficient*coef, c, blk, i, j)
7778
end
7879
if isa(rhs, Vector)
79-
rhs[row] -= val * shift
80+
rhs[output_index(t)] -= st.coefficient * shift
8081
else
81-
rhs -= val * shift
82+
rhs -= st.coefficient * shift
8283
end
8384
end
8485
end
8586
end
86-
for j in 1:length(f.constant)
87+
for j in 1:MOIU.moilength(f)
8788
c = cs[j]
8889
setconstraintconstant!(m.sdoptimizer, rhs[j], c)
8990
end

src/load.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ MOIU.canload(m::SOItoMOIBridge{T}, ::MOI.ObjectiveFunction{MOI.ScalarAffineFunct
1515
function MOIU.load!(optimizer::SOItoMOIBridge, ::MOI.ObjectiveFunction, f::MOI.ScalarAffineFunction)
1616
obj = MOIU.canonical(f)
1717
optimizer.objconstant = f.constant
18-
for (vi, val) in zip(obj.variables, obj.coefficients)
19-
if !iszero(val)
20-
for (blk, i, j, coef, shift) in varmap(optimizer, vi)
18+
for t in obj.terms
19+
if !iszero(t.coefficient)
20+
for (blk, i, j, coef, shift) in varmap(optimizer, t.variable_index)
2121
if !iszero(blk)
2222
# in SDP format, it is max and in MPB Conic format it is min
23-
setobjectivecoefficient!(optimizer.sdoptimizer, optimizer.objsign * coef * val, blk, i, j)
23+
setobjectivecoefficient!(optimizer.sdoptimizer, optimizer.objsign * coef * t.coefficient, blk, i, j)
2424
end
25-
optimizer.objshift += val * shift
25+
optimizer.objshift += t.coefficient * shift
2626
end
2727
end
2828
end

src/setbridges.jl

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)