Objects/Documentation
glouton23.py
A counterexample to maximal batching · glouton23.py
Download ↓"""Exact FIFO segmentation with instantaneous service on consecutive ticks."""
from functools import lru_cache
from itertools import product,combinations
import json
from dispersion21 import scan,primes_to
def compare(costs,delay):
n=len(costs)
dp=[(0,[])]
for j in range(1,n+1):
dp.append(min((dp[i][0]+max(costs[i:j]),dp[i][1]+[j]) for i in range(max(0,j-delay-1),j)))
cuts=list(range(delay+1,n,delay+1))+[n]
def score(cc):return sum(max(costs[i:j]) for i,j in zip([0]+cc,cc))
exhaustive=min(score(list(c)+[n]) for k in range(n) for c in combinations(range(1,n),k) if all(j-i<=delay+1 for i,j in zip((0,)+c,c+(n,))))
assert dp[-1][0]==exhaustive