From 5313a90114b5aaf552e3ac470ece21490ab3cf0b Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 26 Jul 2021 17:50:57 +1200 Subject: [PATCH] [breaking] Remove the Allocate-Load API This API was confusing, never widely used, and didn't support bridges. --- docs/src/submodules/Utilities/overview.md | 70 ---- docs/src/submodules/Utilities/reference.md | 17 - docs/src/tutorials/implementing.md | 4 - src/Utilities/copy.jl | 17 +- src/Utilities/copy/allocate_load.jl | 445 --------------------- src/Utilities/mockoptimizer.jl | 10 +- src/Utilities/model.jl | 26 -- test/Utilities/copy.jl | 66 +-- test/errors.jl | 86 ---- 9 files changed, 12 insertions(+), 729 deletions(-) delete mode 100644 src/Utilities/copy/allocate_load.jl diff --git a/docs/src/submodules/Utilities/overview.md b/docs/src/submodules/Utilities/overview.md index 011b03391f..f744258c90 100644 --- a/docs/src/submodules/Utilities/overview.md +++ b/docs/src/submodules/Utilities/overview.md @@ -318,76 +318,6 @@ $$ \begin{aligned} In IJulia, calling `print` or ending a cell with [`Utilities.latex_formulation`](@ref) will render the model in LaTex. -## Allocate-Load - -The Allocate-Load API allows solvers that do not support loading the problem -incrementally to implement [`copy_to`](@ref) in a way that still allows -transformations to be applied in the copy between the cache and the -model if the transformations are implemented as MOI layers implementing the -Allocate-Load API. - -Loading a model using the Allocate-Load interface consists of two passes -through the model data: -1) the _allocate_ pass where the model typically records the necessary - information about the constraints and attributes such as their number and - size. This information may be used by the solver to allocate datastructures - of appropriate size. -2) the _load_ pass where the model typically loads the constraint and attribute - data to the model. - -The description above only gives a suggestion of what to achieve in each pass. -In fact the exact same constraint and attribute data is provided to each pass, -so an implementation of the Allocate-Load API is free to do whatever is more -convenient in each pass. - -The main difference between each pass, apart from the fact that one is executed -before the other during a copy, is that the allocate pass needs to create and -return new variable and constraint indices, while during the load pass the -appropriate constraint indices are provided. - -If you choose to implement the Allocate-Load API, implement the following -functions, which will be called in order: - -**Allocate** - - * [`Utilities.allocate_variables`](@ref) - * [`Utilities.allocate_constrained_variable`](@ref) - * [`Utilities.allocate_constrained_variables`](@ref) - * [`Utilities.allocate`](@ref) - * [`Utilities.allocate_constraint`](@ref) - -**Load** - - * [`Utilities.load_variables`](@ref) - * [`Utilities.load_constrained_variable`](@ref) - * [`Utilities.load_constrained_variables`](@ref) - * [`Utilities.load`](@ref) - * [`Utilities.load_constraint`](@ref) - -Note that the `_constrained_variable` functions are optional, and are only -needed if the solver requires variables be constrained on creation. - -You must also implement: -```julia -function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike; kwargs...) - return MOI.Utilities.automatic_copy_to(dest, src; kwargs...) -end - -function MOI.Utilities.supports_allocate_load( - model::Optimizer, - copy_names::Bool, -) - # If you support names... - return true - # Otherwise... - return !copy_names -end -``` -See [`Utilities.supports_allocate_load`](@ref) for more details. - -!!! warning - The Allocate-Load API should **not** be used outside [`copy_to`](@ref). - ## Utilities.MatrixOfConstraints The constraints of [`Utilities.Model`](@ref) are stored as a vector of tuples diff --git a/docs/src/submodules/Utilities/reference.md b/docs/src/submodules/Utilities/reference.md index b4777d9bfd..552b27ef47 100644 --- a/docs/src/submodules/Utilities/reference.md +++ b/docs/src/submodules/Utilities/reference.md @@ -64,23 +64,6 @@ Utilities.IndexMap Utilities.identity_index_map ``` -### [Allocate-Load API](@id allocate_load_api_ref) - -```@docs -Utilities.allocate_load -Utilities.supports_allocate_load -Utilities.allocate_variables -Utilities.allocate_constrained_variable -Utilities.allocate_constrained_variables -Utilities.allocate -Utilities.allocate_constraint -Utilities.load_variables -Utilities.load_constrained_variable -Utilities.load_constrained_variables -Utilities.load -Utilities.load_constraint -``` - ## MatrixOfConstraints ```@docs diff --git a/docs/src/tutorials/implementing.md b/docs/src/tutorials/implementing.md index 58f3dd1790..8b5a0523fc 100644 --- a/docs/src/tutorials/implementing.md +++ b/docs/src/tutorials/implementing.md @@ -376,10 +376,6 @@ To implement the [`copy_to`](@ref) interface, implement the following function: * [`copy_to`](@ref) -!!! tip - An alternative is to use the Utilities submodule to implement the - [Allocate-Load] API. - ### The incremental interface !!! warning diff --git a/src/Utilities/copy.jl b/src/Utilities/copy.jl index 9d0bf3913d..09c0262441 100644 --- a/src/Utilities/copy.jl +++ b/src/Utilities/copy.jl @@ -9,10 +9,10 @@ filter_constraints::Union{Nothing,Function} = nothing, ) -Use [`MathOptInterface.supports_incremental_interface`](@ref) and -[`Utilities.supports_allocate_load`](@ref) to automatically choose between -[`Utilities.default_copy_to`](@ref) or [`Utilities.allocate_load`](@ref) to -apply the copy operation. +A default fallback for [`MOI.copy_to`](@ref). + +To use this method, define +[`MathOptInterface.supports_incremental_interface`](@ref). If the `filter_constraints` arguments is given, only the constraints for which this function returns `true` will be copied. This function is given a @@ -24,17 +24,14 @@ function automatic_copy_to( copy_names::Bool = true, filter_constraints::Union{Nothing,Function} = nothing, ) - if MOI.supports_incremental_interface(dest, copy_names) - return default_copy_to(dest, src, copy_names, filter_constraints) - elseif supports_allocate_load(dest, copy_names) - return allocate_load(dest, src, copy_names, filter_constraints) - else + if !MOI.supports_incremental_interface(dest, copy_names) error( "Model $(typeof(dest)) does not support copy", copy_names ? " with names" : "", ".", ) end + return default_copy_to(dest, src, copy_names, filter_constraints) end @deprecate supports_default_copy_to MOI.supports_incremental_interface @@ -662,5 +659,3 @@ function default_copy_to( return idxmap end - -include("copy/allocate_load.jl") diff --git a/src/Utilities/copy/allocate_load.jl b/src/Utilities/copy/allocate_load.jl deleted file mode 100644 index 7494ff807c..0000000000 --- a/src/Utilities/copy/allocate_load.jl +++ /dev/null @@ -1,445 +0,0 @@ -# TODO deprecate this in MOI v0.7 -""" - needs_allocate_load(model::MOI.ModelLike)::Bool - -Return a `Bool` indicating whether `model` does not support `add_variables`/ -`add_constraint`/`set` but supports `allocate_variables`/`allocate_constraint` -/`allocate`/`load_variables`/`load_constraint`/`load`. -That is, the allocate-load interface need to be used to copy an model to `model`. -""" -needs_allocate_load(::MOI.ModelLike) = false - -""" - supports_allocate_load(model::MOI.ModelLike, copy_names::Bool)::Bool - -Return a `Bool` indicating whether `model` supports -[`allocate_load(model, src, copy_names=copy_names)`](@ref) if all the -attributes set to `src` and constraints added to `src` are supported by `model`. -""" -supports_allocate_load(::MOI.ModelLike, copy_names::Bool) = false - -""" - allocate_variables(model::MOI.ModelLike, nvars::Integer) - -Creates `nvars` variables and returns a vector of `nvars` variable indices. -""" -function allocate_variables end - -""" - allocate_constrained_variable( - model::MOI.ModelLike, - set::MOI.AbstractScalarSet, - ) - -Returns a tuple with the variable index and the index for the constraint to be -used in `load_allocate_constraint`. -""" -function allocate_constrained_variable( - model::MOI.ModelLike, - set::MOI.AbstractScalarSet, -) - variables = allocate_variables(model, 1) - variable = variables[1] - func = MOI.SingleVariable(variable) - constraint = allocate_constraint(model, func, set) - return variable, constraint -end - -""" - allocate_constrained_variables( - model::MOI.ModelLike, - set::MOI.AbstractVectorSet, - ) - -Returns a tuple with the variable indices and the index for the constraint to be -used in `load_allocate_constraint`. -""" -function allocate_constrained_variables( - model::MOI.ModelLike, - set::MOI.AbstractVectorSet, -) - variables = allocate_variables(model, MOI.dimension(set)) - func = MOI.VectorOfVariables(variables) - constraint = allocate_constraint(model, func, set) - return variables, constraint -end - -const ALLOCATE_LOAD_NOT_IMPLEMENTED = ErrorException( - "The Allocate-Load interface is" * " not implemented by the model", -) - -""" - allocate( - model::ModelLike, - attr::ModelLikeAttribute, - value, - ) - - allocate( - model::ModelLike, - attr::AbstractVariableAttribute, - v::VariableIndex, - value, - ) - - allocate( - model::ModelLike, - attr::AbstractConstraintAttribute, - c::ConstraintIndex, - value, - ) - -Informs `model` that `load` will be called with the same arguments after -`load_variables` is called. -""" -function allocate(model::MOI.ModelLike, args...) - return MOI.throw_set_error_fallback( - model, - args...; - error_if_supported = ALLOCATE_LOAD_NOT_IMPLEMENTED, - ) -end - -function allocate( - model::MOI.ModelLike, - attr::Union{MOI.AbstractVariableAttribute,MOI.AbstractConstraintAttribute}, - indices::Vector, - values::Vector, -) - for (index, value) in zip(indices, values) - allocate(model, attr, index, value) - end - return -end - -""" - allocate_constraint( - model::MOI.ModelLike, - f::MOI.AbstractFunction, - s::MOI.AbstractSet, - ) - -Returns the index for the constraint to be used in `load_constraint` that will -be called after `load_variables` is called. -""" -function allocate_constraint( - model::MOI.ModelLike, - func::MOI.AbstractFunction, - set::MOI.AbstractSet, -) - return MOI.throw_add_constraint_error_fallback( - model, - func, - set; - error_if_supported = ALLOCATE_LOAD_NOT_IMPLEMENTED, - ) -end - -""" - load_variables(model::MOI.ModelLike, nvars::Integer) - -Prepares `model` for [`load`](@ref) and [`load_constraint`](@ref). -""" -function load_variables end - -""" - load_constrained_variable( - model::MOI.ModelLike, vi::MOI.VariableIndex, - ci::MOI.ConstraintIndex{MOI.SingleVariable}, - set::MOI.AbstractScalarSet, - ) - -Load the constrained variable `vi` to set `set` to `model`. -""" -function load_constrained_variable( - model::MOI.ModelLike, - vi::MOI.VariableIndex, - ci::MOI.ConstraintIndex{MOI.SingleVariable}, - set::MOI.AbstractScalarSet, -) - func = MOI.SingleVariable(vi) - load_constraint(model, ci, func, set) - return -end - -""" - load_constrained_variables( - model::MOI.ModelLike, vi::MOI.VariableIndex, - ci::MOI.ConstraintIndex{MOI.VectorOfVariables}, - set::MOI.AbstractVectorSet, - ) - -Load the constrained variable `vi` to set `set` to `model`. -""" -function load_constrained_variables( - model::MOI.ModelLike, - vis::Vector{MOI.VariableIndex}, - ci::MOI.ConstraintIndex{MOI.VectorOfVariables}, - set::MOI.AbstractVectorSet, -) - func = MOI.VectorOfVariables(vis) - load_constraint(model, ci, func, set) - return -end - -""" - load( - model::ModelLike, - attr::ModelLikeAttribute, - value, - ) - - load( - model::ModelLike, - attr::AbstractVariableAttribute, - v::VariableIndex, - value, - ) - - load( - model::ModelLike, - attr::AbstractConstraintAttribute, - c::ConstraintIndex, - value, - ) - -This has the same effect that `set` with the same arguments except that -`allocate` should be called first before `load_variables`. -""" -function load(model::MOI.ModelLike, args...) - return MOI.throw_set_error_fallback( - model, - args...; - error_if_supported = ALLOCATE_LOAD_NOT_IMPLEMENTED, - ) -end - -function load( - model::MOI.ModelLike, - attr::Union{MOI.AbstractVariableAttribute,MOI.AbstractConstraintAttribute}, - indices::Vector, - values::Vector, -) - for (index, value) in zip(indices, values) - load(model, attr, index, value) - end - return -end - -""" - load_single_variable( - dest::MOI.ModelLike, - src::MOI.ModelLike, - idxmap::IndexMap, - cis_src::Vector{MOI.ConstraintIndex{MOI.SingleVariable, S}}, - ) where {S} - -Load the constraints in `cis_src` from the model `src` into the model `dest` -using `load_constrained_variable`. -""" -function load_single_variable( - dest::MOI.ModelLike, - src::MOI.ModelLike, - idxmap::IndexMap, - cis_src::Vector{MOI.ConstraintIndex{MOI.SingleVariable,S}}, -) where {S} - fs_src = MOI.get( - src, - MOI.ConstraintFunction(), - cis_src, - )::Vector{MOI.SingleVariable} - sets = MOI.get(src, MOI.ConstraintSet(), cis_src)::Vector{S} - for (ci_src, f_src, set) in zip(cis_src, fs_src, sets) - vi_dest = idxmap[f_src.variable] - ci_dest = idxmap[ci_src] - load_constrained_variable(dest, vi_dest, ci_dest, set) - end - return -end - -""" - load_vector_of_variables( - dest::MOI.ModelLike, - src::MOI.ModelLike, - idxmap::IndexMap, - cis_src::Vector{MOI.ConstraintIndex{MOI.VectorOfVariables, S}}, - ) where {S} - -Load the constraints in `cis_src` from the model `src` into the model `dest` -using `load_constrained_variable`. -""" -function load_vector_of_variables( - dest::MOI.ModelLike, - src::MOI.ModelLike, - idxmap::IndexMap, - cis_src::Vector{MOI.ConstraintIndex{MOI.VectorOfVariables,S}}, -) where {S} - fs_src = MOI.get( - src, - MOI.ConstraintFunction(), - cis_src, - )::Vector{MOI.VectorOfVariables} - sets = MOI.get(src, MOI.ConstraintSet(), cis_src)::Vector{S} - for (ci_src, f_src, set) in zip(cis_src, fs_src, sets) - vis_dest = [idxmap[vi] for vi in f_src.variables] - ci_dest = idxmap[ci_src] - load_constrained_variables(dest, vis_dest, ci_dest, set) - end - return -end - -""" - load_constraint( - model::MOI.ModelLike, - ci::MOI.ConstraintIndex, - f::MOI.AbstractFunction, - s::MOI.AbstractSet, - ) - -Sets the constraint function and set for the constraint of index `ci`. -""" -function load_constraint( - model::MOI.ModelLike, - ::MOI.ConstraintIndex, - func::MOI.AbstractFunction, - set::MOI.AbstractSet, -) - return MOI.throw_add_constraint_error_fallback( - model, - func, - set; - error_if_supported = ALLOCATE_LOAD_NOT_IMPLEMENTED, - ) -end - -function allocate_constraints( - dest::MOI.ModelLike, - src::MOI.ModelLike, - idxmap::IndexMap, - cis_src::Vector{<:MOI.ConstraintIndex}, -) - for ci_src in cis_src - f_src = MOI.get(src, MOI.ConstraintFunction(), ci_src) - s = MOI.get(src, MOI.ConstraintSet(), ci_src) - f_dest = map_indices(idxmap, f_src) - ci_dest = allocate_constraint(dest, f_dest, s) - idxmap[ci_src] = ci_dest - end -end - -function load_constraints( - dest::MOI.ModelLike, - src::MOI.ModelLike, - idxmap::IndexMap, - cis_src::Vector{<:MOI.ConstraintIndex}, -) - for ci_src in cis_src - ci_dest = idxmap[ci_src] - f_src = MOI.get(src, MOI.ConstraintFunction(), ci_src) - f_dest = map_indices(idxmap, f_src) - s = MOI.get(src, MOI.ConstraintSet(), ci_src) - load_constraint(dest, ci_dest, f_dest, s) - end - return -end - -""" - allocate_load( - dest::MOI.ModelLike, - src::MOI.ModelLike, - filter_constraints::Union{Nothing,Function} = nothing, - ) - -Implements `MOI.copy_to(dest, src)` using the Allocate-Load API. The function -[`supports_allocate_load`](@ref) can be used to check whether `dest` supports -the Allocate-Load API. - -If the `filter_constraints` arguments is given, only the constraints for which -this function returns `true` will be copied. This function is given a -constraint index as argument. -""" -function allocate_load( - dest::MOI.ModelLike, - src::MOI.ModelLike, - copy_names::Bool, - filter_constraints::Union{Nothing,Function} = nothing, -) - MOI.empty!(dest) - - vis_src = MOI.get(src, MOI.ListOfVariableIndices()) - idxmap = _index_map_for_variable_indices(vis_src) - constraint_types = MOI.get(src, MOI.ListOfConstraintTypesPresent()) - single_variable_types = - [S for (F, S) in constraint_types if F === MOI.SingleVariable] - vector_of_variables_types = - [S for (F, S) in constraint_types if F === MOI.VectorOfVariables] - - # Allocate variables - vector_of_variables_types, - vector_of_variables_allocated, - vector_of_variables_not_allocated, - single_variable_type, - single_variable_allocated, - single_variable_not_allocated = try_constrain_variables_on_creation( - dest, - src, - idxmap, - allocate_constrained_variables, - allocate_constrained_variable, - ) - - copy_free_variables(dest, idxmap, vis_src, allocate_variables) - - # Allocate variable attributes - pass_attributes(dest, src, copy_names, idxmap, vis_src, allocate) - - # Allocate model attributes - pass_attributes(dest, src, copy_names, idxmap, allocate) - - # Allocate constraints - pass_constraints( - dest, - src, - copy_names, - idxmap, - single_variable_types, - single_variable_not_allocated, - vector_of_variables_types, - vector_of_variables_not_allocated, - allocate_constraints, - allocate, - filter_constraints = filter_constraints, - ) - - # Load variables - load_variables(dest, length(vis_src)) - for cis_src in vector_of_variables_allocated - load_vector_of_variables(dest, src, idxmap, cis_src) - end - for cis_src in single_variable_allocated - load_single_variable(dest, src, idxmap, cis_src) - end - - # Load variable attributes - pass_attributes(dest, src, copy_names, idxmap, vis_src, load) - - # Load model attributes - pass_attributes(dest, src, copy_names, idxmap, load) - - # Load constraints - pass_constraints( - dest, - src, - copy_names, - idxmap, - single_variable_types, - single_variable_not_allocated, - vector_of_variables_types, - vector_of_variables_not_allocated, - load_constraints, - load, - filter_constraints = filter_constraints, - ) - - return idxmap -end diff --git a/src/Utilities/mockoptimizer.jl b/src/Utilities/mockoptimizer.jl index d8b5c88f21..dd2c7e80d5 100644 --- a/src/Utilities/mockoptimizer.jl +++ b/src/Utilities/mockoptimizer.jl @@ -12,7 +12,6 @@ mutable struct MockOptimizer{MT<:MOI.ModelLike} <: MOI.AbstractOptimizer inner_model::MT # Flags supports_names::Bool # Allows to test with optimizer not supporting names - needs_allocate_load::Bool # Allows to tests the Allocate-Load interface, see copy_to add_var_allowed::Bool # If false, the optimizer throws AddVariableNotAllowed add_con_allowed::Bool # If false, the optimizer throws AddConstraintNotAllowed modify_allowed::Bool # If false, the optimizer throws Modify...NotAllowed @@ -67,9 +66,8 @@ end function MockOptimizer( inner_model::MOI.ModelLike; supports_names = true, - needs_allocate_load = false, - add_var_allowed = !needs_allocate_load, - add_con_allowed = !needs_allocate_load, + add_var_allowed = true, + add_con_allowed = true, eval_objective_value = true, eval_dual_objective_value = true, eval_variable_constraint_dual = true, @@ -79,7 +77,6 @@ function MockOptimizer( inner_model, # Flags supports_names, - needs_allocate_load, add_var_allowed, add_con_allowed, true, @@ -924,8 +921,7 @@ function MOI.supports_incremental_interface( mock::MockOptimizer, copy_names::Bool, ) - return !mock.needs_allocate_load && - MOI.supports_incremental_interface(mock.inner_model, copy_names) + return MOI.supports_incremental_interface(mock.inner_model, copy_names) end function final_touch(uf::MockOptimizer, index_map) diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index bb7d389217..3f8b2f6da5 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -606,32 +606,6 @@ function final_touch(model::AbstractModel, index_map) return final_touch(model.constraints, index_map) end -# Allocate-Load Interface -# Even if the model does not need it and use default_copy_to, it could be used -# by a layer that needs it -supports_allocate_load(model::AbstractModel, copy_names::Bool) = true - -function allocate_variables(model::AbstractModel, nvars) - return MOI.add_variables(model, nvars) -end -allocate(model::AbstractModel, attr...) = MOI.set(model, attr...) -function allocate_constraint( - model::AbstractModel, - f::MOI.AbstractFunction, - s::MOI.AbstractSet, -) - return MOI.add_constraint(model, f, s) -end - -function load_variables(::AbstractModel, nvars) end -function load(::AbstractModel, attr...) end -function load_constraint( - ::AbstractModel, - ::CI, - ::MOI.AbstractFunction, - ::MOI.AbstractSet, -) end - # Macro to generate Model function _struct_of_constraints_type(name, subtypes, parametrized_type) diff --git a/test/Utilities/copy.jl b/test/Utilities/copy.jl index 8e3a19f07f..fd4bd8145f 100644 --- a/test/Utilities/copy.jl +++ b/test/Utilities/copy.jl @@ -171,7 +171,6 @@ end Model that distinguish variables created constrained """ struct ConstrainedVariablesModel <: MOI.ModelLike - allocate_load::Bool added_constrained::Vector{Bool} end @@ -181,11 +180,7 @@ function MOI.supports_incremental_interface( model::ConstrainedVariablesModel, ::Bool, ) - return !model.allocate_load -end - -function MOIU.supports_allocate_load(model::ConstrainedVariablesModel, ::Bool) - return model.allocate_load + return true end function MOI.copy_to( @@ -204,12 +199,6 @@ function MOI.add_variables(model::ConstrainedVariablesModel, n) return MOI.VariableIndex.(m .+ (1:n)) end -function MOIU.allocate_variables(model::ConstrainedVariablesModel, n) - return MOI.add_variables(model, n) -end - -MOIU.load_variables(::ConstrainedVariablesModel, ::Int) = nothing - function MOI.add_constrained_variables( model::ConstrainedVariablesModel, set::MOI.AbstractVectorSet, @@ -222,22 +211,6 @@ function MOI.add_constrained_variables( return MOI.VariableIndex.(m .+ (1:MOI.dimension(set))), ci end -function MOIU.allocate_constrained_variables( - model::ConstrainedVariablesModel, - set::MOI.AbstractVectorSet, -) - return MOI.add_constrained_variables(model, set) -end - -function MOIU.load_constrained_variables( - ::ConstrainedVariablesModel, - ::Vector{MOI.VariableIndex}, - ::MOI.ConstraintIndex{MOI.VectorOfVariables}, - ::MOI.AbstractVectorSet, -) - return -end - function MOI.add_constraint( ::ConstrainedVariablesModel, func::MOI.VectorOfVariables, @@ -248,45 +221,12 @@ function MOI.add_constraint( ) end -function MOIU.allocate_constraint( - model::ConstrainedVariablesModel, - func::MOI.VectorOfVariables, - set::MOI.AbstractVectorSet, -) - return MOI.add_constraint(model, func, set) -end - -function MOIU.load_constraint( - ::ConstrainedVariablesModel, - ::MOI.ConstraintIndex{MOI.VectorOfVariables}, - ::MOI.VectorOfVariables, - ::MOI.AbstractVectorSet, -) - return -end - -function test_ConstrainedVariablesModel_allocate_true() - src = MOIU.Model{Int}() - x = MOI.add_variables(src, 3) - cx = MOI.add_constraint(src, [x[1], x[3], x[1], x[2]], MOI.Nonnegatives(4)) - y, cy = MOI.add_constrained_variables(src, MOI.Nonpositives(3)) - dest = ConstrainedVariablesModel(true, Bool[]) - idxmap = MOI.copy_to(dest, src) - for vi in x - @test !dest.added_constrained[idxmap[vi].value] - end - for vi in y - @test dest.added_constrained[idxmap[vi].value] - end - return -end - -function test_ConstrainedVariablesModel_allocate_false() +function test_ConstrainedVariablesModel() src = MOIU.Model{Int}() x = MOI.add_variables(src, 3) cx = MOI.add_constraint(src, [x[1], x[3], x[1], x[2]], MOI.Nonnegatives(4)) y, cy = MOI.add_constrained_variables(src, MOI.Nonpositives(3)) - dest = ConstrainedVariablesModel(false, Bool[]) + dest = ConstrainedVariablesModel(Bool[]) idxmap = MOI.copy_to(dest, src) for vi in x @test !dest.added_constrained[idxmap[vi].value] diff --git a/test/errors.jl b/test/errors.jl index eda32a23a9..20420c1d9a 100644 --- a/test/errors.jl +++ b/test/errors.jl @@ -60,15 +60,6 @@ end function test_errors_UnsupportedConstraint() _test_errors_UnsupportedConstraint(MOI.add_constraint) - _test_errors_UnsupportedConstraint(MOI.Utilities.allocate_constraint) - _test_errors_UnsupportedConstraint() do model, func, set - return MOI.Utilities.load_constraint( - model, - MOI.ConstraintIndex{typeof(func),typeof(set)}(1), - func, - set, - ) - end return end @@ -124,39 +115,6 @@ function test_errors_add_constraint() return end -function test_errors_allocate_constraint() - model = DummyModel() - vi = MOI.VariableIndex(1) - func = MOI.SingleVariable(vi) - @test_throws( - MOI.ErrorException, - MOIU.allocate_constraint(model, func, MOI.EqualTo(0.0)), - ) - try - MOIU.allocate_constraint(model, func, MOI.EqualTo(0.0)) - catch err - @test err === MOIU.ALLOCATE_LOAD_NOT_IMPLEMENTED - end - return -end - -function test_errors_load_constraint() - model = DummyModel() - vi = MOI.VariableIndex(1) - func = MOI.SingleVariable(vi) - ci = MOI.ConstraintIndex{typeof(func),MOI.EqualTo{Float64}}(1) - @test_throws( - MOI.ErrorException, - MOIU.load_constraint(model, ci, func, MOI.EqualTo(0.0)), - ) - try - MOIU.load_constraint(model, ci, func, MOI.EqualTo(0.0)) - catch err - @test err === MOIU.ALLOCATE_LOAD_NOT_IMPLEMENTED - end - return -end - function test_errors_DeleteNotAllowed() model = DummyModel() vi = MOI.VariableIndex(1) @@ -211,8 +169,6 @@ end function test_errors_unsupported_attribute() _test_unsupported_attribute(MOI.set) - _test_unsupported_attribute(MOI.Utilities.load) - _test_unsupported_attribute(MOI.Utilities.allocate) return end @@ -233,48 +189,6 @@ function test_errors_SetAttributeNotAllowed() return end -function test_errors_allocate() - model = DummyModel() - vi = MOI.VariableIndex(1) - func = MOI.SingleVariable(vi) - ci = MOI.ConstraintIndex{typeof(func),MOI.EqualTo{Float64}}(1) - @test_throws( - MOI.ErrorException, - MOI.Utilities.allocate(model, MOI.ObjectiveSense(), MOI.MAX_SENSE), - ) - try - MOI.Utilities.allocate(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) - catch err - @test err === MOIU.ALLOCATE_LOAD_NOT_IMPLEMENTED - end - @test_throws( - MOI.ErrorException, - MOI.Utilities.allocate(model, MOI.ConstraintPrimalStart(), ci, 0.0), - ) - return -end - -function test_errors_load() - model = DummyModel() - vi = MOI.VariableIndex(1) - func = MOI.SingleVariable(vi) - ci = MOI.ConstraintIndex{typeof(func),MOI.EqualTo{Float64}}(1) - @test_throws( - MOI.ErrorException, - MOI.Utilities.load(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) - ) - try - MOI.Utilities.load(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) - catch err - @test err === MOIU.ALLOCATE_LOAD_NOT_IMPLEMENTED - end - @test_throws( - MOI.ErrorException, - MOI.Utilities.load(model, MOI.ConstraintPrimalStart(), ci, 0.0), - ) - return -end - function test_errors_ConstraintFunction_NotAllowed() model = DummyModel() vi = MOI.VariableIndex(1)