From 05e9d43533d20e486977be05fcef446de67e096b Mon Sep 17 00:00:00 2001 From: Miles Lubin Date: Fri, 5 Jul 2019 15:26:41 -0400 Subject: [PATCH 1/2] Provide a default instantiation of Model Closes #766 --- docs/src/apimanual.md | 5 +-- docs/src/apireference.md | 18 +++++---- src/Utilities/model.jl | 35 +++++++++++++++++ src/sets.jl | 2 + test/Benchmarks/Benchmarks.jl | 14 ++----- test/Bridges/Constraint/indicator.jl | 4 +- test/Test/config.jl | 4 +- test/Test/contconic.jl | 4 +- test/Test/contlinear.jl | 4 +- test/Test/contquadratic.jl | 4 +- test/Test/intconic.jl | 4 +- test/Test/intlinear.jl | 4 +- test/Test/unit.jl | 13 +++---- test/Utilities/cachingoptimizer.jl | 56 +++++++++------------------- test/Utilities/constraints.jl | 4 +- test/Utilities/copy.jl | 9 ++--- test/Utilities/mockoptimizer.jl | 14 +++---- test/Utilities/model.jl | 24 ++++++------ test/Utilities/universalfallback.jl | 8 ++-- test/model.jl | 21 ----------- test/model_for_mock.jl | 9 ----- 21 files changed, 109 insertions(+), 151 deletions(-) delete mode 100644 test/model.jl delete mode 100644 test/model_for_mock.jl diff --git a/docs/src/apimanual.md b/docs/src/apimanual.md index dffff62af1..de3fbeb71f 100644 --- a/docs/src/apimanual.md +++ b/docs/src/apimanual.md @@ -1110,10 +1110,7 @@ checks that `optimizer` implements support for If the wrapper does not support building the model incrementally (i.e. with `add_variable` and `add_constraint`), then `supports_default_copy_to` can be replaced by `supports_allocate_load` if appropriate (see [Implementing copy](@ref)) and the line `const bridged = ...` can be replaced with ```julia -# Include here the functions/sets supported by the solver wrapper (not those that are supported through bridges) -MOIU.@model(ModelData, (), (MOI.EqualTo, MOI.GreaterThan, MOI.LessThan) (MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives), (), - (), (MOI.ScalarAffineFunction,), (MOI.VectorOfVariables,), (MOI.VectorAffineFunction,)) -const cache = MOIU.UniversalFallback(ModelData{Float64}()) +const cache = MOIU.UniversalFallback(MOIU.Model{Float64}()) const cached = MOIU.CachingOptimizer(cache, optimizer) const bridged = MOIB.full_bridge_optimizer(cached, Float64) ``` diff --git a/docs/src/apireference.md b/docs/src/apireference.md index 650f19cc7d..611f6f6404 100644 --- a/docs/src/apireference.md +++ b/docs/src/apireference.md @@ -406,20 +406,24 @@ DeleteNotAllowed ## Models -MOI is designed to be extensible, so there is no fixed list of possible -functions and sets. This makes it challenging to define efficient storage -representations for MOI models. For cases where the functions and sets of -interest are known in advance (for example, solvers support a fixed list of -functions and sets), we provide the [`Utilities.@model`](@ref) that macro -defines a [`ModelLike`](@ref) given a list of functions and sets to support. +[`Utilities.Model`](@ref) provides an implementation of a [`ModelLike`](@ref) +that efficiently supports all functions and sets defined within MOI. However, +given the extensibility of MOI, this might not over all use cases. [`Utilities.UniversalFallback`](@ref) is a layer that sits on top of any `ModelLike` and provides non-specialized (slower) fallbacks for constraints and attributes that the underlying `ModeLike` does not support. +For advanced use cases that need efficient support for functions and sets +defined outside of MOI (but still known at compile time), we provide the +[`Utilities.@model`](@ref) macro. + + + ```@docs -Utilities.@model +Utilities.Model Utilities.UniversalFallback +Utilities.@model ``` ## Bridges diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index f9a5584f01..9d69737826 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -690,6 +690,8 @@ _getCV(s::SymbolFun) = :($(s.cname){T, $(_getC(s))}()) _callfield(f, s::SymbolFS) = :($f(model.$(_field(s)))) _broadcastfield(b, s::SymbolFS) = :($b(f, model.$(_field(s)))) +# This macro is for expert/internal use only. Prefer the concrete Model type +# instantiated below. """ macro model(model_name, scalar_sets, typed_scalar_sets, vector_sets, typed_vector_sets, scalar_functions, typed_scalar_functions, vector_functions, typed_vector_functions) @@ -934,3 +936,36 @@ macro model(model_name, ss, sst, vs, vst, sf, sft, vf, vft) end return code end + +const LessThanIndicatorSetOne{T} = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE, MOI.LessThan{T}} +const LessThanIndicatorSetZero{T} = MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO, MOI.LessThan{T}} + +@model(Model, + (MOI.ZeroOne, MOI.Integer), + (MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval, + MOI.Semicontinuous, MOI.Semiinteger), + (MOI.Reals, MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives, + MOI.SecondOrderCone, MOI.RotatedSecondOrderCone, + MOI.GeometricMeanCone, MOI.ExponentialCone, MOI.DualExponentialCone, + MOI.PositiveSemidefiniteConeTriangle, MOI.PositiveSemidefiniteConeSquare, + MOI.RootDetConeTriangle, MOI.RootDetConeSquare, MOI.LogDetConeTriangle, + MOI.LogDetConeSquare), + (MOI.PowerCone, MOI.DualPowerCone, MOI.SOS1, MOI.SOS2, + LessThanIndicatorSetOne, LessThanIndicatorSetZero), + (), + (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction), + (MOI.VectorOfVariables,), + (MOI.VectorAffineFunction, MOI.VectorQuadraticFunction)) + +@doc raw""" + +An implementation of `ModelLike` that supports all functions and sets defined +in MOI. It is parameterized by the coefficient type. + +# Examples +```jl +model = Model{Float64}() +x = add_variable(model) +``` +""" +Model diff --git a/src/sets.jl b/src/sets.jl index e769cf3221..b785106ed8 100644 --- a/src/sets.jl +++ b/src/sets.jl @@ -1,5 +1,7 @@ # Sets +# Note: When adding a new set, also add it to Utilities.Model. + """ AbstractSet diff --git a/test/Benchmarks/Benchmarks.jl b/test/Benchmarks/Benchmarks.jl index b391376b46..534ccb8bbf 100644 --- a/test/Benchmarks/Benchmarks.jl +++ b/test/Benchmarks/Benchmarks.jl @@ -3,24 +3,18 @@ using MathOptInterface, Test const MOI = MathOptInterface const MOIU = MOI.Utilities -MOIU.@model( - BenchmarkModel, - (), (MOI.LessThan, ), (), (), - (), (MOI.ScalarAffineFunction, ), (), () -) - const NUM_BENCHMARKS = length(MOI.Benchmarks.BENCHMARKS) @testset "suite" begin suite = MOI.Benchmarks.suite() do - MOIU.MockOptimizer(BenchmarkModel{Float64}()) + MOIU.MockOptimizer(MOIU.Model{Float64}()) end @test length(suite.data) == NUM_BENCHMARKS suite = MOI.Benchmarks.suite( exclude = [r"delete_"] ) do - MOIU.MockOptimizer(BenchmarkModel{Float64}()) + MOIU.MockOptimizer(MOIU.Model{Float64}()) end # Note: update this value whenever more benchmarks are added to # `src/Benchmarks/Benchmarks.jl`. @@ -34,7 +28,7 @@ end @test !isfile(baseline) @testset "create_baseline" begin suite = MOI.Benchmarks.suite() do - MOIU.MockOptimizer(BenchmarkModel{Float64}()) + MOIU.MockOptimizer(MOIU.Model{Float64}()) end MOI.Benchmarks.create_baseline( suite, "baseline"; directory=@__DIR__, seconds = 2, verbose = true @@ -44,7 +38,7 @@ end @test isfile(baseline) @testset "compare_against_baseline" begin suite = MOI.Benchmarks.suite() do - MOIU.MockOptimizer(BenchmarkModel{Float64}()) + MOIU.MockOptimizer(MOIU.Model{Float64}()) end MOI.Benchmarks.compare_against_baseline( suite, "baseline"; directory=@__DIR__, seconds = 2, verbose = true diff --git a/test/Bridges/Constraint/indicator.jl b/test/Bridges/Constraint/indicator.jl index cf3294c8de..32ee1bbe28 100644 --- a/test/Bridges/Constraint/indicator.jl +++ b/test/Bridges/Constraint/indicator.jl @@ -8,8 +8,6 @@ const MOIB = MathOptInterface.Bridges include("../utilities.jl") -include("../../model.jl") - @testset "Indicator" begin # linear problem with indicator constraint # similar to indicator1_test with reversed z1 @@ -18,7 +16,7 @@ include("../../model.jl") # z1 == 0 ==> x2 <= 8 # z2 == 1 ==> x2 + x1/5 <= 9 # (1-z1) + z2 >= 1 <=> z2 - z1 >= 0 - model = MOIU.MockOptimizer(Model{Float64}()); + model = MOIU.MockOptimizer(MOIU.Model{Float64}()); config = MOIT.TestConfig() x1 = MOI.add_variable(model) diff --git a/test/Test/config.jl b/test/Test/config.jl index c1b949ea85..534764c596 100644 --- a/test/Test/config.jl +++ b/test/Test/config.jl @@ -4,8 +4,6 @@ const MOI = MathOptInterface const MOIT = MOI.Test const MOIU = MOI.Utilities -include("../model_for_mock.jl") - function atest(model::MOI.ModelLike, config::MOIT.TestConfig) @test config.atol == 1e-8 @test config.rtol == 1e-8 @@ -25,7 +23,7 @@ const customtests = Dict("a" => atest, MOIT.@moitestset custom @testset "TestConfig" begin - mock = MOIU.MockOptimizer(ModelForMock{Float64}()) + mock = MOIU.MockOptimizer(MOIU.Model{Float64}()) config = MOIT.TestConfig() customtest(mock, config, ["b"]) end diff --git a/test/Test/contconic.jl b/test/Test/contconic.jl index 1efbaf03c4..eea437c2b4 100644 --- a/test/Test/contconic.jl +++ b/test/Test/contconic.jl @@ -4,9 +4,7 @@ const MOI = MathOptInterface const MOIT = MOI.Test const MOIU = MOI.Utilities -include("../model.jl") - -mock = MOIU.MockOptimizer(Model{Float64}()) +mock = MOIU.MockOptimizer(MOIU.Model{Float64}()) config = MOIT.TestConfig() @testset "Linear" begin diff --git a/test/Test/contlinear.jl b/test/Test/contlinear.jl index c6200cf850..b95f205249 100644 --- a/test/Test/contlinear.jl +++ b/test/Test/contlinear.jl @@ -4,9 +4,7 @@ const MOI = MathOptInterface const MOIT = MOI.Test const MOIU = MOI.Utilities -include("../model_for_mock.jl") - -mock = MOIU.MockOptimizer(MOIU.UniversalFallback(ModelForMock{Float64}())) +mock = MOIU.MockOptimizer(MOIU.UniversalFallback(MOIU.Model{Float64}())) config = MOIT.TestConfig(basis = true) config_no_lhs_modif = MOIT.TestConfig(modify_lhs = false) diff --git a/test/Test/contquadratic.jl b/test/Test/contquadratic.jl index dd5beefbde..4850162c2b 100644 --- a/test/Test/contquadratic.jl +++ b/test/Test/contquadratic.jl @@ -4,9 +4,7 @@ const MOI = MathOptInterface const MOIT = MOI.Test const MOIU = MOI.Utilities -include("../model.jl") - -mock = MOIU.MockOptimizer(Model{Float64}()) +mock = MOIU.MockOptimizer(MOIU.Model{Float64}()) config = MOIT.TestConfig() @testset "QP" begin diff --git a/test/Test/intconic.jl b/test/Test/intconic.jl index 1a735a879a..c59d9ef9de 100644 --- a/test/Test/intconic.jl +++ b/test/Test/intconic.jl @@ -4,9 +4,7 @@ const MOI = MathOptInterface const MOIT = MOI.Test const MOIU = MOI.Utilities -include("../model.jl") - -mock = MOIU.MockOptimizer(Model{Float64}()) +mock = MOIU.MockOptimizer(MOIU.Model{Float64}()) config = MOIT.TestConfig() @testset "SOC" begin diff --git a/test/Test/intlinear.jl b/test/Test/intlinear.jl index 000473bc06..0280cfe3e7 100644 --- a/test/Test/intlinear.jl +++ b/test/Test/intlinear.jl @@ -4,9 +4,7 @@ const MOI = MathOptInterface const MOIT = MOI.Test const MOIU = MOI.Utilities -include("../model.jl") - -mock = MOIU.MockOptimizer(Model{Float64}()) +mock = MOIU.MockOptimizer(MOIU.Model{Float64}()) config = MOIT.TestConfig() MOIU.set_mock_optimize!(mock, diff --git a/test/Test/unit.jl b/test/Test/unit.jl index b978c67bbb..02e37c749d 100644 --- a/test/Test/unit.jl +++ b/test/Test/unit.jl @@ -4,21 +4,20 @@ const MOI = MathOptInterface const MOIT = MOI.Test const MOIU = MOI.Utilities -include("../model.jl") - @testset "Basic Constraint Tests" begin - mock = MOIU.MockOptimizer(Model{Float64}()) + mock = MOIU.MockOptimizer(MOIU.Model{Float64}()) config = MOIT.TestConfig() MOIT.basic_constraint_tests(mock, config) end @testset "Unit Tests" begin # `UniversalFallback` needed for `MOI.Silent` - mock = MOIU.MockOptimizer(MOIU.UniversalFallback(Model{Float64}())) + mock = MOIU.MockOptimizer(MOIU.UniversalFallback(MOIU.Model{Float64}())) MOI.set(mock, MOI.Silent(), true) config = MOIT.TestConfig() - for model in [mock, MOIU.CachingOptimizer(MOIU.UniversalFallback(Model{Float64}()), - mock)] + for model in [mock, + MOIU.CachingOptimizer(MOIU.UniversalFallback( + MOIU.Model{Float64}()), mock)] MOIT.unittest(model, config, [ "solve_blank_obj", "solve_constant_obj", @@ -343,7 +342,7 @@ end @testset "modifications" begin # `UniversalFallback` needed for `MOI.Silent` - mock = MOIU.MockOptimizer(MOIU.UniversalFallback(Model{Float64}())) + mock = MOIU.MockOptimizer(MOIU.UniversalFallback(MOIU.Model{Float64}())) config = MOIT.TestConfig() @testset "solve_set_singlevariable_lessthan" begin MOIU.set_mock_optimize!(mock, diff --git a/test/Utilities/cachingoptimizer.jl b/test/Utilities/cachingoptimizer.jl index 995eee02de..d0ea570d20 100644 --- a/test/Utilities/cachingoptimizer.jl +++ b/test/Utilities/cachingoptimizer.jl @@ -4,30 +4,13 @@ const MOI = MathOptInterface const MOIT = MOI.Test const MOIU = MOI.Utilities -include("../model.jl") -include("../model_for_mock.jl") - -MOIU.@model(ModelForCachingOptimizer, - (MOI.ZeroOne, MOI.Integer), - (MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval), - (MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives, MOI.SecondOrderCone, - MOI.RotatedSecondOrderCone, MOI.GeometricMeanCone, - MOI.ExponentialCone, MOI.DualExponentialCone, - MOI.PositiveSemidefiniteConeTriangle, MOI.RootDetConeTriangle, - MOI.LogDetConeTriangle), - (), - (), - (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction), - (MOI.VectorOfVariables,), - (MOI.VectorAffineFunction,)) - @testset "Test default attributes" begin # Without an optimizer attached (i.e., `MOI.state(model) == NO_OPTIMIZER`) we # need throw nice errors for attributes that are based on the optimizer. For # `AbstractModelAttribute`s that `is_set_by_optimize` returns `true` for, we # overload `TerminationStatus`, `PrimalStatus`, or `DualStatus` to return # sane default values. Otherwise we throw a nice error. - model = MOIU.CachingOptimizer(ModelForCachingOptimizer{Float64}(), MOIU.MANUAL) + model = MOIU.CachingOptimizer(MOIU.Model{Float64}(), MOIU.MANUAL) @test MOIU.state(model) == MOIU.NO_OPTIMIZER @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED @@ -60,34 +43,34 @@ MOIU.@model(ModelForCachingOptimizer, end @testset "Copyable solver attributes" begin - cache = MOIU.UniversalFallback(ModelForCachingOptimizer{Float64}()) + cache = MOIU.UniversalFallback(MOIU.Model{Float64}()) cached = MOIU.CachingOptimizer(cache, MOIU.MANUAL) MOI.set(cached, MOI.Silent(), true) - mock = MOIU.MockOptimizer(MOIU.UniversalFallback(ModelForMock{Float64}())) + mock = MOIU.MockOptimizer(MOIU.UniversalFallback(MOIU.Model{Float64}())) MOIU.reset_optimizer(cached, mock) @test MOI.get(mock, MOI.Silent()) @test MOI.get(cached, MOI.Silent()) MOI.set(cached, MOI.Silent(), false) @test !MOI.get(mock, MOI.Silent()) @test !MOI.get(cached, MOI.Silent()) - mock = MOIU.MockOptimizer(MOIU.UniversalFallback(ModelForMock{Float64}())) + mock = MOIU.MockOptimizer(MOIU.UniversalFallback(MOIU.Model{Float64}())) MOIU.reset_optimizer(cached, mock) @test !MOI.get(mock, MOI.Silent()) @test !MOI.get(cached, MOI.Silent()) MOI.set(cached, MOI.Silent(), true) @test MOI.get(mock, MOI.Silent()) @test MOI.get(cached, MOI.Silent()) - mock = MOIU.MockOptimizer(MOIU.UniversalFallback(ModelForMock{Float64}())) + mock = MOIU.MockOptimizer(MOIU.UniversalFallback(MOIU.Model{Float64}())) MOIU.reset_optimizer(cached, mock) @test MOI.get(mock, MOI.Silent()) @test MOI.get(cached, MOI.Silent()) end @testset "CachingOptimizer MANUAL mode" begin - m = MOIU.CachingOptimizer(ModelForCachingOptimizer{Float64}(), MOIU.MANUAL) + m = MOIU.CachingOptimizer(MOIU.Model{Float64}(), MOIU.MANUAL) @test MOIU.state(m) == MOIU.NO_OPTIMIZER - s = MOIU.MockOptimizer(ModelForMock{Float64}(), supports_names=false) + s = MOIU.MockOptimizer(MOIU.Model{Float64}(), supports_names=false) @test MOI.is_empty(s) MOIU.reset_optimizer(m, s) @test MOIU.state(m) == MOIU.EMPTY_OPTIMIZER @@ -126,9 +109,6 @@ end @test MOI.get(m, MOI.VariablePrimal(), [v]) == [3.0] @test MOI.get(m, MOIU.AttributeFromOptimizer(MOI.VariablePrimal()), v) == 3.0 - # ModelForMock doesn't support RotatedSecondOrderCone - @test !MOI.supports_constraint(m, MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) - @test MOI.supports_constraint(m.model_cache, MOI.SingleVariable, MOI.LessThan{Float64}) @test MOI.supports_constraint(m.optimizer.inner_model, MOI.SingleVariable, MOI.LessThan{Float64}) @test MOI.supports_constraint(m.optimizer, MOI.SingleVariable, MOI.LessThan{Float64}) @@ -154,7 +134,7 @@ end end @testset "CachingOptimizer AUTOMATIC mode" begin - m = MOIU.CachingOptimizer(ModelForCachingOptimizer{Float64}(), MOIU.AUTOMATIC) + m = MOIU.CachingOptimizer(MOIU.Model{Float64}(), MOIU.AUTOMATIC) @test MOIU.state(m) == MOIU.NO_OPTIMIZER v = MOI.add_variable(m) @@ -162,7 +142,7 @@ end MOI.set(m, MOI.VariableName(), v, "v") @test MOI.get(m, MOI.VariableName(), v) == "v" - s = MOIU.MockOptimizer(ModelForMock{Float64}(), supports_names=false) + s = MOIU.MockOptimizer(MOIU.Model{Float64}(), supports_names=false) @test MOI.is_empty(s) MOIU.reset_optimizer(m, s) @test MOIU.state(m) == MOIU.EMPTY_OPTIMIZER @@ -264,8 +244,8 @@ end @testset "Constructor with optimizer" begin @testset "Empty model and optimizer" begin - s = MOIU.MockOptimizer(ModelForMock{Float64}(), supports_names=false) - model = ModelForCachingOptimizer{Float64}() + s = MOIU.MockOptimizer(MOIU.Model{Float64}(), supports_names=false) + model = MOIU.Model{Float64}() m = MOIU.CachingOptimizer(model, s) @test m isa MOIU.CachingOptimizer{typeof(s), typeof(model)} @test MOI.is_empty(m) @@ -274,16 +254,16 @@ end @test MOI.get(m, MOI.SolverName()) == "Mock" end @testset "Non-empty optimizer" begin - s = MOIU.MockOptimizer(ModelForMock{Float64}(), supports_names=false) + s = MOIU.MockOptimizer(MOIU.Model{Float64}(), supports_names=false) MOI.add_variable(s) - model = ModelForCachingOptimizer{Float64}() + model = MOIU.Model{Float64}() @test MOI.is_empty(model) @test !MOI.is_empty(s) @test_throws AssertionError MOIU.CachingOptimizer(model, s) end @testset "Non-empty model" begin - s = MOIU.MockOptimizer(ModelForMock{Float64}(), supports_names=false) - model = ModelForCachingOptimizer{Float64}() + s = MOIU.MockOptimizer(MOIU.Model{Float64}(), supports_names=false) + model = MOIU.Model{Float64}() MOI.add_variable(model) @test !MOI.is_empty(model) @test MOI.is_empty(s) @@ -293,9 +273,9 @@ end for state in (MOIU.NO_OPTIMIZER, MOIU.EMPTY_OPTIMIZER, MOIU.ATTACHED_OPTIMIZER) @testset "Optimization tests in state $state and mode $mode" for mode in (MOIU.MANUAL, MOIU.AUTOMATIC) - m = MOIU.CachingOptimizer(ModelForCachingOptimizer{Float64}(), mode) + m = MOIU.CachingOptimizer(MOIU.Model{Float64}(), mode) if state != MOIU.NO_OPTIMIZER - s = MOIU.MockOptimizer(ModelForMock{Float64}(), supports_names=false) + s = MOIU.MockOptimizer(MOIU.Model{Float64}(), supports_names=false) MOIU.reset_optimizer(m, s) if state == MOIU.ATTACHED_OPTIMIZER MOIU.attach_optimizer(m) @@ -313,7 +293,7 @@ for state in (MOIU.NO_OPTIMIZER, MOIU.EMPTY_OPTIMIZER, MOIU.ATTACHED_OPTIMIZER) MOIT.failcopytestia(m) MOIT.failcopytestva(m) MOIT.failcopytestca(m) - MOIT.copytest(m, Model{Float64}()) + MOIT.copytest(m, MOIU.Model{Float64}()) end config = MOIT.TestConfig(solve=false) diff --git a/test/Utilities/constraints.jl b/test/Utilities/constraints.jl index 6216a92b39..e7927e9d2a 100644 --- a/test/Utilities/constraints.jl +++ b/test/Utilities/constraints.jl @@ -2,10 +2,8 @@ using Test import MathOptInterface const MOI = MathOptInterface -include("../model.jl") - @testset "Scalar" begin - model = Model{Float64}() + model = MOIU.Model{Float64}() x = MOI.add_variable(model) @testset "SingleVariable" begin f = MOI.SingleVariable(x) diff --git a/test/Utilities/copy.jl b/test/Utilities/copy.jl index 33968aeb55..93fb22ece9 100644 --- a/test/Utilities/copy.jl +++ b/test/Utilities/copy.jl @@ -5,7 +5,6 @@ const MOIT = MOI.Test const MOIU = MOI.Utilities include("../dummy.jl") -include("../model.jl") @testset "AUTOMATIC" begin src = DummyModel() @@ -21,20 +20,20 @@ end @testset "Default" begin @test !MOIU.supports_default_copy_to(DummyModel(), false) @test !MOIU.supports_default_copy_to(DummyModel(), true) - model = Model{Float64}() + model = MOIU.Model{Float64}() MOIT.failcopytestc(model) MOIT.failcopytestia(model) MOIT.failcopytestva(model) MOIT.failcopytestca(model) - MOIT.copytest(model, Model{Float64}()) + MOIT.copytest(model, MOIU.Model{Float64}()) end @testset "Allocate-Load" begin @test !MOIU.supports_allocate_load(DummyModel(), false) @test !MOIU.supports_allocate_load(DummyModel(), true) - mock = MOIU.MockOptimizer(Model{Float64}(), needs_allocate_load=true) + mock = MOIU.MockOptimizer(MOIU.Model{Float64}(), needs_allocate_load=true) MOIT.failcopytestc(mock) MOIT.failcopytestia(mock) MOIT.failcopytestva(mock) MOIT.failcopytestca(mock) - MOIT.copytest(mock, Model{Float64}()) + MOIT.copytest(mock, MOIU.Model{Float64}()) end diff --git a/test/Utilities/mockoptimizer.jl b/test/Utilities/mockoptimizer.jl index dfc7434dc2..ef9f6b78d2 100644 --- a/test/Utilities/mockoptimizer.jl +++ b/test/Utilities/mockoptimizer.jl @@ -4,25 +4,23 @@ const MOI = MathOptInterface const MOIT = MOI.Test const MOIU = MOI.Utilities -include("../model_for_mock.jl") - @testset "Default objective sense" begin - MOIT.default_objective_test(MOIU.MockOptimizer(ModelForMock{Float64}())) + MOIT.default_objective_test(MOIU.MockOptimizer(MOIU.Model{Float64}())) end @testset "Default statuses" begin - model = MOIU.MockOptimizer(ModelForMock{Float64}()) + model = MOIU.MockOptimizer(MOIU.Model{Float64}()) MOIT.default_status_test(model) MOI.empty!(model) MOIT.default_status_test(model) end @testset "Name test" begin - MOIT.nametest(MOIU.MockOptimizer(ModelForMock{Float64}())) + MOIT.nametest(MOIU.MockOptimizer(MOIU.Model{Float64}())) end @testset "Optimizer attributes" begin - optimizer = MOIU.MockOptimizer(ModelForMock{Float64}()) + optimizer = MOIU.MockOptimizer(MOIU.Model{Float64}()) @test MOI.supports(optimizer, MOIU.MockModelAttribute()) MOI.set(optimizer, MOIU.MockModelAttribute(), 10) @test MOI.get(optimizer, MOIU.MockModelAttribute()) == 10 @@ -44,7 +42,7 @@ end end @testset "Optimizer solve no result" begin - optimizer = MOIU.MockOptimizer(ModelForMock{Float64}()) + optimizer = MOIU.MockOptimizer(MOIU.Model{Float64}()) v1 = MOI.add_variable(optimizer) @@ -56,7 +54,7 @@ end end @testset "Optimizer solve with result" begin - optimizer = MOIU.MockOptimizer(ModelForMock{Float64}(), + optimizer = MOIU.MockOptimizer(MOIU.Model{Float64}(), eval_objective_value=false, eval_variable_constraint_dual=false) diff --git a/test/Utilities/model.jl b/test/Utilities/model.jl index 598f555ad8..b27e0dedeb 100644 --- a/test/Utilities/model.jl +++ b/test/Utilities/model.jl @@ -36,8 +36,6 @@ end MOI.ConstraintIndex{TestExternalModel.NewFunction, MOI.ZeroOne} end -include("../model.jl") - @testset "Setting lower/upper bound twice" begin @testset "flag_to_set_type" begin err = ErrorException("Invalid flag `0x11`.") @@ -47,47 +45,47 @@ include("../model.jl") @test MOIU.flag_to_set_type(0x20, T) == MOI.ZeroOne end @testset "$T" for T in [Int, Float64] - model = Model{T}() + model = MOIU.Model{T}() MOIT.set_lower_bound_twice(model, T) MOIT.set_upper_bound_twice(model, T) end end @testset "Name test" begin - MOIT.nametest(Model{Float64}()) + MOIT.nametest(MOIU.Model{Float64}()) end @testset "Valid test" begin - MOIT.validtest(Model{Float64}()) + MOIT.validtest(MOIU.Model{Float64}()) end @testset "Empty test" begin - MOIT.emptytest(Model{Float64}()) + MOIT.emptytest(MOIU.Model{Float64}()) end @testset "supports_constraint test" begin - MOIT.supports_constrainttest(Model{Float64}(), Float64, Int) - MOIT.supports_constrainttest(Model{Int}(), Int, Float64) + MOIT.supports_constrainttest(MOIU.Model{Float64}(), Float64, Int) + MOIT.supports_constrainttest(MOIU.Model{Int}(), Int, Float64) end @testset "OrderedIndices" begin - MOIT.orderedindicestest(Model{Float64}()) + MOIT.orderedindicestest(MOIU.Model{Float64}()) end @testset "Continuous Linear tests" begin config = MOIT.TestConfig(solve=false) exclude = ["partial_start"] # Model doesn't support VariablePrimalStart. - MOIT.contlineartest(Model{Float64}(), config, exclude) + MOIT.contlineartest(MOIU.Model{Float64}(), config, exclude) end @testset "Continuous Conic tests" begin config = MOIT.TestConfig(solve=false) - MOIT.contconictest(Model{Float64}(), config) + MOIT.contconictest(MOIU.Model{Float64}(), config) end @testset "Quadratic functions" begin - model = Model{Int}() + model = MOIU.Model{Int}() x, y = MOI.add_variables(model, 2) @test 2 == @inferred MOI.get(model, MOI.NumberOfVariables()) @@ -183,7 +181,7 @@ end struct SetNotSupportedBySolvers <: MOI.AbstractSet end @testset "Default fallbacks" begin @testset "set" begin - model = Model{Float64}() + model = MOIU.Model{Float64}() x = MOI.add_variable(model) func = convert(MOI.ScalarAffineFunction{Float64}, MOI.SingleVariable(x)) c = MOI.add_constraint(model, func, MOI.LessThan(0.0)) diff --git a/test/Utilities/universalfallback.jl b/test/Utilities/universalfallback.jl index cc3c20e85b..47283486e7 100644 --- a/test/Utilities/universalfallback.jl +++ b/test/Utilities/universalfallback.jl @@ -52,8 +52,6 @@ end struct UnknownOptimizerAttribute <: MOI.AbstractOptimizerAttribute end -include("../model.jl") - # A few constraint types are supported to test both the fallback and the # delegation to the internal model @MOIU.model(ModelForUniversalFallback, @@ -78,14 +76,14 @@ model = ModelForUniversalFallback{Float64}() uf = MOIU.UniversalFallback(model) @test MOI.is_empty(uf) @testset "Copy Test" begin - MOIT.copytest(uf, Model{Float64}()) + MOIT.copytest(uf, MOIU.Model{Float64}()) @test !MOI.is_empty(uf) MOI.empty!(uf) @test MOI.is_empty(uf) end @testset "Start Values Test" begin - src = MOIU.UniversalFallback(Model{Float64}()) - dest = MOIU.UniversalFallback(Model{Float64}()) + src = MOIU.UniversalFallback(MOIU.Model{Float64}()) + dest = MOIU.UniversalFallback(MOIU.Model{Float64}()) MOIT.start_values_test(dest, src) end @testset "Valid Test" begin diff --git a/test/model.jl b/test/model.jl deleted file mode 100644 index ce5daa633a..0000000000 --- a/test/model.jl +++ /dev/null @@ -1,21 +0,0 @@ - -const LessThanIndicatorSetOne{T} = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE, MOI.LessThan{T}} -const LessThanIndicatorSetZero{T} = MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO, MOI.LessThan{T}} - -# Needed by test spread over several files, defining it here make it easier to comment out tests -# Model supporting every MOI functions and sets - -MOIU.@model(Model, - (MOI.ZeroOne, MOI.Integer), - (MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval, - MOI.Semicontinuous, MOI.Semiinteger), - (MOI.Reals, MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives, - MOI.SecondOrderCone, MOI.RotatedSecondOrderCone, - MOI.GeometricMeanCone, MOI.ExponentialCone, MOI.DualExponentialCone, - MOI.PositiveSemidefiniteConeTriangle, MOI.PositiveSemidefiniteConeSquare, - MOI.RootDetConeTriangle, MOI.RootDetConeSquare, MOI.LogDetConeTriangle, - MOI.LogDetConeSquare), - (MOI.PowerCone, MOI.DualPowerCone, MOI.SOS1, MOI.SOS2, LessThanIndicatorSetOne, LessThanIndicatorSetZero), - (), (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction), - (MOI.VectorOfVariables,), - (MOI.VectorAffineFunction, MOI.VectorQuadraticFunction)) diff --git a/test/model_for_mock.jl b/test/model_for_mock.jl deleted file mode 100644 index 47066f14fb..0000000000 --- a/test/model_for_mock.jl +++ /dev/null @@ -1,9 +0,0 @@ -# Model supporting only SecondOrderCone as non-LP cone. -MOIU.@model(ModelForMock, (MOI.ZeroOne, MOI.Integer), - (MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval), - (MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives, MOI.SecondOrderCone), - (), - (), - (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction), - (MOI.VectorOfVariables,), - (MOI.VectorAffineFunction,)) From 9ab3e88e079e3810e39f684bea8b72b4a81d97e1 Mon Sep 17 00:00:00 2001 From: Miles Lubin Date: Fri, 5 Jul 2019 15:48:52 -0400 Subject: [PATCH 2/2] remove extra newlines --- docs/src/apireference.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/src/apireference.md b/docs/src/apireference.md index 611f6f6404..ddd4eeee31 100644 --- a/docs/src/apireference.md +++ b/docs/src/apireference.md @@ -418,8 +418,6 @@ For advanced use cases that need efficient support for functions and sets defined outside of MOI (but still known at compile time), we provide the [`Utilities.@model`](@ref) macro. - - ```@docs Utilities.Model Utilities.UniversalFallback