Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Bridges/Constraint/Constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function add_all_bridges(model, ::Type{T}) where {T}
# It is also really useful only to PATHSolver.jl, which could add this
# to MOI.ListOfRequiredBridges.
MOI.Bridges.add_bridge(model, IntegerToZeroOneBridge{T})
MOI.Bridges.add_bridge(model, LazyScalarSetBridge{T})
MOI.Bridges.add_bridge(model, LessToGreaterBridge{T})
if T <: AbstractFloat # See note in docstring of AbstractToIntervalBridge
MOI.Bridges.add_bridge(model, LessToIntervalBridge{T})
Expand Down
51 changes: 51 additions & 0 deletions src/Bridges/Constraint/bridges/LazyScalarSetBridge.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.

struct LazyScalarSetBridge{
T,
F<:MOI.AbstractScalarFunction,
S<:MOI.AbstractScalarSet,
} <: MOI.Bridges.Constraint.SetMapBridge{T,S,MOI.LazyScalarSet{S},F,F}
constraint::MOI.ConstraintIndex{F,S}
end

MOI.Bridges.map_function(::Type{<:LazyScalarSetBridge}, f) = f

MOI.Bridges.inverse_map_function(::Type{<:LazyScalarSetBridge}, f) = f

MOI.Bridges.adjoint_map_function(::Type{<:LazyScalarSetBridge}, f) = f

MOI.Bridges.inverse_adjoint_map_function(::Type{<:LazyScalarSetBridge}, f) = f

function MOI.Bridges.map_set(
::Type{LazyScalarSetBridge{T,F,S}},
set::MOI.LazyScalarSet{S},
) where {T,F,S}
return set.set
end

function MOI.Bridges.inverse_map_set(
::Type{LazyScalarSetBridge{T,F,S}},
set::S,
) where {T,F,S}
return MOI.LazyScalarSet(set)
end

function MOI.supports_constraint(
::Type{<:LazyScalarSetBridge},
::Type{<:MOI.AbstractScalarFunction},
::Type{<:MOI.LazyScalarSet},
)
return true
end

function MOI.Bridges.Constraint.concrete_bridge_type(
::Type{<:LazyScalarSetBridge{T}},
::Type{F},
::Type{MOI.LazyScalarSet{S}},
) where {T,F<:MOI.AbstractScalarFunction,S<:MOI.AbstractScalarSet}
return LazyScalarSetBridge{T,F,S}
end
10 changes: 10 additions & 0 deletions src/Utilities/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ end

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

function supports_shift_constant(
::Type{MOI.LazyScalarSet{S}},
) where {S<:MOI.AbstractScalarSet}
return supports_shift_constant(S)
end

function shift_constant(set::MOI.LazyScalarSet, constant)
return MOI.LazyScalarSet(shift_constant(set.set, constant))
end

"""
ScalarLinearSet{T}

Expand Down
7 changes: 7 additions & 0 deletions src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2866,6 +2866,13 @@ function Base.show(io::IO, s::VectorNonlinearOracle{T}) where {T}
return
end

"""
LazyScalarSet(set::AbstractScalarSet) <: AbstractScalarSet
"""
struct LazyScalarSet{S<:AbstractScalarSet} <: AbstractScalarSet
set::S
end

# TODO(odow): these are not necessarily isbits. They may not be safe to return
# without copying if the number is BigFloat, for example.
function Base.copy(
Expand Down
Loading