Closed keithotis closed 3 years ago
I tested this again today and it seems to be an issue in the locking of players. I am able to run the "lateswap" just fine before any contests start but as soon as contests start I get
raise SolverInfeasibleSolutionException(invalid_constraints)
pydfs_lineup_optimizer.solvers.exceptions.SolverInfeasibleSolutionException: ['_C80', '_C105']
or other constraint errors.
Both your csv samples works for me, I had errors that you incorrectly name header columns (P.1, OF.1, OF.2) but maybe it's copy/paste error. I tried to replace datetime.now() with different datetimes and run reoptimize and it worked correctly. It throws me error only when I tried to reoptimize whole DKEntries.csv file after the start of all games, it happened because you have duplicated lineups and optimizer has a rule that all lineups should be unique. Delayed game status confused me, I don't process it somehow but all games with this status have "not started" status for the optimizer.
I need more details how you got this error. When did you run the optimizer? How many games were not started? What version of library are you using? I tested it on the latest version.
So fixing the column names fixed the issue though those aren't the errors I get. (I get no errors when I run the code through lineups = optimizer.load_lineups_from_csv('./test_breaks_DKEntries.csv')
I only get the following once I run the optimization loop:
Traceback (most recent call last):
File "C:\Users\Keith\Anaconda3\envs\dfs\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 455, in optimize_lineups
solved_variables = solver.solve()
File "C:\Users\Keith\Anaconda3\envs\dfs\lib\site-packages\pydfs_lineup_optimizer\solvers\pulp_solver.py", line 57, in solve
raise SolverInfeasibleSolutionException(invalid_constraints)
SolverInfeasibleSolutionException: ['_C11']
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<ipython-input-8-7fee182daabf>", line 1, in <module>
for lineup in optimizer.optimize_lineups(lineups):
File "C:\Users\Keith\Anaconda3\envs\dfs\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 473, in optimize_lineups
raise GenerateLineupException(solver_exception.get_user_defined_constraints())
GenerateLineupException: Can't generate lineups.
If it was a file format error I was expecting something similar to what I get when I don't fake the "Instructions" column the parser is expecting.
This is all in 3.5.0
It's not a file format error it's error from the solver that I'm using under the hood for calculating best lineups. It throws an error that it can not solve this problem because of _C11 constraint, these constraints with the auto-generated name used only for single player constraint such as lock player or unlock, for rule constraints I provide a readable name.
I think it's problem that you are trying to optimize lineup with all locked players in duplicated lineup, you can try to remove unique lineups rule and tell me what do you get:
from pydfs_lineup_optimizer.rules import UniqueLineupRule
optimizer.remove_rule(UniqueLineupRule)
Here's the exact code that generates an error:
#%%
from pydfs_lineup_optimizer import get_optimizer, Site, Sport, CSVLineupExporter, AfterEachExposureStrategy, PositionsStack, TeamStack
#%%
optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASEBALL)
optimizer.load_players_from_csv('./DKEntries.csv')
lineups = optimizer.load_lineups_from_csv('./test_breaks_DKEntries.csv')
#code executes fine to this point
#%%
for lineup in optimizer.optimize_lineups(lineups):
print(lineup)
Gives this error after executing the last cell
runcell(1, 'D:/Analytics/optimizations/downloads/MLB/20210508_1305/test_MLB_basic_lateswap.py')
runcell(2, 'D:/Analytics/optimizations/downloads/MLB/20210508_1305/test_MLB_basic_lateswap.py')
runcell(3, 'D:/Analytics/optimizations/downloads/MLB/20210508_1305/test_MLB_basic_lateswap.py')
Traceback (most recent call last):
File "C:\Users\Keith\Anaconda3\envs\dfs\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 455, in optimize_lineups
solved_variables = solver.solve()
File "C:\Users\Keith\Anaconda3\envs\dfs\lib\site-packages\pydfs_lineup_optimizer\solvers\pulp_solver.py", line 57, in solve
raise SolverInfeasibleSolutionException(invalid_constraints)
SolverInfeasibleSolutionException: ['_C11', '_C350']
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Analytics\optimizations\downloads\MLB\20210508_1305\test_MLB_basic_lateswap.py", line 17, in <module>
for lineup in optimizer.optimize_lineups(lineups):
File "C:\Users\Keith\Anaconda3\envs\dfs\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 473, in optimize_lineups
raise GenerateLineupException(solver_exception.get_user_defined_constraints())
GenerateLineupException: Can't generate lineups.
If I edit the columns in './test_breaks_DKEntries.csv' to be the "expected ones" as below, everything runs. So I think there's an issue with how it locks players based on column name perhaps?
Entry ID,Contest Name,Contest ID,Entry Fee,P,P,C,1B,2B,3B,SS,OF,OF,OF,Blank,Instructions
2671000454,MLB $2K Quarter Jukebox [Just $0.25!] (Early),107744239,$0.25,Tyler Glasnow (17469706),Joe Musgrove (17469708),Yadier Molina (17469909),Colin Moran (17469744),Wilmer Difo (17469867),Phillip Evans (17469794),Erik Gonzalez (17469829),Trent Grisham (17469745),Juan Soto (17469739) (LOCKED),Ka'ai Tom (17469875),,
Pointing to that lineup file works perfectly:
runcell(1, 'D:/Analytics/optimizations/downloads/MLB/20210508_1305/test_MLB_basic_lateswap.py')
runcell(2, 'D:/Analytics/optimizations/downloads/MLB/20210508_1305/test_MLB_basic_lateswap.py')
runcell(3, 'D:/Analytics/optimizations/downloads/MLB/20210508_1305/test_MLB_basic_lateswap.py')
1. P Tyler Glasnow SP TB TB@OAK 28.49 10000.0$
2. P Joe Musgrove SP SD SD@SF 17.08 9100.0$
3. C Yadier Molina C STL COL@STL 9.05 4100.0$
4. 1B Colin Moran 1B PIT PIT@CHC 7.23 4500.0$
5. 2B Wilmer Difo 2B/OF PIT PIT@CHC 2.68 2400.0$
6. 3B Phillip Evans 3B/OF PIT PIT@CHC 6.18 3500.0$
7. SS Erik Gonzalez 3B/SS PIT PIT@CHC 4.76 2800.0$
8. OF Trent Grisham OF SD SD@SF 9.46 4500.0$
9. OF Ka'ai Tom OF PIT PIT@CHC 2.12 2300.0$
10. OF Giancarlo Stanton OF NYY 9.68 5200.0$
Fantasy Points 96.73
Salary 48400.00
Yes, it locks players on specific position that is a column name. If csv file with lineups has incorrect column names players under this column will be incorrectly locked. I'll add checks for column names so this problem can be caught before running solver.
Perfect!
I'm having trouble with some valid rosters crashing the lateswap process. It's not just the example roster below that breaks but it should be reproducable. Here's a toy example:
Contents of test_works
Contents of test_breaks
Full DKEntries for load_players