Error when compiling linear integer programming problem

I’m trying to solve an optimization problem described in the following Stats SE question:

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: GitHub - jump-dev/Cbc.jl: Interface to the Coin-OR Cbc solver for mixed-integer programming

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 GitHub - jump-dev/AmplNLWriter.jl: Julia interface to AMPL-enabled solvers. Just pass the full path to the executable:
GitHub - jump-dev/AmplNLWriter.jl: Julia interface to AMPL-enabled solvers

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