-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from JuliaOpt/bl/intconic
Fix and test intconic tests
- Loading branch information
Showing
3 changed files
with
73 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,69 @@ | ||
# Integer conic problems | ||
|
||
function intsoc1test(model::MOI.ModelLike; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64)) | ||
function intsoc1test(model::MOI.ModelLike, config::TestConfig) | ||
atol = config.atol | ||
rtol = config.rtol | ||
#@test MOI.supportsproblem(model, MOI.ScalarAffineFunction{Float64}, | ||
# [(MOI.VectorAffineFunction{Float64},MOI.Zeros), | ||
# (MOI.SingleVariable,MOI.ZeroOne), | ||
# (MOI.VectorOfVariables,MOI.SecondOrderCone)]) | ||
@testset "INTSOC1" begin | ||
|
||
# Problem SINTSOC1 | ||
# min 0x - 2y - 1z | ||
# st x == 1 | ||
# x >= ||(y,z)|| | ||
# (y,z) binary | ||
|
||
MOI.empty!(model) | ||
@test MOI.isempty(model) | ||
|
||
MOI.canaddvariable(model) | ||
x,y,z = MOI.addvariables!(model, 3) | ||
|
||
@test MOI.canset(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}()) | ||
MOI.set!(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), MOI.ScalarAffineFunction([y,z],[-2.0,-1.0],0.0)) | ||
@test MOI.canset(model, MOI.ObjectiveSense()) | ||
MOI.set!(model, MOI.ObjectiveSense(), MOI.MinSense) | ||
|
||
@test MOI.canaddconstraint(model, MOI.VectorAffineFunction{Float64}, MOI.Zeros) | ||
ceq = MOI.addconstraint!(model, MOI.VectorAffineFunction([1],[x],[1.0],[-1.0]), MOI.Zeros(1)) | ||
@test MOI.canaddconstraint(model, MOI.VectorOfVariables, MOI.SecondOrderCone) | ||
csoc = MOI.addconstraint!(model, MOI.VectorOfVariables([x,y,z]), MOI.SecondOrderCone(3)) | ||
|
||
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}()) == 1 | ||
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}()) == 1 | ||
loc = MOI.get(model, MOI.ListOfConstraints()) | ||
@test length(loc) == 2 | ||
@test (MOI.VectorAffineFunction{Float64},MOI.Zeros) in loc | ||
@test (MOI.VectorOfVariables,MOI.SecondOrderCone) in loc | ||
|
||
@test MOI.canaddconstraint(model, typeof(MOI.SingleVariable(y)), typeof(MOI.ZeroOne)) | ||
bin1 = MOI.addconstraint!(model, MOI.SingleVariable(y), MOI.ZeroOne) | ||
@test MOI.canaddconstraint(model, typeof(MOI.SingleVariable(z)), typeof(MOI.ZeroOne)) | ||
bin2 = MOI.addconstraint!(model, MOI.SingleVariable(z), MOI.ZeroOne) | ||
|
||
if config.solve | ||
MOI.optimize!(model) | ||
|
||
@test MOI.canget(model, MOI.TerminationStatus()) | ||
@test MOI.get(model, MOI.TerminationStatus()) == MOI.Success | ||
|
||
@test MOI.canget(model, MOI.PrimalStatus()) | ||
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FeasiblePoint | ||
|
||
@test MOI.canget(model, MOI.ObjectiveValue()) | ||
@test MOI.get(model, MOI.ObjectiveValue()) ≈ -2 atol=atol rtol=rtol | ||
|
||
@test MOI.canget(model, MOI.VariablePrimal(), MOI.VariableIndex) | ||
@test MOI.get(model, MOI.VariablePrimal(), x) ≈ 1 atol=atol rtol=rtol | ||
@test MOI.get(model, MOI.VariablePrimal(), y) ≈ 1 atol=atol rtol=rtol | ||
@test MOI.get(model, MOI.VariablePrimal(), z) ≈ 0 atol=atol rtol=rtol | ||
end | ||
|
||
# Problem SINTSOC1 | ||
# min 0x - 2y - 1z | ||
# st x == 1 | ||
# x >= ||(y,z)|| | ||
# (y,z) binary | ||
|
||
MOI.empty!(model) | ||
@test MOI.isempty(model) | ||
|
||
MOI.canaddvariable(model) | ||
x,y,z = MOI.addvariables!(model, 3) | ||
|
||
@test MOI.canset(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}()) | ||
MOI.set!(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), MOI.ScalarAffineFunction([y,z],[-2.0,-1.0],0.0)) | ||
@test MOI.canset(model, MOI.ObjectiveSense()) | ||
MOI.set!(model, MOI.ObjectiveSense(), MOI.MinSense) | ||
|
||
@test MOI.canaddconstraint(model, MOI.VectorAffineFunction{Float64}, MOI.Zeros) | ||
ceq = MOI.addconstraint!(model, MOI.VectorAffineFunction([1],[x],[1.0],[-1.0]), MOI.Zeros(1)) | ||
@test MOI.canaddconstraint(model, MOI.VectorOfVariables, MOI.SecondOrderCone) | ||
csoc = MOI.addconstraint!(model, MOI.VectorOfVariables([x,y,z]), MOI.SecondOrderCone(3)) | ||
|
||
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}()) == 1 | ||
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}()) == 1 | ||
loc = MOI.get(model, MOI.ListOfConstraints()) | ||
@test length(loc) == 2 | ||
@test (MOI.VectorAffineFunction{Float64},MOI.Zeros) in loc | ||
@test (MOI.VectorOfVariables,MOI.SecondOrderCone) in loc | ||
|
||
@test MOI.canaddconstraint(model, MOI.SingleVariable, MOI.ZeroOne) | ||
bin1 = MOI.addconstraint!(model, MOI.SingleVariable(y), MOI.ZeroOne()) | ||
@test MOI.canaddconstraint(model, MOI.SingleVariable, MOI.ZeroOne) | ||
bin2 = MOI.addconstraint!(model, MOI.SingleVariable(z), MOI.ZeroOne()) | ||
|
||
if config.solve | ||
MOI.optimize!(model) | ||
|
||
@test MOI.canget(model, MOI.TerminationStatus()) | ||
@test MOI.get(model, MOI.TerminationStatus()) == MOI.Success | ||
|
||
@test MOI.canget(model, MOI.PrimalStatus()) | ||
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FeasiblePoint | ||
|
||
@test MOI.canget(model, MOI.ObjectiveValue()) | ||
@test MOI.get(model, MOI.ObjectiveValue()) ≈ -2 atol=atol rtol=rtol | ||
|
||
@test MOI.canget(model, MOI.VariablePrimal(), MOI.VariableIndex) | ||
@test MOI.get(model, MOI.VariablePrimal(), x) ≈ 1 atol=atol rtol=rtol | ||
@test MOI.get(model, MOI.VariablePrimal(), y) ≈ 1 atol=atol rtol=rtol | ||
@test MOI.get(model, MOI.VariablePrimal(), z) ≈ 0 atol=atol rtol=rtol | ||
end | ||
end | ||
|
||
function intsoctests(model::MOI.ModelLike; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64)) | ||
intsoc1test(model, atol=atol, rtol=rtol) | ||
end | ||
const intsoctests = Dict("intsoc1" => intsoc1test) | ||
|
||
function intconictests(model::MOI.ModelLike; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64)) | ||
intsoctests(model, atol=atol, rtol=rtol) | ||
end | ||
@moitestset intsoc | ||
|
||
const intconictests = Dict("intsoc" => intsoctest) | ||
|
||
@moitestset intconic true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@testset "Integer Conic" begin | ||
optimizer = MOIU.MockOptimizer(Model{Float64}()) | ||
config = MOIT.TestConfig() | ||
optimizer.evalobjective = true | ||
|
||
@testset "SOC" begin | ||
optimizer.optimize! = (optimizer::MOIU.MockOptimizer) -> MOIU.mock_optimize!(optimizer, [1.0, 1.0, 0.0]) | ||
MOIT.intsoc1test(optimizer, config) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters