Skip to content
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

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

Open
resumeman opened this issue Jun 6, 2021 · 8 comments

Comments

@resumeman
Copy link

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
Copy link

iperks commented Jun 7, 2021

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
Copy link
Owner

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

@twhelan22
Copy link

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
Copy link

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

@Denwen12
Copy link

Denwen12 commented Jan 24, 2023 via email

@dexter1964
Copy link

dexter1964 commented Jan 24, 2023

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
Copy link

Denwen12 commented Jan 24, 2023 via email

@dexter1964
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants