Created
August 9, 2018 02:49
-
-
Save kangeugine/3845b098760ad96c18a735fccda6e146 to your computer and use it in GitHub Desktop.
Revisions
-
kangeugine created this gist
Aug 9, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ from pulp import * player = [str(i) for i in range(data.shape[0])] point = {str(i): data['Points'][i] for i in range(data.shape[0])} cost = {str(i): data['Cost'][i] for i in range(data.shape[0])} gk = {str(i): 1 if data['Position'][i] == 'GK' else 0 for i in range(data.shape[0])} defe = {str(i): 1 if data['Position'][i] == 'DEF' else 0 for i in range(data.shape[0])} mid = {str(i): 1 if data['Position'][i] == 'MID' else 0 for i in range(data.shape[0])} stri = {str(i): 1 if data['Position'][i] == 'STR' else 0 for i in range(data.shape[0])} xi = {str(i): 1 for i in range(data.shape[0])} prob = LpProblem("Fantasy Football",LpMaximize) player_vars = LpVariable.dicts("Players",player,0,1,LpBinary) # objective function prob += lpSum([point[i]*player_vars[i] for i in player]), "Total Cost" # constraint prob += lpSum([player_vars[i] for i in player]) == 11, "Total 11 Players" prob += lpSum([cost[i] * player_vars[i] for i in player]) <= 100.0, "Total Cost" prob += lpSum([gk[i] * player_vars[i] for i in player]) == 1, "Only 1 GK" prob += lpSum([defe[i] * player_vars[i] for i in player]) <= 5, "Less than 5 DEF" prob += lpSum([mid[i] * player_vars[i] for i in player]) <= 5, "Less than 5 MID" prob += lpSum([stri[i] * player_vars[i] for i in player]) <= 3, "Less than 3 STR" # solve status = prob.solve()