Skip to content

Commit

Permalink
Goalie restriction for NHL
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBrostoff committed Jan 25, 2024
1 parent c2f0c81 commit b6481d4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions draftfast/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
PlayerBanAndLockException,
)
from draftfast.orm import Player
from draftfast.rules import RuleSet
from draftfast.rules import RuleSet, DK_NHL_RULE_SET
from draftfast.lineup_constraints import LineupConstraints


Expand All @@ -19,6 +19,7 @@ def __init__(
lineup_constraints: LineupConstraints,
exposure_dict: dict,
):
self.rule_set = rule_set
self.solver = pywraplp.Solver(
"FD", pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING
)
Expand Down Expand Up @@ -378,12 +379,18 @@ def _set_no_duplicate_lineups(self):
def _set_min_teams(self):
"""
Add constraints for maximum players on an individual team
and total represented teams if applicable
and total represented teams if applicable.
For NHL, the min team restriction does not count
goalies
Ref: https://www.draftkings.com/help/rules/nhl
"""
teams = []
min_teams = self.min_teams

if min_teams > 1:
is_dk_nhl = self.ruleset == DK_NHL_RULE_SET
for team in self.teams:
if team:
team_var = self.solver.IntVar(0, 1, team)
Expand All @@ -392,6 +399,10 @@ def _set_min_teams(self):
self.variables[i]
for i, p in self.enumerated_players
if p.team == team
and (
not is_dk_nhl
or p.pos != 'G'
)
]

# Constrain to individual team for all players
Expand Down

0 comments on commit b6481d4

Please sign in to comment.