# Need a working example to use Gurobi for multi objective

**URL:** <https://discourse.julialang.org/t/need-a-working-example-to-use-gurobi-for-multi-objective/124760>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [January 14, 2025, 12:38pm UTC](https://discourse.julialang.org/t/need-a-working-example-to-use-gurobi-for-multi-objective/124760 "2025-01-14T12:38:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj.centura](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/manoj.centura/32/216443_2.png) [@manoj.centura](https://discourse.julialang.org/u/manoj.centura)\
**Post date:** [January 14, 2025, 12:38pm UTC](https://discourse.julialang.org/t/need-a-working-example-to-use-gurobi-for-multi-objective/124760/1 "2025-01-14T12:38:55Z")

</div>

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

Thanks in advance

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [January 14, 2025, 7:28pm UTC](https://discourse.julialang.org/t/need-a-working-example-to-use-gurobi-for-multi-objective/124760/2 "2025-01-14T19:28:30Z")

</div>

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

> **[Multi-objective knapsack · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/linear/multi_objective_knapsack/#Multi-objective-knapsack)**
>
> Documentation for JuMP.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [January 14, 2025, 7:29pm UTC](https://discourse.julialang.org/t/need-a-working-example-to-use-gurobi-for-multi-objective/124760/3 "2025-01-14T19:29:26Z")

</div>

To use multi-objective, see:

- [Objectives · JuMP](https://jump.dev/JuMP.jl/stable/manual/objective/#Set-a-vector-valued-objective)

You almost certainly want to use MultiObjectiveAlgorithms.jl [[docs](https://jump.dev/JuMP.jl/stable/packages/MultiObjectiveAlgorithms/)] instead of Gurobi directly.

See these tutorials:

- [Multi-objective knapsack · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/linear/multi_objective_knapsack/)
- [Simple multi-objective examples · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/linear/multi_objective_examples/)

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
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

```
