Bill Seliger
May 11, 2015
This App uses the R lpSolveAPI package in a Shinyapp to optimize airline revenue based on two inputs from the user:
It then constructs a linear programming model using R code, solves the linear program with the lpSolveAPI package, and returns the objective - the maximum revenue given the selected demand for the two inputs.
The LP is formulated with two decision variables
The LP also has five constraints
require(lpSolveAPI)
lprec <- make.lp(5, 2); regular = 150; discount = 100; invisible(lp.control(lprec, sense = "max"))
set.objfn(lprec, c(617, 238))
set.constr.value(lprec, rhs = c(166,regular,discount,0,0), constraints=seq(1:5))
set.constr.type(lprec, c(rep("<=", 3), rep(">=", 2)))
set.row(lprec, 1, c(1, 1), indices = c(1, 2))
set.row(lprec, 2, 1, indices = 1)
set.row(lprec, 3, 1, indices = 2)
set.row(lprec, 4, 1, indices = 1)
set.row(lprec, 5, 1, indices = 2)
dimnames(lprec) <- list(c("capacity","reg_demand", "discount_demand", "reg_positive", "disc_positive"), c("reg","disc"))
print(lprec)
Model name:
reg disc
Maximize 617 238
capacity 1 1 <= 166
reg_demand 1 0 <= 150
discount_demand 0 1 <= 100
reg_positive 1 0 >= 0
disc_positive 0 1 >= 0
Kind Std Std
Type Real Real
Upper Inf Inf
Lower 0 0
The solve() function solves the LP. Possible responses include:
solve(lprec)
[1] 0
## the objective is the optimal (maximum) revenue possible
get.objective(lprec)
[1] 96358
## the decision variables are the number of seats of each class the
## airline should sell to achieve the maximum revenue
get.variables(lprec)
[1] 150 16
This problem is based on the lesson found here
MITx 15.071x The Analytics Edge
Information on the lpSolveAPI package can be found here