-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME.Rmd
123 lines (92 loc) · 4.76 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# MIP Modelling in R
<!-- badges: start -->
[](https://www.tidyverse.org/lifecycle/#experimental)
[](https://github.com/r-opt/rmpk/actions)
[](https://app.codecov.io/gh/r-opt/rmpk?branch=master)
<!-- badges: end -->
`rmpk` is a lightweight package to model mixed integer linear programs. It is based on the API of the [ompr](https://github.com/dirkschumacher/ompr) package and is also inspired by the architecture of [Julia JuMP](https://github.com/JuliaOpt/JuMP.jl).
The goal is to provide a modelling package that can both be used in packages and also in interactive analyses. It also has a different architecture as the modelling layer modifies a central solver. That solver could be an interface to [ROI](https://CRAN.R-project.org/package=ROI) or a shared pointer to a specific solver. Thus giving the option to directly communicate with the solver while still using an algebraic modelling framework.
This is currently work in progress and experimental - but working. I might merge it with [ompr](https://github.com/dirkschumacher/ompr) but it could also become the successor of [ompr](https://github.com/dirkschumacher/ompr) ... not sure yet.
If you want to see the package in action take a look at the [articles](https://r-opt.github.io/rmpk/) in the docs.
Happy to receive feedback!
_Still under development. Anything can change_
## Installation
You can install the released version of RMPK from [CRAN](https://CRAN.R-project.org) with:
``` r
remotes::install_github("r-opt/rmpk")
```
## Supported types
* Linear Programming (LP)
* Mixed Integer Linear Programming (MILP)
* Mixed Integer Quadratic Programming (MIQP)
* Mixed Integer Quadratically Constrained Programming (MIQCP)
## Features
* ✅ Algebraic modelling of mixed integer programming problems
* ✅ Integer, binary and continious variables
* ✅ Linear and quadratic constraints/objective
* ✅ Bindings to most popular solvers through [ROI](https://CRAN.R-project.org/package=ROI)
* ✅ Support for character variable indexes
* ✅ Access row/column duals of Linear Programs
* ✅ Row generation through solver callbacks (e.g. for models with exponential many constraints)
* 🚧 Variable and constraint names
* 🚧 Initial feasible solutions
* 🚧 Almost as fast as matrix code
* ...
## Low Level ROI Example
```{r}
library(rmpk)
library(ROI.plugin.glpk)
set.seed(42)
solver <- ROI_optimizer("glpk")
v <- rnorm(10)
w <- rnorm(10)
model <- optimization_model(solver)
x <- model$add_variable("x", type = "binary", i = 1:10)
model$set_objective(sum_expr(v[i] * x[i], i = 1:10), sense = "max")
model$add_constraint(sum_expr(w[i] * x[i], i = 1:10) <= 10)
model$optimize()
model$get_variable_value(x[i])
```
## List of solvers
`rmpk` supports all solvers that implement the [`MOI` interface](https://github.com/r-opt/MOI). It also comes
with a `ROI_optimzer` that internally uses [`ROI`](https://roi.r-forge.r-project.org/index.html) and thus gives [access to most
popular solvers](https://roi.r-forge.r-project.org) out of the box.
Note that `ROI` has its own plugin system and you need to install these solvers
separately in addition to [`ROIoptimizer`](https://github.com/r-opt/ROIoptimizer).
```{r, echo = FALSE}
roi_solvers <- ROI::ROI_available_solvers()$Package
roi_solvers <- unique(substr(roi_solvers, 12, nchar(roi_solvers)))
df <- data.frame(
solver_name = c(roi_solvers, "glpk"),
r_package = c(rep.int("ROIoptimizer", length(roi_solvers)), "GLPKoptimizer"),
url = c(rep.int("https://github.com/r-opt/ROIoptimizer", length(roi_solvers)), "https://github.com/r-opt/GLPKoptimizer"),
stringsAsFactors = FALSE
)
knitr::kable(df[order(df$solver_name), ],
col.names = c("Solver Name", "R Package", "Github URL"),
row.names = FALSE
)
```
## Contribute
The best way at the moment to contribute is to test the package, write documentation, propose features. Soon, code contributions are welcome as well.
Please note that the 'rmpk' project is released with a
[Contributor Code of Conduct](CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.
## License
MIT
## References and Inspiration
* Dunning, Iain, Joey Huchette, and Miles Lubin. "JuMP: A modeling language for mathematical optimization." SIAM Review 59.2 (2017): 295-320.
* [ompr](https://github.com/dirkschumacher/ompr)
* [pulp](https://github.com/coin-or/pulp)