Optimize your Fantasy Football team! (the crazy way)
My friends invited me to join Fantasy Premier League. In this game you can create a team and join a league with a group of friends or an online community. Sounds cool!
First I need to select the players to be in my team. Using the £100m budget, I need to pick 15 players out of hundreds of players available. The team consists of 2 goalkeepers, 5 defenders, 5 midfielders, 3 forwards. Sounds like a mathematical optimization to me!

Modeling
How should we model the problem to be solved? An example of optimization problem is something like this: Let say a farmer in Lampung has 2500 meter square of land. He can plant coffee or pepper or combination of both. He has 3000kg of fertilizer. Each square meter of coffee needs 2kg of fertilizer, each square meter of pepper needs 3kg of fertilizer. The selling price from each square meter of coffee is $21, each square meter of pepper is $32. We can model it as this.
maximize: 21c + 32p
c + p ≤ 2500
2c + 3p ≤ 3000
What about the fantasy football? What are the variables? Each player has total scores to reflect its performance. I want to maximize the total scores of the players that I pick. So the variables are all the available players, all of them. Each player is a variable with a possible value: being chosen or not being chosen. It seems that we have a much tougher problem. It has so many variables, hundreds of available players. Unlike the square meter of coffee, the player cannot be a decimal between 1 and 0, it’s either 1(chosen) or 0(not chosen).
Some of the constrains: The player has to be 0 or 1, total players with position as a goalkeeper are 2, total defenders: 5, total midfielders: 5, total forwarder: 3.
maximize:
total_score_player1 × total_score_player1 + total_score_player2 × player2 + total_score_player3 × player3 + … + total_score_playerN × playerNconstraints:
player1, player2, player3, …, playerN are either 0 or 1cost_player1 × player1 + cost_player2 × player2 + cost_player3 × player3 + … + cost_playerN × playerN ≤ 100is_gkp_player1 × player1 + is_gkp_player2 × player2 + is_gkp_player3 × player3 + … + is_gkp_playerN × playerN = 2is_def_player1 × player1 + is_def_player2 × player2 + is_def_player3 × player3 + … + is_def_playerN × playerN = 5is_mid_player1 × player1 + is_mid_player2 × player2 + is_mid_player3 × player3 + … + is_mid_playerN × playerN = 5is_fwd_player1 × player1 + is_fwd_player2 × player2 + is_fwd_player3 × player3 + … + is_fwd_playerN × playerN = 3
To create a winning squad, I don’t want to spend all of the budget to 15 players equally. I want to spend more money to 11 main players and less to the 4 subtitutes. Even further, I want to spend more to some key players within those 11 players. Intuition come into play (wild guess actually), I ended up with these budgeting.
Maximize 5 key players with total £41m
maximize: total_score_player1 × total_score_player1 + total_score_player2 × player2 + total_score_player3 × player3 + ... + total_score_playerN × playerNconstraints:
player1, player2, player3, ..., playerN are either 0 or 1cost_player1 × player1 + cost_player2 × player2 + cost_player3 × player3 + ... + cost_playerN × playerN <= 41is_gkp_player1 × player1 + is_gkp_player2 × player2 + is_gkp_player3 × player3 + ... + is_gkp_playerN × playerN = 1is_def_player1 × player1 + is_def_player2 × player2 + is_def_player3 × player3 + ... + is_def_playerN × playerN = 1is_mid_player1 × player1 + is_mid_player2 × player2 + is_mid_player3 × player3 + ... + is_mid_playerN × playerN = 1is_fwd_player1 × player1 + is_fwd_player2 × player2 + is_fwd_player3 × player3 + ... + is_fwd_playerN × playerN = 2
Maximize 6 players with total £39.5m
maximize: total_score_player1 × total_score_player1 + total_score_player2 × player2 + total_score_player3 × player3 + ... + total_score_playerN × playerNconstraints:
player1, player2, player3, ..., playerN are either 0 or 1cost_player1 × player1 + cost_player2 × player2 + cost_player3 × player3 + ... + cost_playerN × playerN <= 39.5is_gkp_player1 × player1 + is_gkp_player2 × player2 + is_gkp_player3 × player3 + ... + is_gkp_playerN × playerN = 0is_def_player1 × player1 + is_def_player2 × player2 + is_def_player3 × player3 + ... + is_def_playerN × playerN = 3is_mid_player1 × player1 + is_mid_player2 × player2 + is_mid_player3 × player3 + ... + is_mid_playerN × playerN = 3is_fwd_player1 × player1 + is_fwd_player2 × player2 + is_fwd_player3 × player3 + ... + is_fwd_playerN × playerN = 0
Maximize 4 subtitutes with total £19.5m
maximize: total_score_player1 × total_score_player1 + total_score_player2 × player2 + total_score_player3 × player3 + ... + total_score_playerN × playerNconstraints:
player1, player2, player3, ..., playerN are either 0 or 1cost_player1 × player1 + cost_player2 × player2 + cost_player3 × player3 + ... + cost_playerN × playerN <= 19.5is_gkp_player1 × player1 + is_gkp_player2 × player2 + is_gkp_player3 × player3 + ... + is_gkp_playerN × playerN = 1is_def_player1 × player1 + is_def_player2 × player2 + is_def_player3 × player3 + ... + is_def_playerN × playerN = 1is_mid_player1 × player1 + is_mid_player2 × player2 + is_mid_player3 × player3 + ... + is_mid_playerN × playerN = 1is_fwd_player1 × player1 + is_fwd_player2 × player2 + is_fwd_player3 × player3 + ... + is_fwd_playerN × playerN = 1
Who’d do the calculation?
Now that we human have done the beautiful peaceful part, let computer do the wild job.
If you are interested to know how I nicely ask my computer, you can check the ipython notebook.
The Squad
Computer, please show me the awesome team I am waiting for! Thank you.

Disclaimer: It is just a fun way of learning math/linear programming by solving an every day problem. Please make sure you have fun playing fantasy football :) !