Skip to content

Commit 7163ab8

Browse files
committed
Update
1 parent 68356d9 commit 7163ab8

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

src/Bridges/Variable/set_map.jl

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ function MOI.get(
8484
bridge::SetMapBridge,
8585
)
8686
f = MOI.get(model, attr, bridge.constraint)
87-
if f === nothing
88-
return nothing
89-
end
9087
return MOI.Bridges.inverse_map_function(bridge, f)
9188
end
9289

@@ -98,12 +95,8 @@ function MOI.set(
9895
bridge::SetMapBridge,
9996
value,
10097
)
101-
if value === nothing
102-
MOI.set(model, attr, bridge.constraint, value)
103-
else
104-
bridged_value = MOI.Bridges.map_function(bridge, value)
105-
MOI.set(model, attr, bridge.constraint, bridged_value)
106-
end
98+
bridged_value = MOI.Bridges.map_function(bridge, value)
99+
MOI.set(model, attr, bridge.constraint, bridged_value)
107100
return
108101
end
109102

@@ -143,9 +136,6 @@ function MOI.get(
143136
bridge::SetMapBridge,
144137
)
145138
value = MOI.get(model, attr, bridge.constraint)
146-
if value === nothing
147-
return nothing
148-
end
149139
return MOI.Bridges.inverse_adjoint_map_function(typeof(bridge), value)
150140
end
151141

@@ -157,12 +147,8 @@ function MOI.set(
157147
bridge::SetMapBridge,
158148
value,
159149
)
160-
if value === nothing
161-
MOI.set(model, attr, bridge.constraint, value)
162-
else
163-
bridged_value = MOI.Bridges.adjoint_map_function(bridge, value)
164-
MOI.set(model, attr, bridge.constraint, bridged_value)
165-
end
150+
bridged_value = MOI.Bridges.adjoint_map_function(bridge, value)
151+
MOI.set(model, attr, bridge.constraint, bridged_value)
166152
return
167153
end
168154

@@ -235,9 +221,6 @@ function MOI.get(
235221
bridge::SetMapBridge,
236222
)
237223
value = MOI.get(model, attr, bridge.variable)
238-
if value === nothing
239-
return nothing
240-
end
241224
return MOI.Bridges.map_function(bridge, value)
242225
end
243226

@@ -247,12 +230,8 @@ function MOI.set(
247230
bridge::SetMapBridge,
248231
value,
249232
)
250-
if value === nothing
251-
MOI.set(model, attr, bridge.variable, nothing)
252-
else
253-
bridged_value = MOI.Bridges.inverse_map_function(bridge, value)
254-
MOI.set(model, attr, bridge.variable, bridged_value)
255-
end
233+
bridged_value = MOI.Bridges.inverse_map_function(bridge, value)
234+
MOI.set(model, attr, bridge.variable, bridged_value)
256235
return
257236
end
258237

@@ -320,12 +299,8 @@ function MOI.set(
320299
value,
321300
i::MOI.Bridges.IndexInVector,
322301
)
323-
if value === nothing
324-
MOI.set(model, attr, bridge.variables[i.value], nothing)
325-
else
326-
bridged_value = MOI.Bridges.inverse_map_function(bridge, value)
327-
MOI.set(model, attr, bridge.variables[i.value], bridged_value)
328-
end
302+
bridged_value = MOI.Bridges.inverse_map_function(bridge, value)
303+
MOI.set(model, attr, bridge.variables[i.value], bridged_value)
329304
return
330305
end
331306

src/Bridges/set_map.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ function map_function(bridge::AbstractBridge, func)
6767
return map_function(typeof(bridge), func)
6868
end
6969

70+
map_function(::AbstractBridge, ::Nothing) = nothing
71+
7072
"""
7173
map_function(::Type{BT}, func, i::IndexInVector) where {BT}
7274
@@ -106,6 +108,8 @@ function inverse_map_function(bridge::AbstractBridge, func)
106108
return inverse_map_function(typeof(bridge), func)
107109
end
108110

111+
inverse_map_function(::AbstractBridge, ::Nothing) = nothing
112+
109113
"""
110114
adjoint_map_function(bridge::MOI.Bridges.AbstractBridge, func)
111115
adjoint_map_function(::Type{BT}, func) where {BT}
@@ -123,6 +127,8 @@ function adjoint_map_function(bridge::AbstractBridge, func)
123127
return adjoint_map_function(typeof(bridge), func)
124128
end
125129

130+
adjoint_map_function(::AbstractBridge, ::Nothing) = nothing
131+
126132
"""
127133
inverse_adjoint_map_function(bridge::MOI.Bridges.AbstractBridge, func)
128134
inverse_adjoint_map_function(::Type{BT}, func) where {BT}
@@ -142,3 +148,5 @@ interface is kept for backward compatibility.
142148
function inverse_adjoint_map_function(bridge::AbstractBridge, func)
143149
return inverse_adjoint_map_function(typeof(bridge), func)
144150
end
151+
152+
inverse_adjoint_map_function(::AbstractBridge, ::Nothing) = nothing

0 commit comments

Comments
 (0)