Skip to content

Deleting variables does not work when a constraint evaluates a variable at multiple time points #376

@vyudu

Description

@vyudu

Describe the bug
In the following example the constraint evaluates Q[1] at 0.5 and 0.6. In this case deleting the variable Q[1] does not delete all the references to it:

To Reproduce
Please provide a minimum working example that causes this behavior (see how here). Do NOT copy your entire script, this makes debugging very difficult. Also, include a copy of the error you encounter if applicable.

using InfiniteOpt, JuMP [plus other packages]

model = InfiniteModel()
@infinite_parameter(model, t in [0, 10], num_supports = 100)
@variable(model, Q[1:3], Infinite(t))
@constraint(model, Q[1](0.6) == Q[1](0.5))
all_variables(model) #works
delete(model, Q[1])
all_variables(model) # throws an error
Error showing value of type Vector{GeneralVariableRef}:

SYSTEM (REPL): showing an error caused an error
ERROR: Invalid infinite variable reference, cannot find corresponding variable in the model. This is likely caused by using the reference of a deleted variable.
Stacktrace:
  [1] print_response(errio::IO, response::Any, backend::Union{Nothing, REPL.REPLBackendRef}, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL ~/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/REPL.jl:446
  [2] (::REPL.var"#70#71"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/REPL.jl:405
  [3] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/REPL.jl:678
  [4] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/REPL.jl:403
  [5] (::REPL.var"#do_respond#100"{Bool, Bool, REPL.var"#116#134"{}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1035
  [6] #invokelatest#2
    @ ./essentials.jl:1055 [inlined]
  [7] invokelatest
    @ ./essentials.jl:1052 [inlined]
  [8] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2755
  [9] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1506
 [10] (::REPL.var"#79#85"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ~/.julia/juliaup/julia-1.11.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.11/REPL/src/REPL.jl:497
Some type information was truncated. Use `show(err)` to see complete types.

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OSX
  • Package Versions: InfiniteOpt 0.5.9, JuMP 1.25.0
  • Julia Version:1.11

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions