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
21 changes: 21 additions & 0 deletions src/Test/test_variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,24 @@ function test_model_VariablePrimalStart(model::MOI.ModelLike, ::Config)
@test MOI.get(model, MOI.VariablePrimalStart(), x) === nothing
return
end

"""
test_add_constrained_variables(model::MOI.ModelLike, config::Config)

Test vector method of `add_constrained_variables`.
"""
function test_add_constrained_variables_vector(
model::MOI.ModelLike,
::Config{T},
) where {T}
@requires MOI.supports_add_constrained_variable(model, MOI.GreaterThan{T})
@test MOI.get(model, MOI.NumberOfVariables()) == 0
sets = [MOI.GreaterThan(zero(T)), MOI.GreaterThan(one(T))]
v, cv = MOI.add_constrained_variables(model, sets)
@test MOI.get(model, MOI.NumberOfVariables()) == 2
@test length(v) == 2
@test length(cv) == 2
@test MOI.get(model, MOI.ConstraintSet(), cv[1]) == sets[1]
@test MOI.get(model, MOI.ConstraintSet(), cv[2]) == sets[2]
return
end
14 changes: 9 additions & 5 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ supports_add_constrained_variables(::ModelLike, ::Type{Reals}) = true
add_constrained_variables(
model::ModelLike,
sets::AbstractVector{<:AbstractScalarSet}
)::Tuple{Vector{MOI.VariableIndex},
Vector{MOI.ConstraintIndex{MOI.SingleVariable, eltype(sets)}}}
)::Tuple{
Vector{MOI.VariableIndex},
Vector{MOI.ConstraintIndex{MOI.SingleVariable,eltype(sets)}},
}

Add to `model` scalar variables constrained to belong to `sets`, returning the
indices of the variables created and the indices of the constraints constraining
Expand Down Expand Up @@ -184,9 +186,11 @@ end
"""
add_constrained_variables(
model::ModelLike,
set::AbstractVectorSet
)::Tuple{Vector{MOI.VariableIndex},
MOI.ConstraintIndex{MOI.VectorOfVariables, typeof(set)}}
set::AbstractVectorSet,
)::Tuple{
Vector{MOI.VariableIndex},
MOI.ConstraintIndex{MOI.VectorOfVariables,typeof(set)},
}

Add to `model` a vector of variables constrained to belong to `set`, returning
the indices of the variables created and the index of the constraint
Expand Down