Need a working example to use Gurobi for multi objective

Hi Everyone, can some one provide working example for Gurobi Multi objective.

Thanks in advance

Something like this? Of course the solver is not Gurobi in the docs but JuMP makes it easy to switch

1 Like

To use multi-objective, see:

You almost certainly want to use MultiObjectiveAlgorithms.jl [docs] instead of Gurobi directly.

See these tutorials:

To use Gurobi directly, just pass a vector of objectives to @objective, but note that it returns only a single solution, not the Pareto frontier:

julia> using JuMP, Gurobi

julia> model = Model(Gurobi.Optimizer)
Set parameter LicenseID to value 890341
A JuMP Model
├ solver: Gurobi
├ objective_sense: FEASIBILITY_SENSE
├ num_variables: 0
├ num_constraints: 0
└ Names registered in the model: none

julia> @variable(model, 0 <= x[1:2] <= 1)
2-element Vector{VariableRef}:
 x[1]
 x[2]

julia> @constraint(model, sum(x) == 1)
x[1] + x[2] = 1

julia> @objective(model, Max, [x[1], 2.0 * x[2] + 1.0])
2-element Vector{AffExpr}:
 x[1]
 2 x[2] + 1

julia> optimize!(model)
Gurobi Optimizer version 12.0.0 build v12.0.0rc1 (mac64[x86] - Darwin 24.1.0 24B83)

CPU model: Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads

Optimize a model with 1 rows, 2 columns and 2 nonzeros
Model fingerprint: 0x99aa5868
Variable types: 2 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [1e+00, 2e+00]
  Bounds range     [1e+00, 1e+00]
  RHS range        [1e+00, 1e+00]

---------------------------------------------------------------------------
Multi-objectives: starting optimization with 2 objectives (1 combined)...
---------------------------------------------------------------------------
---------------------------------------------------------------------------

Multi-objectives: optimize objective 1 (weighted) ...
---------------------------------------------------------------------------

Optimize a model with 1 rows, 2 columns and 2 nonzeros
Model fingerprint: 0xf6d0909a
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  Objective range  [1e+00, 2e+00]
  Bounds range     [1e+00, 1e+00]
  RHS range        [1e+00, 1e+00]
Presolve removed 1 rows and 2 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    3.0000000e+00   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds (0.00 work units)
Optimal objective  3.000000000e+00

---------------------------------------------------------------------------
Multi-objectives: solved in 0.00 seconds (0.00 work units), solution count 1


User-callback calls 43, time in user-callback 0.00 sec

julia> @assert is_solved_and_feasible(model)

julia> objective_value.(model)
2-element Vector{Float64}:
 0.0
 3.0

julia> solution_summary(model)
* Solver : Gurobi

* Status
  Result count       : 1
  Termination status : OPTIMAL
  Message from the solver:
  "Model was solved to optimality (subject to tolerances), and an optimal solution is available."

* Candidate solution (result #1)
  Primal status      : FEASIBLE_POINT
  Dual status        : NO_SOLUTION
  Objective value    : [0.00000e+00,3.00000e+00]

* Work counters
  Solve time (sec)   : 8.91924e-04
  Simplex iterations : 0
  Barrier iterations : 0
  Node count         : 0
2 Likes