Skip to content

Commit c2a40ed

Browse files
committed
Add set conversion bridge
1 parent dc71c13 commit c2a40ed

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
struct SetConversionBridge{T,S2,S1,F} <:
2+
MOI.Bridges.Constraint.SetMapBridge{T,S2,S1,F,F}
3+
constraint::MOI.ConstraintIndex{F,S2}
4+
end
5+
6+
function MOI.supports_constraint(
7+
::Type{SetConversionBridge{T,S2}},
8+
::Type{F},
9+
::Type{S1},
10+
) where {T,F<:MOI.AbstractFunction,S1<:MOI.AbstractSet,S2}
11+
if S1 == MOI.AllDifferent
12+
@show isfinite(MOI.Bridges.Constraint.conversion_cost(S2, S1))
13+
end
14+
return isfinite(MOI.Bridges.Constraint.conversion_cost(S2, S1))
15+
end
16+
17+
function MOI.Bridges.Constraint.concrete_bridge_type(
18+
::Type{SetConversionBridge{T,S2}},
19+
::Type{F},
20+
::Type{S1},
21+
) where {T,F<:MOI.AbstractFunction,S1<:MOI.AbstractSet,S2}
22+
return SetConversionBridge{T,S2,S1,F}
23+
end
24+
25+
function MOI.Bridges.Constraint.conversion_cost(
26+
::Type{<:MOI.AbstractSet},
27+
::Type{<:MOI.AbstractSet},
28+
)
29+
return Inf
30+
end
31+
32+
function MOI.Bridges.bridging_cost(
33+
::Type{<:SetConversionBridge{T,S2,S1}},
34+
) where {T,S2,S1}
35+
return MOI.Bridges.Constraint.conversion_cost(S2, S1)
36+
end
37+
38+
function MOI.Bridges.map_set(
39+
::Type{<:SetConversionBridge{T,S2,S1}},
40+
set::S1,
41+
) where {T,S2,S1}
42+
return convert(S2, set)
43+
end
44+
45+
function MOI.Bridges.inverse_map_set(
46+
::Type{<:SetConversionBridge{T,S2,S1}},
47+
set::S2,
48+
) where {T,S2,S1}
49+
return convert(S1, set)
50+
end
51+
52+
function MOI.Bridges.map_function(::Type{<:SetConversionBridge}, func)
53+
return func
54+
end
55+
56+
function MOI.Bridges.inverse_map_function(::Type{<:SetConversionBridge}, func)
57+
return func
58+
end
59+
60+
function MOI.Bridges.adjoint_map_function(::Type{<:SetConversionBridge}, func)
61+
return func
62+
end
63+
64+
function MOI.Bridges.inverse_adjoint_map_function(
65+
::Type{<:SetConversionBridge},
66+
func,
67+
)
68+
return func
69+
end

0 commit comments

Comments
 (0)