Skip to content

Bridges and final_touch #2088

Closed
Closed

Description

@odow

x-ref: https://discourse.julialang.org/t/jump-scip-error/93958/3

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 bridge

I 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

  1. added
    Submodule: Bridges
    on Feb 3, 2023
  2. odow commented on Feb 3, 2023

    @odow
    MemberAuthor

    So it gets called once here at the end of default_copy_to:

    final_touch(dest, index_map)

    and then again at the start of optimize!:

    function MOI.optimize!(b::AbstractBridgeOptimizer)
    final_touch(b)

    We need it at the end of copy_to so that any queries are consistent. Do we need it before optimize!? 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.

  3. blegat commented on Feb 3, 2023

    @blegat
    Member

    If the constraints are added incrementally and not in copy_to we need the second final_touch. We need to ignore the second final_touch. The user is allowed to call final_touch as many times as he likes

  4. odow commented on Feb 4, 2023

    @odow
    MemberAuthor

    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:

    • bin_packing.jl
    • count_belongs.jl
    • count_distinct_reif.jl
    • count_distinct.jl
    • count_greater_than.jl
    • semi_to_binary.jl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Submodule: BridgesType: Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions