@@ -270,6 +270,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
270
270
is_feasibility:: Bool
271
271
is_objective_function_set:: Bool
272
272
is_objective_sense_set:: Bool
273
+ multi_objective:: Union{Nothing,MOI.VectorAffineFunction{Float64}}
273
274
274
275
# A flag to keep track of whether the objective is linear or quadratic.
275
276
hessian:: Union{Nothing,SparseArrays.SparseMatrixCSC{Float64,HighsInt}}
@@ -305,6 +306,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
305
306
false ,
306
307
false ,
307
308
nothing ,
309
+ nothing ,
308
310
Set {_VariableInfo} (),
309
311
_variable_info_dict (),
310
312
_constraint_info_dict (),
@@ -366,6 +368,7 @@ function MOI.empty!(model::Optimizer)
366
368
model. is_feasibility = true
367
369
model. is_objective_function_set = false
368
370
model. is_objective_sense_set = false
371
+ model. multi_objective = nothing
369
372
model. hessian = nothing
370
373
empty! (model. binaries)
371
374
empty! (model. variable_info)
@@ -871,6 +874,10 @@ function MOI.delete(model::Optimizer, v::MOI.VariableIndex)
871
874
other_info. column -= 1
872
875
end
873
876
end
877
+ if model. multi_objective != = nothing
878
+ model. multi_objective =
879
+ MOI. Utilities. filter_variables (!= (v), model. multi_objective)
880
+ end
874
881
model. name_to_variable = nothing
875
882
model. name_to_constraint_index = nothing
876
883
return
@@ -1017,7 +1024,9 @@ function MOI.supports(
1017
1024
end
1018
1025
1019
1026
function MOI. get (model:: Optimizer , :: MOI.ObjectiveFunctionType )
1020
- if model. hessian === nothing
1027
+ if model. multi_objective != = nothing
1028
+ return MOI. VectorAffineFunction{Float64}
1029
+ elseif model. hessian === nothing
1021
1030
return MOI. ScalarAffineFunction{Float64}
1022
1031
else
1023
1032
return MOI. ScalarQuadraticFunction{Float64}
@@ -1029,6 +1038,11 @@ function MOI.set(
1029
1038
:: MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}} ,
1030
1039
f:: MOI.ScalarAffineFunction{Float64} ,
1031
1040
)
1041
+ if model. multi_objective != = nothing
1042
+ ret = Highs_clearLinearObjectives (model)
1043
+ _check_ret (ret)
1044
+ model. multi_objective = nothing
1045
+ end
1032
1046
num_vars = HighsInt (length (model. variable_info))
1033
1047
obj = zeros (Float64, num_vars)
1034
1048
for term in f. terms
@@ -1062,6 +1076,11 @@ function MOI.set(
1062
1076
:: MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}} ,
1063
1077
f:: MOI.ScalarQuadraticFunction{Float64} ,
1064
1078
)
1079
+ if model. multi_objective != = nothing
1080
+ ret = Highs_clearLinearObjectives (model)
1081
+ _check_ret (ret)
1082
+ model. multi_objective = nothing
1083
+ end
1065
1084
numcol = length (model. variable_info)
1066
1085
obj = zeros (Float64, numcol)
1067
1086
for term in f. affine_terms
@@ -1228,6 +1247,52 @@ function MOI.modify(
1228
1247
return
1229
1248
end
1230
1249
1250
+ function MOI. supports (
1251
+ :: Optimizer ,
1252
+ :: MOI.ObjectiveFunction{MOI.VectorAffineFunction{Float64}} ,
1253
+ )
1254
+ return true
1255
+ end
1256
+
1257
+ function MOI. get (
1258
+ model:: Optimizer ,
1259
+ :: MOI.ObjectiveFunction{MOI.VectorAffineFunction{Float64}} ,
1260
+ )
1261
+ return model. multi_objective
1262
+ end
1263
+
1264
+ function MOI. set (
1265
+ model:: Optimizer ,
1266
+ :: MOI.ObjectiveFunction{MOI.VectorAffineFunction{Float64}} ,
1267
+ f:: MOI.VectorAffineFunction{Float64} ,
1268
+ )
1269
+ num_vars = HighsInt (length (model. variable_info))
1270
+ O = MOI. output_dimension (f)
1271
+ obj_coefs = zeros (Float64, O * num_vars)
1272
+ for term in f. terms
1273
+ col = column (model, term. scalar_term. variable) + 1
1274
+ obj_coefs[O* (term. output_index- 1 )+ col] += term. scalar_term. coefficient
1275
+ end
1276
+ # senseP will be 1 if MIN and -1 if MAX
1277
+ senseP = Ref {HighsInt} ()
1278
+ ret = Highs_getObjectiveSense (model, senseP)
1279
+ _check_ret (ret)
1280
+ ret = Highs_passLinearObjectives (
1281
+ model,
1282
+ O, # num_linear_objective
1283
+ fill (Float64 (senseP[]), O), # weight: set to -1 if maximizing
1284
+ f. constants, # offset
1285
+ obj_coefs, # coefficients
1286
+ zeros (Float64, O), # abs_tolerance
1287
+ zeros (Float64, O), # rel_tolerance
1288
+ ones (Cint, O), # priority
1289
+ )
1290
+ _check_ret (ret)
1291
+ model. multi_objective = f
1292
+ model. is_objective_function_set = true
1293
+ return
1294
+ end
1295
+
1231
1296
# ##
1232
1297
# ## VariableIndex-in-Set constraints.
1233
1298
# ##
0 commit comments