Skip to content

Commit a377327

Browse files
committed
Update
1 parent 80e8234 commit a377327

File tree

1 file changed

+52
-41
lines changed

1 file changed

+52
-41
lines changed

test/Bridges/lazy_bridge_optimizer.jl

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,60 +2300,71 @@ MOI.Utilities.@model(
23002300
()
23012301
)
23022302

2303+
function _test_conflicts(model, inner, c)
2304+
ci = MOI.ConstraintIndex[]
2305+
for (F, S) in MOI.get(inner, MOI.ListOfConstraintTypesPresent())
2306+
append!(ci, MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
2307+
end
2308+
list = (MOI.NOT_IN_CONFLICT, MOI.IN_CONFLICT, MOI.MAYBE_IN_CONFLICT)
2309+
for a in Iterators.product(ntuple(i -> list, length(ci))...)
2310+
MOI.set(inner, MOI.ConflictCount(), 1)
2311+
MOI.set.(inner, MOI.ConstraintConflictStatus(), ci, a)
2312+
MOI.compute_conflict!(model)
2313+
status = MOI.get(model, MOI.ConstraintConflictStatus(), c)
2314+
@test status == reduce(_cmp, a)
2315+
end
2316+
return
2317+
end
2318+
2319+
function _cmp(
2320+
a::MOI.ConflictParticipationStatusCode,
2321+
b::MOI.ConflictParticipationStatusCode,
2322+
)
2323+
if a == MOI.IN_CONFLICT || b == MOI.IN_CONFLICT
2324+
return MOI.IN_CONFLICT
2325+
elseif a == MOI.MAYBE_IN_CONFLICT || b == MOI.MAYBE_IN_CONFLICT
2326+
return MOI.MAYBE_IN_CONFLICT
2327+
else
2328+
return MOI.NOT_IN_CONFLICT
2329+
end
2330+
end
2331+
23032332
function test_issue_2838()
23042333
inner = MOI.Utilities.MockOptimizer(Model2838{Float64}())
23052334
model = MOI.Bridges.full_bridge_optimizer(inner, Float64)
23062335
x = MOI.add_variables(model, 2)
23072336
f = MOI.Utilities.operate(vcat, Float64, (1.0 * x)...)
23082337
c = MOI.add_constraint(model, f, MOI.Nonnegatives(2))
2309-
F, S = MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}
2310-
ci = MOI.get(inner, MOI.ListOfConstraintIndices{F,S}())
2311-
function cmp(a, b)
2312-
if a == MOI.IN_CONFLICT || b == MOI.IN_CONFLICT
2313-
return MOI.IN_CONFLICT
2314-
elseif a == MOI.MAYBE_IN_CONFLICT || b == MOI.MAYBE_IN_CONFLICT
2315-
return MOI.MAYBE_IN_CONFLICT
2316-
else
2317-
return MOI.NOT_IN_CONFLICT
2318-
end
2319-
end
2320-
list = (MOI.NOT_IN_CONFLICT, MOI.IN_CONFLICT, MOI.MAYBE_IN_CONFLICT)
2321-
for a in list, b in list
2322-
MOI.set(inner, MOI.ConflictCount(), 1)
2323-
MOI.set(inner, MOI.ConstraintConflictStatus(), ci[1], a)
2324-
MOI.set(inner, MOI.ConstraintConflictStatus(), ci[2], b)
2325-
MOI.compute_conflict!(model)
2326-
@test MOI.get(model, MOI.ConstraintConflictStatus(), c) == cmp(a, b)
2327-
end
2338+
_test_conflicts(model, inner, c)
23282339
return
23292340
end
23302341

2331-
function test_issue_2870()
2342+
function test_issue_2870_scalar_slack()
23322343
inner = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
23332344
model = MOI.Bridges.Constraint.ScalarSlack{Float64}(inner)
23342345
x = MOI.add_variable(model)
23352346
c = MOI.add_constraint(model, 2.0 * x, MOI.Interval(1.0, -1.0))
2336-
F, S = MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}
2337-
ci_eq = only(MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
2338-
F, S = MOI.VariableIndex, MOI.Interval{Float64}
2339-
ci_iv = only(MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
2340-
function cmp(a, b)
2341-
if a == MOI.IN_CONFLICT || b == MOI.IN_CONFLICT
2342-
return MOI.IN_CONFLICT
2343-
elseif a == MOI.MAYBE_IN_CONFLICT || b == MOI.MAYBE_IN_CONFLICT
2344-
return MOI.MAYBE_IN_CONFLICT
2345-
else
2346-
return MOI.NOT_IN_CONFLICT
2347-
end
2348-
end
2349-
list = (MOI.NOT_IN_CONFLICT, MOI.IN_CONFLICT, MOI.MAYBE_IN_CONFLICT)
2350-
for a in list, b in list
2351-
MOI.set(inner, MOI.ConflictCount(), 1)
2352-
MOI.set(inner, MOI.ConstraintConflictStatus(), ci_eq, a)
2353-
MOI.set(inner, MOI.ConstraintConflictStatus(), ci_iv, b)
2354-
MOI.compute_conflict!(model)
2355-
@test MOI.get(model, MOI.ConstraintConflictStatus(), c) == cmp(a, b)
2356-
end
2347+
_test_conflicts(model, inner, c)
2348+
return
2349+
end
2350+
2351+
function test_issue_2870_geomean_to_power()
2352+
inner = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
2353+
model = MOI.Bridges.Constraint.GeoMeanToPower{Float64}(inner)
2354+
x = MOI.add_variables(model, 4)
2355+
f = MOI.VectorOfVariables(x)
2356+
c = MOI.add_constraint(model, f, MOI.GeometricMeanCone(4))
2357+
_test_conflicts(model, inner, c)
2358+
return
2359+
end
2360+
2361+
function test_issue_2870_relative_entropy()
2362+
inner = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
2363+
model = MOI.Bridges.Constraint.RelativeEntropy{Float64}(inner)
2364+
x = MOI.add_variables(model, 5)
2365+
f = MOI.VectorOfVariables(x)
2366+
c = MOI.add_constraint(model, f, MOI.RelativeEntropyCone(5))
2367+
_test_conflicts(model, inner, c)
23572368
return
23582369
end
23592370

0 commit comments

Comments
 (0)