Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
40f41b3
1
Parent(s):
1362d63
Adding constraints to remove opposing teams against my goalie and forcing 3+ teams used
Browse files
func/dk_nhl_go/NHL_seed_frames.go
CHANGED
|
@@ -656,7 +656,7 @@ func generateBaseArrays(cPlayers, wPlayers, dPlayers, gPlayers, flexPlayers []Pl
|
|
| 656 |
oppMatches++
|
| 657 |
}
|
| 658 |
|
| 659 |
-
if oppMatches
|
| 660 |
continue
|
| 661 |
}
|
| 662 |
}
|
|
|
|
| 656 |
oppMatches++
|
| 657 |
}
|
| 658 |
|
| 659 |
+
if oppMatches >= 1 {
|
| 660 |
continue
|
| 661 |
}
|
| 662 |
}
|
func/fd_nhl_go/NHL_seed_frames.go
CHANGED
|
@@ -661,7 +661,7 @@ func generateBaseArrays(cPlayers, wPlayers, dPlayers, gPlayers, flex1Players, fl
|
|
| 661 |
oppMatches++
|
| 662 |
}
|
| 663 |
|
| 664 |
-
if oppMatches
|
| 665 |
continue
|
| 666 |
}
|
| 667 |
}
|
|
|
|
| 661 |
oppMatches++
|
| 662 |
}
|
| 663 |
|
| 664 |
+
if oppMatches >= 1 {
|
| 665 |
continue
|
| 666 |
}
|
| 667 |
}
|
src/sports/nhl_functions.py
CHANGED
|
@@ -234,6 +234,20 @@ def init_team_results(model_source: DataFrame, position_reqs: dict, salary_cap:
|
|
| 234 |
) <= salary_cap
|
| 235 |
)
|
| 236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
# Max skaters per team (exclude P/SP positions, include UTIL)
|
| 238 |
teams = filtered_df['Team'].unique()
|
| 239 |
for team in teams:
|
|
@@ -254,6 +268,25 @@ def init_team_results(model_source: DataFrame, position_reqs: dict, salary_cap:
|
|
| 254 |
|
| 255 |
solver.Add(team_constraint <= max_skaters)
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
# Total players constraint (include UTIL)
|
| 258 |
total_players = solver.Sum(x[(i, pos)] for i in filtered_df.index for pos in filtered_df.loc[i, 'eligible_positions'])
|
| 259 |
if 'FLEX' in position_reqs or 'FLEX1' in position_reqs or 'FLEX2' in position_reqs:
|
|
@@ -460,7 +493,6 @@ def init_team_results(model_source: DataFrame, position_reqs: dict, salary_cap:
|
|
| 460 |
final_df = final_df.sort_values(by='Total_Median', ascending=False)
|
| 461 |
|
| 462 |
# Add to all results
|
| 463 |
-
print(final_df.head(10))
|
| 464 |
all_team_results.append(final_df)
|
| 465 |
|
| 466 |
return all_team_results
|
|
|
|
| 234 |
) <= salary_cap
|
| 235 |
)
|
| 236 |
|
| 237 |
+
# No opposing skaters against selected G
|
| 238 |
+
for i, row in filtered_df.iterrows():
|
| 239 |
+
if 'G' in row['eligible_positions']:
|
| 240 |
+
goalie_opp = row['Opp']
|
| 241 |
+
goalie_var = x.get((i, 'G'))
|
| 242 |
+
if goalie_var:
|
| 243 |
+
for j, srow in filtered_df.iterrows():
|
| 244 |
+
if srow['Team'] == goalie_opp and 'G' not in srow['eligible_positions']:
|
| 245 |
+
for pos in srow['eligible_positions']:
|
| 246 |
+
if (j, pos) in x:
|
| 247 |
+
solver.Add(goalie_var + x[(j, pos)] <= 1)
|
| 248 |
+
if ('FLEX' in position_reqs or 'FLEX1' in position_reqs or 'FLEX2' in position_reqs) and j in util_x:
|
| 249 |
+
solver.Add(goalie_var + util_x[j] <= 1)
|
| 250 |
+
|
| 251 |
# Max skaters per team (exclude P/SP positions, include UTIL)
|
| 252 |
teams = filtered_df['Team'].unique()
|
| 253 |
for team in teams:
|
|
|
|
| 268 |
|
| 269 |
solver.Add(team_constraint <= max_skaters)
|
| 270 |
|
| 271 |
+
# At least 3 different teams constraint
|
| 272 |
+
team_used = {}
|
| 273 |
+
for team in teams:
|
| 274 |
+
team_used[team] = solver.BoolVar(f'team_used_{team}')
|
| 275 |
+
team_players_sum = solver.Sum(
|
| 276 |
+
x[(i, pos)]
|
| 277 |
+
for i in filtered_df.index
|
| 278 |
+
for pos in filtered_df.loc[i, 'eligible_positions']
|
| 279 |
+
if filtered_df.loc[i, 'Team'] == team
|
| 280 |
+
)
|
| 281 |
+
if 'FLEX' in position_reqs or 'FLEX1' in position_reqs or 'FLEX2' in position_reqs:
|
| 282 |
+
team_util = [util_x[i] for i in util_x.keys() if filtered_df.loc[i, 'Team'] == team]
|
| 283 |
+
if team_util:
|
| 284 |
+
team_players_sum += solver.Sum(team_util)
|
| 285 |
+
M = sum(position_reqs.values())
|
| 286 |
+
solver.Add(team_players_sum <= M * team_used[team])
|
| 287 |
+
solver.Add(team_used[team] <= team_players_sum)
|
| 288 |
+
solver.Add(solver.Sum([team_used[team] for team in teams]) >= 3)
|
| 289 |
+
|
| 290 |
# Total players constraint (include UTIL)
|
| 291 |
total_players = solver.Sum(x[(i, pos)] for i in filtered_df.index for pos in filtered_df.loc[i, 'eligible_positions'])
|
| 292 |
if 'FLEX' in position_reqs or 'FLEX1' in position_reqs or 'FLEX2' in position_reqs:
|
|
|
|
| 493 |
final_df = final_df.sort_values(by='Total_Median', ascending=False)
|
| 494 |
|
| 495 |
# Add to all results
|
|
|
|
| 496 |
all_team_results.append(final_df)
|
| 497 |
|
| 498 |
return all_team_results
|