selection
selection
¶
Squad selection and optimization.
BudgetConstraint
¶
FormationConstraints
¶
Formation constraints for FPL squad.
Rules: - Exactly 11 players - 1 GK - 3-5 DEF - 2-5 MID - 1-3 FWD
validate
classmethod
¶
validate(players: list[Player]) -> bool
Check if squad satisfies formation constraints.
| PARAMETER | DESCRIPTION |
|---|---|
players
|
List of players in squad
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if valid formation |
Source code in fplx/selection/constraints.py
get_valid_formations
classmethod
¶
Get list of valid formation strings.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
Valid formations (e.g., "3-4-3", "4-3-3") |
Source code in fplx/selection/constraints.py
SquadQuotas
¶
Position quotas for the 15-player FPL squad.
Rules: - 2 GK, 5 DEF, 5 MID, 3 FWD (exactly). - Total = 15 players.
TeamDiversityConstraint
¶
LagrangianOptimizer
¶
LagrangianOptimizer(
budget: float = 100.0,
max_from_team: int = 3,
max_iter: int = 200,
tol: float = 0.01,
risk_aversion: float = 0.0,
)
Lagrangian relaxation for the FPL squad selection ILP.
Relaxes the budget constraint into the objective:
L(lambda) = max_{x in X} sum_i (mu_i - lambda * c_i) * x_i + lambda * B
where X encodes squad size, position quotas, and team caps. The inner maximization decomposes: for each position, select the top-k players by modified score (mu_i - lambda * c_i).
The dual problem min_{lambda >= 0} L(lambda) is solved via subgradient ascent.
| PARAMETER | DESCRIPTION |
|---|---|
budget
|
Total budget (default 100.0).
TYPE:
|
max_from_team
|
Maximum players from same club.
TYPE:
|
max_iter
|
Maximum subgradient iterations.
TYPE:
|
tol
|
Convergence tolerance on duality gap.
TYPE:
|
risk_aversion
|
Mean-variance penalty (same as ILP).
TYPE:
|
Source code in fplx/selection/lagrangian.py
solve
¶
solve(
players: list[Player],
expected_points: dict[int, float],
expected_variance: Optional[dict[int, float]] = None,
best_known_primal: Optional[float] = None,
) -> LagrangianResult
Solve via Lagrangian relaxation with subgradient ascent.
| PARAMETER | DESCRIPTION |
|---|---|
players
|
TYPE:
|
expected_points
|
TYPE:
|
expected_variance
|
TYPE:
|
best_known_primal
|
Best known primal objective (e.g., from ILP). Used for better step size computation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LagrangianResult
|
|
Source code in fplx/selection/lagrangian.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
LagrangianResult
dataclass
¶
LagrangianResult(
full_squad: Optional[FullSquad] = None,
primal_objective: float = 0.0,
dual_bound: float = 0.0,
duality_gap: float = 0.0,
n_iterations: int = 0,
converged: bool = False,
solve_time: float = 0.0,
dual_history: list[float] = list(),
primal_history: list[float] = list(),
lambda_history: list[float] = list(),
budget_slack_history: list[float] = list(),
)
Convergence diagnostics for the Lagrangian solver.
GreedyOptimizer
¶
Bases: BaseOptimizer
Greedy baseline: select best-value players per position.
Fast heuristic for comparison. Selects 15-player squad, then picks best 11 as lineup.
Source code in fplx/selection/optimizer.py
optimize
¶
optimize(
players: list[Player],
expected_points: dict[int, float],
expected_variance: Optional[dict[int, float]] = None,
formation: Optional[str] = None,
) -> FullSquad
Greedy squad + lineup selection.
Source code in fplx/selection/optimizer.py
OptimizationResult
dataclass
¶
OptimizationResult(
full_squad: FullSquad,
objective_value: float = 0.0,
solve_time: float = 0.0,
lp_objective: Optional[float] = None,
integrality_gap: Optional[float] = None,
shadow_prices: dict = dict(),
binding_constraints: list = list(),
)
Container for optimization outputs including duality analysis.
TwoLevelILPOptimizer
¶
Bases: BaseOptimizer
Two-level ILP: select 15-player squad then 11-player lineup jointly.
Supports risk-neutral and risk-averse (mean-variance) objectives. Also exposes LP relaxation for shadow price extraction.
| PARAMETER | DESCRIPTION |
|---|---|
budget
|
Maximum total squad budget (applied to 15 players).
TYPE:
|
max_from_team
|
Maximum players from same club.
TYPE:
|
risk_aversion
|
Lambda for mean-variance penalty. 0 = risk-neutral.
TYPE:
|
Source code in fplx/selection/optimizer.py
solve
¶
optimize
¶
optimize(
players: list[Player],
expected_points: dict[int, float],
expected_variance: Optional[dict[int, float]] = None,
downside_risk: Optional[dict[int, float]] = None,
formation: Optional[str] = None,
) -> FullSquad
Solve the two-level ILP.
| PARAMETER | DESCRIPTION |
|---|---|
players
|
Available player pool.
TYPE:
|
expected_points
|
E[P_i] per player.
TYPE:
|
expected_variance
|
Var[P_i] per player.
TYPE:
|
downside_risk
|
Downside spread per player. If provided, risk penalty uses this directly (instead of sqrt(variance)).
TYPE:
|
formation
|
Not used (formation is optimized automatically).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FullSquad
|
|
Source code in fplx/selection/optimizer.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
solve_lp_relaxation
¶
solve_lp_relaxation(
players: list[Player],
expected_points: dict[int, float],
expected_variance: Optional[dict[int, float]] = None,
downside_risk: Optional[dict[int, float]] = None,
) -> OptimizationResult
Solve the LP relaxation and extract shadow prices.
| RETURNS | DESCRIPTION |
|---|---|
OptimizationResult
|
Contains LP objective, shadow prices, binding constraints. |