1

I am trying to develop a code to select the best 11 possible players out of 200 players. I have developed a spreadsheet with the players prices and points so far and imported it to a DF using Pandas as below,

import pandas as pd
import numpy as np
df=pd.read_excel('FPL.xlsx')
print(df)
           Player  Price  Points Position  Select
0           Henderson    4.9      79       GK       1
1              Foster    4.8      79       GK       1
2                Ryan    4.8      78       GK       1
3          Schmeichel    5.4      78       GK       1
4            Ramsdale    4.7      76       GK       1
5              Guaita    5.1      76       GK       1
....
200
df['select price']=df['Price']*df['Select']
df['select points']=df['Points']*df['Select']
sumpoints=df['select points'].sum()
sumplayers=df['Select'].sum()
sumprice=df['select price'].sum()

My idea was to create a select column and multiply it by both the price column and the points columns, then the optimization problem will be as follows:

  • Objective function: maximize the sum of Select*points
  • Constraints:
    • The team is composed of only 11 players
    • The budget to buy the players is 85
    • Number of goalkeepers (GK) must be 1
    • Number of DF must be 3

This will be done by changing the variables in the select column to be 0 or 1 (i.e. 1 if the player of the corresponding row gets selected for taking part of the team, and 0 otherwise).

This is very straight forward if using the excel solver but I want to learn how to do it in Python.

dhasson
  • 248
  • 3
  • 10
  • I don't understand the constraints, can you please edit to explain more clearly what the constraints are – gold_cy Dec 30 '19 at 21:58
  • please change the formatting of the constraints to something more readable. – Christian Sloper Dec 30 '19 at 21:59
  • Sure, my constrains are that: I can only have a total of 11 players and only 1 of them can be GK (Goal Keeper), 5 of them are Midfielders and 2 of them are attackers and 3 of them are defenders (There is a column named "position" where it says if the player is a GK, a defender,..etc. Also, the budget to buy the players is $85 (there is a column with a price tag for each player) – Omar Elbagalati Dec 30 '19 at 22:03
  • Hi @OmarElbagalati, is it mandatory to use scip? (I am asking because I see scip among the tags). Otherwise, I can think of ways to use Python with OR-Tools to solve this. – dhasson Dec 30 '19 at 23:30
  • No, it is not mandatory. I want to learn how to solve with Python – Omar Elbagalati Dec 31 '19 at 02:48

0 Answers0