Error when compiling linear integer programming problem

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

Currently I’m using the COSMO.jl solver, with the following function defining and solving the model:

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, and the CBC solver by default. However, when compiling I get the following error:

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?

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

1 Like

Ah. But I guess you want one for M1: Error when installing solvers for JuMP - #4 by tlorans

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

1 Like

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.

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

The list of solvers is here: Installation Guide · JuMP. 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. Just pass the full path to the executable:
https://github.com/jump-dev/AmplNLWriter.jl#other-binaries

2 Likes

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!

1 Like

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

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

Hi @yasirroni, welcome to the forum :smile:

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.

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

1 Like

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

1 Like

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

1 Like