# The objective function sparse is not supported by JuMP in julia

**URL:** <https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization, sparse, nonlinearsolve, linearsolve\
**Created:** [November 3, 2022, 5:13pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726 "2022-11-03T17:13:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![thiagoselias](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thiagoselias/32/43916_2.png) [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)\
**Post date:** [November 3, 2022, 5:13pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/1 "2022-11-03T17:13:30Z")

</div>

model = Model(Gurobi.Optimizer)  
@objective(model, Min, DRect + 0.6_DBlad + 0.6_DBO)

The objective function `sparse([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,....0.00010553257427534537], 1, 721)` is not supported by JuMP.

---

<div class="post-metadata">

**Author:** ![thiagoselias](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thiagoselias/32/43916_2.png) [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)\
**Post date:** [November 3, 2022, 5:16pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/2 "2022-11-03T17:16:02Z")

</div>

> [@thiagoselias](#):
>
> DRect + 0.6_DBlad + 0.6_DBO

how can i solve this problem i am using a sparse matrix for a minimization problem.

DRect, DBlad, DBO data are in sparse matrix.

---

<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:** [November 3, 2022, 7:01pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/3 "2022-11-03T19:01:14Z")

</div>

What does it mean to minimize a matrix? So you mean something like

`sum(DRect + 0.6DBlad + 0.6DBO)`?

---

<div class="post-metadata">

**Author:** ![thiagoselias](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thiagoselias/32/43916_2.png) [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)\
**Post date:** [November 3, 2022, 7:19pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/4 "2022-11-03T19:19:00Z")

</div>

> [@odow](#):
>
> What does it mean to minimize a matrix? So you mean something like

Each name of this corresponds to a sparse matrix (DRect , Blad, DBO).

Using MatLab I managed to create my cost vector and imported it to Julia.

#Cost Vector  
#c = DRect + 0.6_Blad+ 0.6_DBO;

File = matopen(“c.mat”)  
c = read(File,“c”);  
close(File);

What I want is Minimize ‘‘c’’:

using JuMP, Clp,  
model = Model(Clp.Optimizer)  
@objective(model, Min, c)

---

<div class="post-metadata">

**Author:** ![thiagoselias](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thiagoselias/32/43916_2.png) [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)\
**Post date:** [November 3, 2022, 7:24pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/5 "2022-11-03T19:24:08Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/d/0/d027e49cd9f5e6f0284a39b8536687b0e981bae9.png)

---

<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:** [November 3, 2022, 7:24pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/6 "2022-11-03T19:24:44Z")

</div>

I meant, mathematically, what does it mean to minimize a matrix?

Solvers like Gurobi and Clp all assume that the objective is a _scalar_ expression. They cannot minimize a matrix. You need to apply some reduction operator to convert the matrix into a scalar expression.

> `using JuMP, Clp`  
> `model = Model(Clp.Optimizer)`  
> `@objective(model, Min, c)`

You don’t have any variables or constraints.

Do you mean something like

```Julia
model = Model(Clp.Optimizer)
@variable(model, x[1:length(c)] >= 0)
@objective(model, Min, c' * x)

```

You should read [Getting started with JuMP · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/getting_started_with_JuMP/)

---

<div class="post-metadata">

**Author:** ![thiagoselias](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thiagoselias/32/43916_2.png) [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)\
**Post date:** [November 3, 2022, 7:26pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/7 "2022-11-03T19:26:07Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/e/0/e0a2850e3493726259b7f73c63dfc54e9b21da23.png)

---

<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:** [November 3, 2022, 7:30pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/8 "2022-11-03T19:30:25Z")

</div>

I think you need to step back and think about what you’re trying to achieve.

Do you have, on a piece of paper, a mathematical formulation of your problem as a (mixed-integer) linear program?

- What are the decision variables?
- What are their bounds?
- What are the constraints?
- What is the objective function?

It doesn’t make sense to minimize a vector of numbers, which is what `@objective(model, min, c)` is trying to do.

---

<div class="post-metadata">

**Author:** ![thiagoselias](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thiagoselias/32/43916_2.png) [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)\
**Post date:** [November 3, 2022, 7:46pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/9 "2022-11-03T19:46:48Z")

</div>

I have all the data.

My objective function and  
min (DRect + 0.6\* Blad+ 0.6 \*DBO)

the calculation of this result (DRect + 0.6 x Blad+ 0.6 x DBO) I put it inside the vector c

I’m trying to solve it in stages, so I didn’t post the restrictions.

The problem I’m having is working with the espasa array

---

<div class="post-metadata">

**Author:** ![thiagoselias](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thiagoselias/32/43916_2.png) [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)\
**Post date:** [November 3, 2022, 8:28pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726/10 "2022-11-03T20:28:22Z")

</div>

Thanks, with this example I managed to do something.  
Now I’m going to test it here.
