10
10
Returns a new scalar set `new_set` such that `func`-in-`set` is equivalent to
11
11
`func + offset`-in-`new_set`.
12
12
13
- Only define this function if it makes sense to.
14
-
15
13
Use [`supports_shift_constant`](@ref) to check if the set supports shifting:
16
14
```Julia
17
- if supports_shift_constant(typeof(old_set ))
18
- new_set = shift_constant(old_set, offset )
19
- f .constant = 0
20
- add_constraint(model, f , new_set)
15
+ if MOI.Utilities. supports_shift_constant(typeof(set ))
16
+ new_set = MOI.Utilities. shift_constant(set, -func.constant )
17
+ func .constant = 0
18
+ MOI. add_constraint(model, func , new_set)
21
19
else
22
- add_constraint(model, f, old_set )
20
+ MOI. add_constraint(model, func, set )
23
21
end
24
22
```
25
23
26
- See also [`supports_shift_constant`](@ref).
24
+ ### Note for developers
25
+
26
+ Only define this function if it makes sense and you have implemented
27
+ [`supports_shift_constant`](@ref) to return `true`.
27
28
28
29
## Examples
29
30
30
- The call `shift_constant(MOI.Interval(-2, 3), 1)` is equal to
31
- `MOI.Interval(-1, 4)`.
31
+ ```jldoctest
32
+ julia> import MathOptInterface as MOI
33
+
34
+ julia> set = MOI.Interval(-2.0, 3.0)
35
+ MathOptInterface.Interval{Float64}(-2.0, 3.0)
36
+
37
+ julia> MOI.Utilities.supports_shift_constant(typeof(set))
38
+ true
39
+
40
+ julia> MOI.Utilities.shift_constant(set, 1.0)
41
+ MathOptInterface.Interval{Float64}(-1.0, 4.0)
42
+ ```
32
43
"""
33
44
function shift_constant end
34
45
@@ -38,32 +49,49 @@ function shift_constant end
38
49
Return `true` if [`shift_constant`](@ref) is defined for set `S`.
39
50
40
51
See also [`shift_constant`](@ref).
52
+
53
+ ## Examples
54
+
55
+ ```jldoctest
56
+ julia> import MathOptInterface as MOI
57
+
58
+ julia> MOI.Utilities.supports_shift_constant(MOI.Interval{Float64})
59
+ true
60
+
61
+ julia> MOI.Utilities.supports_shift_constant(MOI.ZeroOne)
62
+ false
63
+ ```
41
64
"""
42
65
supports_shift_constant (:: Type{S} ) where {S<: MOI.AbstractSet } = false
43
66
44
67
function shift_constant (set:: MOI.LessThan , offset)
45
68
return MOI. LessThan (MOI. constant (set) + offset)
46
69
end
70
+
47
71
supports_shift_constant (:: Type{<:MOI.LessThan} ) = true
48
72
49
73
function shift_constant (set:: MOI.GreaterThan , offset)
50
74
return MOI. GreaterThan (MOI. constant (set) + offset)
51
75
end
76
+
52
77
supports_shift_constant (:: Type{<:MOI.GreaterThan} ) = true
53
78
54
79
function shift_constant (set:: MOI.EqualTo , offset)
55
80
return MOI. EqualTo (MOI. constant (set) + offset)
56
81
end
82
+
57
83
supports_shift_constant (:: Type{<:MOI.EqualTo} ) = true
58
84
59
85
function shift_constant (set:: MOI.Interval , offset)
60
86
return MOI. Interval (set. lower + offset, set. upper + offset)
61
87
end
88
+
62
89
supports_shift_constant (:: Type{<:MOI.Interval} ) = true
63
90
64
91
function shift_constant (set:: MOI.Parameter , offset)
65
92
return MOI. Parameter (MOI. constant (set) + offset)
66
93
end
94
+
67
95
supports_shift_constant (:: Type{<:MOI.Parameter} ) = true
68
96
69
97
"""
0 commit comments