Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions docs/src/submodules/Utilities/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,14 @@ function _copy_to(
return
end

function MOI.copy_to(
dest::Optimizer,
src::Model;
copy_names::Bool = false
)
function MOI.copy_to(dest::Optimizer, src::Model)
_copy_to(dest, src)
return MOI.Utilities.identity_index_map(src)
end

function MOI.copy_to(
dest::Optimizer,
src::MOI.Utilities.UniversalFallback{Model};
copy_names::Bool = false
src::MOI.Utilities.UniversalFallback{Model},
)
# Copy attributes from `src` to `dest` and error in case any unsupported
# constraints or attributes are set in `UniversalFallback`.
Expand All @@ -395,8 +390,7 @@ end

function MOI.copy_to(
dest::Optimizer,
src::MOI.ModelLike;
copy_names::Bool = false
src::MOI.ModelLike,
)
model = Model()
index_map = MOI.copy_to(model, src)
Expand Down
7 changes: 1 addition & 6 deletions docs/src/tutorials/implementing.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,12 @@ If you don't want to implement [`copy_to`](@ref), e.g., because the solver has
no API for building the problem in a single function call, define the following
fallback:
```julia
# If you support VariableName and ConstraintName...
MOI.supports_incremental_interface(::Optimizer, copy_names::Bool) = true
# Otherwise...
MOI.supports_incremental_interface(::Optimizer, copy_names::Bool) = !copy_names
MOI.supports_incremental_interface(::Optimizer) = true

function MOI.copy_to(dest::Optimizer, src::MOI.ModelLike; kwargs...)
return MOI.Utilities.default_copy_to(dest, src; kwargs...)
end
```
See [`supports_incremental_interface`](@ref) for more details on whether to
implement the `true` or `!copy_names` version.

## [Names](@id implement_names)

Expand Down
7 changes: 2 additions & 5 deletions src/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,8 @@ function MOI.copy_to(
return MOIU.default_copy_to(dest, src; kwargs...)
end

function MOI.supports_incremental_interface(
b::AbstractBridgeOptimizer,
copy_names::Bool,
)
return MOI.supports_incremental_interface(b.model, copy_names)
function MOI.supports_incremental_interface(b::AbstractBridgeOptimizer)
return MOI.supports_incremental_interface(b.model)
end
function MOIU.final_touch(uf::AbstractBridgeOptimizer, index_map)
return MOIU.final_touch(uf.model, index_map)
Expand Down
76 changes: 38 additions & 38 deletions src/DeprecatedTest/contconic.jl

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions src/DeprecatedTest/contlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function linear1test(model::MOI.ModelLike, config::Config{T}) where {T}
# min -x
# st x + y <= 1 (x + y - 1 ∈ Nonpositives)
# x, y >= 0 (x, y ∈ Nonnegatives)
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -498,7 +498,7 @@ function linear2test(model::MOI.ModelLike, config::Config{T}) where {T}
# Min -x
# s.t. x + y <= 1
# x, y >= 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -596,7 +596,7 @@ function linear3test(model::MOI.ModelLike, config::Config{T}) where {T}
# min x
# s.t. x >= 0
# x >= 3
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -715,7 +715,7 @@ end
function linear4test(model::MOI.ModelLike, config::Config{T}) where {T}
atol = config.atol
rtol = config.rtol
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -810,7 +810,7 @@ function linear5test(model::MOI.ModelLike, config::Config{T}) where {T}
# x >= 0, y >= 0
#
# solution: x = 1.3333333, y = 1.3333333, objv = 2.66666666
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -950,7 +950,7 @@ end
function linear6test(model::MOI.ModelLike, config::Config{T}) where {T}
atol = config.atol
rtol = config.rtol
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1069,7 +1069,7 @@ function linear7test(model::MOI.ModelLike, config::Config{T}) where {T}
# s.t. - z == - 1 (c1)
# w == 1 (c2)
# i.e. z == w == 1
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1202,7 +1202,7 @@ function linear8atest(model::MOI.ModelLike, config::Config{T}) where {T}
# min x
# s.t. 2x+y <= -1
# x,y >= 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1281,7 +1281,7 @@ function linear8btest(model::MOI.ModelLike, config::Config{T}) where {T}
# min -x-y
# s.t. -x+2y <= 0
# x,y >= 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1351,7 +1351,7 @@ function linear8ctest(model::MOI.ModelLike, config::Config{T}) where {T}
# min -x-y
# s.t. x-y == 0
# x,y >= 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1430,7 +1430,7 @@ function linear9test(model::MOI.ModelLike, config::Config{T}) where {T}
#
# solution: (59.0909, 36.3636)
# objv: 71818.1818
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1523,7 +1523,7 @@ function linear10test(model::MOI.ModelLike, config::Config{T}) where {T}
#
# s.t. 5 <= x + y <= 10
# x, y >= 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1699,7 +1699,7 @@ function linear10btest(model::MOI.ModelLike, config::Config{T}) where {T}
#
# s.t. -1 <= x + y <= 10
# x, y >= 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1807,7 +1807,7 @@ function linear11test(model::MOI.ModelLike, config::Config{T}) where {T}
# w + z == 1
# w >= 0, z <= 0
# sol: w = 1, z = 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1883,7 +1883,7 @@ function linear12test(model::MOI.ModelLike, config::Config{T}) where {T}
# s.t. 2x-3y <= -7
# y <= 2
# x,y >= 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -1967,7 +1967,7 @@ function linear13test(model::MOI.ModelLike, config::Config{T}) where {T}
# find x, y
# s.t. 2x + 3y >= 1
# x - y == 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports_constraint(
model,
MOI.ScalarAffineFunction{T},
Expand Down Expand Up @@ -2034,7 +2034,7 @@ function linear14test(model::MOI.ModelLike, config::Config{T}) where {T}
# s.t. 3x + 2y + z <= 2
# x, y, z >= 0
# z <= 1
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down Expand Up @@ -2172,7 +2172,7 @@ function linear15test(model::MOI.ModelLike, config::Config{T}) where {T}
# minimize 0
# s.t. 0 == 0
# x == 1
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down
20 changes: 10 additions & 10 deletions src/DeprecatedTest/contquadratic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function qp1test(model::MOI.ModelLike, config::Config)
# st x + 2y + 3z >= 4 (c1)
# x + y >= 1 (c2)
# x, y, z \in R
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
Expand Down Expand Up @@ -107,7 +107,7 @@ function qp2test(model::MOI.ModelLike, config::Config)
# st x + 2y + 3z >= 4 (c1)
# x + y >= 1 (c2)
# x, y, z \in R
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
Expand Down Expand Up @@ -241,7 +241,7 @@ function qp3test(model::MOI.ModelLike, config::Config)
# minimize 2 x^2 + y^2 + xy + x + y + 1
# s.t. x, y >= 0
# x + y = 1
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
Expand Down Expand Up @@ -363,7 +363,7 @@ function qcp1test(model::MOI.ModelLike, config::Config)
# x² + y <= 2 (c2)
# Optimal solution
# x = 1/2, y = 7/4
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -476,7 +476,7 @@ function qcp2test(model::MOI.ModelLike, config::Config)
rtol = config.rtol
# Max x
# s.t. x^2 <= 2 (c)
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -542,7 +542,7 @@ function qcp3test(model::MOI.ModelLike, config::Config)
rtol = config.rtol
# Min -x
# s.t. x^2 <= 2
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -612,7 +612,7 @@ function _qcp4test(model::MOI.ModelLike, config::Config, less_than::Bool)
# Max x
# s.t. x^2 + x * y + y^2 <= 3 (c)
# y == 1
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -716,7 +716,7 @@ function ncqcp1test(model::MOI.ModelLike, config::Config)
# Max 2x + y
# s.t. x * y <= 4 (c)
# x, y >= 1
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -789,7 +789,7 @@ function ncqcp2test(model::MOI.ModelLike, config::Config)
# s.t. x * y == 4 (c)
# x * x == 4 (c2)
# x, y >= 0
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports_constraint(
model,
MOI.ScalarQuadraticFunction{Float64},
Expand Down Expand Up @@ -864,7 +864,7 @@ function socp1test(model::MOI.ModelLike, config::Config)
# s.t. x + y >= 1 (c1)
# x^2 + y^2 <= t^2 (c2)
# t >= 0 (bound)
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down
2 changes: 1 addition & 1 deletion src/DeprecatedTest/intconic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function intsoc1test(model::MOI.ModelLike, config::Config)
# st x == 1
# x >= ||(y,z)||
# (y,z) binary
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down
12 changes: 6 additions & 6 deletions src/DeprecatedTest/intlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function int1test(model::MOI.ModelLike, config::Config)
# x is continuous: 0 <= x <= 5
# y is integer: 0 <= y <= 10
# z is binary
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -139,7 +139,7 @@ function int2test(model::MOI.ModelLike, config::Config)
atol = config.atol
rtol = config.rtol
@testset "SOSI" begin
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -244,7 +244,7 @@ function int2test(model::MOI.ModelLike, config::Config)
end
end
@testset "SOSII" begin
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -379,7 +379,7 @@ function int3test(model::MOI.ModelLike, config::Config)
# z in {0, 1, 2, ..., 100}
MOI.empty!(model)
@test MOI.is_empty(model)
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -456,7 +456,7 @@ function knapsacktest(model::MOI.ModelLike, config::Config)
# a,b,c,d,e ∈ binary
MOI.empty!(model)
@test MOI.is_empty(model)
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
Expand Down Expand Up @@ -917,7 +917,7 @@ end
function _semitest(model::MOI.ModelLike, config::Config{T}, int::Bool) where {T}
atol = config.atol
rtol = config.rtol
@test MOI.supports_incremental_interface(model, false) #=copy_names=#
@test MOI.supports_incremental_interface(model)
@test MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
Expand Down
Loading