Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListOfConstraints -> ListOfConstraintTypes #357

Closed
wants to merge 1 commit into from
Closed
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/apireference.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Name
ObjectiveSense
NumberOfVariables
ListOfVariableIndices
ListOfConstraints
ListOfConstraintTypes
NumberOfConstraints
ListOfConstraintIndices
ListOfModelAttributesSet
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/bridgeoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ function MOI.get(b::AbstractBridgeOptimizer, attr::Union{MOI.NumberOfConstraints
end
s
end
MOI.canget(b::AbstractBridgeOptimizer, attr::MOI.ListOfConstraints) = MOI.canget(b.model, attr) && MOI.canget(b.bridged, attr)
MOI.canget(b::AbstractBridgeOptimizer, attr::MOI.ListOfConstraintTypes) = MOI.canget(b.model, attr) && MOI.canget(b.bridged, attr)
_noc(b, fs) = MOI.get(b, MOI.NumberOfConstraints{fs...}())
function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.ListOfConstraints)
function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.ListOfConstraintTypes)
loc = MOI.get(b.model, attr)
rm = find(_noc.(b, loc) .== 0)
deleteat!(loc, rm)
Expand Down
4 changes: 2 additions & 2 deletions src/Test/contconic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function _lin1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool)
c = MOI.addconstraint!(model, MOI.VectorAffineFunction([1,1,1,2,2], [v;v[2];v[3]], ones(5), [-3.0,-2.0]), MOI.Zeros(2))
@test MOI.get(model, MOI.NumberOfConstraints{vecofvars ? MOI.VectorOfVariables : MOI.VectorAffineFunction{Float64},MOI.Nonnegatives}()) == 1
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}()) == 1
loc = MOI.get(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraintTypes())
@test length(loc) == 2
@test (vecofvars ? MOI.VectorOfVariables : MOI.VectorAffineFunction{Float64},MOI.Nonnegatives) in loc
@test (MOI.VectorAffineFunction{Float64},MOI.Zeros) in loc
Expand Down Expand Up @@ -357,7 +357,7 @@ function _soc1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool)

@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}()) == 1
@test MOI.get(model, MOI.NumberOfConstraints{vecofvars ? MOI.VectorOfVariables : MOI.VectorAffineFunction{Float64},MOI.SecondOrderCone}()) == 1
loc = MOI.get(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraintTypes())
@test length(loc) == 2
@test (MOI.VectorAffineFunction{Float64},MOI.Zeros) in loc
@test (vecofvars ? MOI.VectorOfVariables : MOI.VectorAffineFunction{Float64},MOI.SecondOrderCone) in loc
Expand Down
2 changes: 1 addition & 1 deletion src/Test/intconic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function intsoc1test(model::MOI.ModelLike, config::TestConfig)

@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())
loc = MOI.get(model, MOI.ListOfConstraintTypes())
@test length(loc) == 2
@test (MOI.VectorAffineFunction{Float64},MOI.Zeros) in loc
@test (MOI.VectorOfVariables,MOI.SecondOrderCone) in loc
Expand Down
8 changes: 4 additions & 4 deletions src/Test/modellike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function emptytest(model::MOI.ModelLike)
@test MOI.get(model, MOI.NumberOfVariables()) == 0
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.Nonnegatives}()) == 0
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}()) == 0
@test isempty(MOI.get(model, MOI.ListOfConstraints()))
@test isempty(MOI.get(model, MOI.ListOfConstraintTypes()))

@test !MOI.isvalid(model, v[1])
@test !MOI.isvalid(model, vc)
Expand All @@ -143,15 +143,15 @@ MOI.get(::BadModel, ::MOI.NumberOfVariables) = 1
MOI.get(::BadModel, ::MOI.ListOfVariableIndices) = [MOI.VariableIndex(1)]
MOI.canget(::BadModel, ::MOI.ListOfVariableAttributesSet) = true
MOI.get(::BadModel, ::MOI.ListOfVariableAttributesSet) = MOI.AbstractVariableAttribute[]
MOI.get(::BadModel, ::MOI.ListOfConstraints) = [(MOI.SingleVariable, MOI.EqualTo{Float64})]
MOI.get(::BadModel, ::MOI.ListOfConstraintTypes) = [(MOI.SingleVariable, MOI.EqualTo{Float64})]
MOI.get(::BadModel, ::MOI.ListOfConstraintIndices{F,S}) where {F,S} = [MOI.ConstraintIndex{F,S}(1)]
MOI.get(::BadModel, ::MOI.ConstraintFunction, ::MOI.ConstraintIndex{MOI.SingleVariable,MOI.EqualTo{Float64}}) = MOI.SingleVariable(MOI.VariableIndex(1))
MOI.get(::BadModel, ::MOI.ConstraintSet, ::MOI.ConstraintIndex{MOI.SingleVariable,MOI.EqualTo{Float64}}) = MOI.EqualTo(0.0)
MOI.canget(::BadModel, ::MOI.ListOfConstraintAttributesSet) = true
MOI.get(::BadModel, ::MOI.ListOfConstraintAttributesSet) = MOI.AbstractConstraintAttribute[]

struct BadConstraintModel <: BadModel end
MOI.get(::BadConstraintModel, ::MOI.ListOfConstraints) = [(MOI.SingleVariable, MOI.EqualTo{Float64}), (MOI.SingleVariable, UnknownSet)]
MOI.get(::BadConstraintModel, ::MOI.ListOfConstraintTypes) = [(MOI.SingleVariable, MOI.EqualTo{Float64}), (MOI.SingleVariable, UnknownSet)]
MOI.get(::BadModel, ::MOI.ConstraintFunction, ::MOI.ConstraintIndex{MOI.SingleVariable,UnknownSet}) = MOI.SingleVariable(MOI.VariableIndex(1))
MOI.get(::BadModel, ::MOI.ConstraintSet, ::MOI.ConstraintIndex{MOI.SingleVariable,UnknownSet}) = UnknownSet()

Expand Down Expand Up @@ -235,7 +235,7 @@ function copytest(dest::MOI.ModelLike, src::MOI.ModelLike)
@test MOI.get(dest, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Float64},MOI.LessThan{Float64}}()) == [dict[csa]]
@test MOI.get(dest, MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}()) == 1
@test MOI.get(dest, MOI.ListOfConstraintIndices{MOI.VectorAffineFunction{Float64},MOI.Zeros}()) == [dict[cva]]
loc = MOI.get(dest, MOI.ListOfConstraints())
loc = MOI.get(dest, MOI.ListOfConstraintTypes())
@test length(loc) == 4
@test (MOI.SingleVariable,MOI.EqualTo{Float64}) in loc
@test (MOI.VectorOfVariables,MOI.Nonnegatives) in loc
Expand Down
6 changes: 3 additions & 3 deletions src/Utilities/copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function defaultcopy!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool)
res.status == MOI.CopySuccess || return res

# Copy constraints
for (F, S) in MOI.get(src, MOI.ListOfConstraints())
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypes())
# do the rest in copyconstraints! which is type stable
res = copyconstraints!(dest, src, copynames, idxmap, F, S)
res.status == MOI.CopySuccess || return res
Expand Down Expand Up @@ -296,7 +296,7 @@ function allocateload!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool)
res.status == MOI.CopySuccess || return res

# Allocate constraints
for (F, S) in MOI.get(src, MOI.ListOfConstraints())
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypes())
# do the rest in copyconstraints! which is type stable
res = allocateconstraints!(dest, src, copynames, idxmap, F, S)
res.status == MOI.CopySuccess || return res
Expand All @@ -314,7 +314,7 @@ function allocateload!(dest::MOI.ModelLike, src::MOI.ModelLike, copynames::Bool)
res.status == MOI.CopySuccess || return res

# Copy constraints
for (F, S) in MOI.get(src, MOI.ListOfConstraints())
for (F, S) in MOI.get(src, MOI.ListOfConstraintTypes())
# do the rest in copyconstraints! which is type stable
res = loadconstraints!(dest, src, copynames, idxmap, F, S)
res.status == MOI.CopySuccess || return res
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,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.ListOfConstraintTypes())
for index in MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
cname = MOI.get(model, MOI.ConstraintName(), index)
if !haskey(seen_name, cname)
Expand Down
6 changes: 3 additions & 3 deletions src/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ end

MOI.get(model::AbstractModel, noc::MOI.NumberOfConstraints) = _getnoc(model, noc)

function MOI.get(model::AbstractModel, loc::MOI.ListOfConstraints)
function MOI.get(model::AbstractModel, loc::MOI.ListOfConstraintTypes)
broadcastvcat(_getloc, model)
end

Expand All @@ -266,7 +266,7 @@ end
MOI.canget(model::AbstractModel, ::Union{MOI.NumberOfVariables,
MOI.ListOfVariableIndices,
MOI.NumberOfConstraints,
MOI.ListOfConstraints,
MOI.ListOfConstraintTypes,
MOI.ListOfConstraintIndices,
MOI.ObjectiveSense}) = true

Expand Down Expand Up @@ -329,7 +329,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 `ListOfConstraintTypes`).

# Examples

Expand Down
4 changes: 2 additions & 2 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ The number of constraints of the type `F`-in-`S` present in the model.
struct NumberOfConstraints{F,S} <: AbstractModelAttribute end

"""
ListOfConstraints()
ListOfConstraintTypes()

A 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 ListOfConstraintTypes <: AbstractModelAttribute end

"""
ObjectiveFunction{F<:AbstractScalarFunction}()
Expand Down
12 changes: 6 additions & 6 deletions test/bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ end
f1 = MOI.ScalarAffineFunction([x], [3], 7)
c1 = MOI.addconstraint!(model, f1, MOI.Interval(-1, 1))

@test MOI.canget(model, MOI.ListOfConstraints())
@test MOI.get(model, MOI.ListOfConstraints()) == [(MOI.ScalarAffineFunction{Int},MOI.Interval{Int})]
@test MOI.canget(model, MOI.ListOfConstraintTypes())
@test MOI.get(model, MOI.ListOfConstraintTypes()) == [(MOI.ScalarAffineFunction{Int},MOI.Interval{Int})]
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.GreaterThan{Int}, 0)
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}, 1)
@test MOI.canget(model, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Int},MOI.Interval{Int}}())
Expand All @@ -43,8 +43,8 @@ end
f2 = MOI.ScalarAffineFunction([x, y], [2, -1], 2)
c2 = MOI.addconstraint!(model, f1, MOI.GreaterThan(-2))

@test MOI.canget(model, MOI.ListOfConstraints())
@test MOI.get(model, MOI.ListOfConstraints()) == [(MOI.ScalarAffineFunction{Int},MOI.GreaterThan{Int}), (MOI.ScalarAffineFunction{Int},MOI.Interval{Int})]
@test MOI.canget(model, MOI.ListOfConstraintTypes())
@test MOI.get(model, MOI.ListOfConstraintTypes()) == [(MOI.ScalarAffineFunction{Int},MOI.GreaterThan{Int}), (MOI.ScalarAffineFunction{Int},MOI.Interval{Int})]
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.GreaterThan{Int}, 1)
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}, 1)
@test MOI.canget(model, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Int},MOI.Interval{Int}}())
Expand All @@ -55,8 +55,8 @@ end
@test MOI.candelete(model, c2)
MOI.delete!(model, c2)

@test MOI.canget(model, MOI.ListOfConstraints())
@test MOI.get(model, MOI.ListOfConstraints()) == [(MOI.ScalarAffineFunction{Int},MOI.Interval{Int})]
@test MOI.canget(model, MOI.ListOfConstraintTypes())
@test MOI.get(model, MOI.ListOfConstraintTypes()) == [(MOI.ScalarAffineFunction{Int},MOI.Interval{Int})]
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.GreaterThan{Int}, 0)
test_noc(model, MOI.ScalarAffineFunction{Int}, MOI.Interval{Int}, 1)
@test MOI.canget(model, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Int},MOI.Interval{Int}}())
Expand Down
6 changes: 3 additions & 3 deletions test/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ end
@test MOI.canget(model, MOI.ListOfConstraintIndices{MOI.VectorQuadraticFunction{Int},MOI.PositiveSemidefiniteConeTriangle}())
@test (@inferred MOI.get(model, MOI.ListOfConstraintIndices{MOI.VectorQuadraticFunction{Int},MOI.PositiveSemidefiniteConeTriangle}())) == [c2]

@test MOI.canget(model, MOI.ListOfConstraints())
loc = MOI.get(model, MOI.ListOfConstraints())
@test MOI.canget(model, MOI.ListOfConstraintTypes())
loc = MOI.get(model, MOI.ListOfConstraintTypes())
@test length(loc) == 2
@test (MOI.VectorQuadraticFunction{Int},MOI.PositiveSemidefiniteConeTriangle) in loc
@test (MOI.VectorQuadraticFunction{Int},MOI.PositiveSemidefiniteConeTriangle) in loc
Expand Down Expand Up @@ -81,7 +81,7 @@ end
c7 = MOI.addconstraint!(model, f7, MOI.Nonpositives(2))
@test MOI.get(model, MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.Nonpositives}()) == 1

loc1 = MOI.get(model, MOI.ListOfConstraints())
loc1 = MOI.get(model, MOI.ListOfConstraintTypes())
loc2 = Vector{Tuple{DataType, DataType}}()
function _pushloc(constrs::Vector{MOIU.C{F, S}}) where {F, S}
if !isempty(constrs)
Expand Down