James McCool
commited on
Commit
·
47189b9
1
Parent(s):
136dc86
ping
Browse files- app.py +0 -3
- global_func/optimize_lineup.py +18 -10
app.py
CHANGED
|
@@ -2999,9 +2999,6 @@ if selected_tab == 'Manage Portfolio':
|
|
| 2999 |
|
| 3000 |
|
| 3001 |
st.session_state['export_base'] = parsed_frame.reset_index(drop=True)
|
| 3002 |
-
|
| 3003 |
-
# st.session_state['export_base'] = predict_dupes(st.session_state['export_base'], st.session_state['map_dict'], site_var, type_var, Contest_Size, strength_var, sport_var)
|
| 3004 |
-
# Load Default base from compressed storage for reassess_edge
|
| 3005 |
default_base = load_base_frame('Default')
|
| 3006 |
st.session_state['export_base'] = reassess_edge(st.session_state['export_base'], default_base, st.session_state['map_dict'], site_var, type_var, Contest_Size, strength_var, sport_var, salary_max)
|
| 3007 |
team_dict = dict(zip(st.session_state['portfolio_inc_proj']['player_names'], st.session_state['portfolio_inc_proj']['team']))
|
|
|
|
| 2999 |
|
| 3000 |
|
| 3001 |
st.session_state['export_base'] = parsed_frame.reset_index(drop=True)
|
|
|
|
|
|
|
|
|
|
| 3002 |
default_base = load_base_frame('Default')
|
| 3003 |
st.session_state['export_base'] = reassess_edge(st.session_state['export_base'], default_base, st.session_state['map_dict'], site_var, type_var, Contest_Size, strength_var, sport_var, salary_max)
|
| 3004 |
team_dict = dict(zip(st.session_state['portfolio_inc_proj']['player_names'], st.session_state['portfolio_inc_proj']['team']))
|
global_func/optimize_lineup.py
CHANGED
|
@@ -53,31 +53,30 @@ def optimize_single_lineup(
|
|
| 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
|
| 78 |
available_players = player_pool[
|
| 79 |
(~player_pool['team'].isin(lock_teams)) &
|
| 80 |
-
(~player_pool['player_names'].isin(
|
| 81 |
].copy()
|
| 82 |
|
| 83 |
if available_players.empty:
|
|
@@ -107,9 +106,18 @@ def optimize_single_lineup(
|
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
# Constraint
|
| 113 |
for i, player in enumerate(player_list):
|
| 114 |
player_positions = player['position'].split('/')
|
| 115 |
for j, col in enumerate(open_columns):
|
|
@@ -120,7 +128,7 @@ def optimize_single_lineup(
|
|
| 120 |
# For Showdown, CPT and FLEX can take any player
|
| 121 |
pass
|
| 122 |
|
| 123 |
-
# Constraint
|
| 124 |
salary_constraint = []
|
| 125 |
for i, player in enumerate(player_list):
|
| 126 |
for j, col in enumerate(open_columns):
|
|
|
|
| 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 and already-locked players
|
| 77 |
available_players = player_pool[
|
| 78 |
(~player_pool['team'].isin(lock_teams)) &
|
| 79 |
+
(~player_pool['player_names'].isin(locked_player_names))
|
| 80 |
].copy()
|
| 81 |
|
| 82 |
if available_players.empty:
|
|
|
|
| 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(num_player_columns)) <= 1)
|
| 110 |
+
|
| 111 |
+
# Constraint 3: Players already in ANY position in the row cannot be selected again
|
| 112 |
+
all_players_in_row = set(row[col] for col in player_columns) # Get ALL players in row
|
| 113 |
+
for i, player in enumerate(player_list):
|
| 114 |
+
player_name = player['player_names']
|
| 115 |
+
if player_name in all_players_in_row:
|
| 116 |
+
# This player is already somewhere in the row, can't use them again
|
| 117 |
+
for j in range(num_open_cols):
|
| 118 |
+
solver.Add(x[i, j] == 0)
|
| 119 |
|
| 120 |
+
# Constraint 4: Position eligibility
|
| 121 |
for i, player in enumerate(player_list):
|
| 122 |
player_positions = player['position'].split('/')
|
| 123 |
for j, col in enumerate(open_columns):
|
|
|
|
| 128 |
# For Showdown, CPT and FLEX can take any player
|
| 129 |
pass
|
| 130 |
|
| 131 |
+
# Constraint 5: Total salary of selected players <= remaining_salary
|
| 132 |
salary_constraint = []
|
| 133 |
for i, player in enumerate(player_list):
|
| 134 |
for j, col in enumerate(open_columns):
|