Skip to content

Commit 21ab4af

Browse files
committed
Update
1 parent 10dbeb4 commit 21ab4af

3 files changed

Lines changed: 16 additions & 34 deletions

File tree

src/Utilities/matrix_of_constraints.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ MOI.is_empty(v::MatrixOfConstraints) = MOI.is_empty(v.sets)
306306
function _reset_caches!(v::MatrixOfConstraints{T}) where {T}
307307
v.caches =
308308
[Tuple{_affine_function_type(T, S),S}[] for S in set_types(v.sets)]
309-
return v.are_indices_mapped = [BitSet() for _ in eachindex(v.caches)]
309+
v.are_indices_mapped = [BitSet() for _ in eachindex(v.caches)]
310+
return
310311
end
311312

312313
function MOI.empty!(v::MatrixOfConstraints)

src/Utilities/sparse_matrix.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,22 @@ function Base.convert(
184184
end
185185

186186
_indexing(A::MutableSparseMatrixCSC) = A.indexing
187-
_indexing(::SparseArrays.SparseMatrixCSC) = OneBasedIndexing()
188187

189-
const _SparseMatrixCSC{Tv,Ti} =
190-
Union{MutableSparseMatrixCSC{Tv,Ti},SparseArrays.SparseMatrixCSC{Tv,Ti}}
188+
_indexing(::SparseArrays.SparseMatrixCSC) = OneBasedIndexing()
191189

192-
function _first_in_column(A::_SparseMatrixCSC, row::Integer, col::Integer)
190+
function _first_in_column(
191+
A::Union{MutableSparseMatrixCSC,SparseArrays.SparseMatrixCSC},
192+
row::Integer,
193+
col::Integer,
194+
)
193195
range = SparseArrays.nzrange(A, col)
194196
row = _shift(row, OneBasedIndexing(), _indexing(A))
195197
idx = searchsortedfirst(view(A.rowval, range), row)
196198
return get(range, idx, last(range) + 1)
197199
end
198200

199201
function extract_function(
200-
A::_SparseMatrixCSC{T},
202+
A::Union{MutableSparseMatrixCSC{T},SparseArrays.SparseMatrixCSC{T}},
201203
row::Integer,
202204
constant::T,
203205
) where {T}
@@ -219,7 +221,7 @@ function extract_function(
219221
end
220222

221223
function extract_function(
222-
A::_SparseMatrixCSC{T},
224+
A::Union{MutableSparseMatrixCSC{T},SparseArrays.SparseMatrixCSC{T}},
223225
rows::UnitRange,
224226
constants::Vector{T},
225227
) where {T}

test/Utilities/matrix_of_constraints.jl

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -738,51 +738,30 @@ end
738738
function test_lp_standard_form()
739739
s = """
740740
variables: x1, x2
741+
minobjective: 7x1 + 8x2
741742
cx1: x1 >= 0.0
742743
cx2: x2 >= 0.0
743744
c1: 1x1 == 5.0
744745
c2: 3x1 + 4x2 == 6.0
745-
minobjective: 7x1 + 8x2
746746
"""
747747
expected = MOI.Utilities.Model{Float64}()
748748
MOI.Utilities.loadfromstring!(expected, s)
749-
750749
var_names = ["x1", "x2"]
751750
con_names = ["c1", "c2"]
752-
753-
A = SparseArrays.sparse([
754-
1.0 0.0
755-
3.0 4.0
756-
])
751+
A = SparseArrays.sparse([1.0 0.0; 3.0 4.0])
757752
b = [5.0, 6.0]
758753
form = MOI.Utilities.GenericModel{Float16}(
759754
expected.objective,
760755
expected.variables,
761756
_equality_constraints(A, b),
762757
)
763-
764758
model = MOI.Utilities.Model{Float64}()
765759
MOI.copy_to(MOI.Bridges.Constraint.Scalarize{Float64}(model), form)
766-
MOI.set(
767-
model,
768-
MOI.VariableName(),
769-
MOI.VariableIndex.(eachindex(var_names)),
770-
var_names,
771-
)
772-
MOI.set(
773-
model,
774-
MOI.ConstraintName(),
775-
MOI.ConstraintIndex{
776-
MOI.ScalarAffineFunction{Float64},
777-
MOI.EqualTo{Float64},
778-
}.(
779-
eachindex(con_names),
780-
),
781-
con_names,
782-
)
783-
760+
MOI.set(model, MOI.VariableName(), MOI.VariableIndex.(1:2), var_names)
761+
F, S = MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}
762+
ci = MOI.ConstraintIndex{F,S}.(1:2)
763+
MOI.set(model, MOI.ConstraintName(), ci, con_names)
784764
MOI.Test.util_test_models_equal(model, expected, var_names, con_names)
785-
786765
return
787766
end
788767

0 commit comments

Comments
 (0)