best_15_optimisation module
Source file that holds the model formulation of the best 15 players optimisation problem.
- Functions in the source file:
OptimisationValuesAllZeroError: Exception for when the values chosen to be used as themain optimisation values in
find_best_15_players_by_value()are all zero.
preprocess_data(): Preprocesses the data needed for the optimisation.post_process_data(): Separate the results returned by the optimisation and bring it to a format suitable fordisplay.
find_best_15_players_by_value(): Calculates the best 15 player selection accordingto the value passed as an argument.
- exception best_15_optimisation.OptimisationValuesAllZeroError
Bases:
ExceptionException for when the values chosen to be used as the main optimisation values in
find_best_15_players_by_value()are all zero. This would technically happen only in the pre-season period when for example ‘Form’ is zero for all players.
- best_15_optimisation.find_best_15_players_by_value(player_ids: List, player_positions: List, player_values: List, player_prices: List, player_teams: List, opt_target: str, players_pre_selected: List = None)
Calculates the best 15 player selection according to the value passed as an argument. Uses the PULP library and default CBC solver. It satisfies the max 3 players per team constraint and the 100 cost constraint.
- Parameters:
player_ids (list) – Player unique ids
player_positions (list) – Player positions
player_values (list) – Player values
player_prices (list) – Player prices
player_teams (list) – Player teams
opt_target (str) – optimisation target (the target value)
players_pre_selected (list) – Players pre-selected by the user (forced to be included)
- Returns:
two pandas dataframes, first containing the players and their details, the second the optimisation information
- best_15_optimisation.post_process_data(players_df: DataFrame, results: DataFrame, statistics: DataFrame)
Separate the results returned by the optimisation and bring it to a format suitable for display.
- Parameters:
players_df (pandas.dataframe) – Dataframe containing the uid, first and last name of players
results (pandas.dataframe) – The results of the optimisation
statistics (pandas.dataframe) – pandas dataframe containing the statistics of the optimisation process