Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jun 12, 2024
1 parent 8b6ef74 commit 28fb249
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
1 change: 1 addition & 0 deletions docs/src/submodules/Bridges/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Bridges.debug_supports
## [SetMap API](@id constraint_set_map)

```@docs
Bridges.MapNotInvertible
Bridges.map_set
Bridges.inverse_map_set
Bridges.map_function
Expand Down
16 changes: 10 additions & 6 deletions src/Bridges/Constraint/set_map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ function MOI.get(
func = try
MOI.Bridges.inverse_map_function(bridge, mapped_func)
catch err
# MapNotInvertible is thrown if the bridge does not support inverting
# the function. The user doesn't need to know this, only that they
# cannot get the attribute.
if err isa MOI.Bridges.MapNotInvertible
throw(MOI.GetAttributeNotAllowed(attr))

Check warning on line 112 in src/Bridges/Constraint/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/set_map.jl#L111-L112

Added lines #L111 - L112 were not covered by tests
else
rethrow(err)
end
rethrow(err)

Check warning on line 114 in src/Bridges/Constraint/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/set_map.jl#L114

Added line #L114 was not covered by tests
end
return MOI.Utilities.convert_approx(G, func)
end
Expand Down Expand Up @@ -154,14 +156,16 @@ function MOI.get(
if value === nothing
return nothing
end
return try
MOI.Bridges.inverse_map_function(bridge, value)
try
return MOI.Bridges.inverse_map_function(bridge, value)
catch err
# MapNotInvertible is thrown if the bridge does not support inverting
# the function. The user doesn't need to know this, only that they
# cannot get the attribute.
if err isa MOI.Bridges.MapNotInvertible
throw(MOI.GetAttributeNotAllowed(attr))

Check warning on line 166 in src/Bridges/Constraint/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/set_map.jl#L165-L166

Added lines #L165 - L166 were not covered by tests
else
rethrow(err)
end
rethrow(err)

Check warning on line 168 in src/Bridges/Constraint/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/set_map.jl#L168

Added line #L168 was not covered by tests
end
end

Expand Down
65 changes: 31 additions & 34 deletions src/Bridges/set_map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,25 @@ used for getting the [`MOI.ConstraintSet`](@ref).
function inverse_map_set end

"""
map_function(bridge::MOI.Bridges.AbstractBridge, func)
map_function(::Type{BT}, func) where {BT}
Return the image of `func` through the linear map `A` defined in
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref). This is
used for getting the [`MOI.ConstraintPrimal`](@ref) of variable
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref).
This function is used for getting the [`MOI.ConstraintPrimal`](@ref) of variable
bridges. For constraint bridges, this is used for bridging the constraint,
setting the [`MOI.ConstraintFunction`](@ref) and
[`MOI.ConstraintPrimalStart`](@ref) and
modifying the function with [`MOI.modify`](@ref).
setting the [`MOI.ConstraintFunction`](@ref) and [`MOI.ConstraintPrimalStart`](@ref)
and modifying the function with [`MOI.modify`](@ref).
The method can alternatively be defined on the bridge type. This legacy
interface is kept for backward compatibility.
"""
function map_function(bridge::AbstractBridge, func)
return map_function(typeof(bridge), func)

Check warning on line 52 in src/Bridges/set_map.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/set_map.jl#L51-L52

Added lines #L51 - L52 were not covered by tests
end

"""
map_function(::Type{BT}, func, i::IndexInVector) where {BT}
Return the scalar function at the `i`th index of the vector function that
Expand All @@ -52,77 +61,65 @@ would be returned by `map_function(BT, func)` except that it may compute the
the [`MOI.VariablePrimal`](@ref) and
[`MOI.VariablePrimalStart`](@ref) of variable bridges.
"""
function map_function end

function map_function(bridge::AbstractBridge, func)
return map_function(typeof(bridge), func)
end

function map_function(::Type{BT}, func, i::IndexInVector) where {BT}
return MOI.Utilities.eachscalar(map_function(BT, func))[i.value]
end

"""
inverse_map_function(bridge::MOI.Bridges.AbstractBridge, func)
inverse_map_function(::Type{BT}, func) where {BT}
Return the image of `func` through the inverse of the linear map `A` defined in
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref). This is
used by [`Variable.unbridged_map`](@ref) and for setting the
[`MOI.VariablePrimalStart`](@ref) of variable bridges
and for getting the [`MOI.ConstraintFunction`](@ref),
the [`MOI.ConstraintPrimal`](@ref) and the
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref).
This function is used by [`Variable.unbridged_map`](@ref) and for setting the
[`MOI.VariablePrimalStart`](@ref) of variable bridges and for getting the
[`MOI.ConstraintFunction`](@ref), the [`MOI.ConstraintPrimal`](@ref) and the
[`MOI.ConstraintPrimalStart`](@ref) of constraint bridges.
If the linear map `A` is not invertible, the error [`MapNotInvertible`](@ref) is
thrown.
inverse_map_function(::Type{BT}, func) where {BT}
The method can alternatively be defined on the bridge type. This legacy
interface is kept for backward compatibility.
"""
function inverse_map_function end

function inverse_map_function(bridge::AbstractBridge, func)
return inverse_map_function(typeof(bridge), func)
end

"""
adjoint_map_function(bridge::MOI.Bridges.AbstractBridge, func)
adjoint_map_function(::Type{BT}, func) where {BT}
Return the image of `func` through the adjoint of the linear map `A` defined in
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref). This is
used for getting the [`MOI.ConstraintDual`](@ref) and
[`MOI.ConstraintDualStart`](@ref) of constraint bridges.
[`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref).
adjoint_map_function(::Type{BT}, func) where {BT}
This function is used for getting the [`MOI.ConstraintDual`](@ref) and
[`MOI.ConstraintDualStart`](@ref) of constraint bridges.
The method can alternatively be defined on the bridge type. This legacy
interface is kept for backward compatibility.
"""
function adjoint_map_function end

function adjoint_map_function(bridge::AbstractBridge, func)
return adjoint_map_function(typeof(bridge), func)
end

"""
inverse_adjoint_map_function(bridge::MOI.Bridges.AbstractBridge, func)
inverse_adjoint_map_function(::Type{BT}, func) where {BT}
Return the image of `func` through the inverse of the adjoint of the linear map
`A` defined in [`Variable.SetMapBridge`](@ref) and
[`Constraint.SetMapBridge`](@ref). This is used for getting the
[`MOI.ConstraintDual`](@ref) of variable bridges and setting the
[`MOI.ConstraintDualStart`](@ref) of constraint bridges.
`A` defined in [`Variable.SetMapBridge`](@ref) and [`Constraint.SetMapBridge`](@ref).
This function is used for getting the [`MOI.ConstraintDual`](@ref) of variable
bridges and setting the [`MOI.ConstraintDualStart`](@ref) of constraint bridges.
If the linear map `A` is not invertible, the error [`MapNotInvertible`](@ref) is
thrown.
inverse_adjoint_map_function(::Type{BT}, func) where {BT}
The method can alternatively be defined on the bridge type. This legacy
interface is kept for backward compatibility.
"""
function inverse_adjoint_map_function end

function inverse_adjoint_map_function(bridge::AbstractBridge, func)
return inverse_adjoint_map_function(typeof(bridge), func)
end

0 comments on commit 28fb249

Please sign in to comment.