COIN-OR branch and cut (CBC) bindings for R
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R Refactor status (#25) May 4, 2018
docs
man
src
tests
tools
.Rbuildignore
.gitignore
.travis.yml Remove unused dependencies May 4, 2017
CONDUCT.md
DESCRIPTION
LICENSE initial commit Nov 13, 2016
NAMESPACE Resonse to code review: Mar 23, 2018
README.Rmd Fix minor typo in Readme May 9, 2017
README.md
Rcbc.Rproj
_pkgdown.yml
appveyor.yml
cleanup
configure

README.md

CBC bindings for R

Build Status Build Status Windows codecov GPL Licence CRAN Status

This package provides bindings to the COIN-CBC solver.

It is currently work in progress.

Installation

The package requires COIN-CBC solver headers and libs. On Debian/Ubuntu:

sudo apt-get install coinor-libcbc-dev coinor-libclp-dev

On Fedora:

sudo yum install coin-or-Cbc-devel coin-or-Clp-devel

And on MacOS:

brew tap coin-or-tools/coinor
brew install cbc

Now install the package in R:

devtools::install_github("dirkschumacher/rcbc")

Getting Started

library(rcbc)
# max 1 * x + 2 * y
# s.t.
#   x + y <= 1
#   x, y binary
A <- matrix(c(1, 1), ncol = 2, nrow = 1)
result <- cbc_solve(
 obj = c(1, 2),
 mat = A, # <- can also be a sparse matrix
 is_integer = c(TRUE, TRUE),
 row_lb = -Inf, row_ub = 1, max = TRUE,
 col_lb = c(0, 0), col_ub = c(1, 1),
 cbc_args = list("SEC" = "1"))
solution_status(result)
#> [1] "optimal"
objective_value(result)
#> [1] 2
column_solution(result)
#> [1] 0 1

Another example

Here we solve a larger Knapsack problem

set.seed(1)
max_capacity <- 1000
n <- 100
weights <- round(runif(n, max = max_capacity))
cost <- round(runif(n) * 100)

A <- matrix(weights, ncol = n, nrow = 1)
result <- cbc_solve(
 obj = cost,
 mat = A, 
 is_integer = rep.int(TRUE, n),
 row_lb = 0, row_ub = max_capacity, max = TRUE,
 col_lb = rep.int(0, n), col_ub = rep.int(1, n))
solution_status(result)
#> [1] "optimal"
objective_value(result)
#> [1] 607
column_solution(result)
#>   [1] 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
#>  [36] 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
#>  [71] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0

Cbc Parameters

CBC has a number of parameters. You can pass them to the solver using the cbc_args argument.

For example the code below sets the timelimit of the solver to 5 seconds:

cbc_solve(..., cbc_args = list("sec" = 5))

ROI plugin

There is now a work in progress ROI plugin.

Contribution

Feel free to open issues and send PRs.