Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
zlisto committed Mar 2, 2017
1 parent c8caf7e commit b3d5003
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
19 changes: 12 additions & 7 deletions baseball_formulations.jl
Expand Up @@ -17,7 +17,7 @@ Pkg.add("GLPKMathProgInterface")
using GLPKMathProgInterface

#uncomment this line only if you installed Gurobi, which costs money :(), but is super fast :)
#using Gurobi
using Gurobi



Expand All @@ -29,6 +29,14 @@ using GLPKMathProgInterface
# Batters with consecutive batting order
#only keep 4th order and earlier batters, cuz they make more points
function baseball_formulation(players, old_lineups, num_overlap,stack_size, P,B1,B2,B3,C,SS,OF, players_teams, players_opp, players_games,players_stacks)


#################################################################################################
#define the model formulation which will be solved using GLPK
m = Model(solver=GLPKSolverMIP())

#uncomment this line only if you are using Gurobi, which costs money :(), but is super fast :)
m = Model(solver=GurobiSolver(OutputFlag=0))

#number of players playing today
num_players = size(players)[1]
Expand All @@ -44,12 +52,7 @@ function baseball_formulation(players, old_lineups, num_overlap,stack_size, P,B1
#number of stacks per team (this is 9)
num_stacks = 9;

#################################################################################################
#define the model formulation which will be solved using GLPK
m = Model(solver=GLPKSolverMIP())

#uncomment this line only if you are using Gurobi, which costs money :(), but is super fast :)
m = Model(solver=GurobiSolver(OutputFlag=0))


# Variable for players in lineup.
Expand Down Expand Up @@ -92,7 +95,7 @@ function baseball_formulation(players, old_lineups, num_overlap,stack_size, P,B1
@addConstraint(m, sum{used_game[i], i=1:num_games} >= 2)


#at most 5 hitters from one team constraint
#HITTERES at most 5 hitters from one team constraint
@addConstraint(m, constr[i=1:num_teams], sum{players_teams[t, i]*(1-P[t])*players_lineup[t], t=1:num_players}<=5)


Expand All @@ -109,9 +112,11 @@ function baseball_formulation(players, old_lineups, num_overlap,stack_size, P,B1
#STACK: at least stack_size hitters from at least 1 team, consecutive hitting order
#define a variable for each stack on each team. This variable =1 if the stack on the team is used
@defVar(m, used_stack_batters[i=1:num_teams,j=1:num_stacks], Bin)

#constraint for each stack, used or not
@addConstraint(m, constraint_stack[i=1:num_teams,j=1:num_stacks], stack_size*used_stack_batters[i,j] <=
sum{players_teams[t, i]*players_stacks[t, j]*(1-P[t])*players_lineup[t], t=1:num_players})

#make sure at least one stack is used
@addConstraint(m, sum{used_stack_batters[i,j], i=1:num_teams,j=1:num_stacks} >= 1)

Expand Down
16 changes: 2 additions & 14 deletions data_cleaning.jl
Expand Up @@ -471,7 +471,7 @@ function lineup_points_proj(path_lineups,path_hitters,path_pitchers,path_output)
name = lineups[i,j]
for k = 1:num_players
if string(players[k,1])==string(name)
lineup_pts = lineup_pts+players[i,:Proj_FP]
lineup_pts = lineup_pts+players[k,:Proj_FP]
end
end
GrowingLineupMatrix = string(GrowingLineupMatrix,name,",")
Expand Down Expand Up @@ -501,7 +501,7 @@ function lineup_points_actual(path_lineups,path_hitters,path_pitchers,path_outpu
for k = 1:num_players
if string(players[k,1])==string(name)
lineup_pts_proj = lineup_pts_proj + players[i,:Proj_FP]
lineup_pts_actual = lineup_pts_actual + players[i,:Actual_FP]
lineup_pts_actual = lineup_pts_actual + players[k,:Actual_FP]

end
end
Expand All @@ -515,15 +515,3 @@ function lineup_points_actual(path_lineups,path_hitters,path_pitchers,path_outpu

end

###########################################################################################
#folder = "2016-08-12\\" #folder where the player projections are
#path_pitchers = string(folder,"dailyfantasynerd_pitchers.csv");
#path_hitters = string(folder,"dailyfantasynerd_hitters.csv");
#path_lineups = string(folder,"baseball_baseball_formulation_stacksize_5_overlap_6_lineups_4.csv");
#path_output = string(folder,"proj_baseball_baseball_formulation_stacksize_5_overlap_6_lineups_4.csv");


#P = read_player_data(path_hitters,path_pitchers);
#L = readtable(path_lineups)

#lineup_points_proj(path_lineups,path_hitters,path_pitchers,path_output)
20 changes: 9 additions & 11 deletions optimize_multiple_lineups_baseball.jl
Expand Up @@ -9,10 +9,8 @@ include("baseball_formulations.jl") #this code has all the different formualati
################################################################################################################

#INPUT PARAMS
folder = "" #folder where the player projections are - this folder is named by the date of the contest

# num_lineups is the total number of lineups
num_lineups = 4;
num_lineups = 3;

# num_overlap is the maximum overlap of players between the lineups
num_overlap = 6

This comment has been minimized.

Copy link
@Dice221026

Dice221026 Mar 29, 2018

10

Expand All @@ -24,17 +22,17 @@ stack_size = 5;
formulation = baseball_formulation

#path to the csv file with the players information (pitchers and hitters);
path_pitchers = string(folder,"2016-08-12 dailyfantasynerd_pitchers.csv")
path_hitters = string(folder,"2016-08-12 dailyfantasynerd_hitters.csv");
path_pitchers = "2016-08-12 pitchers.csv"
path_hitters = "2016-08-12 hitters.csv";

# path_to_output is a string that gives the path to the csv file that will give the outputted results
path_to_output= string(folder,"baseball_", string(formulation), "_stacksize_", stack_size,"_overlap_", num_overlap,"_lineups_", num_lineups,".csv");
path_to_output= string(string(formulation), "_stacksize_", stack_size,"_overlap_", num_overlap,"_lineups_", num_lineups,".csv");

# path_to_output_proj is a string that gives the path to the csv file that will give the outputted results with projected lineup points
path_to_output_proj = string(folder,"proj_baseball_", string(formulation), "_stacksize_", stack_size,"_overlap_", num_overlap,"_lineups_", num_lineups,".csv");
path_to_output_proj = string("proj_baseball_", string(formulation), "_stacksize_", stack_size,"_overlap_", num_overlap,"_lineups_", num_lineups,".csv");

# path_to_output_actual is a string that gives the path to the csv file that will give the outputted results with projected and actual lineup points
path_to_output_actual = string(folder,"actual_baseball_", string(formulation), "_stacksize_", stack_size,"_overlap_", num_overlap,"_lineups_", num_lineups,".csv");
path_to_output_actual = string("actual_baseball_", string(formulation), "_stacksize_", stack_size,"_overlap_", num_overlap,"_lineups_", num_lineups,".csv");


#########################################################################
Expand All @@ -46,14 +44,14 @@ tic()
create_lineups(num_lineups, num_overlap, stack_size,formulation, path_pitchers,path_hitters, path_to_output);
telapsed = toq();

println("Calculated DraftKings baseball lineups.\n", num_lineups, " lineups\n","Stack type ",formulation,
"\nOverlap = ", num_overlap[1],"\n" )
println("\nCalculated DraftKings baseball lineups.\n\tNumber of lineups = ", num_lineups, " \n\tStack size = ",stack_size,
"\n\tOverlap = ", num_overlap,"\n" )

println("Took ", telapsed/60.0, " minutes to calculate ", num_lineups, " lineups")

println("Saving data to file ",path_to_output,"\nDK Mafia 4 life")

#save the projected and actual points for the lineups
lineup_points_proj(path_to_output,path_hitters,path_pitchers,path_to_output_proj);
#lineup_points_proj(path_to_output,path_hitters,path_pitchers,path_to_output_proj);
lineup_points_actual(path_to_output,path_hitters,path_pitchers,path_to_output_actual);

0 comments on commit b3d5003

Please sign in to comment.