-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathbridge.jl
More file actions
105 lines (86 loc) · 3.16 KB
/
bridge.jl
File metadata and controls
105 lines (86 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright (c) 2017: Miles Lubin and contributors
# Copyright (c) 2017: Google Inc.
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
"""
abstract type AbstractBridge <: MOI.Bridges.AbstractType
Subtype of [`MOI.Bridges.AbstractBridge`](@ref) for constraint bridges.
In addition to the required implementation described in
[`MOI.Bridges.AbstractBridge`](@ref), subtypes of `AbstractBridge` must
additionally implement:
* [`MOI.supports_constraint(::Type{<:AbstractBridge}, ::Type{<:MOI.AbstractFunction}, ::Type{<:MOI.AbstractSet})`](@ref)
* [`concrete_bridge_type`](@ref)
* [`bridge_constraint`](@ref)
"""
abstract type AbstractBridge <: MOI.Bridges.AbstractBridge end
"""
MOI.supports_constraint(
BT::Type{<:AbstractBridge},
F::Type{<:MOI.AbstractFunction},
S::Type{<:MOI.AbstractSet},
)::Bool
Return a `Bool` indicating whether the bridges of type `BT` support bridging
`F`-in-`S` constraints.
## Implementation notes
* This method depends only on the type of the inputs, not the runtime values.
* There is a default fallback, so you need only implement this method for
constraint types that the bridge implements.
"""
function MOI.supports_constraint(
::Type{<:AbstractBridge},
::Type{<:MOI.AbstractFunction},
::Type{<:MOI.AbstractSet},
)
return false
end
"""
concrete_bridge_type(
BT::Type{<:AbstractBridge},
F::Type{<:MOI.AbstractFunction},
S::Type{<:MOI.AbstractSet}
)::Type
Return the concrete type of the bridge supporting `F`-in-`S` constraints.
This function can only be called if `MOI.supports_constraint(BT, F, S)` is
`true`.
## Example
The [`SplitIntervalBridge`](@ref) bridges a [`MOI.VariableIndex`](@ref)-in-[`MOI.Interval`](@ref)
constraint into a [`MOI.VariableIndex`](@ref)-in-[`MOI.GreaterThan`](@ref) and a
[`MOI.VariableIndex`](@ref)-in-[`MOI.LessThan`](@ref) constraint.
```jldoctest
julia> MOI.Bridges.Constraint.concrete_bridge_type(
MOI.Bridges.Constraint.SplitIntervalBridge{Float64},
MOI.VariableIndex,
MOI.Interval{Float64},
)
MathOptInterface.Bridges.Constraint.SplitIntervalBridge{Float64, MathOptInterface.VariableIndex, MathOptInterface.Interval{Float64}, MathOptInterface.GreaterThan{Float64}, MathOptInterface.LessThan{Float64}}
```
"""
function concrete_bridge_type(
::Type{BT},
::Type{<:MOI.AbstractFunction},
::Type{<:MOI.AbstractSet},
) where {BT}
return BT
end
function concrete_bridge_type(
b::MOI.Bridges.AbstractBridgeOptimizer,
F::Type{<:MOI.AbstractFunction},
S::Type{<:MOI.AbstractSet},
)
return concrete_bridge_type(MOI.Bridges.bridge_type(b, F, S), F, S)
end
"""
bridge_constraint(
BT::Type{<:AbstractBridge},
model::MOI.ModelLike,
func::AbstractFunction,
set::MOI.AbstractSet,
)::BT
Bridge the constraint `func`-in-`set` using bridge `BT` to `model` and returns
a bridge object of type `BT`.
## Implementation notes
* The bridge type `BT` should be a concrete type, that is, all the type
parameters of the bridge must be set.
"""
function bridge_constraint end