Skip to content

Commit 733e6d7

Browse files
committed
Update
1 parent 0d645cd commit 733e6d7

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

src/Utilities/Utilities.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import LinearAlgebra
1010
import MathOptInterface as MOI
1111
import MutableArithmetics as MA
1212
import OrderedCollections: OrderedDict
13+
import SparseArrays
14+
import Unicode
1315

1416
function print_with_acronym(io::IO, s::AbstractString)
1517
return print(io, replace_acronym(s))

src/Utilities/sparse_matrix.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# Use of this source code is governed by an MIT-style license that can be found
55
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
66

7-
import SparseArrays
8-
97
"""
108
abstract type AbstractIndexing end
119

src/Utilities/struct_of_constraints.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,6 @@ end
213213

214214
_typed(s::SymbolFS) = s.typed ? Expr(:curly, esc(s.s), esc(:T)) : esc(s.s)
215215

216-
# Base.lowercase is moved to Unicode.lowercase in Julia v0.7
217-
import Unicode
218-
219216
function _field(s::SymbolFS)
220217
return Symbol(replace(Unicode.lowercase(string(s.s)), "." => "_"))
221218
end

src/Utilities/variables_container.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ end
117117
# inference.
118118
function _throw_if_lower_bound_set_inner(variable, S2, mask, T)
119119
S1 = _flag_to_set_type(mask, T)
120-
throw(MOI.LowerBoundAlreadySet{S1,S2}(variable))
121-
return
120+
return throw(MOI.LowerBoundAlreadySet{S1,S2}(variable))
122121
end
123122

124123
function _throw_if_lower_bound_set(variable, S2, mask, T)
@@ -135,8 +134,7 @@ end
135134
# inference.
136135
function _throw_if_upper_bound_set_inner(variable, S2, mask, T)
137136
S1 = _flag_to_set_type(mask, T)
138-
throw(MOI.UpperBoundAlreadySet{S1,S2}(variable))
139-
return
137+
return throw(MOI.UpperBoundAlreadySet{S1,S2}(variable))
140138
end
141139

142140
function _throw_if_upper_bound_set(variable, S2, mask, T)

test/Utilities/sparse_matrix.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ function test_extract_function()
122122
empty_f = MOI.Utilities.extract_function(A, 1:0, Float64[])
123123
@test empty_f
124124
MOI.VectorAffineFunction(MOI.VectorAffineTerm{Float64}[], Float64[])
125+
r10 = MOI.Utilities.extract_function(A, 10, 0.5)
126+
@test r10 MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{Float64}[], 0.5)
127+
f1 = 0.6 + 1.0 * x[1] + 1.0 * x[2] + 1.0 * x[3]
128+
r10 = MOI.Utilities.extract_function(A, 0:1, c)
129+
@test r10 MOI.Utilities.vectorize([0.5, f1])
125130
return
126131
end
127132

test/Utilities/variable_container.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ function test_delete_constraint_LessThan()
9898
@test MOI.is_valid(a, c)
9999
MOI.delete(a, c)
100100
@test !MOI.is_valid(a, c)
101+
ci = MOI.ConstraintIndex{MOI.VectorOfVariables,MOI.Zeros}(1)
102+
@test !MOI.is_valid(a, ci)
101103
return
102104
end
103105

@@ -314,6 +316,37 @@ function test_ListOfConstraintTypesPresent_2()
314316
return
315317
end
316318

319+
function test_LowerBoundAlreadySet()
320+
for set in (
321+
MOI.EqualTo(1),
322+
MOI.GreaterThan(1),
323+
MOI.Interval(1),
324+
MOI.Parameter(1),
325+
MOI.Semicontinuous(1, 3),
326+
MOI.Semiinteger(1, 3),
327+
)
328+
model = MOI.Utilities.VariablesContainer{Int}()
329+
x = MOI.add_variable(model)
330+
c = MOI.add_constraint(model, x, set)
331+
@test_throws(
332+
MOI.LowerBoundAlreadySet,
333+
MOI.add_constraint(model, x, MOI.EqualTo(2)),
334+
)
335+
end
336+
return
337+
end
338+
339+
function test_UnsupportedConstraint()
340+
model = MOI.Utilities.VariablesContainer{Int}()
341+
x = [MOI.add_variable(model) for _ in 1:3]
342+
f = MOI.VectorOfVariables(x)
343+
@test_throws(
344+
MOI.UnsupportedConstraint{MOI.VectorOfVariables,MOI.ExponentialCone},
345+
MOI.add_constraint(model, f, MOI.ExponentialCone()),
346+
)
347+
return
348+
end
349+
317350
end # module
318351

319352
TestVariableContainer.runtests()

0 commit comments

Comments
 (0)