# Cbc and Clp performance

**URL:** <https://discourse.julialang.org/t/cbc-and-clp-performance/38505>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, optimization\
**Created:** [April 30, 2020, 8:35pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505 "2020-04-30T20:35:06Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [April 30, 2020, 8:35pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/1 "2020-04-30T20:35:06Z")

</div>

Hello everyone,

I have been testing the solvers of COIN-OR, namely Cbc (MILP solver) and Clp (LP solver).

I obtain for Cbc a very good performance, Cbc even outperforms some commertial solvers in numerically complex problems. But being a MILP solver it does not deliver dual variables.

For Clp the performance I get is very poor in terms of speed, it does not find a solution in times 10 - 20 times the time required by Cbc.

Is anyone able to provide a way out?

1. I could estimate the duals, but I doubt I could find a way to determine them in all cases
2. Is there a way to setup Clp so that its lp delivers the same performance as Cbc?

Thank you!

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 1, 2020, 12:29am UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/2 "2020-05-01T00:29:31Z")

</div>

This is kinda strange because [Cbc says Clp is their default LP solver](https://github.com/coin-or/Cbc) so if you are not using any special configuration, then Cbc is just running Clp under the hood and you should be observing similar performance.

---

<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:** [May 1, 2020, 2:40am UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/3 "2020-05-01T02:40:23Z")

</div>

Do you have a reproducible example?

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [May 1, 2020, 7:11am UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/4 "2020-05-01T07:11:02Z")

</div>

Maybe it’s a question of presolve. SCIP uses SoPlex as LP solver by default, but SCIP has much more presolving implemented, so it might still be faster to call SCIP on LP problems.

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [May 1, 2020, 8:37am UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/5 "2020-05-01T08:37:04Z")

</div>

Thanks, yes this is strange indeed. I have also tried SCIP but it does not work either (there is another post).

The code I am using is:

```julia
using JuMP 
using Cbc
using Clp
using MathOptFormat
using MathOptInterface

mps_model = MathOptFormat.MPS.Model()
MOI.read_from_file(mps_model,string(path,"test_1.mps"))

ucf = Model(with_optimizer(Cbc.Optimizer, logLevel=2))
MOI.copy_to(JuMP.backend(ucf),mps_model)
@time optimize!(ucf) 

ucf = Model(with_optimizer(Clp.Optimizer, LogLevel=4 )) 
MOI.copy_to(JuMP.backend(ucf),mps_model)
@time optimize!(ucf)

```

I have placed a set of three MPS files in WeTransfer to be able to reproduce the problem:

[https://we.tl/t-nHrmMNhben](https://we.tl/t-nHrmMNhben)

Thank you

---

<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:** [May 1, 2020, 1:09pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/6 "2020-05-01T13:09:15Z")

</div>

You can use `JuMP.read_from_file` here: [Solvers · JuMP](https://www.juliaopt.org/JuMP.jl/stable/solvers/#File-formats-1)

```nohighlight
using JuMP
using Clp
model = read_from_file("test_1.mps")
set_optimizer(model, Clp.Optimizer)
optimize!(model)

```

Try with the above code and the latest version of JuMP. Is the time difference in the solver? Or in the JuMP set-up?

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [May 1, 2020, 1:28pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/7 "2020-05-01T13:28:25Z")

</div>

No, the JuMP setup is fine. It is in the execution of the problem (optimize!).

Cbc may take 100-300 seconds, whereas Clp in 1 hour is not finished.

I updated JuMP to version 21.2 and get after running what you suggested I get:

´´´  
**UndefVarError: read\_from\_file not defined**  
in top-level scope at TestOptimizers.jl:8  
´´´

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 1, 2020, 1:36pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/8 "2020-05-01T13:36:41Z")

</div>

If the order was the contrary (i.e., if you called Clp before Cbc) I would question if the time difference has nothing to do with the call to Clp precompiling things Cbc will reuse after.

> [@Diego](#):
>
> **UndefVarError: read\_from\_file not defined**

This is very strange, I have JuMP 0.21.2 in my machine and this method is defined.

> [@odow](#):
>
> set\_optimizer(Clp.Optimizer)

For people trying to replicate, it should read:

```julia
set_optimizer(model, Clp.Optimizer)

```

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [May 1, 2020, 3:43pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/9 "2020-05-01T15:43:14Z")

</div>

Thanks, I managed to run exactly what you were indicating just after restarting Julia.

This code does not complete in 1 hour, it neither prints any log:

```julia
using JuMP 
using Clp
model = read_from_file("test_1.mps")
set_optimizer(model,Clp.Optimizer)
set_optimizer_attribute(model, "LogLevel", 4)
@time optimize!(model) 

```

Whereas this other code is done in less than 200 seconds

```julia
using JuMP
using Cbc
model = read_from_file("test_1.mps")
set_optimizer(model,Cbc.Optimizer)
@time optimize!(model)

```

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [May 1, 2020, 4:07pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/10 "2020-05-01T16:07:02Z")

</div>

To prevent what you described I restarted Julia before every run

---

<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:** [May 1, 2020, 7:35pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/11 "2020-05-01T19:35:06Z")

</div>

Presumably these are just hard models. Try GLPK or a commercial solver. Cbc must apply helpful presolves that Clp doesn’t, or it uses non-default parameters.

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [May 2, 2020, 3:13pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/12 "2020-05-02T15:13:30Z")

</div>

Team, the issue is apparently on the wrapper side:

“but the Cbc version does not seem to have add\_row or add\_column so does things in a different way. The Clp version has both add\_row and add\_rows. If the interface is using add\_row and/or add\_column, then that would explain the large time spent before Clp. There is an example in Clp/examples/addRows.cpp which which is there just to explain why it is not a good idea to add one row at a time for many rows.”

I have also been evaluating performance with GLPK and with SCIP-SoPlex, but the performance is not good enough.

What do you think?

See:

[https://github.com/coin-or/Cbc/issues/301](https://github.com/coin-or/Cbc/issues/301)

---

<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:** [May 2, 2020, 3:25pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/13 "2020-05-02T15:25:14Z")

</div>

There is probably a lot of room for improvement in Clp’s `copy_to` method:

> <https://github.com/jump-dev/Clp.jl/blob/13d37fd7e0cff2d5dedfadd56f90076a63742f38/src/MOIWrapper.jl#L168-L319>

You could probably loop through, build the sparse A matrix with rhs vectors, and then pass to Clp directly.

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [May 2, 2020, 4:17pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/14 "2020-05-02T16:17:27Z")

</div>

I see, why should we focus on the copy\_to method? Is that related to the add\_rows and add\_columns comment of John Forrester?

Do you think it is possible to leverage for this the existing Cbc wrapper?

---

<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:** [May 2, 2020, 4:42pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/15 "2020-05-02T16:42:41Z")

</div>

I haven’t tried your models, but it seems like the speed difference is the loading performance. `copy_to` is where we go from Julia → C.

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [May 2, 2020, 4:54pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/16 "2020-05-02T16:54:20Z")

</div>

How likely it is that the performance loss is in the C interface?

---

<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:** [May 6, 2020, 9:39pm UTC](https://discourse.julialang.org/t/cbc-and-clp-performance/38505/17 "2020-05-06T21:39:22Z")

</div>

Following up on this for prosperity: a new version of Clp has been released that resolves the performance problem.
