diff --git a/src/Bridges/Variable/map.jl b/src/Bridges/Variable/map.jl index 5ab978fd58..a93cb69987 100644 --- a/src/Bridges/Variable/map.jl +++ b/src/Bridges/Variable/map.jl @@ -417,7 +417,8 @@ function add_keys_for_bridge( end push!(map.vector_of_variables_map, -bridge_index) push!(map.vector_of_variables_length, MOI.dimension(set)) - push!(map.info, -length(map.vector_of_variables_length)) + constraint_index = -length(map.vector_of_variables_map) + push!(map.info, constraint_index) push!(map.index_in_vector, 1) push!(map.bridges, nothing) push!(map.sets, typeof(set)) @@ -446,8 +447,7 @@ function add_keys_for_bridge( end end end - return variables, - MOI.ConstraintIndex{F,S}(-length(map.vector_of_variables_map)) + return variables, MOI.ConstraintIndex{F,S}(constraint_index) end """ diff --git a/test/Bridges/lazy_bridge_optimizer.jl b/test/Bridges/lazy_bridge_optimizer.jl index 57ce1f38c3..69c094a29d 100644 --- a/test/Bridges/lazy_bridge_optimizer.jl +++ b/test/Bridges/lazy_bridge_optimizer.jl @@ -332,7 +332,7 @@ function test_MOI_runtests_GeometricSDPAModel() return end -function test_index_conflict() +function test_index_constraint_conflict() optimizer = StandardSDPAModel{Float64}() model = MOI.Bridges.full_bridge_optimizer(optimizer, Float64) x, cx = MOI.add_constrained_variables(model, MOI.Nonpositives(1)) @@ -348,6 +348,22 @@ function test_index_conflict() @test c != b2.slack_in_set end +function test_index_variable_conflict() + optimizer = StandardSDPAModel{Float64}() + model = MOI.Bridges.full_bridge_optimizer(optimizer, Float64) + set = MOI.SecondOrderCone(3) + x = MOI.add_variables(model, 3) + c = MOI.add_constraint(model, MOI.VectorOfVariables(x), set) + @test MOI.is_valid(model, c) + y, cy = MOI.add_constrained_variables(model, set) + @test MOI.is_valid(model, cy) + @test cy != c + z, cz = MOI.add_constrained_variables(model, set) + @test MOI.is_valid(model, cz) + @test cz != c +end + + function test_show_SPDA() model = StandardSDPAModel{Float64}() model_str = sprint(MOI.Utilities.print_with_acronym, string(typeof(model)))