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

Same Game Max Exposure

Open cwolf908 opened this issue 4 years ago • 4 comments

Haven't seen anyone raise this question yet despite searching and doing a lot of reading, so please forgive me if it's already been answered...

But is there a way to limit my exposure to a single game? Regardless of which side a player is on?

For example, I've setup the following optimization:

optimizer.add_stack(PositionsStack(['QB', 'WR', ('WR', 'TE', 'RB')])) optimizer.restrict_positions_for_same_team(('QB', 'DST'),('RB', 'RB')) optimizer.force_positions_for_opposing_team(('QB','WR')) for player in optimizer.players: if 'QB' in player.positions: player.max_exposure = 0.2 if 'RB' in player.positions: player.max_exposure = 0.4 if 'WR' in player.positions: player.max_exposure = 0.4 if 'TE' in player.positions: player.max_exposure = 0.4

for lineup in optimizer.optimize(10): print(lineup)`

As you can see, my individual player exposures at a given position are specified. However, I can still end up with lineups that include 6 players from the same game and I really don't want that if possible. Example lineup:

  1. QB Kirk Cousins QB MIN SEA@MIN 17.5(16.496) 6300.0$
  2. RB Derrick Henry RB TEN IND@TEN 27.2(29.57) 8600.0$
  3. RB Chris Carson RB SEA SEA@MIN 19.4(19.868) 6400.0$
  4. WR Allen Robinson II WR CHI CHI@CLE 20.8(21.589) 6200.0$
  5. WR Tyler Lockett WR SEA SEA@MIN 24.4(26.047) 7400.0$
  6. WR Justin Jefferson WR MIN SEA@MIN 23.2(25.972) 7200.0$
  7. TE Gerald Everett TE SEA SEA@MIN 7.3(8.078) 3000.0$
  8. FLEX Tyler Conklin TE MIN SEA@MIN 7.0(7.252) 2900.0$
  9. DST Lions DST DET BAL@DET 5.4(5.318) 2000.0$

Thank you in advance!

cwolf908 avatar Sep 22 '21 23:09 cwolf908

this will fix your problem but maybe not the cleanest solution

optimizer.set_players_from_one_team({'SEA': 3}) # max 3 seahawks per lineup just rinse and repeat

lightninglarry avatar Sep 22 '21 23:09 lightninglarry

this will fix your problem but maybe not the cleanest solution

optimizer.set_players_from_one_team({'SEA': 3}) # max 3 seahawks per lineup just rinse and repeat

I appreciate the assist! Unfortunately, that seems to have an odd side effect of forcing 3 players from other teams in my stack list into some lineups. I end up with a triple stack of Seahawks and then a triple stack of dumpster Giants like Toney, Kaden Smith, and the Giants DST lol

cwolf908 avatar Sep 23 '21 00:09 cwolf908

You can create a player group with all players from a single game and add max from group parameter, in new version you can do it like this:

for game in optimizer.player_pool.games:
    optimizer.add_players_group(
        PlayersGroup(
            optimizer.player_pool.get_players(PlayerFilter(teams=[game.home_team, game.away_team])),
            max_from_group=4,
        )
    )

DimaKudosh avatar Sep 27 '21 19:09 DimaKudosh

@DimaKudosh Epic stuff here. I'm a python noob, but I've been able to mostly figure this out and I'm loving it. Thanks for your work

Uncle6Pack avatar Oct 22 '21 14:10 Uncle6Pack