Repository navigation
Closed
Labels
Description
If I modify the code of
function MOI.Bridges.final_touch(
bridge::CountBelongsToMILPBridge{T,F},
model::MOI.ModelLike,
) where {T,F}
@warn "Final touch with $(typeof(model))"
@show bridgeI get
julia> model = Model(SCIP.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: SCIP
julia> @variable(model, 0 <= s <= 1, Bin)
s
julia> @variable(model, n)
n
julia> @constraint(model, s + n <= 1)
s + n ≤ 1.0
julia> @constraint(model, [n, s] in MOI.CountBelongs(2, Set([1])))
[n, s] ∈ MathOptInterface.CountBelongs(2, Set([1]))
julia> optimize!(model)
┌ Warning: Final touch with MathOptInterface.Bridges.LazyBridgeOptimizer{SCIP.Optimizer}
└ @ MathOptInterface.Bridges.Constraint ~/.julia/dev/MathOptInterface/src/Bridges/Constraint/bridges/count_belongs.jl:280
bridge = MathOptInterface.Bridges.Constraint.CountBelongsToMILPBridge{Float64, MathOptInterface.VectorOfVariables}(MathOptInterface.VectorOfVariables(MathOptInterface.VariableIndex[MathOptInterface.VariableIndex(2), MathOptInterface.VariableIndex(1)]), MathOptInterface.CountBelongs(2, Set([1])), MathOptInterface.VariableIndex[], MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}[])
┌ Warning: Final touch with MathOptInterface.Bridges.LazyBridgeOptimizer{SCIP.Optimizer}
└ @ MathOptInterface.Bridges.Constraint ~/.julia/dev/MathOptInterface/src/Bridges/Constraint/bridges/count_belongs.jl:280
bridge = MathOptInterface.Bridges.Constraint.CountBelongsToMILPBridge{Float64, MathOptInterface.VectorOfVariables}(MathOptInterface.VectorOfVariables(MathOptInterface.VariableIndex[MathOptInterface.VariableIndex(2), MathOptInterface.VariableIndex(1)]), MathOptInterface.CountBelongs(2, Set([1])), MathOptInterface.VariableIndex[MathOptInterface.VariableIndex(3), MathOptInterface.VariableIndex(4)], MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}[MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}(2), MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}(3), MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}(4)])
ERROR: MathOptInterface.DeleteNotAllowed{MathOptInterface.VariableIndex}: Deleting the index MathOptInterface.VariableIndex(3) cannot be performed: Can not delete variable while model contains constraints! You may want to use a `CachingOptimizer` in `AUTOMATIC` mode or you may need to call `reset_optimizer` before doing this operation if the `CachingOptimizer` is in `MANUAL` mode.
Stacktrace:
[1] delete(o::SCIP.Optimizer, vi::MathOptInterface.VariableIndex)Why is final_touch called twice (!!) times? The first makes sense. To fix up the bridge for each constraint. The second doesn't, and it looks like we're reformulating the problem twice?
Activity
odow commentedon Feb 3, 2023
So it gets called once here at the end of
default_copy_to:MathOptInterface.jl/src/Utilities/copy.jl
Line 499 in 38fc9e4
and then again at the start of
optimize!:MathOptInterface.jl/src/Bridges/bridge_optimizer.jl
Lines 374 to 375 in 38fc9e4
We need it at the end of
copy_toso that any queries are consistent. Do we need it beforeoptimize!? I guess so that any modifications between copy and optimize are respected.We avoid double calls in the various
MatrixOfConstraints, but we don't in the bridge optimizer.blegat commentedon Feb 3, 2023
If the constraints are added incrementally and not in
copy_towe need the secondfinal_touch. We need to ignore the secondfinal_touch. The user is allowed to callfinal_touchas many times as he likesodow commentedon Feb 4, 2023
Okay, that makes sense. I need to update the bridges then. This is also somewhat of a bug in SCIP, because it doesn't support deletion, so it really needs a cache.
Bridges TODO: