diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index 4864f0cc46..8a7b54a12b 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -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) @@ -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) diff --git a/src/attributes.jl b/src/attributes.jl index 7604eb1446..3d9c0e29fe 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -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() diff --git a/test/Utilities/model.jl b/test/Utilities/model.jl index 9244123653..b6ae552e0b 100644 --- a/test/Utilities/model.jl +++ b/test/Utilities/model.jl @@ -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