DimaKudosh / pydfs-lineup-optimizer

Daily Fantasy Sports lineup optimzer for all popular daily fantasy sports sites
MIT License
409 stars 156 forks source link

GenerateLineupException: Can't generate lineups. Following constraints are not valid #274

Open resumeman opened 3 years ago

resumeman commented 3 years ago

This used to work. Now I run it (new version, 3.5) and only get the result:

This is the simplified command I ran: for lineup in optimizer.optimize(n=10): print(lineup)

Error text Traceback (most recent call last):

File "/xxx/lib/python3.9/site-packages/pydfs_lineup_optimizer/lineup_optimizer.py", line 394, in optimize solved_variables = solver.solve()

File "/xxx/lib/python3.9/site-packages/pydfs_lineup_optimizer/solvers/pulp_solver.py", line 57, in solve raise SolverInfeasibleSolutionException(invalid_constraints)

SolverInfeasibleSolutionException: ['positions_P', 'positions_C', 'positions_1B', 'positions_2B', 'positions_3B', 'positions_SS', 'positions_OF', 'total_players']

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "", line 1, in for lineup in optimizer.optimize(n=10):

File "/xxx/lib/python3.9/site-packages/pydfs_lineup_optimizer/lineup_optimizer.py", line 411, in optimize raise GenerateLineupException(solver_exception.get_user_defined_constraints())

GenerateLineupException: Can't generate lineups. Following constraints are not valid: positions_P,positions_C,positions_1B,positions_2B,positions_3B,positions_SS,positions_OF,total_players * End

When I try reverting to v 3.3, the only result I get is: "GenerateLineupException: Can't generate lineups."

Any idea what's happening here? Like I said it worked in previous years.

iperks commented 3 years ago

If you compare the versions you'll see that the SolverInfeasibleSolutionException was added I'm assuming to provide more context to the errors, rather than just a generic one you now get more information on which to take the appropriate action.

DimaKudosh commented 3 years ago

Can you provide more information? What sport did you run? Did you have players for all positions?

twhelan22 commented 2 years ago

I had the same issue for DraftKings and Fanduel NFL. I was trying to import players from a dataframe using a Player object rather than the load_players_from_csv function, using a similar function to row_to_player in issue #281. When using load_players_from_csv the optimiser works, but not when generating a custom Player object and calling optimizer.load_players. I didn't manage to solve this yet, however a workaround in the meantime is to revert to version 3.3 and ensure you have pulp==2.2 to avoid the "GenerateLineupException: Can't generate lineups." error.

dexter1964 commented 1 year ago

Has anyone found a better solution for this, instead of reverting back to version 3.3 and pulp==2.2? thanks

Denwen12 commented 1 year ago

Can you provide the ful code your using to load from dataframe

On Tue, Jan 24, 2023, 12:10 PM dexter1964 @.***> wrote:

Has anyone found a better solution for this, instead of reverting back to version 3.3 and pulp==2.2? thanks

— Reply to this email directly, view it on GitHub https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/274#issuecomment-1402292973, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANBWO7RPTAUB2L4YX645QDTWUAEHJANCNFSM46FIHVAQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

dexter1964 commented 1 year ago

I've actually opened an issue #402, but here's my code. My code is fairly generic:

Data returned from DB Query consists of: (Team, PlayerName, Position, Salary, FantasyPoints) [('SFO', 'Brock Purdy', 'QB', 6900.0, 15.43), ('SFO', 'Christian McCaffrey', 'RB', 9000.0, 18.03), ('SFO', 'Elijah Mitchell', 'RB', 5600.0, 6.56),etc...] optimizer = get_optimizer(Site.FANDUEL, Sport.FOOTBALL) allPlayerInfo=mF.getNFLPlayerInfo('FanDuel') ## Query database and return Player Data.

FDplayers = [] for i, player_info in enumerate(allPlayerInfo): name = player_info[1].split(' ') FDplayers.append(Player( int(i), name[0], #First Name name[1], #Last name player_info[2].split('-'), # Split Positions: for Fanduel use '-' for Draftkings use '/' player_info[0], # This should be TeamShort name. float(player_info[3]), #This should be Fantasy Salary float(player_info[4]) #This should be Fantasy Points )) optimizer.player_pool.load_players(FDplayers) lineup_generator = optimizer.optimize(3)

and the errors that I'm getting... pydfs_lineup_optimizer.solvers.exceptions.SolverInfeasibleSolutionException: ['positions_D']

pydfs_lineup_optimizer.exceptions.GenerateLineupException: Can't generate lineups. Following constraints are not valid: positions_D

Thank you so much for taking a look.

Denwen12 commented 1 year ago

Doesn't fanduel use / for position ? RB/FLEX

On Tue, Jan 24, 2023, 12:54 PM dexter1964 @.***> wrote:

I've actually opened an issue #402 https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/402, but here's my code. My code is fairly generic:

Data returned from DB Query consists of: (Team, PlayerName, Position, Salary, FantasyPoints) [('SFO', 'Brock Purdy', 'QB', 6900.0, 15.43), ('SFO', 'Christian McCaffrey', 'RB', 9000.0, 18.03), ('SFO', 'Elijah Mitchell', 'RB', 5600.0, 6.56),etc...] optimizer = get_optimizer(Site.FANDUEL, Sport.FOOTBALL) allPlayerInfo=mF.getNFLPlayerInfo('FanDuel') ## Query database and return Player Data.

FDplayers = [] for i, player_info in enumerate(allPlayerInfo): name = player_info[1].split(' ') FDplayers.append(Player( int(i), name[0], #First Name name[1], #Last name player_info[2].split('-'), # Split Positions: for Fanduel use '-' for Draftkings use '/' player_info[0], # This should be TeamShort name. float(player_info[3]), #This should be Fantasy Salary float(player_info[4]) #This should be Fantasy Points )) optimizer.player_pool.load_players(FDplayers) lineup_generator = optimizer.optimize(3)

and the errors that I'm getting... pydfs_lineup_optimizer.solvers.exceptions.SolverInfeasibleSolutionException: ['positions_D', 'budget', 'total_players', '_C1']

pydfs_lineup_optimizer.exceptions.GenerateLineupException: Can't generate lineups. Following constraints are not valid: positions_D,budget,total_players

Thank you so much for taking a look.

— Reply to this email directly, view it on GitHub https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/274#issuecomment-1402354905, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANBWO7RB4VK53CQHUEODEDDWUAJOTANCNFSM46FIHVAQ . You are receiving this because you commented.Message ID: @.***>

dexter1964 commented 1 year ago

I think I figured it out, but haven't had a chance to test yet. The data that I scraped, didn't have any Team Defense Data in it, I think that's why that Position_D" constraint was popping up. I may have found a site with all the data pydfs needs. I'm going to try to scrape tomorrow, and retry Optimizing. as for the "-" vs. "/" delimiter, I'll give both a try, once I get the new data.