Skip to content

Commit a0f221e

Browse files
authored
[Bridges] add tests for deleting variable in bridged objective (#2156)
1 parent c4648ee commit a0f221e

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

test/Bridges/Constraint/quad_to_soc.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,53 @@ function test_copy_to_start()
278278
@test MOI.get(dest, MOI.VariablePrimalStart(), index_map[x]) == -1.0
279279
end
280280

281+
function test_deletion_of_variable_in_bridged_constraint()
282+
inner = MOI.Utilities.Model{Float64}()
283+
model = MOI.Bridges.Constraint.QuadtoSOC{Float64}(inner)
284+
x = MOI.add_variables(model, 2)
285+
MOI.set(model, MOI.VariableName(), x, ["x", "y"])
286+
f = 1.0 * x[1] * x[1] + 1.0 * x[2] * x[2]
287+
c = MOI.add_constraint(model, f, MOI.LessThan(1.0))
288+
MOI.delete(model, x[1])
289+
@test MOI.get(model, MOI.ConstraintFunction(), c) 1.0 * x[2] * x[2]
290+
return
291+
end
292+
293+
MOI.Utilities.@model(
294+
Model2153,
295+
(),
296+
(MOI.EqualTo,),
297+
(MOI.RotatedSecondOrderCone,),
298+
(),
299+
(),
300+
(MOI.ScalarAffineFunction,),
301+
(MOI.VectorOfVariables,),
302+
(),
303+
)
304+
305+
function MOI.supports(
306+
::Model2153{T},
307+
::MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{T}},
308+
) where {T}
309+
return false
310+
end
311+
312+
function test_deletion_of_variable_in_bridged_slacked_objective()
313+
model = MOI.Bridges.full_bridge_optimizer(Model2153{Float64}(), Float64)
314+
MOI.Bridges.add_bridge(
315+
model,
316+
MOI.Bridges.Constraint.QuadtoSOCBridge{Float64},
317+
)
318+
x = MOI.add_variables(model, 2)
319+
MOI.set(model, MOI.VariableName(), x, ["x", "y"])
320+
f = 1.0 * x[1] * x[1] + 1.0 * x[2] * x[2]
321+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
322+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
323+
MOI.delete(model, x[1])
324+
@test MOI.get(model, MOI.ObjectiveFunction{typeof(f)}()) 1.0 * x[2] * x[2]
325+
return
326+
end
327+
281328
end # module
282329

283330
TestConstraintQuadToSOC.runtests()

test/Bridges/Objective/slack.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,19 @@ function test_complex_objective()
489489
return
490490
end
491491

492+
function test_deletion_of_variable_in_slacked_objective()
493+
inner = MOI.Utilities.Model{Float64}()
494+
model = MOI.Bridges.Objective.Slack{Float64}(inner)
495+
x = MOI.add_variables(model, 2)
496+
MOI.set(model, MOI.VariableName(), x, ["x", "y"])
497+
f = 1.0 * x[1] * x[1] + 1.0 * x[2] * x[2]
498+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
499+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
500+
MOI.delete(model, x[1])
501+
@test MOI.get(model, MOI.ObjectiveFunction{typeof(f)}()) 1.0 * x[2] * x[2]
502+
return
503+
end
504+
492505
end # module
493506

494507
TestObjectiveSlack.runtests()

0 commit comments

Comments
 (0)