jump-dev / Cbc.jl

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

Cbc_status only available for MIP models #154

Closed Dx-Wang closed 3 years ago

Dx-Wang commented 3 years ago

I got the following errors when solving an LP (no integer variable) with Cbc. The errors arose when I try to get the value of the variables after the problem is solved. I can use Clp instead, but is this a bug?

Cbc_status only available for MIP models.

signal (6): Aborted
in expression starting at /home/eset_engine/wudi176_BSET_test_interface.jl:15
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
Cbc_status at /root/.julia/packages/Cbc/8ANWi/deps/../../../../../../CbcInstall/dist/lib/libCbcSolver.so (unknown line)
Cbc_status at /root/.julia/packages/Cbc/8ANWi/src/gen/libcbc_api.jl:353 [inlined]
get at /root/.julia/packages/Cbc/8ANWi/src/MOI_wrapper/MOI_wrapper.jl:828
get at /root/.julia/packages/MathOptInterface/5WwpK/src/Utilities/cachingoptimizer.jl:706
get at /root/.julia/packages/MathOptInterface/5WwpK/src/Bridges/bridge_optimizer.jl:719
unknown function (ip: 0x7fe5362f05e1)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2141 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2305
get at /root/.julia/packages/MathOptInterface/5WwpK/src/Utilities/cachingoptimizer.jl:706
_moi_get_result at /root/.julia/packages/JuMP/y5vgk/src/JuMP.jl:943
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2141 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2305
get at /root/.julia/packages/JuMP/y5vgk/src/JuMP.jl:976
#value#30 at /root/.julia/packages/JuMP/y5vgk/src/variables.jl:766
value at /root/.julia/packages/JuMP/y5vgk/src/variables.jl:766 [inlined]
_broadcast_getindex_evalf at ./broadcast.jl:630 [inlined]
_broadcast_getindex at ./broadcast.jl:603 [inlined]
getindex at ./broadcast.jl:563 [inlined]
macro expansion at ./broadcast.jl:909 [inlined]
macro expansion at ./simdloop.jl:77 [inlined]
copyto! at ./broadcast.jl:908 [inlined]
copyto! at ./broadcast.jl:863 [inlined]
copy at ./broadcast.jl:839 [inlined]
materialize at ./broadcast.jl:819
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2141 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2305
run at /home/eset_engine/BSET/UOBS_Evaluation_engine.jl:212
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2141 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2305
run at /home/eset_engine/BSET/engine.jl:420
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2141 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2305
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1631 [inlined]
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:328
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:417
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:368 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:778
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:888
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7fe559fd320f)
unknown function (ip: (nil))
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:897
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:814
jl_parse_eval_all at /buildworker/worker/package_linux64/build/src/ast.c:873
jl_load at /buildworker/worker/package_linux64/build/src/toplevel.c:878
include at ./boot.jl:328 [inlined]
include_relative at ./loading.jl:1105
include at ./Base.jl:31
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2135 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2305
exec_options at ./client.jl:287
_start at ./client.jl:460
jfptr__start_2084.clone_1 at /usr/local/julia/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2135 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2305
unknown function (ip: 0x401931)
unknown function (ip: 0x401533)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x4015d4)
Allocations: 191325576 (Pool: 191285950; Big: 39626); GC: 115
Aborted

Thanks!

odow commented 3 years ago

Please provide a reproducible example.

odow commented 3 years ago

/root/.julia/packages/Cbc/8ANWi/deps/../../../../../../CbcInstall/dist/lib/libCbcSolver.so

This looks like you might be using your devel copy (https://github.com/jump-dev/Cbc.jl/issues/152)?

You should be careful using a non-released version. The API might have changed, and you may get errors like this.

Dx-Wang commented 3 years ago

Yes. I got this error with the devel version of Cbc. Let me try if this occurs with v2.10.5 or v2.10.3.

odow commented 3 years ago

We distribute binaries for 2.10.3. There is no guarantee of support for anything else.

odow commented 3 years ago

I've started the process of updating to 2.10.5: https://github.com/JuliaPackaging/Yggdrasil/pull/2661

Let me try if this occurs with v2.10.5 or v2.10.3.

It would be useful to post a reproducible example, or add it to the test suite so we can check if it happen in future. I assume at some point it will be part of a released Cbc version.

Dx-Wang commented 3 years ago

The issue also exists for 2.10.5. I'd expect it would happen to any LP. Here is an example example.txt

Log:

Presolve 0 (-1) rows, 0 (-3) columns and 0 (-3) elements
Optimal - objective value 15
After Postsolve, objective 15, infeasibilities - dual 0 (0), primal 0 (0)
Optimal objective 15 - 0 iterations time 0.002, Presolve 0.00
Optimization statusnothing
ERROR: LoadError: OptimizeNotCalled()
Stacktrace:
 [1] _moi_get_result(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::Vararg{Any,N} where N) at /root/.julia/packages/JuMP/y5vgk/src/JuMP.jl:944
 [2] get(::Model, ::MathOptInterface.VariablePrimal, ::VariableRef) at /root/.julia/packages/JuMP/y5vgk/src/JuMP.jl:976
 [3] #value#30(::Int64, ::typeof(value), ::VariableRef) at /root/.julia/packages/JuMP/y5vgk/src/variables.jl:766
 [4] value at /root/.julia/packages/JuMP/y5vgk/src/variables.jl:766 [inlined]
 [5] _broadcast_getindex_evalf at ./broadcast.jl:630 [inlined]
 [6] _broadcast_getindex at ./broadcast.jl:603 [inlined]
 [7] getindex at ./broadcast.jl:563 [inlined]
 [8] macro expansion at ./broadcast.jl:909 [inlined]
 [9] macro expansion at ./simdloop.jl:77 [inlined]
 [10] copyto! at ./broadcast.jl:908 [inlined]
 [11] copyto! at ./broadcast.jl:863 [inlined]
 [12] copy at ./broadcast.jl:839 [inlined]
 [13] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(value),Tuple{Array{VariableRef,1}}}) at ./broadcast.jl:819
 [14] top-level scope at /home/eset_engine/example.jl:11
 [15] include at ./boot.jl:328 [inlined]
 [16] include_relative(::Module, ::String) at ./loading.jl:1105
 [17] include(::Module, ::String) at ./Base.jl:31
 [18] exec_options(::Base.JLOptions) at ./client.jl:287
 [19] _start() at ./client.jl:460
in expression starting at /home/eset_engine/example.jl:11
Dx-Wang commented 3 years ago

It works fine for 2.10.3.

odow commented 3 years ago

optimize! does not return a status like that.

This works fine for me on 2.10.5. How did you build yours?

julia> using JuMP

julia> using Cbc

julia> m = Model(Cbc.Optimizer);

julia> @variable(m, x[1:3] >= 0);

julia> @constraint(m, sum([1., 2., 3.] .* x) == 10.);

julia> @objective(m, Min, sum([2., 3., 6.] .* x));

julia> optimize!(m);
Welcome to the CBC MILP Solver 
Version: 2.10.5 
Build Date: Apr  5 2020 

command line - Cbc_C_Interface -solve -quit (default strategy 1)
Presolve 0 (-1) rows, 0 (-3) columns and 0 (-3) elements
Empty problem - 0 rows, 0 columns and 0 elements
Optimal - objective value 15
After Postsolve, objective 15, infeasibilities - dual 0 (0), primal 0 (0)
Optimal objective 15 - 0 iterations time 0.002, Presolve 0.00
Total time (CPU seconds):       0.00   (Wallclock seconds):       0.00

julia> status = termination_status(m)
OPTIMAL::TerminationStatusCode = 1

julia> println("Optimization status", status);
Optimization statusOPTIMAL

julia> println("x = ", value.(x));
x = [0.0, 5.0, 0.0]
Dx-Wang commented 3 years ago

That's odd. I built Cbc with coinbrew in an official (but old, 1.3.0) julia docker container (which is based on Debian 10). It worked fine before and it works for MIPs now, just not for LPs.

odow commented 3 years ago

Ah. It seems like we bundle this patch which is the likely culprit: https://github.com/JuliaPackaging/Yggdrasil/blob/master/C/Coin-OR/Cbc/bundled/patches/no_lp.patch

Can you test #155?

odow commented 3 years ago

@Dx-Wang try the latest master. I merged since it seems like the correct thing to do in more cases.

Dx-Wang commented 3 years ago

Thanks, Oscar! The Cbc_status error seems to be gone for the latest master , but there are related errors when calling value on x.

Presolve 0 (-1) rows, 0 (-3) columns and 0 (-3) elements
Optimal - objective value 15
After Postsolve, objective 15, infeasibilities - dual 0 (0), primal 0 (0)
Optimal objective 15 - 0 iterations time 0.002, Presolve 0.00
Optimization statusOPTIMAL
ERROR: LoadError: Result index of attribute MathOptInterface.VariablePrimal(1) out of bounds. There are currently 0 solution(s) in the model.
Stacktrace:
 [1] check_result_index_bounds at /root/.julia/packages/MathOptInterface/5WwpK/src/attributes.jl:139 [inlined]
 [2] get at /root/.julia/packages/Cbc/d781z/src/MOI_wrapper/MOI_wrapper.jl:760 [inlined]
 [3] get(::MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /root/.julia/packages/MathOptInterface/5WwpK/src/Utilities/cachingoptimizer.jl:726
 [4] get(::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /root/.julia/packages/MathOptInterface/5WwpK/src/Bridges/bridge_optimizer.jl:933
 [5] get(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /root/.julia/packages/MathOptInterface/5WwpK/src/Utilities/cachingoptimizer.jl:726
 [6] _moi_get_result(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::Vararg{Any,N} where N) at /root/.julia/packages/JuMP/y5vgk/src/JuMP.jl:946
 [7] get(::Model, ::MathOptInterface.VariablePrimal, ::VariableRef) at /root/.julia/packages/JuMP/y5vgk/src/JuMP.jl:976
 [8] #value#30(::Int64, ::typeof(value), ::VariableRef) at /root/.julia/packages/JuMP/y5vgk/src/variables.jl:766
 [9] value at /root/.julia/packages/JuMP/y5vgk/src/variables.jl:766 [inlined]
 [10] _broadcast_getindex_evalf at ./broadcast.jl:630 [inlined]
 [11] _broadcast_getindex at ./broadcast.jl:603 [inlined]
 [12] getindex at ./broadcast.jl:563 [inlined]
 [13] macro expansion at ./broadcast.jl:909 [inlined]
 [14] macro expansion at ./simdloop.jl:77 [inlined]
 [15] copyto! at ./broadcast.jl:908 [inlined]
 [16] copyto! at ./broadcast.jl:863 [inlined]
 [17] copy at ./broadcast.jl:839 [inlined]
 [18] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(value),Tuple{Array{VariableRef,1}}}) at ./broadcast.jl:819
 [19] top-level scope at /home/eset_engine/example.jl:14
 [20] include at ./boot.jl:328 [inlined]
 [21] include_relative(::Module, ::String) at ./loading.jl:1105
 [22] include(::Module, ::String) at ./Base.jl:31
 [23] exec_options(::Base.JLOptions) at ./client.jl:287
 [24] _start() at ./client.jl:460
in expression starting at /home/eset_engine/example.jl:14
odow commented 3 years ago

See #160 for the fixes.

On Fri, 12 Mar 2021, 12:01 PM Dexin Wang, @.***> wrote:

Thanks, Oscar! The Cbc_status error seems to be gone for the latest master , but there are related errors when calling value on x.

Presolve 0 (-1) rows, 0 (-3) columns and 0 (-3) elements Optimal - objective value 15 After Postsolve, objective 15, infeasibilities - dual 0 (0), primal 0 (0) Optimal objective 15 - 0 iterations time 0.002, Presolve 0.00 Optimization statusOPTIMAL ERROR: LoadError: Result index of attribute MathOptInterface.VariablePrimal(1) out of bounds. There are currently 0 solution(s) in the model. Stacktrace: [1] check_result_index_bounds at /root/.julia/packages/MathOptInterface/5WwpK/src/attributes.jl:139 [inlined] [2] get at /root/.julia/packages/Cbc/d781z/src/MOI_wrapper/MOI_wrapper.jl:760 [inlined] [3] get(::MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /root/.julia/packages/MathOptInterface/5WwpK/src/Utilities/cachingoptimizer.jl:726 [4] get(::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /root/.julia/packages/MathOptInterface/5WwpK/src/Bridges/bridge_optimizer.jl:933 [5] get(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::MathOptInterface.VariableIndex) at /root/.julia/packages/MathOptInterface/5WwpK/src/Utilities/cachingoptimizer.jl:726 [6] _moi_get_result(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.VariablePrimal, ::Vararg{Any,N} where N) at /root/.julia/packages/JuMP/y5vgk/src/JuMP.jl:946 [7] get(::Model, ::MathOptInterface.VariablePrimal, ::VariableRef) at /root/.julia/packages/JuMP/y5vgk/src/JuMP.jl:976 [8] #value#30(::Int64, ::typeof(value), ::VariableRef) at /root/.julia/packages/JuMP/y5vgk/src/variables.jl:766 [9] value at /root/.julia/packages/JuMP/y5vgk/src/variables.jl:766 [inlined] [10] _broadcast_getindex_evalf at ./broadcast.jl:630 [inlined] [11] _broadcast_getindex at ./broadcast.jl:603 [inlined] [12] getindex at ./broadcast.jl:563 [inlined] [13] macro expansion at ./broadcast.jl:909 [inlined] [14] macro expansion at ./simdloop.jl:77 [inlined] [15] copyto! at ./broadcast.jl:908 [inlined] [16] copyto! at ./broadcast.jl:863 [inlined] [17] copy at ./broadcast.jl:839 [inlined] [18] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1},Nothing,typeof(value),Tuple{Array{VariableRef,1}}}) at ./broadcast.jl:819 [19] top-level scope at /home/eset_engine/example.jl:14 [20] include at ./boot.jl:328 [inlined] [21] include_relative(::Module, ::String) at ./loading.jl:1105 [22] include(::Module, ::String) at ./Base.jl:31 [23] exec_options(::Base.JLOptions) at ./client.jl:287 [24] _start() at ./client.jl:460 in expression starting at /home/eset_engine/example.jl:14

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/jump-dev/Cbc.jl/issues/154#issuecomment-797107041, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6MQJOCWKELVYN7TST3P4TTDE4S5ANCNFSM4Y2DJ45A .