![excel solver function for fantasy football excel solver function for fantasy football](https://i0.wp.com/fantasyfootballanalytics.net/wp-content/uploads/2015/02/Evaluate-Projections2.jpg)
In terms of implementing these with pulp, I've found that it's extremely helpful to create your variables using LpVariables.dicts, so that you can iterate through your player list multiple times, and access the same variables each time: player_ids = raw_data.index If the QB is not selected, this equation does nothing because all the other players involved have positive coefficients. + 8* = 0Īgain, if the QB is selected, we must also select one of the other players in this equation to balance it out and keep the total non-negative.
![excel solver function for fantasy football excel solver function for fantasy football](https://nathanbrixius.files.wordpress.com/2014/10/image1.png)
You can also adapt this to force a DST-RB stack. a QB-WR stack) by manipulating what players appear on the left side of that equation. Note that this methodology also lets you stack a spesific position (Ex. When the QB is not selected, this equation does nothing, since the QB variable has the only negative coeofficient. This way, if the optimizer selects the QB, it will also have to select n other players on that QB's team, to satisfy the requirement that when you subtract n from the number of other players from that team, the result is non-negative. Stack at least n players with your QB: You're going to have a new constraint for each QB in your player pool.which QB variable is picked), you'll need to set up a new constraint for each possible choice, in a somewhat clever way to ensure that that constraint only does anything when that variable was chosen. This is my exact specialty! In general, if you want a constraint to depend on the choice for particular variables (e.x. Example: if picks a quarterback, it affects the rest of the 8 players being selected.Īppreciate any help anyone can provide me Ive been looking through the cases in the documentation and i cant find any examples where the optimal output is changed based off what the model picks.
#EXCEL SOLVER FUNCTION FOR FANTASY FOOTBALL HOW TO#
Any idea how I would do this? This data is in my excel file but I'm not sure how to add these constraints to the model? The constraints I am trying to add and cant figure out how: have 2 players of the 9 selected be on the same team as the QB, the opponent of the DST cant be anyone of the 9's team, have 1 players opponent be the QB's team. Total_players = pulp.LpAffineExpression(number_of_players) TE_constraint = pulp.LpAffineExpression(TEs)ĭST_constraint = pulp.LpAffineExpression(DST) WR_constraint = pulp.LpAffineExpression(WRs) RB_constraint = pulp.LpAffineExpression(RBs) QB_constraint = pulp.LpAffineExpression(QBs) Total_points = player # Create Projection DictionaryĬost = player # Create Cost Dictionary Var_name = 'x' + str(i) # Create variable nameĭecision_var = pulp.LpVariable(var_name, cat='Binary') # Initialize Variables # i = row index, player = player attributes Raw_data = (raw_data = 'DST').astype(float) Raw_data = (raw_data = 'TE').astype(float) Raw_data = (raw_data = 'QB').astype(float) Raw_data = (raw_data = 'WR').astype(float) #create new columns that has binary numbers if player = a specific position raw_data = pd.read_csv(file_name,engine="python",index_col=False, header=0, delimiter=",", quoting = 3) The constraints i have done successfully: limit a max of 9 players are selected, only 1 person of position QB, 3-4 of position WR, 1-2 of position TE, 1 position DST, and 2-3 position RB. Name Projection Position Team Salary Opponent Below is what the head of the panda dataframe looks like. The excel sheet holds, player name, player projection, team player is on, opponent player is facing, and position. I have an excel sheet of 400 players and how I project them to play, and I want to find the optimal combination of 9 players given specific constraints. I have successfully made the solver but cant figure out how to add a few constraints I need. The purpose of diving into this library was to make a fantasy football solver in python. It is currently my first time using the PuLP library in python.