-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating 4-3 Stacks in MLB with Fanduel #257
Comments
I'm having the same issues as you. I have seen that setting multiple max or min exposure to over 5-6 players that compete for the same position usually gives a Unable To Solve error. I run into this setting lineups and doing the same wheel of exposures over defense often where I really don't have a favorite. I tried TotalExposureStrategy, AfterExposureStrategy. I went through the code line by line trying to see where setting too many min or max might toss the error. I just can't figure it out. Just seems to be no way to do more or five min or max for any single player. I find min.exposure to be more picky than max where I often can get only 3-4 and never try to total them up to 100% as you did above. I get the best luck when I have 20% or so leftover. As far as the stacks, I also had the exact error today on FanDuel stacking. Seems like anything that effects 7 players is a fail. It's solvable and I can come up with my own lineups that meet all requirements, but getting the error as you. Such as huge part of baseball so I haven't given up searching for a fix. Hoping its all related to some constraint that we can modify. I'll continue to update if I find anything, but if anyone else out there can pinpoint what causes this to fail, it would be greatly appreciated! |
Hey, @lightninglarry! We just got an update that fixed a position bug with FanDuel. Since that update my 4-3 stacks and any other stacks I attempt work fine. I am certain that position bug is what affected the stack bug for FanDuel baseball. I think you should update PYDFS and try again and I bet you you'll see it work. |
will try today my man. Thanks @bigboyz |
I also can confirm that the update fixed these errors. |
Thanks guys. Still having issues setting exposure to more than 1 Pitcher on a slate, what are your thoughts on this? |
Personally, what I do is use the min and max exposure ability on the CSV file. Then just put .30 Cole or whatever. Sounds like the error is FanDuel and you locked a pitcher, but than tried to add another even though 1 is limit. |
@bigboyz how do i message you on here. Id like to learn more if you got time? |
LineupOptimizerException: Unable to build lineup. was working for a tad. |
@lightninglarry Hi ,so I partially retract my statement regarding the original issue. It is fixed with the update, but it looks like when you create no Pitcher vs Batters |
Can also confirm the issue seemed to be fixed for a day or two. Then I think a second update was made and the issue seems to be back. I have a very large pool of players and right now only 23 lineups are being generated before it throws the "unable to build lineup" error. |
still issue comes up. I was able to create 7 lineups before unable to build lineup occurred. |
How do you run optimizer? What stacks do you use? I tried to generate 150 lineups with 4-3 team stacks for today's contest and it didn't throw me error |
@DimaKudosh, ive tried just to leave it empty and let projections dictate my stacks. from pydfs_lineup_optimizer import get_optimizer, Site, Sport, CSVLineupExporter optimizer = get_optimizer(Site.FANDUEL, Sport.BASEBALL) optimizer.load_players_from_csv(r"C:\Users\brand\Downloads\FanDuel-MLB-2021 ET-04 ET-19 ET-57413-players-list.csv") optimizer.restrict_positions_for_opposing_team(['P'], ['C', 'SS', 'OF', '1B', '2B', '3B']) lineups = optimizer.optimize(n=150, max_exposure=.5, exposure_strategy = AfterEachExposureStrategy) |
I noticed you are using spacing=1. I have 57413 as I played that slate today, but can you post the exact file you used? I want to compare it to mine. I noticed when I download a file early the Batting Order is omitted from many teams. If your copy did not have it for all teams it may very well be unsolvable with those constraints. |
no, on that i waited till after lock to use the file just to test it out. All lineups were in. |
@lightninglarry @bigboyz is it possible that the dual positions on FD are creating this issue? I haven't investigated it in the script yet, but I noticed I do miss some stacks that should be generated. |
So if i leave spacing out, your thinking it works @Owen-Slater ? If so thats cool, but still spacing would need to be addressed I think. |
I took the spacing code part out, only created 1 lineup before it crashed tonight using the above code |
I think ive got it working, thanks for all the help. optimizer.add_stack(TeamStack(4, for_teams=['DET', 'PHI', 'NYY', 'CHC'] spacing=1, max_exposure=0.3)) # stack 4 players from any of specified teams Also for anyone who uses Fanduel, if the team lineup hasnt been out yet, and you want them in your stack, do you put a # for batting order for player? or if u leave it blank does it still spit it out at you anyways if there is a projection? @bigboyz |
Can anyone chime in on what im doing incorrectly?
Heres the error:
SolverInfeasibleSolutionException Traceback (most recent call last)
~\anaconda3\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py in optimize(self, n, max_exposure, randomness, with_injured, exposure_strategy)
383 try:
--> 384 solved_variables = solver.solve()
385 lineup_players = []
~\anaconda3\lib\site-packages\pydfs_lineup_optimizer\solvers\pulp_solver.py in solve(self)
55 invalid_constraints = [name for name, constraint in self.prob.constraints.items() if not constraint.valid()]
---> 56 raise SolverInfeasibleSolutionException(invalid_constraints)
SolverInfeasibleSolutionException: ['_C393', '_C507', '_C511', 'min_teams', 'total_players', 'budget']
During handling of the above exception, another exception occurred:
GenerateLineupException Traceback (most recent call last)
in
32 lineups = optimizer.optimize(n=10, max_exposure=.4)
33 optimizer.set_min_salary_cap(34700)
---> 34 for lineup in lineups:
35 print(lineup)
36 optimizer.export(r"C:\Users\brand\Desktop\MLB\FD.csv")
~\anaconda3\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py in optimize(self, n, max_exposure, randomness, with_injured, exposure_strategy)
399 constraint.post_optimize(variables_names)
400 except SolverInfeasibleSolutionException as solver_exception:
--> 401 raise GenerateLineupException(solver_exception.get_user_defined_constraints())
402 self.last_context = context
403
GenerateLineupException: Can't generate lineups. Following constraints are not valid: min_teams,total_players,budget
heres the code creating it:
from pydfs_lineup_optimizer import get_optimizer, Site, Sport, CSVLineupExporter
from pydfs_lineup_optimizer.stacks import TeamStack, PositionsStack, PlayersGroup
from pydfs_lineup_optimizer import AfterEachExposureStrategy
optimizer = get_optimizer(Site.FANDUEL, Sport.BASEBALL)
optimizer.load_players_from_csv(r"C:\Users\brand\Downloads\FanDuel-MLB-2021 ET-04 ET-01 ET-56054-players-list.csv")
optimizer.restrict_positions_for_opposing_team(['P'], ['C', 'SS', 'OF', '1B', '2B', '3B'])
optimizer.add_stack(TeamStack(4, for_teams=['DET', 'PHI', 'NYY', 'CHC'])) # stack 4 players from any of specified teams
optimizer.add_stack(TeamStack(3, spacing=2)) # stack 3 players close to each other in range of 2 spots.**
devers_jd_xander = PlayersGroup([optimizer.get_player_by_name(Nickname) for Nickname in ('Rafael Devers', 'J.D. Martinez', 'Xander Boegarts')], max_exposure=0.5)
optimizer.add_players_group(devers_jd_xander)
bieber = optimizer.get_player_by_name("Shane Bieber")
optimizer.add_player_to_lineup(bieber)
bieber.max_exposure = .5
#cole = optimizer.get_player_by_name("Gerrit Cole")
#optimizer.add_player_to_lineup(cole)
#cole.max_exposure = .1
#darvish = optimizer.get_player_by_name("Yu Darvish")
#optimizer.add_player_to_lineup(darvish)
#darvish.max_exposure = .2
#giolito = optimizer.get_player_by_name("Lucas Giolito")
#optimizer.add_player_to_lineup(giolito)
#giolito.max_exposure = .1
#scherzer = optimizer.get_player_by_name("Max Scherzer")
#optimizer.add_player_to_lineup(scherzer)
#scherzer.max_exposure = .1
lineups = optimizer.optimize(n=10, max_exposure=.4)
optimizer.set_min_salary_cap(34700)
for lineup in lineups:
print(lineup)
optimizer.export(r"C:\Users\brand\Desktop\MLB\FD.csv")
import pandas as pd
df= pd.read_csv(r"C:\Users\brand\Desktop\MLB\FD.csv")
Changing my stack to a 3-3 works, or a 4-2 works, but not 4-3, which still meets the roster requirement of 4 different teams if my Pitcher is a diff player. Wanting 4 man, 3 man, 1 off, and my P type lineups.
also a secondary Q. I had to comment my pitchers out as it didnt like have all the exposures like that. Is there a way to do that?
The text was updated successfully, but these errors were encountered: