Airlines always have a dilemma as to how many seats should be sold at the full price and how many at a discounted price. Any vacant seats cost money to the airline. It is a loss for them. They should have the right combination of full price seats and discounted seats so that they have a perfect balance.
This is an illustration of a single flight from Hyderabad to Delhi. Let’s assume the airline in question uses an A320 aircraft. There are 180 seats to be sold. Advance booking will fetch a seat at Rs.3000/- whereas any last minute booking would result in a ticket price of Rs.5000/-. The cost of operating one flight is Rs.30000/-
The decision would depend on the demand forecast of both the regular seats and discounted seats. Suppose the demand forecast of regular seats is 100, the airline would sell 100 regular seats at the high price and the remaining 80 seats at the discounted price. Suppose the demand of regular seats increases to 150, the airline sells 150 seats at the high price and the remaining 30 seats at the discounted price.
The objective is to find the number of full fare seats (R) and the number of discounted seats to sell (D). We will assume the price of regular seats is Rs.5000/- and the price of discounted seats is Rs.3000/-. The demand of the regular seats is 150 and the demand of the discounted seats is 100. The capacity of the plane is 180.
The objective is to maximize 5000R+3000D.
The total number of seats sold i.e. R+D <=180 R<=150 D<=100
library(lpSolveAPI)
We have three constraints (one capacity constraint and two demand constraints) and two decision variables.
AirlineSingle = make.lp(3,2)
Our objective and three constraints are as follows:
Max 5000R + 3000D subject to 1R + 1D <= 180 1R + 0D <= 150 0R + 1D <= 100
So the first column in our constraint matrix is c(1,1,0), and the second column in our constraint matrix is c(1,0,1). We also need to indicate that these are less-than-or-equal constraints, and set the right-hand-side values to c(180,150,100):
set.column(AirlineSingle, 1, c(1,1,0))
set.column(AirlineSingle, 2, c(1,0,1))
set.constr.type(AirlineSingle, c("<=","<=","<="))
set.rhs(AirlineSingle, c(180,150,100))
Our Objective function coefficients are c(5000,3000)
set.objfn(AirlineSingle, c(5000,3000))
The default setting minimizes the objective function. We need to maximize it. Therefor we use the following code:
lp.control(AirlineSingle,sense='max')
## $anti.degen
## [1] "fixedvars" "stalling"
##
## $basis.crash
## [1] "none"
##
## $bb.depthlimit
## [1] -50
##
## $bb.floorfirst
## [1] "automatic"
##
## $bb.rule
## [1] "pseudononint" "greedy" "dynamic" "rcostfixing"
##
## $break.at.first
## [1] FALSE
##
## $break.at.value
## [1] 1e+30
##
## $epsilon
## epsb epsd epsel epsint epsperturb epspivot
## 1e-10 1e-09 1e-12 1e-07 1e-05 2e-07
##
## $improve
## [1] "dualfeas" "thetagap"
##
## $infinite
## [1] 1e+30
##
## $maxpivot
## [1] 250
##
## $mip.gap
## absolute relative
## 1e-11 1e-11
##
## $negrange
## [1] -1e+06
##
## $obj.in.basis
## [1] TRUE
##
## $pivoting
## [1] "devex" "adaptive"
##
## $presolve
## [1] "none"
##
## $scalelimit
## [1] 5
##
## $scaling
## [1] "geometric" "equilibrate" "integers"
##
## $sense
## [1] "maximize"
##
## $simplextype
## [1] "dual" "primal"
##
## $timeout
## [1] 0
##
## $verbose
## [1] "neutral"
To look at the objective function, we can do the following:
AirlineSingle
## Model name:
## C1 C2
## Maximize 5000 3000
## R1 1 1 <= 180
## R2 1 0 <= 150
## R3 0 1 <= 100
## Kind Std Std
## Type Real Real
## Upper Inf Inf
## Lower 0 0
To solve our model
solve(AirlineSingle)
## [1] 0
An output of zero means that the model was successfully solved. You can look at the optimal objective function value or optimal decision variable values with get.objective and get.variables:
get.objective(AirlineSingle)
## [1] 840000
get.variables(AirlineSingle)
## [1] 150 30
Since the cost of operating one flight for this airline is Rs.30000/-, this flight happens to be profitable.