# Category Archives: Linear Programming

## Optimally Resting NBA Players

To celebrate the start of the 2013-2014 NBA season this past Tuesday, I decided to write a post on basketball. More specifically, on the important issue of how to give players some much needed rest in an “optimal” way. My inspiration came from an article by Michael Wallace published on ESPN.com on October 19. Here are some relevant excerpts:

After playing in the Miami Heat’s first five preseason games, LeBron James sat out Saturday night’s 121-96 victory over the San Antonio Spurs to rest…James said the decision to sit was part of the team’s “maintenance” process. Heat teammate Dwyane Wade played Saturday and scored 25 points in 26 minutes, but previously skipped three preseason games…”No, no injuries — just not suiting up,” James said. “It’s OK for LeBron to take one off.”

The key term here is maintenance process. You may also recall that, back in November 2012, the Spurs were fined $250,000 by the league after coach Popovich sent Duncan, Parker, Ginobili, and Green home right before a game against the Miami Heat. So we want to rest our players to keep them healthy, but this cannot come at the expense of losing games. There are many factors to be taken into account here, such as players’ current physical condition, strength and tightness of schedule, and match-ups (how well a team stacks up against another team), to name a few. This is definitely not an easy problem. However, some insight is better than no insight at all. Therefore, let’s see what we can do with a simple O.R. model, and then we can talk about the strengths and weaknesses of our initial approach. (Here’s where you, dear reader, are supposed to chime in!) Let’s begin with two simple assumptions: (i) when it comes to resting, we have to take players’ individual needs into account, i.e., we’ll use player-specific data; and (ii) when it comes to the likelihood of beating an opposing team, it’s better to think in terms of full lineups, rather than in terms of individual players, i.e., we’ll use lineup-specific data. The data in assumption (i) comes from doctors, players’ medical records, and coaches’ strategies. In essence, it boils down to one number: how many minutes, at most, should each player play in each game, under ideal circumstances. A useful measure of the strength of a lineup is its adjusted plus-minus score (see, for example, the work of Wayne Winston and his book Mathletics). In summary, it’s a number that tells you how many points a given lineup plays above (or below) an average lineup in the league over 48 minutes (or over 100 possessions, or another metric of reference). For the sake of explanation, I’ll pretend to be in charge of resting Miami Heat players (surprise!). I’ll refer to a generic lineup by the letter $i$ ($i=1,\ldots,8$), to a generic player by the letter $j$ ($j=$ LeBron, D-Wade, …, Andersen (Bird Man)), and to a generic game by the letter $k$. We’re now ready to begin. Fasten your seat belts! What are the decisions to be made? Let’s consider a planning horizon that consists of the next 7 games (or pick your favorite number). So $k=1,\ldots,7$. For the Heat, the first 7 games of the 2013-2014 season are against the following teams: Bulls, 76ers, Nets, Wizards, Raptors, Clippers, and Celtics. For each one of my potential lineups $i$ and each game $k$, I want to figure out the number of minutes I should use lineup $i$ during game $k$. Because this is an unknown number right now, it’s a variable in the model. Let’s call it $x_{ik}$. Note it’s also OK to think of $x_{ik}$ as a percentage, rather than minutes. I’ll adopt the latter interpretation. What are the constraints in this problem? There are three main constraints to worry about: (a) make sure to pick enough lineups to play each game in its entirety; (b) make sure your lineups are good enough to hopefully beat your opponents in each game; (c) keep track of players’ minutes, and don’t let them get out of hand. The next step is to represent each constraint mathematically. Constraint (a): Pick enough lineups to completely cover each game. For every game $k$, we want to impose the following constraint: $\displaystyle \sum_{i=1}^{10} x_{ik}=1$ This means that if we sum the percentage of time each lineup is used during game $k$, we reach 100%. Constraint (b): Choose your lineups so that you expect to score enough points in every game to beat your opponents. In this example, I’ll focus on plus-minus scores, but as a coach you could focus on any metric that matters to you. Given a lineup $i$, let $p_i$ be its adjusted plus-minus score. For example, the lineup of LeBron, Wade, Bosh, Chalmers, and Allen in the 2012-2013 season had the amazing $p_i$ score of +36.9 (you can obtain these numbers, and many other neat statistics, from the web site stats.nba.com). Now let’s say you have the plus-minus score of your opponent in game $k$, which we’ll call $P_k$. One way to increase your chances of victory is by requiring that the expected plus-minus score of your lineup combination in game $k$ exceed $P_k$ by a certain amount. Therefore, for every game $k$, we write the following constraint: $\displaystyle \sum_{i=1}^{10} p_i x_{ik} \geq P_k + 0.5$ I want to emphasize two things. First, $p_i$ can be any measure of goodness of your lineup, and it can take into account the specific opponent in game $k$. Likewise, $P_k$ can be any measure of goodness of team $k$, as long as it’s consistent with $p_i$. Second, you’re not restricted to having only one of these constraints. If many measures of goodness matter to you, add them all in. For example, if you’re playing a team that’s particularly good at rebounding and you believe that rebounding is the key to beating them (e.g. Heat vs. Pacers), then either replace the constraint above with the analogous rebounding version, or include the rebounding version in addition to the constraint above. Finally, note that I picked 0.5 as a fixed amount by which to exceed $P_k$, but it could be any number you wish, of course. It can even be a number that varies depending on the opponent. Constraint (c): Keep track of how many minutes your players are playing above and beyond what you’d like them to play. For any given player $j$ and any given game $k$, let $m_{jk}$ be $j$‘s ideal number of playing minutes in game $k$ (make it zero if you want the player to sit out). When it’s not possible to match $m_{jk}$ exactly, we need to know how many minutes player $j$ played under or over $m_{jk}$. Let’s call these two unknown numbers (variables) $u_{jk}$ and $o_{jk}$, respectively. So, for every player $j$ and game $k$, we write the following constraint: $\displaystyle 48\left(\sum_{i \text{ that includes } j} x_{ik}\right) + u_{jk} - o_{jk}=m_{jk}$ The expression “$i$ that includes $j$” under the summation means that we’re summing variables $x_{ik}$ for all lineups of which $j$ is a member. We’re multiplying the summation by 48 minutes because $x_{ik}$ is in percentage points and $m_{jk}$ is in minutes. What is our goal? (a.k.a. objective function) It’s simple: we don’t want players to play too many minutes above $m_{jk}$. Because this overage amount is captured by variable $o_{jk}$, we can write our goal as: $\displaystyle \text{minimize } \sum_{j=1}^{9} \sum_{k=1}^{7} o_{jk}$ This minimizes the total overage in playing minutes. For a more balanced solution, it’s also possible to minimize the maximum overage over all players, or add weights in front of the $o_{jk}$ variables to give preference to some players. Now what? Well, the next step would be to solve this model and see what happens. I created a Microsoft Excel spreadsheet that can be solved with Excel Solver or OpenSolver. You can download it from here. Feel free to adapt it to your own needs and play around with it (this is the fun part!). Because my model was limited in size (I can’t use OpenSolver on my Mac at home), the solution isn’t very good (too many overage minutes). However, by adding more players and more lineups, the quality will certainly improve (use OpenSolver to break free from limits on model size). Here are some notes to help you understand the spreadsheet: • Variables $x_{ik}$ are in the range B18:H25. • Variables $u_{jk}$ and $o_{jk}$ are in ranges B56:J62 and B65:J71, respectively. • Constraints (a) are implemented in rows 27, 28, 29. • Constraints (b) are implemented in rows 33, 34, 35. • The left-hand side of constraints (c) are in the range B74:J80. This range is required to be equal to the range B47:J53 (where the $m_{jk}$ are) inside the Solver window. • The objective function whose formula appears above is in cell J21. What are the pros and cons of this model? Can you make it better? No model is perfect. There are always real-life details that get omitted. The art of modeling is creating a model that is detailed enough to provide useful answers, but not too detailed to the point of requiring an unreasonable amount of time to solve. The definitions of “detailed enough” and “unreasonable amount of time” are mostly client-specific. (What would please Erik Spoelstra and his coaching staff?) What do you think are the main strengths and weaknesses in the model I describe above? What would you change? Good data is a big issue in this particular case. If you don’t like my data, can you propose alternative sources that are practical? I believe there’s plenty to talk about in this context, and I’m looking forward to receiving your feedback. Maybe we can converge to a model that is good enough for me to go knocking on the Miami Heat’s door! (Don’t worry. In the unlikely event they open the door, I’ll share the consulting fees.) 3 Comments Filed under Applications, Linear Programming, Modeling, Motivation, Sports ## Best Known European Book on LP, in 1966 Today, as I entered my department’s Xerox/coffee room to make myself some tea, I noticed a big pile of old books and a note from one of my colleagues saying they were up for grabs. As I browsed through the titles, one of them caught my attention: And here’s the text that appears on the flaps of the outer paper cover: The publication date is 1966. And here’s an interesting quote: “The best-known European book on linear programming. Considered one of the most complete studies of the field ever written,…” I must confess I didn’t know about this book, but I decided to keep it for its (potential) historical value. A little Googling led me to discover that Adi Ben-Israel wrote a half-page SIAM Review about this book in 1967 (volume 9, no. 3, p. 608). Here are some highlights: “This book is, in my opinion, among the best in the class of general reference and self-instruction L.P. texts presently available, and as such is most valuable to practitioners and students of L.P.” Later on Adi also says that the book has “Many well-chosen, worked out examples.” That sounds pretty good! I haven’t had time to browse through it yet, but if anyone knows about this book, I’d love to hear your thoughts. Leave a comment Filed under Books, Linear Programming ## Big Bang Theory Party Planning Penny is organizing a party at her apartment, but she is on a tight budget. Having a working knowledge of all of the important things in the universe, Sheldon knows everything about linear programming and offered to help her. He postulates that it’s ideal to have two kinds of mixed nuts: a plain party mix, and a luxury mix (for those with a distinct taste like himself). Based on the expected number of guests, Howard quickly calculates that they’ll need a total of at least 10 pounds of snacks, but no more than 6 pounds of each kind of mix. On his white board, Sheldon has already come up with the following table: Raj wants to dip the hazelnuts into liquor, but that’s not in the budget, so he gives up. Leonard reminds everyone that, because of their allergies, it’s important to keep the average allergenicity level per pound in both mixes to no more than 3. Write an optimization model to help Penny prepare the two kinds of snacks at minimum cost. But be careful: Sheldon will check it later for correctness! This post is part of my series “Having Fun with Exam Questions”. Previous questions dealt with Farmville, vampires, and (potentially) Valentine’s day. 1 Comment Filed under Big Bang Theory, Exam Fun, Linear Programming, Modeling, Teaching ## Twilight Network Flow CAUTION: Spoiler Alert! Part of a professor’s job is to come up with new exam questions each year. That may be a time-consuming (and sometimes tedious) task. You want the question to be just right: not too easy, not too difficult, and capable of testing whether or not the students understood a given concept. This year, I figured I might as well have some fun while doing it. Inspired by Laura McLay’s insightful (and very popular) post on vampire populations, I decided to create a Twilight-themed network flow question: Alice is in charge of planning Edward and Bella’s wedding and she ordered 2000 roses to be delivered to three locations as shown in the network below. The Cullen’s house (node 2) needs 1000 roses, Charlie’s house (node 4) needs 800 roses, and Billy’s house (node 7) is supposed to get 200 roses (just to tease Jacob). The numbers next to the arcs of the network represent shipping costs per rose (in cents); they’re proportional to the distance between each node. The roses are coming from two local growers in Forks (nodes 1 and 3). Each of them can supply 1000 roses. Arrows with two heads indicate that shipments can be made in both directions. Write down the supply and/or demand values next to each node and write a linear programming model to determine the shipment plan that minimizes the total cost of delivering all the roses (include all the necessary constraints). (Note: Alice already knows whether you’re going to get the right answer.) The second half of the fun is to see if any students react to it. In fact, I got a couple of interesting written comments: “How dare you incorporate Twilight into Management Science?”, and a Harry Potter enthusiast wrote “Team Harry!”, while at the same time substituting the names of Hermione, Harry, Ginny and Malfoy for Alice, Edward, Bella, and Jacob. 4 Comments Filed under Exam Fun, Linear Programming, Modeling, Network Flows, Teaching ## YouTube Videos on Solving LPs with Excel This had been in the back burner for a long while. Each time I taught my O.R. class (either undergrad or MBA), I kept thinking that the students would like to be able to see the Excel setup of an LP model over and over again. Many of them are not proficient in Excel, and my class is their first contact with things like absolute cell references and SUMPRODUCT. I watched a number of YouTube videos on the topic, but I wasn’t happy with any of them. Besides, I wanted the video to be about the same example that I use in the classroom. So I decided to bite the bullet and go for it. I think the outcome was decent: not great, but not terrible either. My wife said I sound a little stilted. I agree. I was only willing to do it once, no second takes, which means I was a little nervous :-) Before I give you the link to the videos, I need to bring your attention to two disclaimers: Disclaimer 1: I used the demo version of iShowU to record my screen action. That means you’ll see a green watermark on top of the video. I know it’s ugly, but I didn’t want to pay$29.95 for it. At least not until I get some feedback to convince me that I’ll be doing more of these videos.

Disclaimer 2: I shamelessly use the same example that they (used to?) use at the Tepper School in my classes: the “famous” farmer problem (sorry Javier :-). I was the head TA for that class a number of times and I literally sat through it at least 3 or 4 times.

Here they are:

I hope these videos turn out to be useful to my students and to anyone who wants to learn about linear programming and Excel Solver. I’m thinking about doing more videos on the diet problem, transportation, sensitivity analysis, etc. Let’s see how things go.