@@ -471,11 +471,12 @@ Translate an outer index (in `b`'s user-facing namespace) to its inner
471471counterpart (`b.model`'s namespace). Returns `idx` unchanged when no
472472translation is in effect at this layer:
473473
474- * For a `VariableIndex`, the variable mapping must be active
475- (`Variable.is_variable_mapping_active(map)`) AND `idx` must not refer to
476- an outer-only bridged variable (`idx.value < 0`).
477- * For a `ConstraintIndex{F, S}`, the constraint mapping for `(F, S)` must
478- be active AND `idx.value >= 0`.
474+ * For a `VariableIndex`, only when variable bridges are used
475+ (`Variable.has_bridges(map)`). The caller is responsible for having
476+ already established that `idx` is not bridged at `b`'s layer.
477+ * For a `ConstraintIndex{F, S}`, only when the constraint mapping for
478+ `(F, S)` has been activated (see
479+ [`Variable.is_constraint_mapping_active`](@ref)).
479480
480481This is the canonical "if variable bridges are used, use the index map;
481482else return the index unchanged" helper.
@@ -485,9 +486,7 @@ function outer_to_inner(
485486 vi:: MOI.VariableIndex ,
486487)
487488 map = Variable. bridges (b)
488- if map isa Variable. Map &&
489- vi. value > 0 &&
490- Variable. is_variable_mapping_active (map)
489+ if Variable. has_bridges (map)
491490 return map. outer_to_inner[vi]
492491 end
493492 return vi
@@ -498,8 +497,7 @@ function outer_to_inner(
498497 ci:: MOI.ConstraintIndex{F,S} ,
499498) where {F,S}
500499 map = Variable. bridges (b)
501- if map isa Variable. Map &&
502- ci. value > 0 &&
500+ if Variable. has_bridges (map) &&
503501 Variable. is_constraint_mapping_active (map, F, S)
504502 return map. outer_to_inner[ci]
505503 end
@@ -529,7 +527,7 @@ function inner_to_outer(
529527 vi:: MOI.VariableIndex ,
530528)
531529 map = Variable. bridges (b)
532- if map isa Variable. Map && Variable . is_variable_mapping_active (map)
530+ if Variable. has_bridges (map)
533531 return map. inner_to_outer[vi]
534532 end
535533 return vi
@@ -540,7 +538,8 @@ function inner_to_outer(
540538 ci:: MOI.ConstraintIndex{F,S} ,
541539) where {F,S}
542540 map = Variable. bridges (b)
543- if map isa Variable. Map && Variable. is_constraint_mapping_active (map, F, S)
541+ if Variable. has_bridges (map) &&
542+ Variable. is_constraint_mapping_active (map, F, S)
544543 return map. inner_to_outer[ci]
545544 end
546545 return ci
@@ -625,10 +624,7 @@ namespace. When `recursive_model(b) !== b` (for example,
625624(see [`bridged_variable_function`](@ref)) so this is the identity.
626625"""
627626function _to_inner_value (b:: AbstractBridgeOptimizer , value)
628- map = Variable. bridges (b)
629- if map isa Variable. Map &&
630- Variable. is_variable_mapping_active (map) &&
631- recursive_model (b) === b
627+ if Variable. has_bridges (Variable. bridges (b)) && recursive_model (b) === b
632628 return MOI. Utilities. map_indices (_OuterToInner (b), value)
633629 end
634630 return value
@@ -644,8 +640,7 @@ unchanged; the caller is expected to substitute them out via
644640[`unbridged_function`](@ref).
645641"""
646642function _from_inner_value (b:: AbstractBridgeOptimizer , value)
647- map = Variable. bridges (b)
648- if map isa Variable. Map && Variable. is_variable_mapping_active (map)
643+ if Variable. has_bridges (Variable. bridges (b))
649644 return MOI. Utilities. map_indices (_TotalInnerToOuter (b), value)
650645 end
651646 return value
@@ -688,8 +683,7 @@ is active, regardless of `recursive_model(b)`, because such functions are
688683never rewritten by [`bridged_function`](@ref).
689684"""
690685function _to_inner_index_function (b:: AbstractBridgeOptimizer , f)
691- map = Variable. bridges (b)
692- if map isa Variable. Map && Variable. is_variable_mapping_active (map)
686+ if Variable. has_bridges (Variable. bridges (b))
693687 return MOI. Utilities. map_indices (_OuterToInner (b), f)
694688 end
695689 return f
@@ -711,7 +705,7 @@ function _record_inner_constraint!(
711705 inner_ci:: MOI.ConstraintIndex{F,S} ,
712706) where {F,S}
713707 map = Variable. bridges (b)
714- if map isa Variable. Map &&
708+ if Variable. has_bridges (map) &&
715709 Variable. is_constraint_mapping_active (map, F, S)
716710 outer_ci =
717711 MOI. ConstraintIndex {F,S} (Variable. next_outer_constraint! (map, F, S))
@@ -734,7 +728,7 @@ function MOI.is_valid(b::AbstractBridgeOptimizer, vi::MOI.VariableIndex)
734728 return haskey (Variable. bridges (b), vi)
735729 end
736730 map = Variable. bridges (b)
737- if map isa Variable. Map && Variable . is_variable_mapping_active (map)
731+ if Variable. has_bridges (map)
738732 # Outer/inner translation is in effect. Outer `vi` must be in
739733 # `outer_to_inner` to be valid; the entry then points to the inner
740734 # index to forward.
@@ -801,9 +795,7 @@ function _inner_index_or_nothing(
801795 vi:: MOI.VariableIndex ,
802796)
803797 map = Variable. bridges (b)
804- if map isa Variable. Map &&
805- vi. value > 0 &&
806- Variable. is_variable_mapping_active (map)
798+ if Variable. has_bridges (map)
807799 return get (map. outer_to_inner. var_map, vi, nothing )
808800 end
809801 return vi
@@ -814,8 +806,7 @@ function _inner_index_or_nothing(
814806 ci:: MOI.ConstraintIndex{F,S} ,
815807) where {F,S}
816808 map = Variable. bridges (b)
817- if map isa Variable. Map &&
818- ci. value > 0 &&
809+ if Variable. has_bridges (map) &&
819810 Variable. is_constraint_mapping_active (map, F, S)
820811 if haskey (map. outer_to_inner. con_map, ci)
821812 return map. outer_to_inner. con_map[ci]
@@ -1076,7 +1067,7 @@ function _remove_inner_variable_mapping!(
10761067 vi:: MOI.VariableIndex ,
10771068)
10781069 map = Variable. bridges (b)
1079- if ! (map isa Variable. Map) || ! Variable . is_variable_mapping_active (map)
1070+ if ! Variable. has_bridges (map)
10801071 return
10811072 end
10821073 inner_vi = get (map. outer_to_inner. var_map, vi, nothing )
@@ -1239,8 +1230,7 @@ function _get_all_including_bridged(
12391230 key = inner_variable
12401231 if ! haskey (bridge_var_map, key)
12411232 map_b = Variable. bridges (b)
1242- if map_b isa Variable. Map &&
1243- Variable. is_variable_mapping_active (map_b) &&
1233+ if Variable. has_bridges (map_b) &&
12441234 haskey (map_b. inner_to_outer, key)
12451235 key = map_b. inner_to_outer[key]
12461236 end
@@ -2363,7 +2353,7 @@ function _outer_variable_for_name_lookup(
23632353 vi:: MOI.VariableIndex ,
23642354)
23652355 map = Variable. bridges (b)
2366- if ! (map isa Variable. Map) || ! Variable . is_variable_mapping_active (map)
2356+ if ! Variable. has_bridges (map)
23672357 return vi
23682358 end
23692359 if haskey (map. inner_to_outer. var_map, vi)
@@ -2861,16 +2851,17 @@ end
28612851"""
28622852 _record_inner_variable!(b::AbstractBridgeOptimizer, inner_vi::MOI.VariableIndex)
28632853
2864- If variable mapping is active in `b`, allocate a fresh outer `VariableIndex`
2865- value and record the bidirectional mapping. Otherwise (identity mode, or `b`
2866- does not own a `Variable.Map` at all), return `inner_vi` unchanged.
2854+ If `b` uses variable bridges (`Variable.has_bridges`), allocate a fresh
2855+ outer `VariableIndex` value and record the bidirectional mapping.
2856+ Otherwise (identity mode, or `b` does not own a `Variable.Map` at all),
2857+ return `inner_vi` unchanged.
28672858"""
28682859function _record_inner_variable! (
28692860 b:: AbstractBridgeOptimizer ,
28702861 inner_vi:: MOI.VariableIndex ,
28712862)
28722863 map = Variable. bridges (b)
2873- if ! (map isa Variable. Map) || ! Variable . is_variable_mapping_active (map)
2864+ if ! Variable. has_bridges (map)
28742865 return inner_vi
28752866 end
28762867 outer_vi = MOI. VariableIndex (Variable. next_outer_variable! (map))
0 commit comments