JuMP interface problem with constraint modification after optimization
stelmo opened this issue ยท 5 comments
Hi, I think there is a problem with the interface between Tulip and JuMP when you modify constraints after an optimization has already occurred. This comes up when you want to modify the problem subject to the outcome of the previous omptimization. Below is a MWE of the issue. This seems to be an issue only for constraints that are vectors.
using JuMP
using Tulip
model = Model(Tulip.Optimizer)
@variable(model, -1.0 <= x[1:2] <= 2)
@objective(model, Max, 5x[1] + 3 * x[2])
@constraint(model, con1, 1x[1] + 5x[2] <= 3)
@constraint(model, con2, 0.0 .<= x)
optimize!(model)
objective_value(model)
set_normalized_rhs(con2[2], 0.2) # throws an error
The following error is thrown:
ERROR: Invalid constraint index 3
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] set_attribute at C:\Users\St. Elmo\.julia\packages\Tulip\za0u9\src\Interfaces\tulip_julia_api.jl:138 [inlined]
[3] set at C:\Users\St. Elmo\.julia\packages\Tulip\za0u9\src\Interfaces\MOI\constraints.jl:629 [inlined]
[4] _set_substituted at C:\Users\St. Elmo\.julia\packages\MathOptInterface\5WwpK\src\Bridges\bridge_optimizer.jl:1119 [inlined]
[5] set(::MathOptInterface.Bridges.LazyBridgeOptimizer{Tulip.Optimizer{Float64}}, ::MathOptInterface.ConstraintSet, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}}, ::MathOptInterface.LessThan{Float64}) at C:\Users\St. Elmo\.julia\packages\MathOptInterface\5WwpK\src\Bridges\bridge_optimizer.jl:1048
[6] replace_constraint_function_or_set(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.ConstraintSet, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}}, ::MathOptInterface.LessThan{Float64}) at C:\Users\St. Elmo\.julia\packages\MathOptInterface\5WwpK\src\Utilities\cachingoptimizer.jl:472
[7] set(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.ConstraintSet, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}}, ::MathOptInterface.LessThan{Float64}) at C:\Users\St. Elmo\.julia\packages\MathOptInterface\5WwpK\src\Utilities\cachingoptimizer.jl:503
[8] set(::Model, ::MathOptInterface.ConstraintSet, ::ConstraintRef{Model,MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}},ScalarShape}, ::MathOptInterface.LessThan{Float64}) at C:\Users\St. Elmo\.julia\packages\JuMP\y5vgk\src\JuMP.jl:1001
[9] set_normalized_rhs(::ConstraintRef{Model,MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}},ScalarShape}, ::Float64) at C:\Users\St. Elmo\.julia\packages\JuMP\y5vgk\src\constraints.jl:554
[10] top-level scope at REPL[82]:1
Any idea what the issue is?
Thanks for reporting this!
Long story short: I don't know. Let me look into this.
Found it ๐
It was a stupid typo that somehow managed to remain undetected.
It wouldn't raise any error unless one tries to modify a constraint whose index was larger than the number of variables.
Can you check that #84 solves the problem for you?
Thanks for helping so quickly ๐ Cool, once it's merged I'll check it! Unless there is a way to check it before it gets merged?
Unless there is a way to check it before it gets merged?
Yes, you can checkout that specific branch as follows:
julia> ]
pkg> add "https://github.com/mtanneau/Tulip.jl.git"#issue83
(don't forget to include the #issue83
, that's for selecting the branch)
I've tried this locally, so everything should work for you too. Just want to double check ๐ค
To go back to the lastest tagged version:
julia> ]
pkg> free Tulip
I didn't know you can do that, I guess I learnt something new today ๐ I checked out that branch and it works. Thanks again for the prompt help!