Skip to content

Commit 066f68b

Browse files
committed
Add doc and tests
1 parent 4835fc5 commit 066f68b

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

src/Bridges/Constraint/bridges/functionize.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ for these pairs of functions:
187187
* [`MOI.ScalarQuadraticFunction`](@ref) to [`MOI.ScalarNonlinearFunction`](@ref)
188188
* [`MOI.VectorAffineFunction`](@ref) to [`MOI.VectorQuadraticFunction`](@ref)
189189
190+
See also [`SetConversionBridge`](@ref).
191+
190192
## Source node
191193
192194
`FunctionConversionBridge` supports:

src/Bridges/Constraint/bridges/set_conversion.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
"""
2+
SetConversionBridge{T,S2,S1,F} <:
3+
MOI.Bridges.Constraint.SetMapBridge{T,S2,S1,F,F}
4+
5+
`SetConversionBridge` implements the following reformulations:
6+
7+
* ``f(x) \\in S1`` into ``f(x) \\in S2``
8+
9+
See also [`FunctionConversionBridge`](@ref).
10+
11+
## Source node
12+
13+
`SetConversionBridge` supports:
14+
15+
* `F` in `S1`
16+
17+
## Target nodes
18+
19+
`SetConversionBridge` creates:
20+
21+
* `F` in `S2`
22+
"""
23+
124
struct SetConversionBridge{T,S2,S1,F} <:
225
MOI.Bridges.Constraint.SetMapBridge{T,S2,S1,F,F}
326
constraint::MOI.ConstraintIndex{F,S2}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
module TestConstraintSetConversion
8+
9+
using Test
10+
11+
import MathOptInterface as MOI
12+
13+
function runtests()
14+
for name in names(@__MODULE__; all = true)
15+
if startswith("$(name)", "test_")
16+
@testset "$(name)" begin
17+
getfield(@__MODULE__, name)()
18+
end
19+
end
20+
end
21+
return
22+
end
23+
24+
struct Zero <: MOI.AbstractScalarSet
25+
end
26+
27+
MOI.Bridges.Constraint.conversion_cost(::Type{MOI.EqualTo{Float64}}, ::Type{Zero}) = 1.0
28+
29+
Base.convert(::Type{MOI.EqualTo{Float64}}, ::Zero) = MOI.EqualTo(0.0)
30+
31+
function test_runtests()
32+
MOI.Bridges.runtests(
33+
MOI.Bridges.Constraint.ScalarFunctionizeBridge,
34+
model -> begin
35+
x = MOI.add_variable(model)
36+
MOI.add_constraint(model, Zero())
37+
end,
38+
model -> begin
39+
x = MOI.add_variable(model)
40+
MOI.add_constraint(model, MOI.EqualTo(0.0))
41+
end,
42+
)
43+
return
44+
end
45+
46+
end # module
47+
48+
TestConstraintSetConversion.runtests()

0 commit comments

Comments
 (0)