Skip to content

Commit 21e8c35

Browse files
authored
Add support to MOI 0.10 (#28)
* add support to MOI 0.10 * handle properly names in tests
1 parent 4652d04 commit 21e8c35

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1010
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1111

1212
[compat]
13-
MathOptInterface = "0.9"
13+
MathOptInterface = "0.10"
1414
julia = "1"
1515

1616
[extras]

src/conic_form.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ end
9494
function MOI.set(model::GeometricConicForm, ::MOI.ObjectiveSense, sense::MOI.OptimizationSense)
9595
model.sense = sense
9696
end
97-
variable_index_value(t::MOI.ScalarAffineTerm) = t.variable_index.value
97+
variable_index_value(t::MOI.ScalarAffineTerm) = t.variable.value
9898
variable_index_value(t::MOI.VectorAffineTerm) = variable_index_value(t.scalar_term)
9999
function MOI.set(model::GeometricConicForm{T}, ::MOI.ObjectiveFunction,
100100
f::MOI.ScalarAffineFunction{T}) where {T}
@@ -141,14 +141,14 @@ function _load_constraints(model::GeometricConicForm, src, indexmap, cone_offset
141141
end
142142
end
143143

144-
function MOI.copy_to(dest::GeometricConicForm{T}, src::MOI.ModelLike; copy_names::Bool=true) where T
144+
function MOI.copy_to(dest::GeometricConicForm{T}, src::MOI.ModelLike) where T
145145
MOI.empty!(dest)
146146

147147
vis_src = MOI.get(src, MOI.ListOfVariableIndices())
148148
idxmap = MOIU.IndexMap()
149149

150150
has_constraints = BitSet()
151-
for (F, S) in MOI.get(src, MOI.ListOfConstraints())
151+
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent())
152152
i = get(dest.cone_types_dict, S, nothing)
153153
if i === nothing || F != MOI.VectorAffineFunction{T}
154154
throw(MOI.UnsupportedConstraint{F, S}())
@@ -167,10 +167,10 @@ function MOI.copy_to(dest::GeometricConicForm{T}, src::MOI.ModelLike; copy_names
167167
_load_variables(dest, length(vis_src))
168168

169169
# Set variable attributes
170-
MOIU.pass_attributes(dest, src, copy_names, idxmap, vis_src)
170+
MOIU.pass_attributes(dest, src, idxmap, vis_src)
171171

172172
# Set model attributes
173-
MOIU.pass_attributes(dest, src, copy_names, idxmap)
173+
MOIU.pass_attributes(dest, src, idxmap)
174174

175175
# Load constraints
176176
offset = 0

src/matrix_input.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct LPStandardForm{T, AT<:AbstractMatrix{T}, VT <: AbstractVector{T}} <: Abst
6464
b::VT
6565
end
6666

67-
function MOI.get(::LPStandardForm{T}, ::MOI.ListOfConstraints) where T
67+
function MOI.get(::LPStandardForm{T}, ::MOI.ListOfConstraintTypesPresent) where T
6868
return [(MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}),
6969
(MOI.VectorOfVariables, MOI.Nonnegatives)]
7070
end
@@ -117,7 +117,7 @@ struct LPGeometricForm{T, AT<:AbstractMatrix{T}, VT <: AbstractVector{T}} <: Abs
117117
b::VT
118118
end
119119

120-
function MOI.get(::LPGeometricForm{T}, ::MOI.ListOfConstraints) where T
120+
function MOI.get(::LPGeometricForm{T}, ::MOI.ListOfConstraintTypesPresent) where T
121121
return [(MOI.ScalarAffineFunction{T}, MOI.LessThan{T})]
122122
end
123123
const LT{T} = MOI.ConstraintIndex{MOI.ScalarAffineFunction{T}, MOI.LessThan{T}}
@@ -139,10 +139,10 @@ end
139139

140140
abstract type LPMixedForm{T} <: AbstractLPForm{T} end
141141

142-
function MOI.get(model::LPMixedForm{T}, ::MOI.ListOfConstraints) where T
142+
function MOI.get(model::LPMixedForm{T}, ::MOI.ListOfConstraintTypesPresent) where T
143143
list = Tuple{DataType, DataType}[]
144144
for S in [MOI.EqualTo{T}, MOI.Interval{T}, MOI.GreaterThan{T}, MOI.LessThan{T}]
145-
for F in [MOI.SingleVariable, MOI.ScalarAffineFunction{T}]
145+
for F in [MOI.VariableIndex, MOI.ScalarAffineFunction{T}]
146146
if !iszero(MOI.get(model, MOI.NumberOfConstraints{F, S}()))
147147
push!(list, (F, S))
148148
end
@@ -176,14 +176,14 @@ function MOI.get(model::LPMixedForm{T}, ::MOI.ListOfConstraintIndices{MOI.Scalar
176176
))
177177
end
178178

179-
const VBOUND{S} = MOI.ConstraintIndex{MOI.SingleVariable, S}
180-
function MOI.get(model::LPMixedForm{T}, ::MOI.NumberOfConstraints{MOI.SingleVariable, S}) where {T, S <: LinearBounds{T}}
179+
const VBOUND{S} = MOI.ConstraintIndex{MOI.VariableIndex, S}
180+
function MOI.get(model::LPMixedForm{T}, ::MOI.NumberOfConstraints{MOI.VariableIndex, S}) where {T, S <: LinearBounds{T}}
181181
s = _sense(S)
182182
return count(MOI.get(model, MOI.ListOfVariableIndices())) do vi
183183
MOI.get(model, BoundSense(), vi) == s
184184
end
185185
end
186-
function MOI.get(model::LPMixedForm{T}, ::MOI.ListOfConstraintIndices{MOI.SingleVariable, S}) where {T, S <: LinearBounds{T}}
186+
function MOI.get(model::LPMixedForm{T}, ::MOI.ListOfConstraintIndices{MOI.VariableIndex, S}) where {T, S <: LinearBounds{T}}
187187
s = _sense(S)
188188
return collect(MOIU.LazyMap{VBOUND{S}}(
189189
Base.Iterators.Filter(MOI.get(model, MOI.ListOfVariableIndices())) do vi
@@ -194,7 +194,7 @@ function MOI.get(model::LPMixedForm{T}, ::MOI.ListOfConstraintIndices{MOI.Single
194194
end)
195195
end
196196
function MOI.get(::LPMixedForm, ::MOI.ConstraintFunction, ci::VBOUND)
197-
return MOI.SingleVariable(MOI.VariableIndex(ci.value))
197+
return MOI.VariableIndex(ci.value)
198198
end
199199
function MOI.get(model::LPMixedForm, ::MOI.ConstraintSet, ci::VBOUND)
200200
return _bound_set(model.v_lb[ci.value], model.v_ub[ci.value])

src/sparse_matrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ function final_touch(A::SparseMatrixCSRtoCSC)
3939
end
4040
function _allocate_terms(colptr, indexmap, terms)
4141
for term in terms
42-
colptr[indexmap[term.scalar_term.variable_index].value + 1] += 1
42+
colptr[indexmap[term.scalar_term.variable].value + 1] += 1
4343
end
4444
end
4545
function allocate_terms(A::SparseMatrixCSRtoCSC, indexmap, func)
4646
_allocate_terms(A.colptr, indexmap, func.terms)
4747
end
4848
function _load_terms(colptr, rowval, nzval, indexmap, terms, offset)
4949
for term in terms
50-
ptr = colptr[indexmap[term.scalar_term.variable_index].value] += 1
50+
ptr = colptr[indexmap[term.scalar_term.variable].value] += 1
5151
rowval[ptr] = offset + term.output_index
5252
nzval[ptr] = -term.scalar_term.coefficient
5353
end

test/runtests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const MatOI = MatrixOptInterface
66
const MOI = MatOI.MOI
77
const MOIU = MatOI.MOIU
88
const MOIB = MOI.Bridges
9+
const MOIT = MOI.Test
910

1011

1112
const ATOL = 1e-4
@@ -45,11 +46,10 @@ const dense_A = [1.0 2.0
4546
v_ub = [Inf, Inf]
4647

4748
function test_expected(form)
48-
MOI.copy_to(MOI.Bridges.Constraint.Scalarize{Float64}(model), form, copy_names = false)
49+
MOI.copy_to(MOI.Bridges.Constraint.Scalarize{Float64}(model), form)
4950
MOI.set(model, MOI.VariableName(), MOI.VariableIndex.(1:2), var_names)
5051
MOI.set(model, MOI.ConstraintName(), MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}}.(1:2), con_names)
51-
MOI.set(model, MOI.ConstraintName(), MOI.ConstraintIndex{MOI.SingleVariable, MOI.GreaterThan{Float64}}.(1:2), vcon_names)
52-
MOIU.test_models_equal(model, expected, var_names, [con_names; vcon_names])
52+
MOIT.util_test_models_equal(model, expected, var_names, con_names)
5353
end
5454

5555
@testset "change $(typeof(lp))" for lp in [
@@ -92,10 +92,10 @@ const dense_A = [1.0 2.0
9292
v_ub = [Inf, Inf]
9393

9494
function test_expected(form)
95-
MOI.copy_to(model, form, copy_names = false)
95+
MOI.copy_to(model, form)
9696
MOI.set(model, MOI.VariableName(), MOI.VariableIndex.(1:2), var_names)
9797
MOI.set(model, MOI.ConstraintName(), MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}}.(1:2), con_names)
98-
MOIU.test_models_equal(model, expected, var_names, con_names)
98+
MOIT.util_test_models_equal(model, expected, var_names, con_names)
9999
end
100100

101101
@testset "change $(typeof(lp))" for lp in [

0 commit comments

Comments
 (0)