gverger / ruby-cbc Goto Github PK
View Code? Open in Web Editor NEWA wrapper around Coin-Or Cbc Integer Linear Programming solver
License: MIT License
A wrapper around Coin-Or Cbc Integer Linear Programming solver
License: MIT License
Hey @gverger, thanks for this great library! I wanted to share some notes about installation that can hopefully be incorporated into the readme.
I think this line is outdated with the release of cbc-wrapper 2.9.9.4.
The gem includes a version of the Coin-Or Cbc library. If the system on which it is installed is not Linux 64bits, it downloads the library sources and recompiles them at installation.
On Ubuntu, users need to do:
sudo apt install coinor-libcbc-dev
On Heroku, I was able to get it working with the Apt buildpack with an Aptfile
of:
coinor-libcbc-dev
And setting LD_LIBRARY_PATH
so it can find LAPACK and BLAS.
heroku config:set LD_LIBRARY_PATH=/app/.apt/usr/lib/x86_64-linux-gnu/lapack:/app/.apt/usr/lib/x86_64-linux-gnu/blas
The last part is needed due to this issue, or it'll fail at runtime with liblapack.so.3: cannot open shared object file: No such file or directory - /app/vendor/bundle/ruby/2.6.0/gems/cbc-wrapper-2.9.9.4/ext/cbc-wrapper/cbc_wrapper.so
.
I also tried an older cbc-wrapper on Heroku without the Apt buildpack (gem "cbc-wrapper", "2.9.9.3"
), and it installs, but fails at runtime with libCgl.so.1: cannot open shared object file: No such file or directory - /app/vendor/bundle/ruby/2.6.0/gems/cbc-wrapper-2.9.9.3/ext/cbc-wrapper/cbc_wrapper.so (LoadError)
.
Hopefully this is helpful to other users.
Hey,
Is it supposed to take an abnormal amount of time to download the gem into a rails app?
Thanks!
It looks like CBC has a function for this purpose Cbc_readMps
, a similar function in ruby-cbc would make it possible to call problem.find_conflict
with an MPS file.
I am evaluating the ruby-cbc gem on a Debian Unstable system.
Linux faerun 4.3.0-1-amd64 #1 SMP Debian 4.3.5-1 (2016-02-06) x86_64 GNU/Linux
$ ruby --version
ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu]
I installed ruby-cbc and cbc-wrapper using "gem install ruby-cbc".
$ gem -list | grep cbc
cbc-wrapper (2.9.9.2)
ruby-cbc (0.3.16)
I tried running this script.
#!/usr/bin/env ruby
require 'forwardable'
require 'ruby-cbc'
m = Cbc::Model.new
x1, x2, x3 = m.int_var_array(3, 0..Cbc::INF)
m.maximize(10 * x1 + 6 * x2 + 4 * x3)
m.enforce(x1 + x2 + x3 <= 100)
m.enforce(10 * x1 + 4 * x2 + 5 * x3 <= 600)
m.enforce(2 * x1 + 2 * x2 + 6* x3 <= 300)
p = m.to_problem
p.solve
if ! p.proven_infeasible?
puts "x1 = #{p.value_of(x1)}"
puts "x2 = #{p.value_of(x2)}"
puts "x3 = #{p.value_of(x3)}"
end
The script is inspired by the example on the github.com page for ruby-cbc. Without the require
'forwardable', I get this:
$ ruby cbctest.rb
/var/lib/gems/2.3.0/gems/ruby-cbc-0.3.16/lib/ruby-cbc/ilp/term_array.rb:3:in `<class:TermArray>': uninitialized constant Ilp::TermArray::Forwardable (NameError)
from /var/lib/gems/2.3.0/gems/ruby-cbc-0.3.16/lib/ruby-cbc/ilp/term_array.rb:2:in `<module:Ilp>'
from /var/lib/gems/2.3.0/gems/ruby-cbc-0.3.16/lib/ruby-cbc/ilp/term_array.rb:1:in `<top (required)>'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /var/lib/gems/2.3.0/gems/ruby-cbc-0.3.16/lib/ruby-cbc.rb:21:in `block in <top (required)>'
from /var/lib/gems/2.3.0/gems/ruby-cbc-0.3.16/lib/ruby-cbc.rb:20:in `each'
from /var/lib/gems/2.3.0/gems/ruby-cbc-0.3.16/lib/ruby-cbc.rb:20:in `<top (required)>'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require'
Adding the require 'forwardable'
resolves this issue; although, it seems to me that term_array.rb should have the require.
Running the script after fixing this issue yields:
$ ruby cbctest.rb
1 was provided for - valid range is 0 to 0
1e+08 was provided for - valid range is 0 to 0
5 was provided for - valid range is 0 to 0
2147483647 was provided for - valid range is 0 to 0
5 was provided for - valid range is 0 to 0
1e-06 was provided for - valid range is 0 to 0
1e-05 was provided for - valid range is 0 to 0
-1 was provided for - valid range is 0 to 0
1003 was provided for - valid range is 0 to 0
1057 was provided for - valid range is 0 to 0
1 was provided for - valid range is 0 to 0
-1 was provided for - valid range is 0 to 0
100 was provided for - valid range is 0 to 0
2 was provided for - valid range is 0 to 0
30 was provided for - valid range is 0 to 0
1005043 was provided for - valid range is 0 to 0
6 was provided for - valid range is 0 to 0
Abort
Once solve
is called Ctrl+C will not interrupt the program. I'm guessing it does something with a signal handler or mask and never resets it.
require 'ruby-cbc'
m = Cbc::Model.new
x1, x2, x3 = m.int_var_array(3, 0..Cbc::INF)
m.maximize(10*x1 + 6*x2 + 4*x3)
m.enforce(x1 + x2 + x3 <= 100)
m.to_problem.solve # comment this line out and Ctrl+C will work
puts "Press Ctrl+C to quit"
# Ctrl+C doesn't work here if we ran solve -- need to use Ctrl+\ to kill
sleep 9999
Hi,
model.enforce(a != b) # outputs "Not a constraint: false"
So how do you express "doesn't equal" (โ ) with this library?
Rather than specify only a range of values, is it possible to do something like the following?
x1 = m.int_var([1, 5,6] , name: "X")
x2 = m.int_var([5,6] , name: "X1")
x3 = m.int_var([6, 7, 8] , name: "X2")
m.enforce(x1 != x2)
m.enforce(x2 != x3)
m.enforce(x3 != x1)
Hey, one more question.
I can't seem to express an inequality constraint.
m.enforce(x1 == x2)
[#<Ilp::Constraint:0x00007fa0c4841220
@bound=0,
@terms=
#<Ilp::TermArray:0x00007fa0c4841068
@terms=[#<Ilp::Term:0x00007fa0c4841018 @mult=1, @var=#<Ilp::Var:0x00007fa0c2f01120 @kind=:integer, @lower_bound=0, @name="mjqbruid", @upper_bound=Infinity>>, #<Ilp::Term:0x00007fa0c4840ff0 @mult=-1, @var=#<Ilp::Var:0x00007fa0c2f00ab8 @kind=:integer, @lower_bound=0, @name="eylhbsfm", @upper_bound=Infinity>>]>,
@type=:equals>]
m.enforce(x1 != x2)
Not a constraint: false
=> [false]
We've been using this library with great success to speed up our large computations in one of our projects. But we've been seeing this error message:
/usr/local/bundle/gems/ruby-cbc-0.3.18/lib/ruby-cbc/problem.rb:188:in `block (2 levels) in finalizer': undefined method `delete_intArray' for Cbc_wrapper:Module (NoMethodError)
int_arrays.each { |ar| Cbc_wrapper.delete_intArray(ar) }
^^^^^^^^^^^^^^^^
from /usr/local/bundle/gems/ruby-cbc-0.3.18/lib/ruby-cbc/problem.rb:188:in `each'
from /usr/local/bundle/gems/ruby-cbc-0.3.18/lib/ruby-cbc/problem.rb:188:in `block in finalizer'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/core_ext/time/conversions.rb:55:in `strftime'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/core_ext/time/conversions.rb:55:in `to_formatted_s'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/quoting.rb:123:in `quoted_date'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/quoting.rb:56:in `quoted_date'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/quoting.rb:245:in `_type_cast'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/quoting.rb:162:in `_type_cast'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/quoting.rb:43:in `type_cast'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/quoting.rb:205:in `block in type_casted_binds'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/quoting.rb:203:in `map'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/quoting.rb:203:in `type_casted_binds'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql_adapter.rb:669:in `exec_no_cache'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql_adapter.rb:649:in `execute_and_clear'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:55:in `exec_query'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `exec_insert'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:93:in `exec_insert'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:171:in `insert'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/query_cache.rb:22:in `insert'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/persistence.rb:375:in `_insert_record'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/persistence.rb:929:in `_create_record'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/counter_cache.rb:166:in `_create_record'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/locking/optimistic.rb:79:in `_create_record'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/attribute_methods/dirty.rb:201:in `_create_record'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/callbacks.rb:461:in `block in _create_record'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:106:in `run_callbacks'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:824:in `_run_create_callbacks'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/callbacks.rb:461:in `_create_record'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/timestamp.rb:108:in `_create_record'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/persistence.rb:900:in `create_or_update'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/callbacks.rb:457:in `block in create_or_update'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:117:in `block in run_callbacks'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/autosave_association.rb:385:in `around_save_collection_association'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:126:in `block in run_callbacks'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:137:in `run_callbacks'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/callbacks.rb:824:in `_run_save_callbacks'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/callbacks.rb:457:in `create_or_update'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/timestamp.rb:126:in `create_or_update'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/persistence.rb:507:in `save!'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/validations.rb:53:in `save!'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/transactions.rb:302:in `block in save!'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/transactions.rb:354:in `block in with_transaction_returning_status'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/transactions.rb:302:in `save!'
from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/suppressor.rb:48:in `save!'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/evaluation.rb:18:in `create'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/strategy/create.rb:12:in `block in result'
from <internal:kernel>:90:in `tap'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/strategy/create.rb:9:in `result'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/factory.rb:43:in `run'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/factory_runner.rb:29:in `block in run'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/notifications.rb:205:in `instrument'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/factory_runner.rb:28:in `run'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
from /app/spec/factories/facilities.rb:52:in `block (3 levels) in <main>'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/callback.rb:13:in `instance_exec'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/callback.rb:13:in `run'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/callbacks_observer.rb:11:in `block in update'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/callbacks_observer.rb:10:in `each'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/callbacks_observer.rb:10:in `update'
from /usr/local/lib/ruby/3.1.0/observer.rb:222:in `block in notify_observers'
from /usr/local/lib/ruby/3.1.0/observer.rb:221:in `each'
from /usr/local/lib/ruby/3.1.0/observer.rb:221:in `notify_observers'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/evaluation.rb:24:in `notify'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/strategy/create.rb:13:in `block in result'
from <internal:kernel>:90:in `tap'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/strategy/create.rb:9:in `result'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/factory.rb:43:in `run'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/factory_runner.rb:29:in `block in run'
from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/notifications.rb:205:in `instrument'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/factory_runner.rb:28:in `run'
from /usr/local/bundle/gems/factory_bot-6.2.1/lib/factory_bot/strategy_syntax_method_registrar.rb:28:in `block in define_singular_strategy_method'
from /app/spec/models/optimization_spec.rb:37:in `block (3 levels) in <top (required)>'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:343:in `block (2 levels) in let'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179:in `block (3 levels) in fetch_or_store'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179:in `fetch'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179:in `block (2 levels) in fetch_or_store'
from /usr/local/bundle/gems/rspec-support-3.11.0/lib/rspec/support/reentrant_mutex.rb:23:in `synchronize'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:178:in `block in fetch_or_store'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:177:in `fetch'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:177:in `fetch_or_store'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:343:in `block in let'
from /app/spec/models/optimization_spec.rb:31:in `block (3 levels) in <top (required)>'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:343:in `block (2 levels) in let'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179:in `block (3 levels) in fetch_or_store'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179:in `fetch'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179:in `block (2 levels) in fetch_or_store'
from /usr/local/bundle/gems/rspec-support-3.11.0/lib/rspec/support/reentrant_mutex.rb:23:in `synchronize'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:178:in `block in fetch_or_store'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:177:in `fetch'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:177:in `fetch_or_store'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:343:in `block in let'
from /app/spec/models/optimization_spec.rb:19:in `block (3 levels) in <top (required)>'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:343:in `block (2 levels) in let'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179:in `block (3 levels) in fetch_or_store'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179:in `fetch'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179:in `block (2 levels) in fetch_or_store'
from /usr/local/bundle/gems/rspec-support-3.11.0/lib/rspec/support/reentrant_mutex.rb:23:in `synchronize'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:178:in `block in fetch_or_store'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:177:in `fetch'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:177:in `fetch_or_store'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:343:in `block in let'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:402:in `block in let!'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:365:in `run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:529:in `block in run_owned_hooks_for'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:528:in `each'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:528:in `run_owned_hooks_for'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:615:in `block in run_example_hooks_for'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:614:in `reverse_each'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:614:in `run_example_hooks_for'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:484:in `run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:505:in `run_before_example'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:261:in `block in run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:511:in `block in with_around_and_singleton_context_hooks'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:468:in `block in with_around_example_hooks'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:486:in `block in run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:626:in `block in run_around_example_hooks_for'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:352:in `call'
from /usr/local/bundle/gems/rspec-rails-5.1.2/lib/rspec/rails/adapters.rb:75:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:457:in `instance_exec'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:390:in `execute_with'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:352:in `call'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:629:in `run_around_example_hooks_for'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/hooks.rb:486:in `run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:468:in `with_around_example_hooks'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:511:in `with_around_and_singleton_context_hooks'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example.rb:259:in `run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:646:in `block in run_examples'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:642:in `map'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:642:in `run_examples'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:607:in `run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `block in run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `map'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `block in run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `map'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/example_group.rb:608:in `run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:121:in `map'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/configuration.rb:2068:in `with_suite_hooks'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:116:in `block in run_specs'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/reporter.rb:74:in `report'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:115:in `run_specs'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:89:in `run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:71:in `run'
from /usr/local/bundle/gems/rspec-core-3.11.0/lib/rspec/core/runner.rb:45:in `invoke'
from /usr/local/bundle/gems/rspec-core-3.11.0/exe/rspec:4:in `<top (required)>'
from /usr/local/bundle/bin/rspec:25:in `load'
from /usr/local/bundle/bin/rspec:25:in `<top (required)>'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/cli/exec.rb:58:in `load'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/cli/exec.rb:58:in `kernel_load'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/cli/exec.rb:23:in `run'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/cli.rb:483:in `exec'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/cli.rb:31:in `dispatch'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/cli.rb:25:in `start'
from /usr/local/bundle/gems/bundler-2.3.19/exe/bundle:48:in `block in <top (required)>'
from /usr/local/bundle/gems/bundler-2.3.19/lib/bundler/friendly_errors.rb:120:in `with_friendly_errors'
from /usr/local/bundle/gems/bundler-2.3.19/exe/bundle:36:in `<top (required)>'
from /usr/local/bundle/bin/bundle:25:in `load'
from /usr/local/bundle/bin/bundle:25:in `<main>'
We're using these versions of ruby-cbc
and cbc-wrapper
:
ruby-cbc (0.3.18)
cbc-wrapper (2.9.9.4)
It looks like the delete_intArray
method is not listed in the Cbc_C_interface.h
in the cbc-wrapper readme, so the error message makes sense. This also happens in the finalizer
class method, so we're not actually seeing incorrect results from this. But, it is making our logs pretty difficult to read. We'd appreciate any help!
On OSX, if solve
is called in a web request a SystemStackError
in the C code will occur. This does not happen on Linux, and it does not happen if the solve
call is outside of a web request.
I initially encountered this in Rails, but was able to produce a small test case with Sinatra. I tested with Ruby 2.5.1 and 2.4.4 without improvement. I also tried Webbrick, Puma, and Thin. No difference.
Sample (https://github.com/jackc/cbc-sinatra-crash):
require 'sinatra'
require 'ruby-cbc'
def solve_it
m = Cbc::Model.new
x1, x2, x3 = m.int_var_array(3, 0..Cbc::INF)
m.maximize(10*x1 + 6*x2 + 4*x3)
m.enforce(x1 + x2 + x3 <= 100)
m.to_problem.solve
end
solve_it
puts "Solve works outside of web server"
get '/' do
solve_it
"doesn't get here on Mac"
end
I ran into #17 while trying to diagnose this issue. Not sure if they're related.
Stack Trace:
jack@hk-47~/dev/ccsalespro/cbc-sinatra-crash$ bundle exec ruby main.rb
Solve works outside of web server
[2018-05-04 14:44:05] INFO WEBrick 1.4.2
[2018-05-04 14:44:05] INFO ruby 2.5.1 (2018-03-29) [x86_64-darwin17]
== Sinatra (v2.0.1) has taken the stage on 4567 for development with backup from WEBrick
[2018-05-04 14:44:05] INFO WEBrick::HTTPServer#start: pid=47244 port=4567
2018-05-04 14:44:10 - SystemStackError - stack level too deep:
/Users/jack/.rvm/gems/ruby-2.5.1/gems/ruby-cbc-0.3.17/lib/ruby-cbc/problem.rb:132:in `Cbc_solve'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/ruby-cbc-0.3.17/lib/ruby-cbc/problem.rb:132:in `solve'
main.rb:9:in `solve_it'
main.rb:16:in `block in <main>'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1634:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1634:in `block in compile!'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:992:in `block (3 levels) in route!'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1011:in `route_eval'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:992:in `block (2 levels) in route!'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1039:in `block in process_route'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1037:in `catch'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1037:in `process_route'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:990:in `block in route!'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:989:in `each'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:989:in `route!'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1096:in `block in dispatch!'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `block in invoke'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `catch'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `invoke'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1093:in `dispatch!'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:924:in `block in call!'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `block in invoke'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `catch'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `invoke'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:924:in `call!'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:913:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-protection-2.0.1/lib/rack/protection/xss_header.rb:18:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-protection-2.0.1/lib/rack/protection/path_traversal.rb:16:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-protection-2.0.1/lib/rack/protection/json_csrf.rb:26:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-protection-2.0.1/lib/rack/protection/base.rb:50:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-protection-2.0.1/lib/rack/protection/base.rb:50:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-protection-2.0.1/lib/rack/protection/frame_options.rb:31:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/logger.rb:15:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/common_logger.rb:33:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:231:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:224:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/head.rb:12:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/show_exceptions.rb:22:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:194:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1957:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1501:in `block in call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1728:in `synchronize'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/sinatra-2.0.1/lib/sinatra/base.rb:1501:in `call'
/Users/jack/.rvm/gems/ruby-2.5.1/gems/rack-2.0.5/lib/rack/handler/webrick.rb:86:in `service'
/Users/jack/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/webrick/httpserver.rb:140:in `service'
/Users/jack/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/webrick/httpserver.rb:96:in `run'
/Users/jack/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/webrick/server.rb:307:in `block in start_thread'
127.0.0.1 - - [04/May/2018:14:44:10 CDT] "GET / HTTP/1.1" 500 138906
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.