# Error when compiling linear integer programming problem

**URL:** <https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization\
**Created:** [November 8, 2021, 4:39am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121 "2021-11-08T04:39:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jyscao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jyscao/32/29181_2.png) [@jyscao](https://discourse.julialang.org/u/jyscao)\
**Post date:** [November 8, 2021, 4:39am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/1 "2021-11-08T04:39:27Z")

</div>

I’m trying to solve an optimization problem described in the following Stats SE question:  
[https://stats.stackexchange.com/questions/544065/how-to-fit-data-to-a-discrete-linear-model](https://stats.stackexchange.com/questions/544065/how-to-fit-data-to-a-discrete-linear-model)

Currently I’m using the [`COSMO.jl`](https://github.com/oxfordcontrol/COSMO.jl) solver, with the following function defining and solving the model:

```julia
function solve_linear_program(perc_drops::Vector{Float64}, omega::Float64)
    # NOTE: see - http://lpsolve.sourceforge.net/5.1/absolute.htm (Objective function - minimization and sign is positive or maximization and sign is negative)
    model = Model(with_optimizer(COSMO.Optimizer))
    @variable(model, x[1:length(perc_drops)] >= 0, Int)
    @variable(model, X[1:length(perc_drops)] >= 0, Int)
    @constraint(model, omega*x - perc_drops .>= X)
    @constraint(model, perc_drops - omega*x .>= X)
    @objective(model, Min, sum(X))
    optimize!(model)
end

```

The function above is effectively a port of the working Python code I already had, which used [PuLP](https://github.com/coin-or/pulp), and the `CBC` solver by default. However, when compiling I get the following error:

```julia
ERROR: LoadError: `MOI.SingleVariable`-in-`MOI.Integer` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
 [2] constrained variables in `MOI.Integer` are not supported because no added bridge supports bridging it.
   Cannot add free variables and then constrain them because:
   (6) `MOI.SingleVariable`-in-`MOI.Integer` constraints are not supported
 (6) `MOI.SingleVariable`-in-`MOI.Integer` constraints are not supported because:
   Cannot use `MOIB.Constraint.ScalarFunctionizeBridge{Float64, MOI.Integer}` because:
   (7) `MOI.ScalarAffineFunction{Float64}`-in-`MOI.Integer` constraints are not supported
 (7) `MOI.ScalarAffineFunction{Float64}`-in-`MOI.Integer` constraints are not supported because:
   Cannot use `MOIB.Constraint.ScalarSlackBridge{Float64, MOI.ScalarAffineFunction{Float64}, MOI.Integer}` because:
   [2] constrained variables in `MOI.Integer` are not supported

```

What exactly does the above error mean? Is the limitation due to `JuMP`, its dependency library `MathOptInterface` or the `COSMO` solver that I’m using? Or perhaps I’m just not using the library correctly?

---

<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 8, 2021, 5:23am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/2 "2021-11-08T05:23:59Z")

</div>

Cosmo does not support integer variables. You need to choose an appropriate solver. Try Cbc instead.

---

<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 8, 2021, 5:26am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/3 "2021-11-08T05:26:37Z")

</div>

Ah. But I guess you want one for M1: [Error when installing solvers for JuMP - #4 by tlorans](https://discourse.julialang.org/t/error-when-installing-solvers-for-jump/71114/4)

Follow the custom installation instructions: [https://github.com/jump-dev/Cbc.jl#custom-installation](https://github.com/jump-dev/Cbc.jl#custom-installation)

---

<div class="post-metadata">

**Author:** ![jyscao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jyscao/32/29181_2.png) [@jyscao](https://discourse.julialang.org/u/jyscao)\
**Post date:** [November 8, 2021, 5:41am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/4 "2021-11-08T05:41:41Z")

</div>

I tried the custom installation instructions, but couldn’t get it to work in the REPL. I’ll give it a shot again and report back.

---

<div class="post-metadata">

**Author:** ![jyscao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jyscao/32/29181_2.png) [@jyscao](https://discourse.julialang.org/u/jyscao)\
**Post date:** [November 8, 2021, 5:44am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/5 "2021-11-08T05:44:32Z")

</div>

Alternatively, do you have any suggestions for solvers that support integer programming and are written in pure Julia without dependencies in another language?

---

<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 8, 2021, 6:01am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/6 "2021-11-08T06:01:31Z")

</div>

The list of solvers is here: [Installation Guide · JuMP](https://jump.dev/JuMP.jl/stable/installation/#Supported-solvers). But I don’t think there is a pure Julia MILP solver.

If you can compile a Cbc binary (or get one from homebrew), you can use [https://github.com/jump-dev/AmplNLWriter.jl](https://github.com/jump-dev/AmplNLWriter.jl). Just pass the full path to the executable:  
[https://github.com/jump-dev/AmplNLWriter.jl#other-binaries](https://github.com/jump-dev/AmplNLWriter.jl#other-binaries)

---

<div class="post-metadata">

**Author:** ![jyscao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jyscao/32/29181_2.png) [@jyscao](https://discourse.julialang.org/u/jyscao)\
**Post date:** [November 14, 2021, 6:12pm UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/7 "2021-11-14T18:12:53Z")

</div>

I tried the custom installation instructions for Cbc.jl again, and it’s working now. It probably would’ve worked before too, but what happened was I got confused by the error output from running `Pkg.add("Cbc")`, which I’m guessing still tries to use the CBC library that comes from Julia’s package repository, despite `ENV["JULIA_CBC_LIBRARY_PATH"]` being set. However, with `Pkg.build("Cbc")`, the user’s custom CBC library path gets picked up, and the build succeeds, allowing `using Cbc` to work too.

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![yasirroni](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yasirroni/32/212529_2.png) [@yasirroni](https://discourse.julialang.org/u/yasirroni)\
**Post date:** [October 10, 2024, 3:25am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/8 "2024-10-10T03:25:23Z")

</div>

Hi @jyscao, could you share to us how you set `ENV["JULIA_CBC_LIBRARY_PATH"]`?

* * *

Edit: I solved it. Very long way as Cbc require v2.10.0

```shell
julia
import Pkg
Pkg.rm("Cbc")
exit()
sudo cd /usr/local/lib
sudo curl -LO https://github.com/coin-or/Cbc/archive/refs/tags/2.10.0.tar.gz
sudo tar -xvzf 2.10.0.tar.gz
cd Cbc-releases-2.10.0
sudo ./configure
make
sudo make install
julia
ENV["JULIA_CBC_LIBRARY_PATH"] = "/usr/local/lib/Cbc-releases-2.10.0/lib"
import Pkg
Pkg.build("Cbc")
using Cbc

```

---

<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:** [October 10, 2024, 4:25am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/9 "2024-10-10T04:25:26Z")

</div>

Hi @yasirroni, welcome to the forum 😄

You don’t need to compile Cbc locally. Just do `Pkg.add("Cbc")` and we will install the binaries for you.

I would also encourage you to use HiGHS.jl instead of Cbc.jl. The former is better maintained, and typically has better performance.

---

<div class="post-metadata">

**Author:** ![yasirroni](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yasirroni/32/212529_2.png) [@yasirroni](https://discourse.julialang.org/u/yasirroni)\
**Post date:** [October 10, 2024, 5:10am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/10 "2024-10-10T05:10:02Z")

</div>

Hi @odow,

Sadly, using `Pkg.add("Cbc")` will fails in Mac M1. I’m using it as part as PandaModels. It is reported on `Python` `pandapower` bug in [[bug] Failed to precompile PandaModels on Mac M1 · Issue #2417 · e2nIEE/pandapower · GitHub](https://github.com/e2nIEE/pandapower/issues/2417). Thanks for the `HIGHS.jl` recommendation. Currently I’m only using `Ipopt.jl` though. I’ve read about HIGHS since a long time ago but haven’t look at it yet.

---

<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:** [October 10, 2024, 5:33am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/11 "2024-10-10T05:33:42Z")

</div>

Please use HiGHS instead. I haven’t priortized fixing Cbc on M1 because HiGHS is a better replacement regardless.

---

<div class="post-metadata">

**Author:** ![yasirroni](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yasirroni/32/212529_2.png) [@yasirroni](https://discourse.julialang.org/u/yasirroni)\
**Post date:** [October 10, 2024, 7:24am UTC](https://discourse.julialang.org/t/error-when-compiling-linear-integer-programming-problem/71121/12 "2024-10-10T07:24:25Z")

</div>

Thanks @odow. Sadly, I’m not the one to decide that as I only use and partly contributing to `pandapower`. I will raise Issue there so that `pandapower` should migrate `PandaModels` to use `HiGHS` by default instead of `Cbc`.

Now tracking `PandaModels.jl` at [Migrate to `HiGHS.jl` for default solver · Issue #117 · e2nIEE/PandaModels.jl · GitHub](https://github.com/e2nIEE/PandaModels.jl/issues/117)
