Skip to content

Commit 4124111

Browse files
committed
Fix and test intconic tests
1 parent a88cb73 commit 4124111

File tree

3 files changed

+73
-63
lines changed

3 files changed

+73
-63
lines changed

src/Test/intconic.jl

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,69 @@
11
# Integer conic problems
22

3-
function intsoc1test(model::MOI.ModelLike; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64))
3+
function intsoc1test(model::MOI.ModelLike, config::TestConfig)
4+
atol = config.atol
5+
rtol = config.rtol
46
#@test MOI.supportsproblem(model, MOI.ScalarAffineFunction{Float64},
57
# [(MOI.VectorAffineFunction{Float64},MOI.Zeros),
68
# (MOI.SingleVariable,MOI.ZeroOne),
79
# (MOI.VectorOfVariables,MOI.SecondOrderCone)])
8-
@testset "INTSOC1" begin
9-
10-
# Problem SINTSOC1
11-
# min 0x - 2y - 1z
12-
# st x == 1
13-
# x >= ||(y,z)||
14-
# (y,z) binary
15-
16-
MOI.empty!(model)
17-
@test MOI.isempty(model)
18-
19-
MOI.canaddvariable(model)
20-
x,y,z = MOI.addvariables!(model, 3)
21-
22-
@test MOI.canset(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}())
23-
MOI.set!(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), MOI.ScalarAffineFunction([y,z],[-2.0,-1.0],0.0))
24-
@test MOI.canset(model, MOI.ObjectiveSense())
25-
MOI.set!(model, MOI.ObjectiveSense(), MOI.MinSense)
26-
27-
@test MOI.canaddconstraint(model, MOI.VectorAffineFunction{Float64}, MOI.Zeros)
28-
ceq = MOI.addconstraint!(model, MOI.VectorAffineFunction([1],[x],[1.0],[-1.0]), MOI.Zeros(1))
29-
@test MOI.canaddconstraint(model, MOI.VectorOfVariables, MOI.SecondOrderCone)
30-
csoc = MOI.addconstraint!(model, MOI.VectorOfVariables([x,y,z]), MOI.SecondOrderCone(3))
31-
32-
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}()) == 1
33-
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}()) == 1
34-
loc = MOI.get(model, MOI.ListOfConstraints())
35-
@test length(loc) == 2
36-
@test (MOI.VectorAffineFunction{Float64},MOI.Zeros) in loc
37-
@test (MOI.VectorOfVariables,MOI.SecondOrderCone) in loc
38-
39-
@test MOI.canaddconstraint(model, typeof(MOI.SingleVariable(y)), typeof(MOI.ZeroOne))
40-
bin1 = MOI.addconstraint!(model, MOI.SingleVariable(y), MOI.ZeroOne)
41-
@test MOI.canaddconstraint(model, typeof(MOI.SingleVariable(z)), typeof(MOI.ZeroOne))
42-
bin2 = MOI.addconstraint!(model, MOI.SingleVariable(z), MOI.ZeroOne)
43-
44-
if config.solve
45-
MOI.optimize!(model)
46-
47-
@test MOI.canget(model, MOI.TerminationStatus())
48-
@test MOI.get(model, MOI.TerminationStatus()) == MOI.Success
49-
50-
@test MOI.canget(model, MOI.PrimalStatus())
51-
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FeasiblePoint
52-
53-
@test MOI.canget(model, MOI.ObjectiveValue())
54-
@test MOI.get(model, MOI.ObjectiveValue()) -2 atol=atol rtol=rtol
55-
56-
@test MOI.canget(model, MOI.VariablePrimal(), MOI.VariableIndex)
57-
@test MOI.get(model, MOI.VariablePrimal(), x) 1 atol=atol rtol=rtol
58-
@test MOI.get(model, MOI.VariablePrimal(), y) 1 atol=atol rtol=rtol
59-
@test MOI.get(model, MOI.VariablePrimal(), z) 0 atol=atol rtol=rtol
60-
end
61-
10+
# Problem SINTSOC1
11+
# min 0x - 2y - 1z
12+
# st x == 1
13+
# x >= ||(y,z)||
14+
# (y,z) binary
15+
16+
MOI.empty!(model)
17+
@test MOI.isempty(model)
18+
19+
MOI.canaddvariable(model)
20+
x,y,z = MOI.addvariables!(model, 3)
21+
22+
@test MOI.canset(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}())
23+
MOI.set!(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), MOI.ScalarAffineFunction([y,z],[-2.0,-1.0],0.0))
24+
@test MOI.canset(model, MOI.ObjectiveSense())
25+
MOI.set!(model, MOI.ObjectiveSense(), MOI.MinSense)
26+
27+
@test MOI.canaddconstraint(model, MOI.VectorAffineFunction{Float64}, MOI.Zeros)
28+
ceq = MOI.addconstraint!(model, MOI.VectorAffineFunction([1],[x],[1.0],[-1.0]), MOI.Zeros(1))
29+
@test MOI.canaddconstraint(model, MOI.VectorOfVariables, MOI.SecondOrderCone)
30+
csoc = MOI.addconstraint!(model, MOI.VectorOfVariables([x,y,z]), MOI.SecondOrderCone(3))
31+
32+
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}()) == 1
33+
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}()) == 1
34+
loc = MOI.get(model, MOI.ListOfConstraints())
35+
@test length(loc) == 2
36+
@test (MOI.VectorAffineFunction{Float64},MOI.Zeros) in loc
37+
@test (MOI.VectorOfVariables,MOI.SecondOrderCone) in loc
38+
39+
@test MOI.canaddconstraint(model, MOI.SingleVariable, MOI.ZeroOne)
40+
bin1 = MOI.addconstraint!(model, MOI.SingleVariable(y), MOI.ZeroOne())
41+
@test MOI.canaddconstraint(model, MOI.SingleVariable, MOI.ZeroOne)
42+
bin2 = MOI.addconstraint!(model, MOI.SingleVariable(z), MOI.ZeroOne())
43+
44+
if config.solve
45+
MOI.optimize!(model)
46+
47+
@test MOI.canget(model, MOI.TerminationStatus())
48+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.Success
49+
50+
@test MOI.canget(model, MOI.PrimalStatus())
51+
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FeasiblePoint
52+
53+
@test MOI.canget(model, MOI.ObjectiveValue())
54+
@test MOI.get(model, MOI.ObjectiveValue()) -2 atol=atol rtol=rtol
55+
56+
@test MOI.canget(model, MOI.VariablePrimal(), MOI.VariableIndex)
57+
@test MOI.get(model, MOI.VariablePrimal(), x) 1 atol=atol rtol=rtol
58+
@test MOI.get(model, MOI.VariablePrimal(), y) 1 atol=atol rtol=rtol
59+
@test MOI.get(model, MOI.VariablePrimal(), z) 0 atol=atol rtol=rtol
6260
end
6361
end
6462

65-
function intsoctests(model::MOI.ModelLike; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64))
66-
intsoc1test(model, atol=atol, rtol=rtol)
67-
end
63+
const intsoctests = Dict("intsoc1" => intsoc1test)
6864

69-
function intconictests(model::MOI.ModelLike; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64))
70-
intsoctests(model, atol=atol, rtol=rtol)
71-
end
65+
@moitestset intsoc
66+
67+
const intconictests = Dict("intsoc" => intsoctest)
68+
69+
@moitestset intconic true

test/intconic.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@testset "Integer Conic" begin
2+
optimizer = MOIU.MockOptimizer(Model{Float64}())
3+
config = MOIT.TestConfig()
4+
optimizer.evalobjective = true
5+
6+
@testset "SOC" begin
7+
optimizer.optimize! = (optimizer::MOIU.MockOptimizer) -> MOIU.mock_optimize!(optimizer, [1.0, 1.0, 0.0])
8+
MOIT.intsoc1test(optimizer, config)
9+
end
10+
end

test/runtests.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ include("interval.jl")
1111
# Needed by test spread over several files, defining it here make it easier to comment out tests
1212
# Model supporting every MOI functions and sets
1313
MOIU.@model(Model,
14-
(), # <- example of giving no set
14+
(ZeroOne,),
1515
(EqualTo, GreaterThan, LessThan, Interval),
1616
(Reals, Zeros, Nonnegatives, Nonpositives, SecondOrderCone, RotatedSecondOrderCone, GeometricMeanCone, ExponentialCone, DualExponentialCone, PositiveSemidefiniteConeTriangle, RootDetConeTriangle, LogDetConeTriangle),
1717
(PowerCone, DualPowerCone),
18-
(SingleVariable,), # <- example of giving only one set
18+
(SingleVariable,),
1919
(ScalarAffineFunction, ScalarQuadraticFunction),
2020
(VectorOfVariables,),
2121
(VectorAffineFunction, VectorQuadraticFunction))
@@ -35,3 +35,5 @@ include("copy.jl")
3535
# It tests that the ConstraintPrimal value requested in the tests is consistent with the VariablePrimal
3636
include("contlinear.jl")
3737
include("contconic.jl")
38+
39+
include("intconic.jl")

0 commit comments

Comments
 (0)