Package ompr. November 18, 2017

Similar documents
Package ECctmc. May 1, 2018

Package messaging. May 27, 2018

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package canvasxpress

Package dbx. July 5, 2018

Package fastdummies. January 8, 2018

Package validara. October 19, 2017

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package strat. November 23, 2016

Package tidyimpute. March 5, 2018

Package nngeo. September 29, 2018

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package purrrlyr. R topics documented: May 13, Title Tools at the Intersection of 'purrr' and 'dplyr' Version 0.0.2

Package rgho. R topics documented: January 18, 2017

Package readobj. November 2, 2017

Package jstree. October 24, 2017

Package deductive. June 2, 2017

Package farver. November 20, 2018

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package triebeard. August 29, 2016

Package robotstxt. November 12, 2017

Package datasets.load

Package wrswor. R topics documented: February 2, Type Package

Package clipr. June 23, 2018

Package spark. July 21, 2017

Package combiter. December 4, 2017

Package SimilaR. June 21, 2018

Package lumberjack. R topics documented: July 20, 2018

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package mixsqp. November 14, 2018

Package RPresto. July 13, 2017

Package tidyselect. October 11, 2018

Package sfc. August 29, 2016

Package inca. February 13, 2018

Package mdftracks. February 6, 2017

Package raker. October 10, 2017

Package rmumps. September 19, 2017

Package projector. February 27, 2018

Package gtrendsr. October 19, 2017

Package ramcmc. May 29, 2018

Package readxl. April 18, 2017

Package rsppfp. November 20, 2018

Package geogrid. August 19, 2018

Package opencage. January 16, 2018

Package repec. August 31, 2018

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package tropicalsparse

Package ECOSolveR. February 18, 2018

Package ecoseries. R topics documented: September 27, 2017

Package reconstructr

Package chunked. July 2, 2017

Package SEMrushR. November 3, 2018

Package crossword.r. January 19, 2018

Package pmatch. October 19, 2018

Package knitrprogressbar

Package rtext. January 23, 2019

Package slickr. March 6, 2018

Package nmslibr. April 14, 2018

Package quadprogxt. February 4, 2018

Package bisect. April 16, 2018

Package facerec. May 14, 2018

Package queuecomputer

Package ether. September 22, 2018

Package available. November 17, 2017

Package coga. May 8, 2018

Package ibm. August 29, 2016

Package fst. December 18, 2017

Package crochet. January 8, 2018

Package embed. November 19, 2018

Package assertr. R topics documented: February 23, Type Package

Package Rcplex. June 12, 2016

Package librarian. R topics documented:

Package rbgm. May 18, 2018

Package NFP. November 21, 2016

Package sparsehessianfd

Package tidytree. June 13, 2018

Package comparedf. February 11, 2019

Package Rglpk. May 18, 2017

Package gtrendsr. August 4, 2018

Package textstem. R topics documented:

Package oec. R topics documented: May 11, Type Package

Package calpassapi. August 25, 2018

Package fasttextr. May 12, 2017

Package censusr. R topics documented: June 14, Type Package Title Collect Data from the Census API Version 0.0.

Package resumer. R topics documented: August 29, 2016

Package milr. June 8, 2017

Package diffusr. May 17, 2018

Package Rcplex. February 15, 2013

Package widyr. August 14, 2017

Package lexrankr. December 13, 2017

Package TVsMiss. April 5, 2018

Package semver. January 6, 2017

Package kdtools. April 26, 2018

Package githubinstall

Package barcoder. October 26, 2018

Package vinereg. August 10, 2018

Package qap. February 27, Index 5. Solve Quadratic Assignment Problems (QAP)

Package BiocManager. November 13, 2018

Package taxizedb. June 21, 2017

R topics documented: 2 clone

Transcription:

Type Package Package ompr November 18, 2017 Title Model and Solve Mixed Integer Linear Programs Version 0.7.0 Model mixed integer linear programs in an algebraic way directly in R. The is solver-independent and thus offers the possibility to solve a with different solvers. It currently only supports linear constraints and objective functions. See the 'ompr' website <https://dirkschumacher.github.io/ompr> for more information, documentation and examples. License GPL-3 LazyData TRUE RoxygenNote 6.0.1 URL https://github.com/dirkschumacher/ompr BugReports https://github.com/dirkschumacher/ompr/issues Depends R (>= 3.3.0) Imports dplyr, lazyeval, progress, Rcpp (>= 0.12.12), Matrix Suggests magrittr, testthat ByteCompile Yes LinkingTo Rcpp NeedsCompilation yes Author Dirk Schumacher [aut, cre] Maintainer Dirk Schumacher <mail@dirk-schumacher.net> Repository CRAN Date/Publication 2017-11-17 23:09:28 UTC R topics documented: add_constraint........................................ 2 add_variable......................................... 3 1

2 add_constraint extract_constraints..................................... 4 get_solution......................................... 4 MIPModel.......................................... 5 new_solution........................................ 6 nvars............................................. 6 objective_function..................................... 7 objective_value....................................... 7 ompr............................................. 8 set_bounds......................................... 8 set_objective........................................ 9 solver_status........................................ 9 solve_......................................... 10 sum_expr.......................................... 10 variable_bounds....................................... 11 variable_keys........................................ 12 variable_types........................................ 12 Index 14 add_constraint Add a constraint Add one or more constraints to the using quantifiers. add_constraint(.,.constraint_expr,...,.show_progress_bar = TRUE) add_constraint_(.,.constraint_expr,...,.dots,.show_progress_bar = TRUE). the.constraint_expr the constraint. Must be a linear (in)equality with operator "<=", "==" or ">=".... quantifiers for the indexed variables. For all combinations of bound variables a new constraint is created. In addition you can add filter expressions.show_progress_bar displays a progressbar when adding multiple constraints.dots a Model with new constraints added Used to work around non-standard evaluation.

add_variable 3 MIPModel() %>% add_variable(x[i], i = 1:5) %>% add_constraint(x[i] >= 1, i = 1:5) # creates 5 constraints add_variable Add a variable to the A variable can either be a name or an indexed name. See examples. add_variable(.,.variable,..., type = "continuous", lb = -Inf, ub = Inf) add_variable_(.,.variable,..., type = "continuous", lb = -Inf, ub = Inf,.dots). the.variable the variable name/definition... quantifiers for the indexed variable. Including filters type must be either continuous, integer or binary lb the lower bound of the variable ub the upper bound of the variable.dots Used to work around non-standard evaluation. MIPModel() %>% add_variable(x) %>% # creates 1 variable named x add_variable(y[i], i = 1:10, i %% 2 == 0, type = "binary") # creates 4 variables

4 get_solution extract_constraints Extract the constraint matrix, the right hand side and the sense from a Extract the constraint matrix, the right hand side and the sense from a extract_constraints() the a list with three named elements. matrix the (sparse) constraint matrix from the Matrix package. rhs is the right hand side vector in the order of the matrix. sense is a vector of the constraint senses <- MIPModel() %>% add_variable(x[i], i = 1:3) %>% add_variable(y[i], i = 1:3) %>% add_constraint(x[i] + y[i] <= 1, i = 1:3) extract_constraints() get_solution Get variable values from a solution Get variable values from a solution get_solution(solution, expr) get_solution_(solution, expr) get_solution_(solution, expr)

MIPModel 5 solution expr the solution object a variable expression. You can partially bind indexes. a data.frame. One row for each variable instance and a column for each index. Unless it is a single variable, then it returns a single number. ## Not run: result <- MIPModel() %>% add_variable(x[i], i = 1:5) %>% add_variable(y[i, j], i = 1:5, j = 1:5) %>% add_constraint(x[i] >= 1, i = 1:5) %>% set_bounds(x[i], lb = 3, i = 1:3) %>% set_objective(0) %>% solve_(with_roi("glpk")) solution <- get_solution(result, x[i]) solution2 <- get_solution(result, y[i, 1]) solution3 <- get_solution(result, y[i, j]) ## End(Not run) MIPModel Create a new MIP Model Create a new MIP Model MIPModel()

6 nvars new_solution Create a new solution This function/class should only be used if you develop your own solver. new_solution(, objective_value, status, solution) the optimization that was solved objective_value a numeric objective value status solution the status of the solution a named numeric vector containing the solution values nvars Number of variables of a Number of variables of a nvars() the a list with three named elements. binary => number of binary variables, integer => number of integer variables, continuous => number of continuous variables. <- MIPModel() %>% add_variable(x[i], i = 1:10, type = "binary") %>% add_variable(y[i], i = 1:5, type = "continuous") %>% add_variable(z[i], i = 1:2, type = "integer") nvars()

objective_function 7 objective_function Extract the objective function from a Extract the objective function from a objective_function() the a list with two named elements, solution and constant. solution is a sparse vector from the Matrix package. constant is a constant that needs to be added to get the final obj. value. <- MIPModel() %>% add_variable(x[i], i = 1:5) %>% set_objective(sum_expr(i * x[i], i = 1:5) + 10) objective_function() objective_value Extract the numerical objective value from a solution Extract the numerical objective value from a solution objective_value(solution) solution a solution numeric single item vector

8 set_bounds ompr A package to Model (Mixed) Integer Programs A package to (mixed) integer programs. It provides an algebraic way to mixed integer linear optimization problems directly in R. The is solver-independent and thus offers the possibility to solve a with different solvers. See the ompr website <https://dirkschumacher.github.io/ompr/> for more information, documentation and examples. set_bounds Set the bounds of a variable Change the lower and upper bounds of a named variable, indexed variable or a group of variables. set_bounds(.,.variable,..., lb = NULL, ub = NULL) set_bounds_(.,.variable,..., lb = NULL, ub = NULL,.dots). the.variable the variable name/definition... quantifiers for the indexed variable lb the lower bound of the variable ub the upper bound of the variable.dots Used to work around non-standard evaluation. MIPModel() %>% add_variable(x[i], i = 1:5) %>% add_constraint(x[i] >= 1, i = 1:5) %>% # creates 5 constraints set_bounds(x[i], lb = 3, i = 1:3)

set_objective 9 set_objective Set the objective Set the objective set_objective(, expression, sense = c("max", "min")) set_objective_(, expression, sense = c("max", "min")) expression sense the the linear objective as a sum of variables and constants the sense. Must be either "max" or "min". a Model with a new objective function definition MIPModel() %>% add_variable(x, lb = 2) %>% add_variable(y, lb = 40) %>% set_objective(x + y, sense = "min") solver_status Get the solver status from a solution Get the solver status from a solution solver_status(solution) solution a solution

10 sum_expr character vector being either "infeasible", "optimal", "unbounded", "userlimit" or "error solve_ Solve a Solve a solve_(, solver) solver the a function mapping a to a solution solver() sum_expr Construct a sum expression This functions helps to create dynamic sum expression based on external variables. Should only be used within other ompr functions. sum_expr(expr,...) expr an expression that can be expanded to a sum... bind variables in expr using dots. See examples. the expanded sum as an AST

variable_bounds 11 See Also add_constraint set_objective # create a sum from x_1 to x_10 sum_expr(x[i], i = 1:10) # create a sum from x_2 to x_10 with even indexes sum_expr(x[i], i = 1:10, i %% 2 == 0) variable_bounds Variable lower and upper bounds of a Variable lower and upper bounds of a variable_bounds() the a list with two components lower and upper each having a numeric vector of bounds. One for each variable. <- MIPModel() %>% add_variable(x, type = "binary") %>% add_variable(y, type = "continuous", lb = 2) %>% add_variable(z, type = "integer", ub = 3) variable_bounds()

12 variable_types variable_keys Get all unique names of the variables Get all unique names of the variables variable_keys() the a character vector ordered in the same way as the constraint matrix columns and objective vector <- MIPModel() %>% add_variable(x[i], i = 1:3) variable_keys() variable_types Variable types of a One component for each variable in the correct order variable_types() the a factor with levels binary, continuous, integer

variable_types 13 <- MIPModel() %>% add_variable(x, type = "binary") %>% add_variable(y, type = "continuous") %>% add_variable(z, type = "integer") variable_types()

Index Topic package ompr, 8 add_constraint, 2, 11 add_constraint_ (add_constraint), 2 add_variable, 3 add_variable_ (add_variable), 3 extract_constraints, 4 get_solution, 4 get_solution_ (get_solution), 4 MIPModel, 5 new_solution, 6 nvars, 6 objective_function, 7 objective_value, 7 ompr, 8 ompr-package (ompr), 8 set_bounds, 8 set_bounds_ (set_bounds), 8 set_objective, 9, 11 set_objective_ (set_objective), 9 solve_, 10 solver_status, 9 sum_expr, 10 variable_bounds, 11 variable_keys, 12 variable_types, 12 14