Category Archives: Optimization in R

How to use R to solve optimization problems in Operations Research. All available packages are listed in the CRAN Task View: Optimization and Mathematical Programming.

Another Quadratic Programming Example with R

Following Quadratic Programming with R, this is another example of how to solve quadratic programming problem with R package “quadprog“.

Why Another Example?

Quadratic programming matrix math notation
quadratic programming matrix notation

quadprog” package requires us to rewrite the quadratic equation in the proper matrix equation as above. You may have the following questions:

  • What if our equation is to maximize the objective function instead of minimize it?
  • What if the inequality constraints are “less than (<=)” instead of “more than (>=)”?
  • What if there is no equality constraints?

To give you an idea how to answer these questions, this post will give you another example.

Continue reading

Transportation and Assignment problems with R

In the previous post “Linear Programming with R” we examined the approach to solve general linear programming problems with “Rglpk” and “lpSolve” packages. Today, let’s explore “lpSolve” package in depth with two specific problems of linear programming: transportation and assignment.

1. Transportation problem

Transportation problem, Frederick & Mark (2014, p.95)

Usage:

lp.transport(cost.mat, direction="min", row.signs, row.rhs, col.signs,
               col.rhs, presolve=0, compute.sens=0, integers = 1:(nc*nr))
Continue reading

Quadratic Programming with R

Optimization of a quadratic function

Quadratic programming problems can be solved with “quadprog” package in R and the key point is to find the matrix notation of quadratic programming problems:

Example

Let’s figure out how to do it with an example of “Applying Nonlinear Programming to Portfolio Selection”:

Please note that, this example involves three variables (x1, x2, and x3). If you want an example of two variables (x1 and x2), please check my another post: Another Quadratic Programming Example with R.

Continue reading

Maximum Flow Problem with R

Maximum flow is one of the Network Optimization problems in Operations Research and can be solved in R by “igraph“, which is a network analysis package.

6.2 A CASE STUDY: THE BMZ CO. MAXIMUM FLOW PROBLEM

The BMZ Co. distribution network from its main factory in Stuttgart, Germany, to a distribution center in Los Angeles.

The function to solve maximum flow problem in igraph package is called max_flow.

Usage:

max_flow(graph, source, target, capacity = NULL)
Continue reading

Linear Programming with R

Linear Programming in Matrix Notation, Stefan Feuerriegel (2015)

After finished the Business Statistics course in my Pre-Master at Nyenrode, I felt myself comfortable to deal with data analysis, and I did not have big plans for the six-week winter holiday, so I was wondering maybe I could try some different things about data analytics. However, since I am not a fan of drag-and-drop tools such as Excel and SPSS, I ended up with R, which many friends have recommended before.

Meanwhile, I realized that there will be a course about Operation Research called “Introduction to Management Science: A Modeling and Cases Studies Approach with Spreadsheets“, which is about how to solve Operation Research questions with excel Modeling, so I began to looking for R packages for Operation Research.

Continue reading