Skip to content

Commit 78c7f6c

Browse files
committed
Add MapNotInvertible
1 parent 2d57b73 commit 78c7f6c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Bridges/Constraint/set_map.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ function MOI.get(
102102
bridge::MultiSetMapBridge{T,S1,G},
103103
) where {T,S1,G}
104104
mapped_func = MOI.get(model, attr, bridge.constraint)
105-
func = MOI.Bridges.inverse_map_function(bridge, mapped_func)
105+
func = try
106+
MOI.Bridges.inverse_map_function(bridge, mapped_func)
107+
catch err
108+
if err isa MOI.Bridges.MapNotInvertible
109+
throw(MOI.GetAttributeNotAllowed(attr))
110+
else
111+
rethrow(err)
112+
end
113+
end
106114
return MOI.Utilities.convert_approx(G, func)
107115
end
108116

@@ -146,7 +154,16 @@ function MOI.get(
146154
if value === nothing
147155
return nothing
148156
end
149-
return MOI.Bridges.inverse_map_function(bridge, value)
157+
return try
158+
MOI.Bridges.inverse_map_function(bridge, value)
159+
catch err
160+
if err isa MOI.Bridges.MapNotInvertible
161+
throw(MOI.GetAttributeNotAllowed(attr))
162+
else
163+
rethrow(err)
164+
end
165+
end
166+
150167
end
151168

152169
function MOI.set(

src/Bridges/set_map.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# Use of this source code is governed by an MIT-style license that can be found
55
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
66

7+
struct MapNotInvertible <: Exception end
8+
79
"""
810
map_set(::Type{BT}, set) where {BT}
911
@@ -44,6 +46,10 @@ the [`MOI.VariablePrimal`](@ref) and
4446
"""
4547
function map_function end
4648

49+
function map_function(bridge::AbstractBridge, func)
50+
return map_function(typeof(bridge), func)
51+
end
52+
4753
function map_function(::Type{BT}, func, i::IndexInVector) where {BT}
4854
return MOI.Utilities.eachscalar(map_function(BT, func))[i.value]
4955
end

0 commit comments

Comments
 (0)