pydfs-lineup-optimizer icon indicating copy to clipboard operation
pydfs-lineup-optimizer copied to clipboard

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

Open resumeman opened this issue 3 years ago • 8 comments

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.

resumeman avatar Jun 06 '21 01:06 resumeman

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.

iperks avatar Jun 07 '21 08:06 iperks

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

DimaKudosh avatar Jul 12 '21 15:07 DimaKudosh

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.

twhelan22 avatar Sep 11 '21 13:09 twhelan22

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

dexter1964 avatar Jan 24 '23 17:01 dexter1964

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: @.***>

Denwen12 avatar Jan 24 '23 17:01 Denwen12

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.

dexter1964 avatar Jan 24 '23 17:01 dexter1964

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: @.***>

Denwen12 avatar Jan 24 '23 23:01 Denwen12

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.

dexter1964 avatar Jan 25 '23 02:01 dexter1964