@@ -82,9 +82,10 @@ function set_objective_sense(model::Model, sense::MOI.OptimizationSense)
82
82
end
83
83
84
84
"""
85
- set_objective_function(
86
- model::Model,
87
- func::Union{AbstractJuMPScalar, MathOptInterface.AbstractScalarFunction})
85
+ set_objective_function(model::Model, func::MOI.AbstractFunction)
86
+ set_objective_function(model::Model, func::AbstractJuMPScalar)
87
+ set_objective_function(model::Model, func::Real)
88
+ set_objective_function(model::Model, func::Vector{<:AbstractJuMPScalar})
88
89
89
90
Sets the objective function of the model to the given function. See
90
91
[`set_objective_sense`](@ref) to set the objective sense. These are low-level
@@ -178,10 +179,13 @@ function objective_function_type(model::Model)
178
179
end
179
180
180
181
"""
181
- objective_function(model::Model,
182
- T::Type{<:AbstractJuMPScalar}=objective_function_type(model))
182
+ objective_function(
183
+ model::Model,
184
+ T::Type = objective_function_type(model),
185
+ )
183
186
184
187
Return an object of type `T` representing the objective function.
188
+
185
189
Error if the objective is not convertible to type `T`.
186
190
187
191
## Examples
@@ -223,14 +227,21 @@ ERROR: InexactError: convert(MathOptInterface.VariableIndex, MathOptInterface.Sc
223
227
"""
224
228
function objective_function (
225
229
model:: Model ,
226
- FunType:: Type{<:AbstractJuMPScalar} = objective_function_type (model),
227
- )
228
- MOIFunType = moi_function_type (FunType)
229
- func =
230
- MOI. get (backend (model), MOI. ObjectiveFunction {MOIFunType} ()):: MOIFunType
230
+ :: Type{F} ,
231
+ ) where {F<: MOI.AbstractFunction }
232
+ func = MOI. get (backend (model), MOI. ObjectiveFunction {F} ()):: F
231
233
return jump_function (model, func)
232
234
end
233
235
236
+ function objective_function (model:: Model , :: Type{T} ) where {T}
237
+ return objective_function (model, moi_function_type (T))
238
+ end
239
+
240
+ function objective_function (model:: Model )
241
+ F = MOI. get (backend (model), MOI. ObjectiveFunctionType ())
242
+ return objective_function (model, F)
243
+ end
244
+
234
245
"""
235
246
set_objective_coefficient(model::Model, variable::VariableRef, coefficient::Real)
236
247
0 commit comments