All Projects → dirkschumacher → Ompr

dirkschumacher / Ompr

Licence: gpl-3.0
R package to model Mixed Integer Linear Programs

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Ompr

Squid
Squid – type-safe metaprogramming and compilation framework for Scala
Stars: ✭ 172 (-13.13%)
Mutual labels:  optimization
Ml Systems
papers on scalable and efficient machine learning systems
Stars: ✭ 182 (-8.08%)
Mutual labels:  optimization
Coz
Coz: Causal Profiling
Stars: ✭ 2,719 (+1273.23%)
Mutual labels:  optimization
Mlrmbo
Toolbox for Bayesian Optimization and Model-Based Optimization in R
Stars: ✭ 173 (-12.63%)
Mutual labels:  optimization
Dropcss
An exceptionally fast, thorough and tiny unused-CSS cleaner
Stars: ✭ 2,102 (+961.62%)
Mutual labels:  optimization
Hyperactive
A hyperparameter optimization and data collection toolbox for convenient and fast prototyping of machine-learning models.
Stars: ✭ 182 (-8.08%)
Mutual labels:  optimization
Fe Performance Journey
🚵 a Journey of Performance Optimizing in Frontend 🚀
Stars: ✭ 169 (-14.65%)
Mutual labels:  optimization
Pygpgo
Bayesian optimization for Python
Stars: ✭ 196 (-1.01%)
Mutual labels:  optimization
Quant Notes
Quantitative Interview Preparation Guide, updated version here ==>
Stars: ✭ 180 (-9.09%)
Mutual labels:  optimization
Flips
Fsharp LInear Programming System
Stars: ✭ 188 (-5.05%)
Mutual labels:  optimization
Scikit Opt
Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Optimization Algorithm,Immune Algorithm, Artificial Fish Swarm Algorithm, Differential Evolution and TSP(Traveling salesman)
Stars: ✭ 2,791 (+1309.6%)
Mutual labels:  optimization
Openwrt Sfe Flowoffload Ath79
Openwrt firmware with SFE and FlowOffload
Stars: ✭ 178 (-10.1%)
Mutual labels:  optimization
Hybridizer Basic Samples
Examples of C# code compiled to GPU by hybridizer
Stars: ✭ 186 (-6.06%)
Mutual labels:  optimization
Iminuit
Jupyter-friendly Python interface for C++ MINUIT2
Stars: ✭ 172 (-13.13%)
Mutual labels:  optimization
Aerosandbox
Aircraft design optimization made fast through modern automatic differentiation. Plug-and-play analysis tools for aerodynamics, propulsion, structures, trajectory design, and much, much more.
Stars: ✭ 193 (-2.53%)
Mutual labels:  optimization
Mathtoolbox
Mathematical tools (interpolation, dimensionality reduction, optimization, etc.) written in C++11 with Eigen
Stars: ✭ 172 (-13.13%)
Mutual labels:  optimization
Optaplanner
AI constraint solver in Java to optimize the vehicle routing problem, employee rostering, task assignment, maintenance scheduling, conference scheduling and other planning problems.
Stars: ✭ 2,454 (+1139.39%)
Mutual labels:  optimization
Cornell Moe
A Python library for the state-of-the-art Bayesian optimization algorithms, with the core implemented in C++.
Stars: ✭ 198 (+0%)
Mutual labels:  optimization
Peroxide
Rust numeric library with R, MATLAB & Python syntax
Stars: ✭ 191 (-3.54%)
Mutual labels:  optimization
Powermodels.jl
A Julia/JuMP Package for Power Network Optimization
Stars: ✭ 187 (-5.56%)
Mutual labels:  optimization

Mixed integer linear programming in R

R build status CRAN Status

OMPR (Optimization Modeling Package) is a DSL to model and solve Mixed Integer Linear Programs. It is inspired by the excellent Jump project in Julia.

Here are some problems you could solve with this package:

  • What is the cost minimal way to visit a set of clients and return home afterwards?
  • What is the optimal conference time table subject to certain constraints (e.g. availability of a projector)?
  • Sudokus

The Wikipedia article gives a good starting point if you would like to learn more about the topic.

I am always happy to get bug reports or feedback.

Install

CRAN

install.packages("ompr")
install.packages("ompr.roi")

Development version

To install the current development version use devtools:

devtools::install_github("dirkschumacher/ompr")
devtools::install_github("dirkschumacher/ompr.roi")

Available solver bindings

Package Description Build Linux Build Windows Test coverage
ompr.roi Bindings to ROI (GLPK, Symphony, CPLEX etc.) Build Status Build Status Windows Coverage Status

A simple example:

library(dplyr)
library(ROI)
library(ROI.plugin.glpk)
library(ompr)
library(ompr.roi)

result <- MIPModel() %>%
  add_variable(x, type = "integer") %>%
  add_variable(y, type = "continuous", lb = 0) %>%
  set_bounds(x, lb = 0) %>%
  set_objective(x + y, "max") %>%
  add_constraint(x + y <= 11.25) %>%
  solve_model(with_ROI(solver = "glpk")) 
get_solution(result, x)
get_solution(result, y)

API

These functions currently form the public API. More detailed docs can be found in the package function docs or on the website

DSL

  • MIPModel() create an empty mixed integer linear model (the old way)
  • MILPModel() create an empty mixed integer linear model (an alternative way; experimental, especially suitable for large models)
  • add_variable() adds variables to a model
  • set_objective() sets the objective function of a model
  • set_bounds() sets bounds of variables
  • add_constraint() add constraints
  • solve_model() solves a model with a given solver
  • get_solution() returns the column solution (primal or dual) of a solved model for a given variable or group of variables
  • get_row_duals() returns the row duals of a solution (only if it is an LP)
  • get_column_duals() returns the column duals of a solution (only if it is an LP)

Backends

There are currently two backends. A backend is the function that initializes an empty model.

  • MIPModel() is the standard MILP Model
  • MILPModel() is another backend specifically optimized for linear models and is about 1000 times faster than MIPModel(). It has slightly different semantics, as it is vectorized. Currently experimental.

Solver

Solvers are in different packages. ompr.ROI uses the ROI package which offers support for all kinds of solvers.

  • with_ROI(solver = "glpk") solve the model with GLPK. Install ROI.plugin.glpk
  • with_ROI(solver = "symphony") solve the model with Symphony. Install ROI.plugin.symphony
  • with_ROI(solver = "cplex") solve the model with CPLEX. Install ROI.plugin.cplex
  • ... See the ROI package for more plugins.

Further Examples

Please take a look at the docs for bigger examples.

Knapsack

library(dplyr)
library(ROI)
library(ROI.plugin.glpk)
library(ompr)
library(ompr.roi)
max_capacity <- 5
n <- 10
weights <- runif(n, max = max_capacity)
MIPModel() %>%
  add_variable(x[i], i = 1:n, type = "binary") %>%
  set_objective(sum_expr(weights[i] * x[i], i = 1:n), "max") %>%
  add_constraint(sum_expr(weights[i] * x[i], i = 1:n) <= max_capacity) %>%
  solve_model(with_ROI(solver = "glpk")) %>% 
  get_solution(x[i]) %>% 
  filter(value > 0)

Bin Packing

An example of a more difficult model solved by symphony.

library(dplyr)
library(ROI)
library(ROI.plugin.symphony)
library(ompr)
library(ompr.roi)
max_bins <- 10
bin_size <- 3
n <- 10
weights <- runif(n, max = bin_size)
MIPModel() %>%
  add_variable(y[i], i = 1:max_bins, type = "binary") %>%
  add_variable(x[i, j], i = 1:max_bins, j = 1:n, type = "binary") %>%
  set_objective(sum_expr(y[i], i = 1:max_bins), "min") %>%
  add_constraint(sum_expr(weights[j] * x[i, j], j = 1:n) <= y[i] * bin_size, i = 1:max_bins) %>%
  add_constraint(sum_expr(x[i, j], i = 1:max_bins) == 1, j = 1:n) %>%
  solve_model(with_ROI(solver = "symphony", verbosity = 1)) %>% 
  get_solution(x[i, j]) %>%
  filter(value > 0) %>%
  arrange(i)

License

Currently GPL.

Contributing

Please post an issue first before sending a PR.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Related Projects

  • CVXR - an excellent package for "object-oriented modeling language for convex optimization". LP/MIP is a special case.
  • ROML follows a similiar approach, but it seems the package is still under initial development.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].