Creating a pandemic-proof IPL Schedule in Python

Samrudha Kelkar
4 min readApr 17, 2021

Yes.. let’s try this!!

Watching an IPL match in the middle of the pandemic is weird, isn’t it? Those empty stadiums, that artificial audience noise, and that untouchable Air-bubble. Conducting such an international event in tough times must be really really challenging for the organizers. Kudos to their efforts!!

I was thinking of all the travel involved in the IPL schedule. In a regular IPL, each team plays one match home and one match away. Can we optimize the schedule such that there is less travel involved in the event?

Optimizing Travel

Use all destinations

Well yeah, there is an option to just make IPL, a single-place event. But let’s say we must use all the destinations because of legal compliance with the participating team or because there is a local economy associated with the IPL. Also, there is lesser impact/dependence on a single location.

Not all destinations are the same in the Pandemic

Covid numbers in Mumbai would be very different than say Chennai. Maybe you want to avoid one destination as much as possible in such cases.

All such requirements call for a scientific approach to the scheduling problem. There is a need for an optimized way of looking at travel.

Enters PuLP: A Linear Programming Package

Let's start looking at the IPL scheduling as a linear programming problem where we want to minimize the travel subject to certain constraints.

PuLP expects you to define the problem in three simple steps:

  1. Define your variables
  2. Write constraints that must be followed (Typically inequality constraints)
  3. Write objective (The cost function you would like to minimize or maximize)

That’s it(it actually isn’t :P).. you are ready to get your solution.

Problem definition:

We have 8 teams, 8 destinations (home location of each team) and in the league, each team will play with every other 2 times

Total league matches will be : (7 + 6 + …+ 1)*2 = 56 . This can also be computed as triangular number of 7.

dests = [‘Mumbai’, ‘Hyderabad’, ‘Chennai’, ‘Delhi’,
‘Kolkata’, ‘Chandigadh’, ‘Jaipur’, ‘Bangaluru’]

teams = [‘MI’, ‘SRH’, ‘CSK’, ‘DC’, ‘KKR’, ‘PK’, ‘RR’, ‘RCB’]

matches = list(range(56))

Possibility of the match number match_num, happening at a particular place p, between teams t1 and t2 can be expressed as a binary variable 1 or 0.

match_var[match_num][p][t1][t2] = 0 or 1

PuLP provides an elegant way of creating LP variables using built-in Python data types like lists, dictionaries.

Similarly, the cost of conducting a match can be defined for a team for a destination.

LP problem can be created as maximization or minimization. It really does not matter which one you choose as maximizing X can also be thought of as minimizing -X. So you can think about it while designing your objective function.

Problem formulation:

This is a critical step. Everything about the schedule should be explicitly expressed as an LP constraint. Something as simple as saying a team can not play a match with itself, NEEDS to be specified.

Here is the list of constraints I have considered:

LP constraints
Constraints in LP code

Reducing travel should be expressed as some numeric cost function where more travel means more cost. There are many ways to do that.

Let’s say we start with the problem where every team would want to have home matches as much as possible. So the cost of not having a home match will be high.

Since my teams are ordered in their corresponding home destinations already, I can express the cost matrix as below:

We can opt for different cost matrices. That provides much-needed flexibility in the scheduling. If you want to avoid a destination, you can increase the cost of it.
Let's say for MI, you want to prefer Hyderabad along with its home location, Mumbai, the cost matrix can be defined as:

Once we have cost, we can add that along with the variable which decides the match possibility to create our objective function.

Results

Let’s see how the schedule turns out eventually. We need to look for all the match variables where the value has been assigned as 1

Final Schedule Results

Every match has at least one home team playing, as the optimization tried to grab the least travel path.

However, since we do not have the constraint of a mandatory one home and one away match between every team pair, there is a variation in the number of home matches played by each team. In the below image you can see Mumbai played only 5 home matches where SRH got 7.

Team-wise schedule

Did you find this LP problem formulation useful? There is less stuff on PuLP and linear programming in general on the internet. Feel free to connect with me if you want to explore this further.

--

--