jump-dev / Cbc.jl

A Julia interface to the Coin-OR Branch and Cut solver (CBC)
https://projects.coin-or.org/Cbc
Other
81 stars 35 forks source link

Cbc backend returns primal status feasible for infeasible problem #122

Closed DrChainsaw closed 4 years ago

DrChainsaw commented 5 years ago

Sorry if this is the wrong place for this.

MWE with a constraint that 10 binary variables shall add up to 11:

julia> using JuMP, Cbc

julia> mmm = Model(with_optimizer(Cbc.Optimizer));

julia> @variable(mmm, x[1:10], Bin);

julia> @objective(mmm, Max, sum(x))
x[1] + x[2] + x[3] + x[4] + x[5] + x[6] + x[7] + x[8] + x[9] + x[10]

julia> @constraint(mmm, infeasible, sum(x) == 11)
infeasible : x[1] + x[2] + x[3] + x[4] + x[5] + x[6] + x[7] + x[8] + x[9] + x[10] == 11.0

julia> JuMP.optimize!(mmm)
Welcome to the CBC MILP Solver
Version: 2.9.9
Build Date: Dec 31 2018

command line - Cbc_C_Interface -solve -quit (default strategy 1)
Problem is infeasible - 0.00 seconds
Total time (CPU seconds):       0.01   (Wallclock seconds):       0.01

julia> JuMP.termination_status(mmm)
INFEASIBLE::TerminationStatusCode = 2

julia> JuMP.primal_status(mmm)
FEASIBLE_POINT::ResultStatusCode = 1

Also sorry if this is intended/unavoidable behaviour or if I'm just misinformed (not very experienced with optimization).

For the real problem I am interested in a feasible solution even though it is not optimal so I ran into the issue because I only checked the primal status.

I guess it is enough to look at the termination status to determine that the solver considered the problem infeasible and only look at the primal status if not infeasible.

mlubin commented 5 years ago

This indeed appears to be a bug.

blegat commented 5 years ago

The if and elseif might need to be swapped here: https://github.com/JuliaOpt/Cbc.jl/blob/17e0bd7b1e7f309eebf0426a00cfad7153cf3bf3/src/MOI_wrapper.jl#L536-L540