Path: blob/main/notebooks/10/01-aircraft-seat-allocation.ipynb
663 views
10.1 Aircraft seat allocation problem
Preamble: Install Pyomo and a solver
The following cell sets and verifies a global SOLVER for the notebook. If run on Google Colab, the cell installs Pyomo and the HiGHS solver, while, if run elsewhere, it assumes Pyomo and HiGHS have been previously installed. It then sets to use HiGHS as solver via the appsi module and a test is performed to verify that it is available. The solver interface is stored in a global object SOLVER for later use.
Problem description
An airline is deciding how to partition a new plane for the Amsterdam-Buenos Aires route. This plane can seat 200 economy-class passengers. A section can be created for first-class seats, but each of these seats takes the space of 2 economy-class seats. A business-class section can also be created, but each of these takes the space of 1.5 economy-class seats. The profit for a first-class ticket is three times the profit of an economy ticket, while a business-class ticket has a profit of two times an economy ticket's profit. Once the plane is partitioned into these seating classes, it cannot be changed.
The airline knows that the plane will not always be full in every section. The airline has initially identified three scenarios to consider with about equal frequency:
Weekday morning and evening traffic;
Weekend traffic; and
Weekday midday traffic.
Under Scenario 1 the airline thinks they can sell as many as 20 first-class tickets, 50 business-class tickets, and 200 economy tickets. Under Scenario 2 these figures are 10 , 24, and 175, while under Scenario 3, they are 6, 10, and 150, respectively. The following table summarizes the forecast demand for these three scenarios.
| Scenario | First-class seats | Business-class seats | Economy-class seats |
|---|---|---|---|
| (1) weekday morning and evening | 20 | 50 | 200 |
| (2) weekend | 10 | 24 | 175 |
| (3) weekday midday | 6 | 10 | 150 |
| Average Scenario | 12 | 28 | 175 |
The goal of the airline is to maximize ticket revenue. For marketing purposes, the airline will not sell more tickets than seats in each of the sections (hence no overbooking strategy). We further assume customers seeking a first-class or business-class seat will not downgrade if those seats are unavailable.
Attribution
This problem statement is adapted from an exercise and examples presented the following book:
Birge, J. R., & Louveaux, F. (2011). Introduction to stochastic programming. Springer Science & Business Media.
The adaptations include a change to parameters for consistency among reformulations of the problem, and additional treatments for sample average approximation (SAA) with chance constraints.
Problem data
Pandas DataFrames and Series are used to encode problem data in the following cell, and to encode problem solutions in subsequent cells.
Analytics
Prior to optimization, a useful first step is to prepare an analytics function to display performance for any given allocation of seats. The first-stage decision variables are the number of seats allocated for each class . We would like to provide a analysis showing the operational consequences for any proposed allocation of seats. For this purpose, we create a function seat_report() that show the tickets that can be sold in each scenario, the resulting revenue, and the unsatisfied demand ('spillage').
To establish a basis for analyzing possible solutions to the airline's problem, this function first is demonstrated for the case where the airplane is configured as entirely economy-class.
Model 1. Deterministic solution for the average demand scenario
A common starting point in stochastic optimization is to solve the deterministic problem where future demands are fixed at their mean values and compute the corresponding optimal solution. The resulting value of the objective has been called the expectation of the expected value problem (EEV) by Birge, or the expected value of the mean (EVM) solution by others.
Let us introduce the set of the three possible classes, i.e., . The objective function is to maximize ticket revenue.
where is the revenue from selling a ticket for a seat in class .
Let denote the number of seats of class installed in the new plane. Let be the scale factor denoting the number of economy seats displaced by one seat in class . Then, since there is a total of 200 economy-class seats that could fit on the plane, the capacity constraint reads as
Let be the mean demand for seats of class , and let be the number of tickets of class that are sold. To ensure we do not sell more tickets than available seats nor more than demand, we need to add two more constraints:
Lastly, both ticket and seat variables need to be nonnegative integers, so we add the constraints .
The following cell presents a Pyomo model implementing this model.
Model 2. Two-stage stochastic optimization and its extensive form
If we assume demand is not certain, we can formulate a two-stage stochastic optimization problem. The first-stage or here-and-now variables are the 's, those related to the seat allocations. Due to their dependence on the realized demand , the variables 's describing the number of tickets sold, are second-stage or recourse decision variables. The full problem formulation is as follows: the first stage problem is
where is the value of the second-stage problem, defined as
In view of the assumption that there is only a finite number of scenarios for ticket demand, we can write the extensive form of the two-stage stochastic optimization problem above and solve it exactly. To do so, we modify the second-stage variables so that they are indexed by both class and scenario . The expectation can thus be replaced with the average revenue over the scenarios, that is
where the fraction appears since we assume that all scenarios are equally likely. The first stage constraint remains unchanged, while the second stage constraints are tuplicated for each scenario , namely
The following cell presents a Pyomo model implementing this model and solving it for the equiprobable scenarios introduced above.
Model 3. Adding chance constraints
The airline wishes a special guarantee for its clients enrolled in its loyalty program. In particular, it wants probability to cover the demand of first-class seats and probability to cover the demand of business-class seats (by clients of the loyalty program). First-class passengers are covered if they can purchase a first-class seat. Business-class passengers are covered if they purchase a business-class seat or upgrade to a first-class seat.
Assume the demand of loyalty-program passengers is normally distributed as and for first-class and business, respectively, where the parameters are given in the table below. For completeness, we also include the parameters for economy-class passengers.
| F | 12 | 4 |
| B | 28 | 8 |
| E | 175 | 20 |
We further assume that the demands for first-class and business-class seats are independent of each other and of the scenario (time of the week).
Let be the number of first-class seats and the number of business seats. The probabilistic constraints are
These are can be written equivalently as linear constraints, specifically
For the second constraint, we use the fact that the sum of the two independent random variables and is normally distributed with mean and variance .
We add these equivalent linear counterparts of the two chance constraints to the stochastic optimization model. Rather than writing a function to create a whole new model, we can use the prior function to create and add the two chance constraints using decorators.
Model 4. Solving the case of continuous demand distributions using the SAA method
Let us now move past the simplifying assumption that there are only three equally likely scenarios and consider the case where the demand is described by a random vector , where is the demand for seats of class . The demand for class is assumed to be independent and normally distributed with mean and variance as reported in the following table
| F | 12 | 4 |
| B | 28 | 8 |
| E | 175 | 20 |
Note that we model the demand for each class using a continuous random variable, which is a simplification of the real world, where the ticket demand is always a discrete nonnegative number. Therefore, we round down all the obtained random numbers.
However, now that the number of scenarios is not finite anymore, we cannot solve the problem exactly. Instead, we can use the SAA method to approximate the expected value appearing in the objective function. The first step of the SAA is to generate a collection of scenarios for . We can do this by sampling from the normal distributions with the given means and variances.
For sake of generality, we create a script to generate scenarios in which the three demands have a general correlation structure captured by a correlation matrix .
Scenario generation (uncorrelated case)
We also introduce a new function to report the solution and its features in this more general continuous demand case.
We can now solve the stochastic optimization problem using the generated scenarios. Note that we can use the previously defined function aircraft_stochastic to solve the model by simply calling it with a different dataframe as argument.
Model 5. Adding correlations between different demand types
Now assume the ticket demand for the three categories is captured by a -dimensional multivariate normal distribution mean , variances and a symmetric correlation matrix
The covariance matrix is given by or
We assume , and .
We now sample scenarios from this multivariate correlated normal distribution and use the SAA method to approximate the solution of the two-stage stochastic optimization problem.
Model 6. Tackling chance constraints using SAA in the case of correlated demand
The linear counterparts of the chance constraints used above in Model 3 were derived under the assumption of independent normal distributions of demand for first-class and business travel. That assumption no longer holds for the case where demand scenarios are sampled from correlated distributions.
This final model replaces the chance constraints by approximating them using two linear constraints that explicitly track unsatisfied demand. In doing so, we introduce two new sets of integer variables and and a big-M constant and approximate the true multivariate distribution with the empirical one obtained from the sample.
The first stage remains unchanged and so does the objective value of the second stage. The adjusted second-stage constraints are:
where and are binary variables indicating those scenarios which do not satisfy the requirements of the airline's loyalty programs for first-class and business-class passengers.
The following cell implements this new model. Note that the running time for the cell can be up to a few minutes for a large number of scenarios.
Exercise
Compared the results of using positive correlation in demand for first and business-class tickets results in lower expected revenue. What happens if there is no correlation, or there is negative correlation? Verify your predictions by simulation.