James McCool
commited on
Commit
·
136dc86
1
Parent(s):
fdea99f
Enhance lineup optimization by tracking all players in the row and updating player pool filtering to exclude them. Adjusted constraints for player usage across open columns.
Browse files
global_func/optimize_lineup.py
CHANGED
|
@@ -53,30 +53,31 @@ def optimize_single_lineup(
|
|
| 53 |
locked_salary = 0
|
| 54 |
locked_player_names = set()
|
| 55 |
|
|
|
|
|
|
|
|
|
|
| 56 |
for col in player_columns:
|
| 57 |
player_name = row[col]
|
|
|
|
|
|
|
| 58 |
player_team = map_dict['team_map'].get(player_name, '')
|
| 59 |
|
| 60 |
if player_team in lock_teams:
|
| 61 |
-
# Keep this player locked
|
| 62 |
locked_players[col] = player_name
|
| 63 |
locked_salary += get_effective_salary(player_name, col, map_dict, type_var)
|
| 64 |
locked_player_names.add(player_name)
|
| 65 |
else:
|
| 66 |
-
# This position is open for optimization
|
| 67 |
open_columns.append(col)
|
| 68 |
|
| 69 |
-
# If no open columns, nothing to optimize
|
| 70 |
if not open_columns:
|
| 71 |
return optimized_row
|
| 72 |
|
| 73 |
-
# Calculate remaining salary budget
|
| 74 |
remaining_salary = salary_max - locked_salary
|
| 75 |
|
| 76 |
-
# Filter player pool: exclude locked teams
|
| 77 |
available_players = player_pool[
|
| 78 |
(~player_pool['team'].isin(lock_teams)) &
|
| 79 |
-
(~player_pool['player_names'].isin(
|
| 80 |
].copy()
|
| 81 |
|
| 82 |
if available_players.empty:
|
|
@@ -106,7 +107,7 @@ def optimize_single_lineup(
|
|
| 106 |
|
| 107 |
# Constraint 2: Each player can only be used once across all open columns
|
| 108 |
for i in range(num_players):
|
| 109 |
-
solver.Add(sum(x[i, j] for j in range(
|
| 110 |
|
| 111 |
# Constraint 3: Position eligibility
|
| 112 |
for i, player in enumerate(player_list):
|
|
|
|
| 53 |
locked_salary = 0
|
| 54 |
locked_player_names = set()
|
| 55 |
|
| 56 |
+
# IMPORTANT: Track ALL players currently in the row, not just locked ones
|
| 57 |
+
all_current_players = set()
|
| 58 |
+
|
| 59 |
for col in player_columns:
|
| 60 |
player_name = row[col]
|
| 61 |
+
all_current_players.add(player_name) # Add to set of all players in row
|
| 62 |
+
|
| 63 |
player_team = map_dict['team_map'].get(player_name, '')
|
| 64 |
|
| 65 |
if player_team in lock_teams:
|
|
|
|
| 66 |
locked_players[col] = player_name
|
| 67 |
locked_salary += get_effective_salary(player_name, col, map_dict, type_var)
|
| 68 |
locked_player_names.add(player_name)
|
| 69 |
else:
|
|
|
|
| 70 |
open_columns.append(col)
|
| 71 |
|
|
|
|
| 72 |
if not open_columns:
|
| 73 |
return optimized_row
|
| 74 |
|
|
|
|
| 75 |
remaining_salary = salary_max - locked_salary
|
| 76 |
|
| 77 |
+
# Filter player pool: exclude locked teams AND all players already in the row
|
| 78 |
available_players = player_pool[
|
| 79 |
(~player_pool['team'].isin(lock_teams)) &
|
| 80 |
+
(~player_pool['player_names'].isin(all_current_players)) # ✅ Changed this line
|
| 81 |
].copy()
|
| 82 |
|
| 83 |
if available_players.empty:
|
|
|
|
| 107 |
|
| 108 |
# Constraint 2: Each player can only be used once across all open columns
|
| 109 |
for i in range(num_players):
|
| 110 |
+
solver.Add(sum(x[i, j] for j in range(num_open_cols)) <= 1)
|
| 111 |
|
| 112 |
# Constraint 3: Position eligibility
|
| 113 |
for i, player in enumerate(player_list):
|