Skip to content

Commit 9cb4c7d

Browse files
Adds delete_variables_in_a_batch in the modification tests. MOI.delete taking a vector may be specialized to be 'smarter' (i.e., not O(n^2) in some situations as it is now) but this 'smarter' code needs extra tests.
1 parent b123627 commit 9cb4c7d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/Test/UnitTests/modifications.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,38 @@ function delete_variable_with_single_variable_obj(model::MOI.ModelLike,
353353
end
354354
modificationtests["delete_variable_with_single_variable_obj"] = delete_variable_with_single_variable_obj
355355

356+
357+
"""
358+
delete_variables_in_a_batch(model::MOI.ModelLike, config::TestConfig)
359+
360+
Test deleting many variables in a batch (i.e. using the delete method which
361+
takes a vector of variable references). If `config.solve=true` confirm that it
362+
solves correctly.
363+
"""
364+
function delete_variables_in_a_batch(model::MOI.ModelLike,
365+
config::TestConfig)
366+
MOI.empty!(model)
367+
@test MOI.is_empty(model)
368+
MOIU.loadfromstring!(model,"""
369+
variables: x, y, z
370+
minobjective: 1.0 * x + 2.0 * y + 3.0 * z
371+
c1: x >= 1.0
372+
c2: y >= 1.0
373+
c3: z >= 1.0
374+
""")
375+
x, y, z = MOI.get(model, MOI.ListOfVariableIndices())
376+
@test MOI.is_valid(model, x) == true
377+
@test MOI.is_valid(model, y) == true
378+
@test MOI.is_valid(model, z) == true
379+
MOI.optimize!(model)
380+
@test MOI.get(model, MOI.ObjectiveValue()) == 6.0
381+
MOI.delete(model, [x, z])
382+
@test MOI.is_valid(model, x) == false
383+
@test MOI.is_valid(model, y) == true
384+
@test MOI.is_valid(model, z) == false
385+
MOI.optimize!(model)
386+
@test MOI.get(model, MOI.ObjectiveValue()) == 2.0
387+
end
388+
modificationtests["delete_variables_in_a_batch"] = delete_variables_in_a_batch
389+
356390
@moitestset modification

0 commit comments

Comments
 (0)