Cbc Ruby
Cbc - the mixed-integer programming solver - for Ruby
Check out Opt for a high-level interface
Installation
First, install Cbc. For Homebrew, use:
brew install cbc
And for Ubuntu, use:
sudo apt-get install coinor-libcbc3.1 # or coinor-libcbc3
Then add this line to your application’s Gemfile:
gem "cbc"
Getting Started
The API is fairly low-level at the moment
Load a problem
model =
Cbc.load_problem(
sense: :minimize,
start: [0, 3, 6],
index: [0, 1, 2, 0, 1, 2],
value: [2, 3, 2, 2, 4, 1],
col_lower: [0, 0],
col_upper: [1e30, 1e30],
obj: [8, 10],
row_lower: [7, 12, 6],
row_upper: [1e30, 1e30, 1e30],
col_type: [:integer, :continuous]
)
Solve
model.solve
Write the problem to an LP or MPS file (LP requires Cbc 2.10+)
model.write_lp("hello.lp")
# or
model.write_mps("hello") # adds .mps.gz
Read a problem from an LP or MPS file (LP requires Cbc 2.10+)
model = Cbc.read_lp("hello.lp")
# or
model = Cbc.read_mps("hello.mps.gz")
Reference
Set the log level (requires Cbc 2.10+)
model.solve(log_level: 1) # 0 = off, 3 = max
Set the time limit in seconds (requires Cbc 2.10+)
model.solve(time_limit: 30)
History
View the changelog
Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development:
git clone https://github.com/ankane/cbc-ruby.git
cd cbc-ruby
bundle install
bundle exec rake test