-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the readme according to issue #22 Making sure we can use ruby-cbc on different linux distributions with docker tests.
Showing
8 changed files
with
155 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2.3 | ||
before_install: gem install bundler -v 1.10.6 | ||
before_install: | ||
- sudo apt-get -y install coinor-libcbc-dev | ||
- gem install bundler -v 1.10.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM archlinux:latest | ||
|
||
RUN pacman -Sy --noconfirm gcc make ruby coin-or-cbc | ||
|
||
RUN gem install ruby-cbc | ||
|
||
COPY ./cbc_test.rb /cbc_test.rb | ||
|
||
CMD ["ruby", "/cbc_test.rb"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM debian:bullseye-slim | ||
|
||
RUN apt-get update && apt-get install -y gcc make coinor-libcbc-dev ruby-full | ||
|
||
RUN gem install ruby-cbc | ||
|
||
COPY ./cbc_test.rb /cbc_test.rb | ||
|
||
CMD ["ruby", "/cbc_test.rb"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM ubuntu:18.04 | ||
|
||
RUN apt-get update && apt-get install -y gcc make coinor-libcbc-dev ruby-full | ||
|
||
RUN gem install ruby-cbc | ||
|
||
COPY ./cbc_test.rb /cbc_test.rb | ||
|
||
CMD ["ruby", "/cbc_test.rb"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Testing installation of ruby-cbc | ||
|
||
Since there have been numerous problems with the installation of ruby-cbc on different platforms, | ||
I have set up some tests for installing ruby-cbc in different environments. | ||
|
||
These tests use docker, and thus only test linux distributions. | ||
These tests use the production ruby-cbc gem, installing it with `gem install ruby-cbc`. | ||
|
||
To run it: | ||
|
||
```bash | ||
ruby tests.rb | ||
``` | ||
|
||
For each distribution (1 per dockerfile), we install ruby-cbc, and run a little sample to make sure | ||
everything is ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
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 'Infeasible problem!' | ||
exit 1 | ||
end | ||
|
||
unless p.proven_optimal? | ||
puts 'Not proven optimal!' | ||
exit 1 | ||
end | ||
|
||
if p.objective_value != 732 | ||
puts "Objective value should be 732, but it is #{p.objective_value}" | ||
exit 1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
def can_install_on?(os) | ||
image = "cbc-test-#{os}" | ||
install_ok = system("docker build . -q -f Dockerfile-#{os} -t #{image} >/dev/null") | ||
return false unless install_ok | ||
|
||
run_ok = system("docker run --rm #{image}") | ||
|
||
!!run_ok | ||
end | ||
|
||
os_list = %w[ubuntu debian archlinux] | ||
|
||
passed = os_list.all? do |os| | ||
puts "Testing ruby-cbc on #{os}" | ||
can_install_on?(os) | ||
end | ||
|
||
if passed | ||
puts 'Sucessfully launched ruby-cbc on all os' | ||
else | ||
puts 'Error!' | ||
exit 1 | ||
end |