style(fase1): ruff format spike modules

This commit is contained in:
Kjell Tore Guttormsen 2026-06-24 10:34:27 +02:00
commit c1317689f1
6 changed files with 123 additions and 26 deletions

View file

@ -120,11 +120,15 @@ def _solve_max_feasible(items: list[AffectedItem], fraction: float) -> float:
prob += pulp.lpSum(xs) <= fraction * sum(it.total for it in items)
status = prob.solve(solver)
if pulp.LpStatus[status] != "Optimal":
raise CbcUnavailable(f"CBC did not reach an optimal solution (status={pulp.LpStatus[status]})")
raise CbcUnavailable(
f"CBC did not reach an optimal solution (status={pulp.LpStatus[status]})"
)
return float(pulp.value(prob.objective))
def _monte_carlo(proposal: SavingsProposal, *, fraction: float = MAX_SAVING_FRACTION) -> tuple[float, float, float]:
def _monte_carlo(
proposal: SavingsProposal, *, fraction: float = MAX_SAVING_FRACTION
) -> tuple[float, float, float]:
"""Vary uncertain unit-costs (seeded) and return (P10, P50, P90) of the feasible
saving. Uses the LP's closed-form optimum (= fraction x sum of sampled totals), which
is exact here, so we do NOT spawn a CBC subprocess per sample (D6)."""