-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathParameterToEqualToBridge.jl
More file actions
86 lines (67 loc) · 2.07 KB
/
ParameterToEqualToBridge.jl
File metadata and controls
86 lines (67 loc) · 2.07 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
# 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.
"""
ParameterToEqualToBridge{T} <: Bridges.Variable.AbstractBridge
`ParameterToEqualToBridge` implements the following reformulation:
* ``x \\in Parameter(v)`` into ``x == v``
## Source node
`ParameterToEqualToBridge` supports:
* [`MOI.VariableIndex`](@ref) in [`MOI.Parameter`](@ref)
## Target nodes
`ParameterToEqualToBridge` creates:
* One variable node: [`MOI.VariableIndex`](@ref) in [`MOI.EqualTo{T}`](@ref)
"""
struct ParameterToEqualToBridge{T} <:
SetMapBridge{T,MOI.EqualTo{T},MOI.Parameter{T}}
variable::MOI.VariableIndex
constraint::MOI.ConstraintIndex{MOI.VariableIndex,MOI.EqualTo{T}}
end
const ParameterToEqualTo{T,OT<:MOI.ModelLike} =
SingleBridgeOptimizer{ParameterToEqualToBridge{T},OT}
function MOI.Bridges.map_set(
::Type{<:ParameterToEqualToBridge{T}},
set::MOI.EqualTo{T},
) where {T}
return MOI.Parameter{T}(set.value)
end
function MOI.Bridges.inverse_map_set(
::Type{<:ParameterToEqualToBridge{T}},
set::MOI.Parameter{T},
) where {T}
return MOI.EqualTo{T}(set.value)
end
MOI.Bridges.map_function(::Type{<:ParameterToEqualToBridge}, f) = f
MOI.Bridges.inverse_map_function(::Type{<:ParameterToEqualToBridge}, f) = f
MOI.Bridges.adjoint_map_function(::Type{<:ParameterToEqualToBridge}, f) = f
function MOI.Bridges.inverse_adjoint_map_function(
::Type{<:ParameterToEqualToBridge},
f,
)
return f
end
function MOI.supports(
::MOI.ModelLike,
::MOI.VariableName,
::Type{<:ParameterToEqualToBridge},
)
return true
end
function MOI.get(
model::MOI.ModelLike,
attr::MOI.VariableName,
bridge::ParameterToEqualToBridge,
)
return MOI.get(model, attr, bridge.variable)
end
function MOI.set(
model::MOI.ModelLike,
attr::MOI.VariableName,
bridge::ParameterToEqualToBridge,
name::String,
)
MOI.set(model, attr, bridge.variable, name)
return
end