Skip to content

Commit 01f8690

Browse files
committed
fix conflict
2 parents 82d3d56 + 9970dbd commit 01f8690

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2528
-2326
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ os:
44
- linux
55
# - osx
66
julia:
7-
- 0.7
87
- 1.0
98
- 1.1
109
notifications:

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1010
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
1111
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1212

13+
[compat]
14+
julia = "1"
15+
1316
[extras]
1417

1518
[targets]

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
environment:
22
matrix:
3-
# - julia_version: 0.7 # tested on Linux with Travis
43
- julia_version: 1.0
54

65
platform:

src/Bridges/bridgeoptimizer.jl

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,42 @@ function MOI.get(b::AbstractBridgeOptimizer,
227227
attr::MOI.AbstractConstraintAttribute,
228228
ci::CI)
229229
if is_bridged(b, typeof(ci))
230-
if MOI.is_set_by_optimize(attr)
231-
MOI.get(b, attr, bridge(b, ci))
232-
else
233-
MOI.get(b.bridged, attr, ci)
234-
end
230+
return MOI.get(b, attr, bridge(b, ci))
231+
else
232+
return MOI.get(b.model, attr, ci)
233+
end
234+
end
235+
function MOI.supports(b::AbstractBridgeOptimizer,
236+
attr::MOI.AbstractConstraintAttribute,
237+
IndexType::Type{CI{F, S}}) where {F,S}
238+
if is_bridged(b, IndexType)
239+
return MOI.supports(b, attr, concrete_bridge_type(b, F, S))
240+
else
241+
return MOI.supports(b.model, attr, IndexType)
242+
end
243+
end
244+
245+
function MOI.set(b::AbstractBridgeOptimizer,
246+
attr::MOI.AbstractConstraintAttribute,
247+
index::CI, value)
248+
if is_bridged(b, typeof(index))
249+
return MOI.set(b, attr, bridge(b, index), value)
250+
else
251+
return MOI.set(b.model, attr, index, value)
252+
end
253+
end
254+
## Getting and Setting names
255+
function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.ConstraintName,
256+
constraint_index::CI)
257+
if is_bridged(b, typeof(constraint_index))
258+
return MOI.get(b.bridged, attr, constraint_index)
235259
else
236-
MOI.get(b.model, attr, ci)
260+
return MOI.get(b.model, attr, constraint_index)
237261
end
238262
end
239-
## Setting names
263+
240264
function MOI.supports(b::AbstractBridgeOptimizer, attr::MOI.ConstraintName,
241-
Index::Type{<:CI})
265+
Index::Type{CI{F,S}}) where {F,S}
242266
if is_bridged(b, Index)
243267
return MOI.supports(b.bridged, attr, Index)
244268
else
@@ -253,6 +277,22 @@ function MOI.set(b::AbstractBridgeOptimizer, attr::MOI.ConstraintName,
253277
MOI.set(b.model, attr, constraint_index, name)
254278
end
255279
end
280+
## Getting functions and sets
281+
function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.ConstraintSet, ci::CI)
282+
if is_bridged(b, typeof(ci))
283+
return MOI.get(b.bridged, attr, ci)
284+
else
285+
return MOI.get(b.model, attr, ci)
286+
end
287+
end
288+
function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.ConstraintFunction,
289+
ci::CI)
290+
if is_bridged(b, typeof(ci))
291+
return MOI.get(b.bridged, attr, ci)
292+
else
293+
return MOI.get(b.model, attr, ci)
294+
end
295+
end
256296
## Setting functions and sets
257297
function MOI.set(b::AbstractBridgeOptimizer, ::MOI.ConstraintSet,
258298
constraint_index::CI{F, S}, set::S) where {F, S}

src/constraints.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct UnsupportedConstraint{F<:AbstractFunction, S<:AbstractSet} <: Unsupported
2222
end
2323
UnsupportedConstraint{F, S}() where {F, S} = UnsupportedConstraint{F, S}("")
2424

25-
element_name(::UnsupportedConstraint{F, S}) where {F, S} = "`$F`-in-`$S` constraints"
25+
element_name(::UnsupportedConstraint{F, S}) where {F, S} = "`$F`-in-`$S` constraint"
2626

2727
"""
2828
struct AddConstraintNotAllowed{F<:AbstractFunction, S<:AbstractSet} <: NotAllowedError

test/Bridges/Bridges.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Test
2+
3+
@testset "BridgeOptimizer" begin
4+
include("bridgeoptimizer.jl")
5+
end
6+
@testset "LazyBridgeOptimizer" begin
7+
include("lazybridgeoptimizer.jl")
8+
end
9+
@testset "Separate bridges" begin
10+
include("flip_sign_bridge.jl")
11+
include("vectorizebridge.jl")
12+
include("scalarizebridge.jl")
13+
include("slackbridge.jl")
14+
include("functionize_bridge.jl")
15+
include("intervalbridge.jl")
16+
include("rsocbridge.jl")
17+
include("quadtosocbridge.jl")
18+
include("geomeanbridge.jl")
19+
include("squarepsdbridge.jl")
20+
include("detbridge.jl")
21+
include("soctopsdbridge.jl")
22+
end
23+
include("external.jl")

test/Bridges/bridgeoptimizer.jl

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using Test
2+
3+
using MathOptInterface
4+
const MOI = MathOptInterface
5+
const MOIT = MathOptInterface.Test
6+
const MOIU = MathOptInterface.Utilities
7+
const MOIB = MathOptInterface.Bridges
8+
9+
include("simple_model.jl")
10+
include("utilities.jl")
11+
12+
struct UnknownConstraintAttribute <: MOI.AbstractConstraintAttribute end
13+
MOI.is_set_by_optimize(::UnknownConstraintAttribute) = true
14+
15+
mock = MOIU.MockOptimizer(SimpleModel{Float64}())
16+
bridged_mock = MOIB.SplitInterval{Float64}(mock)
17+
18+
@testset "Unsupported constraint attribute" begin
19+
attr = UnknownConstraintAttribute()
20+
err = ArgumentError(
21+
"Constraint bridge of type `MathOptInterface.Bridges.SplitIntervalBridge{Float64,MathOptInterface.SingleVariable}` " *
22+
"does not support accessing the attribute `$attr`.")
23+
x = MOI.add_variable(bridged_mock)
24+
ci = MOI.add_constraint(bridged_mock, MOI.SingleVariable(x),
25+
MOI.Interval(0.0, 1.0))
26+
@test_throws err MOI.get(bridged_mock, attr, ci)
27+
end
28+
29+
@testset "Issue #453" begin
30+
MOI.empty!(bridged_mock)
31+
MOIU.loadfromstring!(bridged_mock, """
32+
variables: x
33+
maxobjective: 3.0x
34+
c: 2.0x in Interval(1.0, 4.0)
35+
d: x in LessThan(1.5)
36+
""")
37+
x = MOI.get(bridged_mock, MOI.VariableIndex, "x")
38+
@test isa(x, MOI.VariableIndex)
39+
c1 = MOI.get(bridged_mock, MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64}, MOI.Interval{Float64}}, "c")
40+
@test isa(c1, MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64}, MOI.Interval{Float64}})
41+
c2 = MOI.get(bridged_mock, MOI.ConstraintIndex, "c")
42+
@test c1 == c2
43+
d1 = MOI.get(bridged_mock, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}}, "d")
44+
@test isa(d1, MOI.ConstraintIndex{MOI.SingleVariable, MOI.LessThan{Float64}})
45+
d2 = MOI.get(bridged_mock, MOI.ConstraintIndex, "d")
46+
@test d1 == d2
47+
end
48+
49+
MOI.empty!(bridged_mock)
50+
51+
@testset "Name test" begin
52+
MOIT.nametest(bridged_mock)
53+
end
54+
55+
@testset "Copy test" begin
56+
MOIT.failcopytestc(bridged_mock)
57+
MOIT.failcopytestia(bridged_mock)
58+
MOIT.failcopytestva(bridged_mock)
59+
MOIT.failcopytestca(bridged_mock)
60+
MOIT.copytest(bridged_mock, SimpleModel{Float64}())
61+
end
62+
63+
@testset "Custom test" begin
64+
model = MOIB.SplitInterval{Int}(SimpleModel{Int}())
65+
@test !MOIB.supports_bridging_constraint(model, MOI.VectorAffineFunction{Float64}, MOI.Interval{Float64})
66+
67+
x, y = MOI.add_variables(model, 2)
68+
@test MOI.get(model, MOI.NumberOfVariables()) == 2
69+
70+
f1 = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(3, x)], 7)
71+
c1 = MOI.add_constraint(model, f1, MOI.Interval(-1, 1))
72+
73+
@test MOI.get(model, MOI.ListOfConstraints()) == [(MOI.ScalarAffineFunction{Int},MOI.Interval{Int})]
74+
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.GreaterThan{Int}, 0)
75+
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}, 1)
76+
@test (@inferred MOI.get(model, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Int},MOI.Interval{Int}}())) == [c1]
77+
78+
f2 = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([2, -1], [x, y]), 2)
79+
c2 = MOI.add_constraint(model, f1, MOI.GreaterThan(-2))
80+
81+
@test MOI.get(model, MOI.ListOfConstraints()) == [(MOI.ScalarAffineFunction{Int},MOI.GreaterThan{Int}), (MOI.ScalarAffineFunction{Int},MOI.Interval{Int})]
82+
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.GreaterThan{Int}, 1)
83+
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}, 1)
84+
@test (@inferred MOI.get(model, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Int},MOI.Interval{Int}}())) == [c1]
85+
@test (@inferred MOI.get(model, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Int},MOI.GreaterThan{Int}}())) == [c2]
86+
87+
@test MOI.is_valid(model, c2)
88+
MOI.delete(model, c2)
89+
90+
@test MOI.get(model, MOI.ListOfConstraints()) == [(MOI.ScalarAffineFunction{Int},MOI.Interval{Int})]
91+
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.GreaterThan{Int}, 0)
92+
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}, 1)
93+
@test (@inferred MOI.get(model, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Int},MOI.Interval{Int}}())) == [c1]
94+
end
95+
96+
@testset "Continuous Linear" begin
97+
exclude = ["partial_start"] # VariablePrimalStart not supported.
98+
MOIT.contlineartest(bridged_mock, MOIT.TestConfig(solve=false), exclude)
99+
end

test/Bridges/detbridge.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@testset "LogDet" begin
2+
bridged_mock = MOIB.LogDet{Float64}(mock)
3+
mock.optimize! = (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, [0, 1, 0, 1, 1, 0, 1, 0, 0, 1])
4+
MOIT.logdett1vtest(bridged_mock, config)
5+
MOIT.logdett1ftest(bridged_mock, config)
6+
# Dual is not yet implemented for LogDet bridge
7+
ci = first(MOI.get(bridged_mock, MOI.ListOfConstraintIndices{MOI.VectorAffineFunction{Float64}, MOI.LogDetConeTriangle}()))
8+
test_delete_bridge(bridged_mock, ci, 5, ((MOI.VectorAffineFunction{Float64}, MOI.ExponentialCone, 0), (MOI.VectorAffineFunction{Float64}, MOI.PositiveSemidefiniteConeTriangle, 0)))
9+
end
10+
11+
@testset "RootDet" begin
12+
bridged_mock = MOIB.RootDet{Float64}(mock)
13+
mock.optimize! = (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, [1, 1, 0, 1, 1, 0, 1])
14+
MOIT.rootdett1vtest(bridged_mock, config)
15+
MOIT.rootdett1ftest(bridged_mock, config)
16+
# Dual is not yet implemented for RootDet bridge
17+
ci = first(MOI.get(bridged_mock, MOI.ListOfConstraintIndices{MOI.VectorAffineFunction{Float64}, MOI.RootDetConeTriangle}()))
18+
test_delete_bridge(bridged_mock, ci, 4, ((MOI.VectorAffineFunction{Float64}, MOI.RotatedSecondOrderCone, 0),
19+
(MOI.VectorAffineFunction{Float64}, MOI.GeometricMeanCone, 0),
20+
(MOI.VectorAffineFunction{Float64}, MOI.PositiveSemidefiniteConeTriangle, 0)))
21+
end

test/Bridges/external.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Test
2+
3+
using MathOptInterface
4+
const MOI = MathOptInterface
5+
const MOIU = MathOptInterface.Utilities
6+
7+
include("simple_model.jl")
8+
9+
# We need to test this in a module at the top level because it can't be defined
10+
# in a testset. If it runs without error, then we're okay.
11+
module TestExternalBridge
12+
using MathOptInterface
13+
14+
struct StrictlyGreaterThan <: MathOptInterface.AbstractScalarSet end
15+
struct StrictlyGreaterBridge{T} <: MathOptInterface.Bridges.AbstractBridge end
16+
17+
function StrictlyGreaterBridge(
18+
model,
19+
func::MathOptInterface.SingleVariable,
20+
set::StrictlyGreaterThan)
21+
return StrictlyGreaterBridge{Float64}()
22+
end
23+
24+
function MathOptInterface.supports_constraint(
25+
::Type{StrictlyGreaterBridge{T}},
26+
::Type{MathOptInterface.SingleVariable},
27+
::Type{StrictlyGreaterThan}) where {T}
28+
return true
29+
end
30+
31+
function MathOptInterface.Bridges.added_constraint_types(
32+
::Type{StrictlyGreaterBridge{T}},
33+
::Type{MathOptInterface.SingleVariable},
34+
::Type{StrictlyGreaterThan}) where {T}
35+
return [(
36+
MathOptInterface.SingleVariable,
37+
MathOptInterface.GreaterThan{T}
38+
)]
39+
end
40+
41+
MathOptInterface.Bridges.@bridge(StrictlyGreater, StrictlyGreaterBridge,
42+
(StrictlyGreaterThan, ),
43+
(),
44+
(),
45+
(),
46+
(MathOptInterface.SingleVariable, ),
47+
(),
48+
(),
49+
()
50+
)
51+
end
52+
53+
@testset "@bridge with external components" begin
54+
model = SimpleModel{Float64}();
55+
@test MOI.supports_constraint(model, MOI.SingleVariable, MOI.GreaterThan{Float64})
56+
@test !MOI.supports_constraint(model, MOI.SingleVariable, TestExternalBridge.StrictlyGreaterThan)
57+
58+
bridge = TestExternalBridge.StrictlyGreater{Float64}(model);
59+
@test MOI.supports_constraint(bridge, MOI.SingleVariable, MOI.GreaterThan{Float64})
60+
@test MOI.supports_constraint(bridge, MOI.SingleVariable, TestExternalBridge.StrictlyGreaterThan)
61+
end

0 commit comments

Comments
 (0)