Skip to content

Commit 6fd7071

Browse files
committed
[Bridges] add support for querying ConstraintConflictStatus
1 parent 14d5af5 commit 6fd7071

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/Bridges/bridge_optimizer.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,27 @@ function MOI.set(
17441744
return throw(MOI.SettingVariableIndexNotAllowed())
17451745
end
17461746

1747+
function MOI.get(
1748+
model::AbstractBridgeOptimizer,
1749+
attr::MOI.ConstraintConflictStatus,
1750+
bridge::AbstractBridge,
1751+
)
1752+
ret = MOI.NOT_IN_CONFLICT
1753+
for (F, S) in MOI.Bridges.added_constraint_types(typeof(bridge))
1754+
for ci in MOI.get(bridge, MOI.ListOfConstraintIndices{F,S}())
1755+
status = MOI.get(model, attr, ci)
1756+
if status == MOI.IN_CONFLICT
1757+
return status
1758+
elseif status == MOI.MAYBE_IN_CONFLICT
1759+
ret = status
1760+
# elseif status == MOI.NOT_IN_CONFLICT
1761+
# Nothing to do here.
1762+
end
1763+
end
1764+
end
1765+
return ret
1766+
end
1767+
17471768
## Getting and Setting names
17481769
function MOI.get(
17491770
b::AbstractBridgeOptimizer,

test/Bridges/lazy_bridge_optimizer.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,46 @@ function test_wrong_coefficient_2()
22882288
return
22892289
end
22902290

2291+
MOI.Utilities.@model(
2292+
Model2838,
2293+
(),
2294+
(MOI.GreaterThan,),
2295+
(),
2296+
(),
2297+
(),
2298+
(MOI.ScalarAffineFunction,),
2299+
(),
2300+
()
2301+
)
2302+
2303+
function test_issue_2838()
2304+
inner = MOI.Utilities.MockOptimizer(Model2838{Float64}())
2305+
model = MOI.Bridges.full_bridge_optimizer(inner, Float64)
2306+
x = MOI.add_variables(model, 2)
2307+
f = MOI.Utilities.operate(vcat, Float64, (1.0 * x)...)
2308+
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
2328+
return
2329+
end
2330+
22912331
end # module
22922332

22932333
TestBridgesLazyBridgeOptimizer.runtests()

0 commit comments

Comments
 (0)