Skip to content

Commit d30c2d8

Browse files
committed
[Bridges] fix ConstraintConflictStatus in added_constrained_variable_types
1 parent ec8434e commit d30c2d8

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/Bridges/bridge_optimizer.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,9 @@ function MOI.set(
17491749
return throw(MOI.SettingVariableIndexNotAllowed())
17501750
end
17511751

1752+
_f_type(::Type{S}) where {S<:MOI.AbstractScalarSet} = MOI.VariableIndex
1753+
_f_type(::Type{S}) where {S<:MOI.AbstractVectorSet} = MOI.VectorOfVariables
1754+
17521755
function MOI.get(
17531756
model::MOI.ModelLike,
17541757
attr::MOI.ConstraintConflictStatus,
@@ -1765,6 +1768,17 @@ function MOI.get(
17651768
end
17661769
end
17671770
end
1771+
for (S,) in MOI.Bridges.added_constrained_variable_types(typeof(bridge))
1772+
F = _f_type(S)
1773+
for ci in MOI.get(bridge, MOI.ListOfConstraintIndices{F,S}())
1774+
status = MOI.get(model, attr, ci)
1775+
if status == MOI.IN_CONFLICT
1776+
return status
1777+
elseif status == MOI.MAYBE_IN_CONFLICT
1778+
ret = status
1779+
end
1780+
end
1781+
end
17681782
return ret
17691783
end
17701784

test/Bridges/lazy_bridge_optimizer.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,47 @@ function test_issue_2838()
23282328
return
23292329
end
23302330

2331+
MOI.Utilities.@model(
2332+
Model2870,
2333+
(),
2334+
(MOI.EqualTo,),
2335+
(),
2336+
(),
2337+
(),
2338+
(MOI.ScalarAffineFunction,),
2339+
(),
2340+
()
2341+
)
2342+
2343+
function test_issue_2870()
2344+
inner = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
2345+
model = MOI.Bridges.Constraint.ScalarSlack{Float64}(inner)
2346+
x = MOI.add_variable(model)
2347+
c = MOI.add_constraint(model, 2.0 * x, MOI.Interval(1.0, -1.0))
2348+
F, S = MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}
2349+
ci_eq = only(MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
2350+
F, S = MOI.VariableIndex, MOI.Interval{Float64}
2351+
ci_iv = only(MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
2352+
function cmp(a, b)
2353+
if a == MOI.IN_CONFLICT || b == MOI.IN_CONFLICT
2354+
return MOI.IN_CONFLICT
2355+
elseif a == MOI.MAYBE_IN_CONFLICT || b == MOI.MAYBE_IN_CONFLICT
2356+
return MOI.MAYBE_IN_CONFLICT
2357+
else
2358+
return MOI.NOT_IN_CONFLICT
2359+
end
2360+
end
2361+
list = (MOI.NOT_IN_CONFLICT, MOI.IN_CONFLICT, MOI.MAYBE_IN_CONFLICT)
2362+
for a in list, b in list
2363+
MOI.set(inner, MOI.ConflictCount(), 1)
2364+
MOI.set(inner, MOI.ConstraintConflictStatus(), ci_eq, a)
2365+
MOI.set(inner, MOI.ConstraintConflictStatus(), ci_iv, b)
2366+
MOI.compute_conflict!(model)
2367+
@test MOI.get(model, MOI.ConstraintConflictStatus(), c) == cmp(a, b)
2368+
end
2369+
return
2370+
end
2371+
23312372
end # module
23322373

23332374
TestBridgesLazyBridgeOptimizer.runtests()

0 commit comments

Comments
 (0)