Spaces:
Running
Running
Commit ·
6e30e73
1
Parent(s): c3e906f
updates
Browse files- solver.py +24 -50
- solver_engine.py +4 -4
solver.py
CHANGED
|
@@ -102,12 +102,6 @@ def run_milp_model(data: dict):
|
|
| 102 |
vice_captain = pulp.LpVariable.dicts("vice_captain", (players, gws), cat="Binary")
|
| 103 |
transfer_in = pulp.LpVariable.dicts("transfer_in", (players, gws), cat="Binary")
|
| 104 |
transfer_out = pulp.LpVariable.dicts("transfer_out", (players, gws), cat="Binary")
|
| 105 |
-
fh_gws = [w for w in gws if chip_gws.get(w) == "fh"]
|
| 106 |
-
squad_fh = (
|
| 107 |
-
pulp.LpVariable.dicts("squad_fh", (players, fh_gws), cat="Binary")
|
| 108 |
-
if fh_gws
|
| 109 |
-
else {}
|
| 110 |
-
)
|
| 111 |
itb = pulp.LpVariable.dicts("itb", all_gws, lowBound=0, cat="Continuous")
|
| 112 |
fts = pulp.LpVariable.dicts(
|
| 113 |
"fts", all_gws, lowBound=1, upBound=max_ft, cat="Integer"
|
|
@@ -298,12 +292,11 @@ def run_milp_model(data: dict):
|
|
| 298 |
eff_prev = effective_prev[w]
|
| 299 |
chip = chip_gws.get(w)
|
| 300 |
|
| 301 |
-
|
| 302 |
-
prob += pulp.lpSum(
|
| 303 |
-
prob += pulp.lpSum(
|
| 304 |
-
prob += pulp.lpSum(
|
| 305 |
-
prob += pulp.lpSum(
|
| 306 |
-
prob += pulp.lpSum(sq[p][w] for p in players if positions[p] == "F") == 3
|
| 307 |
|
| 308 |
prob += pulp.lpSum(lineup[p][w] for p in players) == 11
|
| 309 |
prob += pulp.lpSum(lineup[p][w] for p in players if positions[p] == "G") == 1
|
|
@@ -317,38 +310,31 @@ def run_milp_model(data: dict):
|
|
| 317 |
prob += pulp.lpSum(vice_captain[p][w] for p in players) == 1
|
| 318 |
|
| 319 |
for p in players:
|
| 320 |
-
prob += lineup[p][w] <=
|
| 321 |
prob += captain[p][w] <= lineup[p][w]
|
| 322 |
prob += vice_captain[p][w] <= lineup[p][w]
|
| 323 |
prob += captain[p][w] + vice_captain[p][w] <= 1
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
)
|
| 329 |
-
else:
|
| 330 |
-
# Force normal transfers to 0 on FH
|
| 331 |
-
prob += transfer_in[p][w] == 0
|
| 332 |
-
prob += transfer_out[p][w] == 0
|
| 333 |
|
| 334 |
for t in set(teams.values()):
|
| 335 |
-
sq = squad_fh if chip == "fh" else squad
|
| 336 |
prob += (
|
| 337 |
-
pulp.lpSum(
|
|
|
|
| 338 |
)
|
| 339 |
|
| 340 |
if gws.index(w) >= len(gws) - no_transfer_last_gws and chip not in ("wc", "fh"):
|
| 341 |
prob += pulp.lpSum(transfer_in[p][w] for p in players) == 0
|
| 342 |
|
| 343 |
if chip == "fh":
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
fh_sell_price[p] * squad[p][eff_prev] for p in players
|
| 347 |
-
|
| 348 |
-
|
| 349 |
)
|
| 350 |
-
# ITB carries over unchanged (no real transfers happened)
|
| 351 |
-
prob += itb[w] == itb[eff_prev]
|
| 352 |
else:
|
| 353 |
prob += (
|
| 354 |
itb[eff_prev]
|
|
@@ -551,25 +537,13 @@ def run_milp_model(data: dict):
|
|
| 551 |
for p in players
|
| 552 |
if lineup[p][w].varValue is not None and lineup[p][w].varValue > 0.5
|
| 553 |
]
|
| 554 |
-
gw_bench_raw =
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
and squad_fh[p][w].varValue > 0.5
|
| 562 |
-
and (lineup[p][w].varValue is None or lineup[p][w].varValue < 0.5)
|
| 563 |
-
]
|
| 564 |
-
if chip == "fh"
|
| 565 |
-
else [
|
| 566 |
-
p
|
| 567 |
-
for p in players
|
| 568 |
-
if squad[p][w].varValue is not None
|
| 569 |
-
and squad[p][w].varValue > 0.5
|
| 570 |
-
and (lineup[p][w].varValue is None or lineup[p][w].varValue < 0.5)
|
| 571 |
-
]
|
| 572 |
-
)
|
| 573 |
|
| 574 |
# Safe extractions with fallbacks so indexing never crashes the loop
|
| 575 |
gw_cap_list = [
|
|
|
|
| 102 |
vice_captain = pulp.LpVariable.dicts("vice_captain", (players, gws), cat="Binary")
|
| 103 |
transfer_in = pulp.LpVariable.dicts("transfer_in", (players, gws), cat="Binary")
|
| 104 |
transfer_out = pulp.LpVariable.dicts("transfer_out", (players, gws), cat="Binary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
itb = pulp.LpVariable.dicts("itb", all_gws, lowBound=0, cat="Continuous")
|
| 106 |
fts = pulp.LpVariable.dicts(
|
| 107 |
"fts", all_gws, lowBound=1, upBound=max_ft, cat="Integer"
|
|
|
|
| 292 |
eff_prev = effective_prev[w]
|
| 293 |
chip = chip_gws.get(w)
|
| 294 |
|
| 295 |
+
prob += pulp.lpSum(squad[p][w] for p in players) == 15
|
| 296 |
+
prob += pulp.lpSum(squad[p][w] for p in players if positions[p] == "G") == 2
|
| 297 |
+
prob += pulp.lpSum(squad[p][w] for p in players if positions[p] == "D") == 5
|
| 298 |
+
prob += pulp.lpSum(squad[p][w] for p in players if positions[p] == "M") == 5
|
| 299 |
+
prob += pulp.lpSum(squad[p][w] for p in players if positions[p] == "F") == 3
|
|
|
|
| 300 |
|
| 301 |
prob += pulp.lpSum(lineup[p][w] for p in players) == 11
|
| 302 |
prob += pulp.lpSum(lineup[p][w] for p in players if positions[p] == "G") == 1
|
|
|
|
| 310 |
prob += pulp.lpSum(vice_captain[p][w] for p in players) == 1
|
| 311 |
|
| 312 |
for p in players:
|
| 313 |
+
prob += lineup[p][w] <= squad[p][w]
|
| 314 |
prob += captain[p][w] <= lineup[p][w]
|
| 315 |
prob += vice_captain[p][w] <= lineup[p][w]
|
| 316 |
prob += captain[p][w] + vice_captain[p][w] <= 1
|
| 317 |
+
prob += (
|
| 318 |
+
squad[p][w]
|
| 319 |
+
== squad[p][eff_prev] + transfer_in[p][w] - transfer_out[p][w]
|
| 320 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
for t in set(teams.values()):
|
|
|
|
| 323 |
prob += (
|
| 324 |
+
pulp.lpSum(squad[p][w] for p in players if teams[p] == t)
|
| 325 |
+
<= max_per_team
|
| 326 |
)
|
| 327 |
|
| 328 |
if gws.index(w) >= len(gws) - no_transfer_last_gws and chip not in ("wc", "fh"):
|
| 329 |
prob += pulp.lpSum(transfer_in[p][w] for p in players) == 0
|
| 330 |
|
| 331 |
if chip == "fh":
|
| 332 |
+
prob += (
|
| 333 |
+
itb[eff_prev]
|
| 334 |
+
+ pulp.lpSum(fh_sell_price[p] * squad[p][eff_prev] for p in players)
|
| 335 |
+
- pulp.lpSum(buy_prices[p] * squad[p][w] for p in players)
|
| 336 |
+
== itb[w]
|
| 337 |
)
|
|
|
|
|
|
|
| 338 |
else:
|
| 339 |
prob += (
|
| 340 |
itb[eff_prev]
|
|
|
|
| 537 |
for p in players
|
| 538 |
if lineup[p][w].varValue is not None and lineup[p][w].varValue > 0.5
|
| 539 |
]
|
| 540 |
+
gw_bench_raw = [
|
| 541 |
+
p
|
| 542 |
+
for p in players
|
| 543 |
+
if squad[p][w].varValue is not None
|
| 544 |
+
and squad[p][w].varValue > 0.5
|
| 545 |
+
and (lineup[p][w].varValue is None or lineup[p][w].varValue < 0.5)
|
| 546 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
|
| 548 |
# Safe extractions with fallbacks so indexing never crashes the loop
|
| 549 |
gw_cap_list = [
|
solver_engine.py
CHANGED
|
@@ -182,10 +182,10 @@ def prep_solver_data(payload_data: dict):
|
|
| 182 |
raw_ev = p["evs"].get(gw, p["evs"].get(str(gw), 0))
|
| 183 |
ev_matrix[pid][gw] = float(raw_ev) * decay_factor
|
| 184 |
raw_ev_matrix[pid][gw] = float(raw_ev)
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
|
| 190 |
# --- CROSS-PLAY FIXTURE PREP ---
|
| 191 |
global _FIXTURE_CACHE
|
|
|
|
| 182 |
raw_ev = p["evs"].get(gw, p["evs"].get(str(gw), 0))
|
| 183 |
ev_matrix[pid][gw] = float(raw_ev) * decay_factor
|
| 184 |
raw_ev_matrix[pid][gw] = float(raw_ev)
|
| 185 |
+
fh_sell_price = {
|
| 186 |
+
pid: sell_prices[pid] if pid in current_squad_ids else buy_prices[pid]
|
| 187 |
+
for pid in buy_prices
|
| 188 |
+
}
|
| 189 |
|
| 190 |
# --- CROSS-PLAY FIXTURE PREP ---
|
| 191 |
global _FIXTURE_CACHE
|