I am currently learning Julia in college and i would need your expert help to better define a linear constraint in the frame of an assignment.
Our professor is passionate about MLB and our assignment is about optimizing a fantasy baseball game.
Fantasy is about picking players during certain games. Based on their real life performances, these players score point.
The constraints come from the game format : 8 hitters total and a salary cap not to exceed.
I have modeled all the basic constraints using JuMP & GLPK.
m = Model(with_optimizer(GLPK.Optimizer)) # Variable for hitters @variable(m, hitters_lineup[i=1:num_hitters], Bin) # Variable for pitchers in lineup. @variable(m, pitchers_lineup[i=1:num_pitchers], Bin) # 8 hitters total @constraint(m, sum(hitters_lineup[i] for i=1:num_hitters) == 8) # Two pitchers constraint @constraint(m, sum(pitchers_lineup[i] for i=1:num_pitchers) == 2)
@constraint(m, sum(hitters[i,:Salary]*hitters_lineup[i] for i=1:num_hitters) + sum(pitchers[j,:Salary]*pitchers_lineup[j] for j=1:num_pitchers) <= 50000)
After consulting the available benchmarks & state of the art on the subject, a common fantasy practice seems to be “stacking”. Due to the rules of baseball, the total point variace gets higher by stacking consecutive hitters from the same team.
I have input data concerning each player, their team and their batting order.
Name Salary Team Position Opponent Projection Order
David Peralta 4500 ARI OF MIL 9.12 1
Eduardo Escobar 5400 ARI 2B/3B MIL 9.23 2
Jake Lamb 3800 ARI 1B/3B MIL 8.03 3
Yasmani Grandal 4300 MIL C ARI 8.6 6
Mike Moustakas 4800 MIL 2B/3B ARI 8.8 5
Christian Yelich 5900 MIL OF ARI 10.92 3
Ketel Marte 5600 ARI 2B/OF MIL 8.27 4
Jarrod Dyson 4800 ARI OF MIL 7.96 7
Luis Arraez 4100 MIN 2B/3B DET 6.94 3
Jake Cave 3200 MIN OF DET 6.1 8
Ehire Adrianza 3700 MIN 3B/SS DET 6.6 3
Jason Castro 3600 MIN C DET 6.01 3
Jordy Mercer 2900 DET SS MIN 5.94 3
Eric Thames 4600 MIL 1B ARI 7.79 4
Using this data, i am unsuccessful at defining a linear constraint forcing the model to pick 5 consecutive hitters from the same lineup ( there are 8 batters total, so the algorithm would need to pick a combination like (5 6 7 8 1 2) based on the batting order input).
Would you be able to help me with that and point me in a more productive direction ?
Thank you a lot for your help and let me know you need more details!