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
2 changes: 1 addition & 1 deletion docs/src/manual/implementing.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ Constraint-related attributes:
| ---------------------- | --------------| ------------- | ------------------ |
| [`ListOfConstraintAttributesSet`](@ref) | Yes | No | No |
| [`NumberOfConstraints`](@ref) | Yes | No | No |
| [`ListOfConstraints`](@ref) | Yes | No | No |
| [`ListOfConstraintTypesPresent`](@ref) | Yes | No | No |
| [`ConstraintFunction`](@ref) | Yes | Yes | No |
| [`ConstraintSet`](@ref) | Yes | Yes | No |

Expand Down
2 changes: 1 addition & 1 deletion docs/src/reference/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ObjectiveFunctionType
ObjectiveSense
NumberOfVariables
ListOfVariableIndices
ListOfConstraints
ListOfConstraintTypesPresent
NumberOfConstraints
ListOfConstraintIndices
ListOfOptimizerAttributesSet
Expand Down
8 changes: 4 additions & 4 deletions docs/src/submodules/Bridges/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ MOI.VariableIndex(1)
julia> MOI.add_constraint(optimizer, MOI.SingleVariable(x), MOI.Interval(0.0, 1.0))
MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.Interval{Float64}}(1)

julia> MOI.get(optimizer, MOI.ListOfConstraints())
julia> MOI.get(optimizer, MOI.ListOfConstraintTypesPresent())
1-element Array{Tuple{DataType,DataType},1}:
(MathOptInterface.SingleVariable, MathOptInterface.Interval{Float64})

julia> MOI.get(inner_optimizer, MOI.ListOfConstraints())
julia> MOI.get(inner_optimizer, MOI.ListOfConstraintTypesPresent())
2-element Array{Tuple{DataType,DataType},1}:
(MathOptInterface.SingleVariable, MathOptInterface.GreaterThan{Float64})
(MathOptInterface.SingleVariable, MathOptInterface.LessThan{Float64})
Expand Down Expand Up @@ -181,11 +181,11 @@ MOI.VariableIndex(1)
julia> MOI.add_constraint(optimizer, MOI.SingleVariable(x), MOI.Interval(0.0, 1.0))
MathOptInterface.ConstraintIndex{MathOptInterface.SingleVariable,MathOptInterface.Interval{Float64}}(1)

julia> MOI.get(optimizer, MOI.ListOfConstraints())
julia> MOI.get(optimizer, MOI.ListOfConstraintTypesPresent())
1-element Array{Tuple{DataType,DataType},1}:
(MathOptInterface.SingleVariable, MathOptInterface.Interval{Float64})

julia> MOI.get(inner_optimizer, MOI.ListOfConstraints())
julia> MOI.get(inner_optimizer, MOI.ListOfConstraintTypesPresent())
1-element Array{Tuple{DataType,DataType},1}:
(MathOptInterface.SingleVariable, MathOptInterface.Interval{Float64})
```
5 changes: 4 additions & 1 deletion src/Bridges/bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,10 @@ function MOI.get(
end
return s
end
function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.ListOfConstraints)
function MOI.get(
b::AbstractBridgeOptimizer,
attr::MOI.ListOfConstraintTypesPresent,
)
if Constraint.has_bridges(Constraint.bridges(b)) &&
Variable.has_bridges(Variable.bridges(b))
set_of_types = Constraint.list_of_key_types(Constraint.bridges(b))
Expand Down
2 changes: 1 addition & 1 deletion src/FileFormats/MOF/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function write_constraints(
model::Model,
name_map::Dict{MOI.VariableIndex,String},
)
for (F, S) in MOI.get(model, MOI.ListOfConstraints())
for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent())
for index in MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
push!(object["constraints"], moi_to_object(index, model, name_map))
end
Expand Down
4 changes: 2 additions & 2 deletions src/FileFormats/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ function create_unique_constraint_names(
replacements::Vector{Function},
)
original_names = Set{String}()
for (F, S) in MOI.get(model, MOI.ListOfConstraints())
for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent())
for index in MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
name = MOI.get(model, MOI.ConstraintName(), index)
push!(original_names, _replace(name, replacements))
end
end
added_names = Set{String}()
for (F, S) in MOI.get(model, MOI.ListOfConstraints())
for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent())
for index in MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
original_name = MOI.get(model, MOI.ConstraintName(), index)
new_name = _replace(
Expand Down
12 changes: 6 additions & 6 deletions src/Test/contconic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function _lin1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool)
model,
MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(),
) == 1
loc = MOI.get(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test length(loc) == 2
@test (
vecofvars ? MOI.VectorOfVariables : MOI.VectorAffineFunction{Float64},
Expand Down Expand Up @@ -599,7 +599,7 @@ function _norminf1test(
MOI.NormInfinityCone,
}(),
) == 1
loc = MOI.get(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test length(loc) == 2
@test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc
@test (
Expand Down Expand Up @@ -819,7 +819,7 @@ function norminf3test(model::MOI.ModelLike, config::TestConfig)
MOI.Nonnegatives,
}(),
) == 1
loc = MOI.get(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test length(loc) == 2
@test (MOI.VectorAffineFunction{Float64}, MOI.NormInfinityCone) in loc
@test (MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) in loc
Expand Down Expand Up @@ -955,7 +955,7 @@ function _normone1test(
MOI.NormOneCone,
}(),
) == 1
loc = MOI.get(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test length(loc) == 2
@test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc
@test (
Expand Down Expand Up @@ -1175,7 +1175,7 @@ function normone3test(model::MOI.ModelLike, config::TestConfig)
MOI.Nonnegatives,
}(),
) == 1
loc = MOI.get(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test length(loc) == 2
@test (MOI.VectorAffineFunction{Float64}, MOI.NormOneCone) in loc
@test (MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) in loc
Expand Down Expand Up @@ -1298,7 +1298,7 @@ function _soc1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool)
MOI.SecondOrderCone,
}(),
) == 1
loc = MOI.get(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test length(loc) == 2
@test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc
@test (
Expand Down
2 changes: 1 addition & 1 deletion src/Test/intconic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function intsoc1test(model::MOI.ModelLike, config::TestConfig)
model,
MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}(),
) == 1
loc = MOI.get(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test length(loc) == 2
@test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc
@test (MOI.VectorOfVariables, MOI.SecondOrderCone) in loc
Expand Down
18 changes: 9 additions & 9 deletions src/Test/modellike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ function emptytest(model::MOI.ModelLike)
model,
MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(),
) == 0
@test isempty(MOI.get(model, MOI.ListOfConstraints()))
@test isempty(MOI.get(model, MOI.ListOfConstraintTypesPresent()))

@test !MOI.is_valid(model, v[1])
@test !MOI.is_valid(model, vc)
Expand All @@ -471,7 +471,7 @@ MOI.get(::BadModel, ::MOI.ListOfVariableIndices) = [MOI.VariableIndex(1)]
function MOI.get(::BadModel, ::MOI.ListOfVariableAttributesSet)
return MOI.AbstractVariableAttribute[]
end
function MOI.get(::BadModel, ::MOI.ListOfConstraints)
function MOI.get(::BadModel, ::MOI.ListOfConstraintTypesPresent)
return [(MOI.SingleVariable, MOI.EqualTo{Float64})]
end
function MOI.get(::BadModel, ::MOI.ListOfConstraintIndices{F,S}) where {F,S}
Expand All @@ -496,7 +496,7 @@ function MOI.get(::BadModel, ::MOI.ListOfConstraintAttributesSet)
end

struct BadConstraintModel <: BadModel end
function MOI.get(::BadConstraintModel, ::MOI.ListOfConstraints)
function MOI.get(::BadConstraintModel, ::MOI.ListOfConstraintTypesPresent)
return [
(MOI.SingleVariable, MOI.EqualTo{Float64}),
(MOI.SingleVariable, UnknownScalarSet{Float64}),
Expand Down Expand Up @@ -902,7 +902,7 @@ function copytest(dest::MOI.ModelLike, src::MOI.ModelLike; copy_names = false)
MOI.Zeros,
}(),
) == [dict[cva]]
loc = MOI.get(dest, MOI.ListOfConstraints())
loc = MOI.get(dest, MOI.ListOfConstraintTypesPresent())
@test length(loc) == 4
@test (MOI.SingleVariable, MOI.EqualTo{Float64}) in loc
@test (MOI.VectorOfVariables, MOI.Nonnegatives) in loc
Expand Down Expand Up @@ -1151,7 +1151,7 @@ function delete_test(model::MOI.ModelLike)
@test MOI.get(model, MOI.ConstraintFunction(), cy) ==
MOI.VectorOfVariables(y)
@test MOI.get(model, MOI.ConstraintSet(), cy) == MOI.Nonpositives(4)
@test Set(MOI.get(model, MOI.ListOfConstraints())) == Set([
@test Set(MOI.get(model, MOI.ListOfConstraintTypesPresent())) == Set([
(MOI.SingleVariable, MOI.GreaterThan{Float64}),
(MOI.VectorOfVariables, MOI.Nonpositives),
])
Expand Down Expand Up @@ -1179,7 +1179,7 @@ function delete_test(model::MOI.ModelLike)
@test MOI.get(model, MOI.ConstraintFunction(), cy) ==
MOI.VectorOfVariables(y[[1, 2, 4]])
@test MOI.get(model, MOI.ConstraintSet(), cy) == MOI.Nonpositives(3)
@test Set(MOI.get(model, MOI.ListOfConstraints())) == Set([
@test Set(MOI.get(model, MOI.ListOfConstraintTypesPresent())) == Set([
(MOI.SingleVariable, MOI.GreaterThan{Float64}),
(MOI.VectorOfVariables, MOI.Nonpositives),
])
Expand Down Expand Up @@ -1207,7 +1207,7 @@ function delete_test(model::MOI.ModelLike)
@test MOI.get(model, MOI.ConstraintFunction(), cy) ==
MOI.VectorOfVariables(y[[2, 4]])
@test MOI.get(model, MOI.ConstraintSet(), cy) == MOI.Nonpositives(2)
@test Set(MOI.get(model, MOI.ListOfConstraints())) == Set([
@test Set(MOI.get(model, MOI.ListOfConstraintTypesPresent())) == Set([
(MOI.SingleVariable, MOI.GreaterThan{Float64}),
(MOI.VectorOfVariables, MOI.Nonpositives),
])
Expand All @@ -1233,7 +1233,7 @@ function delete_test(model::MOI.ModelLike)
@test MOI.get(model, MOI.ConstraintFunction(), cy) ==
MOI.VectorOfVariables(y[[2, 4]])
@test MOI.get(model, MOI.ConstraintSet(), cy) == MOI.Nonpositives(2)
@test MOI.get(model, MOI.ListOfConstraints()) ==
@test MOI.get(model, MOI.ListOfConstraintTypesPresent()) ==
[(MOI.VectorOfVariables, MOI.Nonpositives)]
@test isempty(
MOI.get(
Expand All @@ -1256,7 +1256,7 @@ function delete_test(model::MOI.ModelLike)
@test !MOI.is_valid(model, y[4])
@test !MOI.is_valid(model, cx)
@test !MOI.is_valid(model, cy)
@test isempty(MOI.get(model, MOI.ListOfConstraints()))
@test isempty(MOI.get(model, MOI.ListOfConstraintTypesPresent()))
@test isempty(
MOI.get(
model,
Expand Down
9 changes: 5 additions & 4 deletions src/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,8 @@ function pass_constraints(
end

nonvariable_constraint_types = [
(F, S) for (F, S) in MOI.get(src, MOI.ListOfConstraints()) if
(F, S) for
(F, S) in MOI.get(src, MOI.ListOfConstraintTypesPresent()) if
F != MOI.SingleVariable && F != MOI.VectorOfVariables
]
pass_nonvariable_constraints(
Expand Down Expand Up @@ -576,7 +577,7 @@ function default_copy_to(dest::MOI.ModelLike, src::MOI.ModelLike)
end

function sorted_variable_sets_by_cost(dest::MOI.ModelLike, src::MOI.ModelLike)
constraint_types = MOI.get(src, MOI.ListOfConstraints())
constraint_types = MOI.get(src, MOI.ListOfConstraintTypesPresent())
single_or_vector_variables_types = [
(F, S) for (F, S) in constraint_types if
F === MOI.SingleVariable || F === MOI.VectorOfVariables
Expand Down Expand Up @@ -673,7 +674,7 @@ function default_copy_to(

# The `NLPBlock` assumes that the order of variables does not change (#849)
if MOI.NLPBlock() in MOI.get(src, MOI.ListOfModelAttributesSet())
constraint_types = MOI.get(src, MOI.ListOfConstraints())
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 =
Expand Down Expand Up @@ -1044,7 +1045,7 @@ function allocate_load(

vis_src = MOI.get(src, MOI.ListOfVariableIndices())
idxmap = index_map_for_variable_indices(vis_src)
constraint_types = MOI.get(src, MOI.ListOfConstraints())
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 =
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ function test_variablenames_equal(model, variablenames)
end
function test_constraintnames_equal(model, constraintnames)
seen_name = Dict(name => false for name in constraintnames)
for (F, S) in MOI.get(model, MOI.ListOfConstraints())
for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent())
for index in MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
cname = MOI.get(model, MOI.ConstraintName(), index)
if !haskey(seen_name, cname)
Expand Down
5 changes: 4 additions & 1 deletion src/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,10 @@ function _add_contraint_type(
end
return
end
function MOI.get(model::AbstractModel{T}, loc::MOI.ListOfConstraints) where {T}
function MOI.get(
model::AbstractModel{T},
loc::MOI.ListOfConstraintTypesPresent,
) where {T}
list = copy(MOI.get(model.constraints, loc))
for S in (
MOI.EqualTo{T},
Expand Down
4 changes: 2 additions & 2 deletions src/Utilities/results.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function get_fallback(
T::Type,
)
value = zero(T) # sum will not work if there are zero constraints
for (F, S) in MOI.get(model, MOI.ListOfConstraints())
for (F, S) in MOI.get(model, MOI.ListOfConstraintTypesPresent())
value += dual_objective_value(model, F, S, T, attr.result_index)::T
end
if MOI.get(model, MOI.ObjectiveSense()) != MOI.MAX_SENSE
Expand Down Expand Up @@ -436,7 +436,7 @@ function variable_dual(
)
end
end
for FS in MOI.get(model, MOI.ListOfConstraints())
for FS in MOI.get(model, MOI.ListOfConstraintTypesPresent())
dual -= variable_dual(model, attr, ci, vi, FS[1], FS[2])
end
return dual
Expand Down
4 changes: 2 additions & 2 deletions src/Utilities/struct_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end

function MOI.get(
model::StructOfConstraints,
loc::MOI.ListOfConstraints,
loc::MOI.ListOfConstraintTypesPresent,
) where {T}
return broadcastvcat(model) do v
return MOI.get(v, loc)
Expand Down Expand Up @@ -142,7 +142,7 @@ function broadcastcall end
"""
broadcastvcat(f::Function, model::AbstractModel)

Calls `f(contrs)` for every vector `constrs::Vector{ConstraintIndex{F, S}, F, S}` of the model and concatenate the results with `vcat` (this is used internally for `ListOfConstraints`).
Calls `f(contrs)` for every vector `constrs::Vector{ConstraintIndex{F, S}, F, S}` of the model and concatenate the results with `vcat` (this is used internally for `ListOfConstraintTypesPresent`).

# Examples

Expand Down
5 changes: 4 additions & 1 deletion src/Utilities/universalfallback.jl
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,10 @@ function MOI.get(
) where {F,S}
return MOI.get(constraints(uf, F, S), listattr)
end
function MOI.get(uf::UniversalFallback, listattr::MOI.ListOfConstraints)
function MOI.get(
uf::UniversalFallback,
listattr::MOI.ListOfConstraintTypesPresent,
)
list = MOI.get(uf.model, listattr)
for (S, constraints) in uf.single_variable_constraints
if !isempty(constraints)
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/vector_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ end

function MOI.get(
v::VectorOfConstraints{F,S},
::MOI.ListOfConstraints,
::MOI.ListOfConstraintTypesPresent,
)::Vector{Tuple{DataType,DataType}} where {F,S}
return isempty(v.constraints) ? [] : [(F, S)]
end
Expand Down
9 changes: 5 additions & 4 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -881,13 +881,14 @@ A model attribute for the number of constraints of the type `F`-in-`S` present i
struct NumberOfConstraints{F,S} <: AbstractModelAttribute end

"""
ListOfConstraints()
ListOfConstraintTypesPresent()

A model attribute for the list of tuples of the form `(F,S)`, where `F` is a function type
and `S` is a set type indicating that the attribute `NumberOfConstraints{F,S}()`
has value greater than zero.
"""
struct ListOfConstraints <: AbstractModelAttribute end
struct ListOfConstraintTypesPresent <: AbstractModelAttribute end
@deprecate ListOfConstraints ListOfConstraintTypesPresent

"""
ObjectiveFunction{F<:AbstractScalarFunction}()
Expand Down Expand Up @@ -1628,7 +1629,7 @@ method should be defined for attributes which are copied indirectly during
* [`ObjectiveFunctionType`](@ref): this attribute is set indirectly when setting
the [`ObjectiveFunction`](@ref) attribute.
* [`NumberOfConstraints`](@ref), [`ListOfConstraintIndices`](@ref),
[`ListOfConstraints`](@ref), [`CanonicalConstraintFunction`](@ref),
[`ListOfConstraintTypesPresent`](@ref), [`CanonicalConstraintFunction`](@ref),
[`ConstraintFunction`](@ref) and [`ConstraintSet`](@ref):
these attributes are set indirectly by
[`add_constraint`](@ref) and [`add_constraints`](@ref).
Expand All @@ -1649,7 +1650,7 @@ function is_copyable(
NumberOfConstraints,
ObjectiveFunctionType,
ListOfConstraintIndices,
ListOfConstraints,
ListOfConstraintTypesPresent,
CanonicalConstraintFunction,
ConstraintFunction,
ConstraintSet,
Expand Down
2 changes: 1 addition & 1 deletion src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ end
function precompile_model(model, constraints)
Base.precompile(empty!, (model,))
Base.precompile(is_empty, (model,))
Base.precompile(get, (model, ListOfConstraints))
Base.precompile(get, (model, ListOfConstraintTypesPresent))
Base.precompile(optimize!, (model,))
Base.precompile(add_variable, (model,))
Base.precompile(add_variables, (model, Int))
Expand Down
Loading