@@ -723,10 +723,27 @@ function _get_all_including_bridged(
723723 # distinction, the tail variables are set to `nothing`.
724724 map = Variable. bridges (b)
725725 inner_to_outer = Dict {MOI.VariableIndex,Union{Nothing,MOI.VariableIndex}} ()
726+ # These are variables which appear in `b` but do NOT appear in `b.model`.
727+ # One reason might be the Zero bridge in which they are replaced by `0.0`.
728+ user_only_variables = MOI. VariableIndex[]
726729 for (user_variable, bridge) in map
727730 variables = MOI. get (bridge, MOI. ListOfVariableIndices ())
728- if ! isempty (variables)
729- # Some bridges, like Zeros, don't add any variables.
731+ if isempty (variables)
732+ # This bridge maps `user_variable` to constants in `b.model`. We
733+ # still need to report back `user_variable` to the user. In
734+ # addition, it might represent the start of a VectorOfVariables
735+ # function, so we may need to report multiple variables.
736+ push! (user_only_variables, user_variable)
737+ n = Variable. length_of_vector_of_variables (map, user_variable)
738+ for i in 1 : n- 1
739+ push! (user_only_variables, MOI. VariableIndex (user_variable. value - i))
740+ end
741+ else
742+ # This bridge maps `user_variable` to a list of `variables`. We need
743+ # to swap out only the `first` variable. The others can be flagged
744+ # with `nothing`. To simplify the first/tail loop, we set
745+ # `first(variables)` twice; first to `nothing` and then to
746+ # `user_variable`.
730747 for bridged_variable in variables
731748 inner_to_outer[bridged_variable] = nothing
732749 end
@@ -760,6 +777,12 @@ function _get_all_including_bridged(
760777 end
761778 end
762779 end
780+ # Since these were replaced by constants, we don't actually know when they
781+ # were added to the model. Tack them on at the end...
782+ #
783+ # If you, future reader, find this troublesome, come up with a better
784+ # solution.
785+ append! (ret, user_only_variables)
763786 return ret
764787end
765788
0 commit comments