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

DNMY: Add support for vector-valued objective functions #968

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
16 changes: 14 additions & 2 deletions src/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,12 @@ function MOI.supports(
::MOI.ObjectiveFunction{<:Union{
MOI.SingleVariable,
MOI.ScalarAffineFunction{T},
MOI.ScalarQuadraticFunction{T}}}) where T
MOI.ScalarQuadraticFunction{T},
MOI.VectorOfVariables,
MOI.VectorAffineFunction{T},
MOI.VectorQuadraticFunction{T}
}}
) where T
return true
end
function MOI.set(model::AbstractModel, ::MOI.ObjectiveFunction, f::MOI.AbstractFunction)
Expand Down Expand Up @@ -901,7 +906,14 @@ macro model(model_name, ss, sst, vs, vst, sf, sft, vf, vft)
senseset::Bool
sense::$MOI.OptimizationSense
objectiveset::Bool
objective::Union{$MOI.SingleVariable, $MOI.ScalarAffineFunction{T}, $MOI.ScalarQuadraticFunction{T}}
objective::Union{
$MOI.SingleVariable,
$MOI.ScalarAffineFunction{T},
$MOI.ScalarQuadraticFunction{T},
$MOI.VectorOfVariables,
$MOI.VectorAffineFunction{T},
$MOI.VectorQuadraticFunction{T}
}
num_variables_created::Int64
# If nothing, no variable has been deleted so the indices of the
# variables are VI.(1:num_variables_created)
Expand Down
17 changes: 11 additions & 6 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -802,15 +802,20 @@ has value greater than zero.
struct ListOfConstraints <: AbstractModelAttribute end

"""
ObjectiveFunction{F<:AbstractScalarFunction}()
ObjectiveFunction{F<:AbstractFunction}()

A model attribute for the objective function which has a type
`F<:AbstractFunction`.

`F` should be guaranteed to be equivalent but not necessarily identical to the
function type provided by the user.

A model attribute for the objective function which has a type `F<:AbstractScalarFunction`.
`F` should be guaranteed to be equivalent but not necessarily identical to the function type provided by the user.
Throws an `InexactError` if the objective function cannot be converted to `F`,
e.g. the objective function is quadratic and `F` is `ScalarAffineFunction{Float64}` or
it has non-integer coefficient and `F` is `ScalarAffineFunction{Int}`.
e.g. the objective function is quadratic and `F` is
`ScalarAffineFunction{Float64}` or it has non-integer coefficient and `F` is
`ScalarAffineFunction{Int}`.
"""
struct ObjectiveFunction{F<:AbstractScalarFunction} <: AbstractModelAttribute end
struct ObjectiveFunction{F<:AbstractFunction} <: AbstractModelAttribute end

"""
ObjectiveFunctionType()
Expand Down
14 changes: 14 additions & 0 deletions test/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,17 @@ end
@test !haskey(dest.ext, :my_store)
@test model.ext[:my_store] == 2
end

@testset "Vector-valued objectives" begin
model = MOIU.Model{Float64}()
x = MOI.add_variables(model, 3)
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.set(
model,
MOI.ObjectiveFunction{MOI.VectorOfVariables}(),
MOI.VectorOfVariables(x)
)
@test MOI.get(model, MOI.ObjectiveFunctionType()) == MOI.VectorOfVariables
@test MOI.get(model, MOI.ObjectiveFunction{MOI.VectorOfVariables}()) ==
MOI.VectorOfVariables(x)
end