Case—AdWords to AdWards: Online Optimization for Hospital Patient Placement

Published Online:https://doi.org/10.1287/ited.2025.0147cs

Abstract

This case illustrates online optimization algorithms for sequential decision making. Students are asked to translate an unfamiliar healthcare setting into a well-known online optimization problem, the Google AdWords problem. The case is based on an actual process improvement project aimed at maximizing the use of a hospital’s capacity. The main character, Dr. Kelly, heads an observation unit and had tried a predictive model for patient assignments to her unit versus the hospital wards, which, however, can sometimes lead to inefficient bed capacity management. She is looking to improve patient allocation decisions made in real time. The complexity of the healthcare environment makes the mapping challenging, requires discussions with experts with domain knowledge and various stakeholders in the process, and raises ethical questions.

Dr. Kelly’s Dilemma

Dr. Erin Kelly was in charge of a 23-bed observation unit at Montanaro, a 260-bed hospital in a medium-sized U.S. city. Observation units (OUs) house observation status patients with complex but not life-threatening symptoms so that healthcare providers can observe such patients for a period of time and decide whether inpatient hospitalization is required or whether the patient can be safely discharged from the hospital. In practice, not all observation status patients are placed in the OU, which has a limited capacity; some are placed directly in the inpatient wards. Patients placed in the OU are expected to spend, on average, 48 hours before being moved to the wards or discharged.

After analyzing data from the OU several months ago, Dr. Kelly had become concerned about the long length of stay (LOS) for some OU patients, as well as the high percentage of OU patients who “flipped,” or acquired inpatient status, while in the OU. The former group of patients took up space in the OU that could be assigned to patients who could benefit more from the OU beds. The latter group of patients spent a lot of time in transit between departments at the hospital. Dr. Kelly focused on patients placed in her OU after presenting at the emergency department (ED) and collaborated with a professor at a nearby university, Professor Viviana Devis, to build predictive models to identify patients who were likely to flip after being placed in the OU. Such patients could be placed directly in the inpatient wards after presentation at the ED. Appendix A contains the data dictionary for the data set Dr. Kelly and Professor Devis used in the original analysis (Table A.1), as well as an example of what the final predictive model could have looked like (Figure A.1).

Decisions in healthcare settings are never easy or clear-cut. Predictions of the likelihood that a patient would flip were not perfect, and many patients were borderline cases, so they could be considered for both OU and inpatient ward placement. In addition, when testing the recommendations of the predictive model on past patient arrival data, Dr. Kelly and Professor Devis observed that sometimes the OU would not be very busy while the inpatient wards would be full, and vice versa. Dr. Kelly wanted to know when she could take in more patients to help congestion in the inpatient wards and when she should save capacity in the OU.

Dr. Kelly reached out to Professor Devis once again. Professor Devis had been working on online optimization algorithms for ad placement and order fulfillment. The description of Dr. Kelly’s problem reminded her of such settings. She wondered whether online optimization algorithms could be used to address Dr. Kelly’s question.

Sequential Decision Making and Online Optimization

Offline optimization algorithms are built on the assumption that all necessary data are available beforehand, allowing for decisions to be made after analyzing the entire data set and enabling careful planning to achieve the optimal solution. There are settings where this is an appropriate approach; typically, such settings have a static environment where conditions remain relatively stable over time and do not require an immediate response. Many decisions in the real world, however, must be made in a dynamic environment where conditions change rapidly and unpredictably. The person or system issuing a request requires a response immediately; it is not feasible to wait for additional information to arrive before deciding how to serve the request in the most cost-efficient or profit-maximizing way. Such situations call for real-time (also referred to as online) decision making in which decisions are made sequentially as new data become available. Examples of such settings include sales of different fare classes of airline tickets, online advertising, dynamic pricing, and inventory management for new products.

An Illustrative Example

A classic example of the online decision-making setting is the so-called “AdWords problem” that arises in online advertising. The goal is for an online advertising platform to allocate a sequence of advertising spaces associated with search queries to budget-constrained advertisers in a way that maximizes the platform’s expected revenue. This problem is an example of online matching problems, studied extensively in computer science.

Let’s consider a particular instance of the AdWords problem (Figure 1). Suppose there are N advertisers (bidders), {A1,A2,…,AN}, with specified budgets {B1,B2,…,BN}. Q is a set of M query words {Q1,Q2,…,QM}. Each advertiser An specifies a bid bnQm for query word Qm. If advertiser An‘s ad is shown when query word Qm arrives, the platform realizes the revenue from the bid bnQm only if the customer who generated the query clicks on the ad. Assume that the click-through rate cnQm for An‘s ad for query word Qm is approximately known based on past data. This means that the expected revenue to the platform from showing An‘s ad for query word Qm can be estimated as bnQmcnQm.

Figure 1. A Sketch of the AdWords Problem
Note. Advertisers (nodes on the left) need to be matched with arriving queries over time (nodes on the right).

A sequence of query words {q1,q2,…,qT} arrive during the day, where qt∈{Q1,Q2,…,QM} denotes the type of the tth word that arrives. Suppose that there is a single ad slot and each query qt must be assigned to an advertiser An. Which advertiser should be selected?

The “Clairvoyant” Problem

If the sequence of query words {q1,q2,…,qT} were known in advance, the problem could be solved as follows. Consider decision variables xqtAn=1 if query word qt arriving at time t is allocated to advertiser An, and zero otherwise. (The subscript t here is only used to denote the different query word arrivals. The relative ordering of and the exact time at which queries arrive do not matter.) We can formulate the following offline optimization problem:

Maximize

∑t∈1,…,T∑n∈{1,…,N}bqtAn⋅cqtAn⋅xqtAn,
subject to requests allocated to each advertiser cannot be more than the advertiser’s budget:
∑t∈1,…,T bqtAn⋅cqtAn⋅xqtAn≤Bn, ∀n∈{1,…,N};
each query should be allocated to only one advertiser:
∑n∈{1,…,N}xqtAn=1, t∈1,…,T;
and the decision variables are binary (take only values zero and one):
xqtAn∈0,1, t∈1,…,T, n∈{1,…,N}.

This formulation is referred to as the “clairvoyant” problem because the resulting allocations are created assuming that future arrivals are known, and therefore, they are the best they can be. If all information is known in advance (i.e., we know what the query type of each arriving query will be over the time horizon T), the optimal allocation across all arriving queries and all advertisers over T given their budgets can be found. A simple example is described in Appendix B.

Heuristics

Unfortunately, the types of queries arriving over time are not known in advance, and decisions need to be made in an online fashion. Heuristics—quick methods to arrive at decisions that “make sense” but are not guaranteed to be optimal—can be employed in such circumstances; however, some heuristics are better than others. A purely “greedy” heuristic—one that allocates each arriving query to the advertiser with the highest bid for that query until the advertiser’s budget is exhausted—may seem logical, but it often performs poorly in practice.

What Constitutes “Good” Performance for an Online Algorithm?

The performance of an online algorithm is often evaluated through the competitive ratio: the ratio of the worst-case value obtained by the online algorithm (revenue in the case in the AdWords problem) over the sequence of arrivals and the best value achievable by the offline clairvoyant algorithm. How do we know the best value achievable by the offline clairvoyant algorithm if we do not know the sequence of arrivals in advance? We can sometimes calculate a bound for it. An online algorithm is said to be α-competitive if, for every instance, the ratio of the revenue of the online algorithm to the revenue of the best offline algorithm is at least α.

An important breakthrough in developing online algorithms for online matching problems (and the AdWords problem in particular) was the realization that instead of a purely greedy algorithm that assigns queries to advertisers based on the magnitude of their bids, one can calculate “rewards” that represent the bids scaled to reflect the remainder of the advertisers’ budgets at that point in time and use those rewards for allocation purposes. Having observed a query and calculated the rewards for each query-advertiser pair, the online algorithm would allocate the current query to the advertiser with the highest reward rqtAn (rather than the highest bid bqtAn). An advertiser whose budget is almost exhausted (i.e., the ratio γtAnBn is very small) would have its bid scaled down, reducing the reward of allocating the current query to that advertiser relative to other advertisers with comparable bids but whose budgets have not been exhausted yet.

The reward rqtAn of allocating query qt to advertiser An with bid bqtAn, initial budget Bn, and current (remaining) budget γtAn is defined as

rqtAn=bqtAn⋅cqtAn⋅Ψ γtAn Bn,
where Ψx is an increasing function that represents the relative penalty incurred for depleting the budget of the advertiser. Selecting the linear function Ψlinx=x means that the penalty for depleting the budget of the advertiser is proportional to the fraction of advertiser budget left, and the reward is calculated as
rqtAn=bqtAn⋅cqtAn⋅ γtAn Bn.

Selecting an exponential function instead, 1−e−x, results in a greater penalty the first time an advertiser’s budget is used but then less dramatic further penalties for depleting the budget; see Figure 2. In practice, this exponential function is often scaled by a factor of e/(e−1), which keeps it in the range [0,1] and ensures more balanced penalties as the budget is decreased. The reward for the scaled exponential function Ψexpx=ee−1⋅1−e−x is determined as

rqtAn=bqtAn⋅cqtAn⋅ee−1⋅1−e− γtAn Bn.

Figure 2. Penalty for Allocating an Advertiser’s Budget (on the y-Axis) vs. Remaining Proportion of Budget (on the x-Axis) for Linear Function Ψlinx=x and Exponential Functions Ψx=1−e−x and Ψexpx=ee−11−e−x

The choice of Ψx affects the performance of the online optimization algorithm. In particular, using the exponential function Ψexp has been shown to result in a good competitive ratio of 1−1e under certain conditions. The exact definition of the function Ψx is sometimes guided by the so-called “dual” problem of the “primal” clairvoyant optimization problem. The dual variables corresponding to the constraints in the primal problem are used to assess the incremental value of depleting a particular budget or resource. Such primal-dual approaches have been successfully applied, for example, by online retailers when deciding from which warehouse orders should be shipped to customers given shipping costs and available inventories or to determine personalized assortments to offer to customers given limited inventories of the products used in the assortments.

Appendix B describes further the difference between the greedy and the “scaled greedy” online algorithms for simple examples, and shows how one could calculate the competitive ratio.

Online Capacity Balancing for Montanaro?

Professor Devis reviewed the summary data provided by Dr. Kelly. (See Table 1 and file OUSummaryData.xlsx.) Use this information to address the following questions:

Table

Table 1. Summary Data from Dr. Kelly’s Data Set

Table 1. Summary Data from Dr. Kelly’s Data Set

DRG codeDescriptionPercentageProbability of flippingExpected LOS, OU startExpected LOS, W startDifference W-OU LOS
276Dehydration0.11750.60335.716.731.01
428Congestive heart failure0.04380.61223.755.762.02
486Pneumonia0.05690.57893.445.462.02
558Colitis0.03360.72735.713.69−2.02
577Pancreatitis0.01870.76193.423.420.00
578GI bleeding0.03920.53665.478.503.03
599Urinary tract infection0.07650.65857.995.97−2.02
780Syncope0.27610.37255.689.724.04
782Edema0.01960.39134.803.79−1.01
786Chest pain0.13710.33783.209.266.06
787Nausea0.07930.45783.337.374.04
789Abdominal pain0.10170.32873.666.693.03


Note. The columns in the table show the 12 most frequently encountered diagnoses in the ED (“DRG code” column), the definition of the diagnosis (“Description” column), the average percentage of cases for each diagnosis (“Percentage” column), the probability of flipping for each diagnosis, the expected length of stay (LOS) when the patient starts in the OU vs. the wards (“Expected LOS, OU start” and “Expected LOS, W start” columns, respectively), and the difference between the two expected LOS (“Difference W-OU LOS”).

  1. Can Dr. Kelly’s problem be represented as an online optimization problem similar to the AdWords problem? If yes, what would be the equivalent for the advertisers, budgets, bids, click-through rates, queries, and query types in Dr. Kelly’s problem?

  2. What could constitute a “revenue” associated with matching a query with an advertiser in Dr. Kelly’s context?

Appendix A. Predictive Model Information

Figure A.1. Decision Tree Predictive Model
Table

Table A.1. A List of Variables and Their Definitions Used by Dr. Kelly and Professor Devis to Build the Predictive Model

Table A.1. A List of Variables and Their Definitions Used by Dr. Kelly and Professor Devis to Build the Predictive Model

VariableDefinition
AgeAge of patient, in years
GenderPatient gender (recorded as male/female)
PrimaryInsuranceCategoryInsurance provider for the patient, e.g., Medicare, Medicaid, Private, other
Flipped?The value of this variable is “flipped” if a patient flipped from OBSERVATION status to INPATIENT status, and “not flipped” if the patient stayed in OBSERVATION status during the whole stay in the OU
OU_LOS_hrsLength of stay in the OU in hours
DRG01Primary diagnosis-related group (code) upon admission of the patient in the OU:
276 Dehydration
428 Congestive heart failure
486 Pneumonia
558 Colitis
577 Pancreatitis
578 GI bleeding
599 Urinary tract infection
780 Syncope
782 Edema
786 Chest pain
787 Nausea
789 Abdominal pain
BPUpper, BPLower, BPDiff, Pulse, PulseOximetry, Respirations, TemperaturePatient vital signs
(BP = blood pressure)

Appendix B. Simple Examples of Online Algorithms

Let us see some examples of how online optimization algorithms work.

Consider a simple setup in which there are two advertisers, A1 and A2, with equal starting budgets, B1 and B2, of two units each. There are two types of query words, Q1 and Q2, and the bids advertisers A1 and A2 have placed on those queries are shown in Figure B.1(b). Assume that the click-through rates are always one, and one ad is shown for each arriving query. Suppose that four queries have arrived, the first two of type Q1 and the last two of type Q2.

Figure B.1. Simple AdWords Example
Notes. (a) Advertisers and budgets. (b) Query types, advertiser bids for each query type, and click-through rates. (c) A sketch of the simple example setup.

We next discuss the optimal clairvoyant solution and two “reasonable” algorithms and illustrate the allocations in Figure B.2.

Figure B.2. Allocation of Incoming Queries to Advertisers
Notes. (a) Optimal clairvoyant solution (revenue = 4). (b) Greedy solution (revenue = 2; competitive ratio = 1/2). (c) Balance-budget solution (revenue = 3; competitive ratio = 3/4).

B.1. Clairvoyant Solution

If we knew in advance that the sequence of query types would be {q1,q2,q3,q4}={Q1,Q1,Q2,Q2}, we would allocate the first two queries, q1 (of type Q1) and q2 (of type Q1), to advertiser A2, and the last two queries, q3 (of type Q2) and q4 (of type Q2), to advertiser A1. This would generate the maximum possible revenue of four.

Let’s see how this insight would map to the clairvoyant optimization problem formulation. We know that q1=Q1, q2=Q1, q3=Q2, q4=Q2 in advance. We want to find the maximum of the expression for the total revenue in the objective function

∑t∈1,2,3,4∑n∈{1,2}bqtAn⋅cqtAn⋅xqtAn=bq1A1⋅cq1A1⋅xq1A1+bq1A2⋅cq1A2⋅xq1A2+⋯+bq4A1⋅cq4A1⋅xq4A1+bq4A2⋅cq4A2⋅xq4A2=bQ1A1⋅cQ1A1⋅xq1A1+bQ1A2⋅cQ1A2⋅xq1A2+⋯+bQ2A1⋅cQ2A1⋅xq4A1+bQ2A2⋅cQ2A2⋅xq4A2,
where each xqtAn is a decision variable that can only take value one (assign the incoming query qt to advertiser An) or zero (do not).

We know bQ1A1=1, bQ1A2=1, bQ2A1=1, bQ2A2=0, and all the click-through rates are one. So, the expression for the total revenue resulting from the allocation is

=1⋅1⋅xq1A1+1⋅1⋅xq1A2+1⋅1⋅xq2A1+1⋅1⋅xq2A2++1⋅1⋅xq3A1+0⋅1⋅xq3A2++1⋅1⋅xq4A1+0⋅1⋅xq4A2,
subject to the budget constraints
xq1A1+xq2A1+xq3A1+xq4A1≤2 (total budget for A1)xq1A2+xq2A2+xq3A2+xq4A2≤2 total budget for A2 
and the constraints that each arriving query {q1,q2,q3,q4} can be allocated to only one advertiser:
xq1A1+xq1A2=1xq2A1+xq2A2=1xq3A1+xq3A2=1xq4A1+xq4A2=1.

It is easy to see that the best combination of values for xqtAn that maximizes the expression for the total revenue is

xq1A1=0, xq1A2=1

xq2A1=0, xq2A2=1

xq3A1=1, xq3A2=0

xq4A1=1, xq4A2=0,
which translates into the allocation described at the beginning of this section. This is because this allocation assigns zero to the values of xq3A2 and xq4A2 in the terms with zero coefficients in the total revenue calculation, and it maximizes the value of the remaining terms given the constraints.

B.2. Greedy Solution

Under imperfect information about future queries, suppose that we follow a greedy algorithm: assign each arriving query to the advertiser with the highest bid for that query.

The allocation of the four arriving queries from Figure 2(c) will work as follows:

  1. When the first query q1 (of type Q1) arrives, both A1’s and A2’s bids are one. (See first row of the table in Figure B.1(b)) We can allocate q1 randomly to one of the two advertisers then. Let’s pick A1. Revenue so far equals one.

  2. When the second query q2 (of type Q1) arrives, both A1 and A2’s bids are one. (See first row of the table in Figure B.1(b).) Again, let’s allocate q2 randomly to one of the two advertisers, A1. Cumulative revenue so far equals two.

  3. When the third query q3 (of type Q2) arrives, A1’s bid is one, and A2’s bid is zero. (See second row of the table in Figure B.1(b).) If we could, we would allocate the arriving query to A1; however, A1 has no budget left. The cumulative revenue therefore remains two.

  4. The situation in query 3 repeats when the fourth query q4 (of type Q2) arrives.

The total revenue generated by the greedy algorithm is therefore two, and the competitive ratio is 2/4 = 0.50.

B.3. Balance-Budget Solution

Based on the performance of the greedy algorithm, where one advertiser ran out of budget and the other advertiser kept its entire budget but whose ad did not receive any impressions, it seems that it would be important to keep track of the remaining budget of an advertiser. What if, instead of allocating the incoming query to the advertiser with the highest bid, we allocate it to the advertiser with the highest remaining unused budget?

The allocation of the four arriving queries from Figure B.1(c) will work as follows:

  1. When the first query q1 (of type Q1) arrives, both A1’s and A2’s budgets are two. We can then allocate q1 randomly to one of the two advertisers. Let’s pick A1. Revenue so far equals one (A1’s bid for query type Q1).

  2. When the second query q2 (of type Q1) arrives, A1’s remaining budget is one, and A2’s remaining budget is two. We allocate q2 to A2 given its higher remaining budget. Cumulative revenue so far equals two. (A2’s bid of one for query type Q1 was added to the revenue from step 1.)

  3. When the third query q3 (of type Q2) arrives, A1’s budget is one, and A2’s budget is one. We allocate the arriving query to A1. A1’s bid for query of type Q2 is one, so the cumulative revenue is now 2 + 1 = 3.

  4. When the third query q4 (of type Q2) arrives, A1’s budget is zero, and A2’s budget is one. We allocate the arriving query to A2. However, A2’s bid for query of type Q2 is zero, so the cumulative revenue does not increase—it remains at three.

The total revenue generated by the balance-budget algorithm is higher than the total revenue generated by the greedy algorithm (three versus two), and the competitive ratio is better: 3/4 = 0.75.

However, further examples can be constructed to show that (1) taking into consideration not the remaining budget but the percentage of the remaining budget of each advertiser leads to a fairer process (so that smaller advertisers are not ignored), and (2) both the remaining budget percentage and the bid of each advertiser for each keyword should be taken into consideration for better algorithm performance. (In fact, the click-through rate should also be considered, but here we assumed it to be one for all ads.) This is why a calculation for reward of the form

rqtAn=bqtAn⋅cqtAn⋅Ψ γtAn Bn
makes sense in the most general case.

Worksheets AlgLinear and AlgExp in the file OnlineAlgorithmsIllustration.xlsx walk through the calculation with the more sophisticated definition of rewards for linear and exponential function Ψ.

Online capacity-balancing algorithms have been studied extensively in computer science, operations research, and operations management. Good references to learn more about the subject include:

Further Reading

  • Acimovic J, Farias VF (2019) The Fulfillment-Optimization Problem, INFORMS TutORials in Operations Research (INFORMS, Catonsville, MD), 218–237.Link, Google Scholar
  • Acimovic J, Graves SC (2015) Making better fulfillment decisions on the fly in an online retail environment. Manufacturing Service Oper. Management 17(1):34–51.Link, Google Scholar
  • Dwyer‐Matzky K, Pachamanova D, Tilson V (2021) Accounting for capacity: A real‐time optimization approach to managing observation unit utilization. Naval Res. Logist. 68(5):534–555.Crossref, Google Scholar
  • Golrezaei N, Nazerzadeh H, Rusmevichientong P (2014) Real-time optimization of personalized assortments. Management Sci. 60(6):1532–1551.Link, Google Scholar
  • Kalyanasundaram B, Pruhs KR (2000) An optimal deterministic algorithm for online B-matching. Theor. Comput. Sci. 233(1–2):319–325.Crossref, Google Scholar
  • Mehta A (2013) Online matching and ad allocation. Foundations Trends Theoret. Comput. Sci. 8(4):265–368.Crossref, Google Scholar
  • Mehta A, Saberi A, Vazirani U, Vazirani V (2007) Adwords and generalized online matching. J. ACM 54(5):22-es.Crossref, Google Scholar