# Unable to add objectives in vector form using JuMP

**URL:** <https://discourse.julialang.org/t/unable-to-add-objectives-in-vector-form-using-jump/94041>\
**Category:** Optimization (Mathematical)\
**Created:** [February 4, 2023, 11:46am UTC](https://discourse.julialang.org/t/unable-to-add-objectives-in-vector-form-using-jump/94041 "2023-02-04T11:46:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gokhan\_Kof](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gokhan_kof/32/43267_2.png) [@Gokhan\_Kof](https://discourse.julialang.org/u/Gokhan_Kof)\
**Post date:** [February 4, 2023, 11:46am UTC](https://discourse.julialang.org/t/unable-to-add-objectives-in-vector-form-using-jump/94041/1 "2023-02-04T11:46:30Z")

</div>

Hi,

I was trying to test multi-objective support of JuMP

```julia
(MOO) pkg> st
     Project MOO v0.0.1
      Status `~/Desktop/MOO.jl/Project.toml`
  [60bf3e95] GLPK v1.1.0
  [4076af6c] JuMP v1.7.0 `https://github.com/jump-dev/JuMP.jl.git#od/vector-optimization`
  [b8f27783] MathOptInterface v1.11.5
  [44cfe95a] Pkg

```

Running the following snippet

```julia
using JuMP, MOO, GLPK

model = JuMP.Model()

p1 = [77, 94, 71, 63, 96, 82, 85, 75, 72, 91, 99, 63, 84, 87, 79, 94, 90]
p2 = [65, 90, 90, 77, 95, 84, 70, 94, 66, 92, 74, 97, 60, 60, 65, 97, 93]
w = [80, 87, 68, 72, 66, 77, 99, 85, 70, 93, 98, 72, 100, 89, 67, 86, 91]
model = Model()
set_silent(model)
@variable(model, x[1:length(w)], Bin)
@objective(model, Max, [p1' * x, p2' * x])
@constraint(model, w' * x <= 900)
model

```

I get the following error:

```julia
ERROR: TypeError: in ObjectiveFunction, in F, expected F<:MathOptInterface.AbstractScalarFunction, got Type{MathOptInterface.VectorAffineFunction{Float64}}
Stacktrace:
 [1] set_objective_function(model::Model, func::MathOptInterface.VectorAffineFunction{Float64})
   @ JuMP ~/anaconda3/share/julia/packages/JuMP/3qle2/src/objective.jl:104
 [2] set_objective_function(model::Model, func::Vector{AffExpr})
   @ JuMP ~/anaconda3/share/julia/packages/JuMP/3qle2/src/objective.jl:143
 [3] set_objective(model::Model, sense::MathOptInterface.OptimizationSense, func::Vector{AffExpr})
   @ JuMP ~/anaconda3/share/julia/packages/JuMP/3qle2/src/objective.jl:172
 [4] macro expansion
   @ ~/anaconda3/share/julia/packages/JuMP/3qle2/src/macros.jl:1297 [inlined]
 [5] top-level scope
   @ ~/Desktop/MOO.jl/ttt.jl:11

```

Is Julia still trying to use the default version of 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:** [February 4, 2023, 8:02pm UTC](https://discourse.julialang.org/t/unable-to-add-objectives-in-vector-form-using-jump/94041/2 "2023-02-04T20:02:49Z")

</div>

You need to follow the installation instructions:

> **[GitHub - jump-dev/MultiObjectiveAlgorithms.jl](https://github.com/jump-dev/MultiObjectiveAlgorithms.jl#installation)**
>
> Contribute to jump-dev/MultiObjectiveAlgorithms.jl development by creating an account on GitHub.

You need the master branch of MathOptInterface.

---

<div class="post-metadata">

**Author:** ![Gokhan\_Kof](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gokhan_kof/32/43267_2.png) [@Gokhan\_Kof](https://discourse.julialang.org/u/Gokhan_Kof)\
**Post date:** [February 4, 2023, 8:17pm UTC](https://discourse.julialang.org/t/unable-to-add-objectives-in-vector-form-using-jump/94041/3 "2023-02-04T20:17:54Z")

</div>

Thanks! With the master branch of MOI, it works. I skipped that part I think.

---

<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:** [February 4, 2023, 8:24pm UTC](https://discourse.julialang.org/t/unable-to-add-objectives-in-vector-form-using-jump/94041/4 "2023-02-04T20:24:55Z")

</div>

Great. This is still in development so let me know if you have any feedback or suggestions.

---

<div class="post-metadata">

**Author:** ![Gokhan\_Kof](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gokhan_kof/32/43267_2.png) [@Gokhan\_Kof](https://discourse.julialang.org/u/Gokhan_Kof)\
**Post date:** [February 4, 2023, 8:33pm UTC](https://discourse.julialang.org/t/unable-to-add-objectives-in-vector-form-using-jump/94041/5 "2023-02-04T20:33:46Z")

</div>

Thanks so much! I am actually trying to add some MODO algorithms from the literature into the package. I have implementations in Julia but it is a back and forth between JuMP and other steps of the algorithms. Trying to adapt it to work with MOI.

---

<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:** [February 4, 2023, 8:51pm UTC](https://discourse.julialang.org/t/unable-to-add-objectives-in-vector-form-using-jump/94041/6 "2023-02-04T20:51:11Z")

</div>

Okay, great! Feel free to make a pull request, even if it is only half working, and we can go from there.

Each algorithm needs a file like this:

> <https://github.com/odow/MOO.jl/blob/master/src/algorithms/Lexicographic.jl>

The main part is a struct that subtypes `AbstractAlgorithm`:

> <https://github.com/odow/MOO.jl/blob/652c899b6705f0280100e041098fc21b50058188/src/algorithms/Lexicographic.jl#L6-L16>

Then you need to implement

> <https://github.com/odow/MOO.jl/blob/652c899b6705f0280100e041098fc21b50058188/src/algorithms/Lexicographic.jl#L34>

and return a vector of Pareto solutions:

> <https://github.com/odow/MOO.jl/blob/652c899b6705f0280100e041098fc21b50058188/src/algorithms/Lexicographic.jl#L67>

They also need a corresponding test file:

> <https://github.com/odow/MOO.jl/blob/master/test/algorithms/Lexicographic.jl>
