Skip to content

Commit fea3408

Browse files
committed
♻️ Add function supertype for flip sign bridges
This allows e.g. GreaterToLessBridge{Int} to be a subtype of FlipSignBridge{GreaterThan{Int}}
1 parent f654e05 commit fea3408

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/Bridges/flip_sign_bridge.jl

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ abstract type FlipSignBridge{
1010
S1<:MOI.AbstractSet, S2<:MOI.AbstractSet,
1111
F<:MOI.AbstractFunction} <: AbstractBridge end
1212

13-
# Apparently, Julia does not consider, say `GreaterToLessBridge{T}` to be a
14-
# subtype of `FlipSignBridge{MOI.GreaterTo{T}, MOI.LessThan{T}}` but consider
15-
# it to be a subtype of `FlipSignBridge{MOI.GreaterTo{T}, MOI.LessThan{T}, <:Any}`
16-
function MOI.supports_constraint(::Type{<:FlipSignBridge{S1, S2, <:Any}},
13+
function MOI.supports_constraint(::Type{<:FlipSignBridge{S1}},
1714
::Type{<:MOI.AbstractScalarFunction},
18-
::Type{S1}) where {S1<:MOI.AbstractSet, S2<:MOI.AbstractSet}
15+
::Type{S1}) where {S1<:MOI.AbstractSet}
1916
return true
2017
end
2118
function added_constraint_types(
@@ -67,14 +64,14 @@ function MOI.modify(model::MOI.ModelLike, bridge::FlipSignBridge,
6764
end
6865

6966
"""
70-
GreaterToLessBridge{T, F} <: FlipSignBridge{MOI.GreaterThan{T},
71-
MOI.LessThan{T}, F}
67+
GreaterToLessBridge{T, F<:MOI.AbstractScalarFunction} <:
68+
FlipSignBridge{MOI.GreaterThan{T}, MOI.LessThan{T}, F}
7269
7370
Transforms a `G`-in-`GreaterThan{T}` constraint into an `F`-in-`LessThan{T}`
7471
constraint.
7572
"""
76-
struct GreaterToLessBridge{T, F} <: FlipSignBridge{MOI.GreaterThan{T},
77-
MOI.LessThan{T}, F}
73+
struct GreaterToLessBridge{T, F<:MOI.AbstractScalarFunction} <:
74+
FlipSignBridge{MOI.GreaterThan{T}, MOI.LessThan{T}, F}
7875
flipped_constraint::CI{F, MOI.LessThan{T}}
7976
end
8077
function GreaterToLessBridge{T, F}(model::MOI.ModelLike,
@@ -97,14 +94,14 @@ function MOI.set(model::MOI.ModelLike, attr::MOI.ConstraintSet,
9794
end
9895

9996
"""
100-
LessToGreaterBridge{T, F} <: FlipSignBridge{MOI.LessThan{T},
101-
MOI.GreaterThan{T}, F}
97+
LessToGreaterBridge{T, F<:MOI.AbstractScalarFunction} <:
98+
FlipSignBridge{MOI.LessThan{T}, MOI.GreaterThan{T}, F}
10299
103100
Transforms a `G`-in-`LessThan{T}` constraint into an `F`-in-`GreaterThan{T}`
104101
constraint.
105102
"""
106-
struct LessToGreaterBridge{T, F} <: FlipSignBridge{MOI.LessThan{T},
107-
MOI.GreaterThan{T}, F}
103+
struct LessToGreaterBridge{T, F<:MOI.AbstractScalarFunction} <:
104+
FlipSignBridge{MOI.LessThan{T}, MOI.GreaterThan{T}, F}
108105
flipped_constraint::CI{F, MOI.GreaterThan{T}}
109106
end
110107
function LessToGreaterBridge{T, F}(model::MOI.ModelLike,
@@ -127,13 +124,13 @@ function MOI.set(model::MOI.ModelLike, attr::MOI.ConstraintSet,
127124
end
128125

129126
"""
130-
NonnegToNonposBridge{T, F}
127+
NonnegToNonposBridge{T, F<:MOI.AbstractVectorFunction}
131128
132129
Transforms a `G`-in-`Nonnegatives` constraint into a `F`-in-`Nonpositives`
133130
constraint.
134131
"""
135-
struct NonnegToNonposBridge{T, F} <: FlipSignBridge{MOI.Nonnegatives,
136-
MOI.Nonpositives, F}
132+
struct NonnegToNonposBridge{T, F<:MOI.AbstractVectorFunction} <:
133+
FlipSignBridge{MOI.Nonnegatives, MOI.Nonpositives, F}
137134
flipped_constraint::CI{F, MOI.Nonpositives}
138135
end
139136
function NonnegToNonposBridge{T, F}(model::MOI.ModelLike,
@@ -152,13 +149,13 @@ function concrete_bridge_type(::Type{<:NonnegToNonposBridge{T}},
152149
end
153150

154151
"""
155-
NonposToNonnegBridge{T, F}
152+
NonposToNonnegBridge{T, F<:MOI.AbstractVectorFunction}
156153
157154
Transforms a `G`-in-`Nonpositives` constraint into a `F`-in-`Nonnegatives`
158155
constraint.
159156
"""
160-
struct NonposToNonnegBridge{T, F} <: FlipSignBridge{MOI.Nonpositives,
161-
MOI.Nonnegatives, F}
157+
struct NonposToNonnegBridge{T, F<:MOI.AbstractVectorFunction} <:
158+
FlipSignBridge{MOI.Nonpositives, MOI.Nonnegatives, F}
162159
flipped_constraint::CI{F, MOI.Nonnegatives}
163160
end
164161
function NonposToNonnegBridge{T, F}(model::MOI.ModelLike,

0 commit comments

Comments
 (0)