Skip to content

Commit ba209f2

Browse files
committed
Add LazyScalarSet
1 parent e3c6918 commit ba209f2

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

src/Bridges/Constraint/Constraint.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function add_all_bridges(model, ::Type{T}) where {T}
7272
# It is also really useful only to PATHSolver.jl, which could add this
7373
# to MOI.ListOfRequiredBridges.
7474
MOI.Bridges.add_bridge(model, IntegerToZeroOneBridge{T})
75+
MOI.Bridges.add_bridge(model, LazyScalarSetBridge{T})
7576
MOI.Bridges.add_bridge(model, LessToGreaterBridge{T})
7677
if T <: AbstractFloat # See note in docstring of AbstractToIntervalBridge
7778
MOI.Bridges.add_bridge(model, LessToIntervalBridge{T})
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2017: Miles Lubin and contributors
2+
# Copyright (c) 2017: Google Inc.
3+
#
4+
# Use of this source code is governed by an MIT-style license that can be found
5+
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
6+
7+
struct LazyScalarSetBridge{
8+
T,
9+
F<:MOI.AbstractScalarFunction,
10+
S<:MOI.AbstractScalarSet,
11+
} <: MOI.Bridges.Constraint.SetMapBridge{T,S,MOI.LazyScalarSet{S},F,F}
12+
constraint::MOI.ConstraintIndex{F,S}
13+
end
14+
15+
MOI.Bridges.map_function(::Type{<:LazyScalarSetBridge}, f) = f
16+
17+
MOI.Bridges.inverse_map_function(::Type{<:LazyScalarSetBridge}, f) = f
18+
19+
MOI.Bridges.adjoint_map_function(::Type{<:LazyScalarSetBridge}, f) = f
20+
21+
MOI.Bridges.inverse_adjoint_map_function(::Type{<:LazyScalarSetBridge}, f) = f
22+
23+
function MOI.Bridges.map_set(
24+
::Type{LazyScalarSetBridge{T,F,S}},
25+
set::MOI.LazyScalarSet{S},
26+
) where {T,F,S}
27+
return set.set
28+
end
29+
30+
function MOI.Bridges.inverse_map_set(
31+
::Type{LazyScalarSetBridge{T,F,S}},
32+
set::S,
33+
) where {T,F,S}
34+
return MOI.LazyScalarSet(set)
35+
end
36+
37+
function MOI.supports_constraint(
38+
::Type{<:LazyScalarSetBridge},
39+
::Type{<:MOI.AbstractScalarFunction},
40+
::Type{<:MOI.LazyScalarSet},
41+
)
42+
return true
43+
end
44+
45+
function MOI.Bridges.Constraint.concrete_bridge_type(
46+
::Type{<:LazyScalarSetBridge{T}},
47+
::Type{F},
48+
::Type{MOI.LazyScalarSet{S}},
49+
) where {T,F<:MOI.AbstractScalarFunction,S<:MOI.AbstractScalarSet}
50+
return LazyScalarSetBridge{T,F,S}
51+
end

src/Utilities/sets.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ end
9090

9191
supports_shift_constant(::Type{<:MOI.Parameter}) = true
9292

93+
function supports_shift_constant(
94+
::Type{MOI.LazyScalarSet{S}},
95+
) where {S<:MOI.AbstractScalarSet}
96+
return supports_shift_constant(S)
97+
end
98+
99+
function shift_constant(set::MOI.LazyScalarSet, constant)
100+
return MOI.LazyScalarSet(shift_constant(set.set, constant))
101+
end
102+
93103
"""
94104
ScalarLinearSet{T}
95105

src/sets.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,13 @@ function Base.show(io::IO, s::VectorNonlinearOracle{T}) where {T}
28662866
return
28672867
end
28682868

2869+
"""
2870+
LazyScalarSet(set::MOI.AbstractScalarSet) <: MOI.AbstractScalarSet
2871+
"""
2872+
struct LazyScalarSet{S<:MOI.AbstractScalarSet} <: MOI.AbstractScalarSet
2873+
set::S
2874+
end
2875+
28692876
# TODO(odow): these are not necessarily isbits. They may not be safe to return
28702877
# without copying if the number is BigFloat, for example.
28712878
function Base.copy(

0 commit comments

Comments
 (0)