File size: 1,573 Bytes
987b273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Brute force over real-phase cells (integer input lattice for all endpoints)."""
from fractions import Fraction
from itertools import product
import json,sys
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'src'))
from phase_schedule import compare,clustered
if not __debug__:raise SystemExit("use active assertions")
variable=binary=0
for T in range(3,11):
    for w in range(1,T):
        for seq in product(range(T),repeat=3):
            res=compare(T,seq,w);misses=0
            for n in range(3):
                b=n*T;cuts=[(n-1)*T+seq[n-1],n*T+seq[n]]
                for u in range(b-w+1,b+1):
                    misses+=int(not any(u<=s<u+w for s in cuts))
            assert misses==res['lost_start_measure']
            h=max(seq)
            if h:
                H=min(w,T-w,h,T-h)
                assert misses*h>=sum(seq)*H
            variable+=1
for T in range(3,12):
    for h in range(1,T):
        for w in range(1,T):
            for seq in product((0,h),repeat=6):
                k=sum(x>0 for x in seq);R=sum(x>0 and seq[i-1]==0 for i,x in enumerate(seq))
                H=min(w,T-w,h,T-h);J=min(w,h)-H
                m=compare(T,seq,w)['lost_start_measure']
                assert m==k*H+R*J
                assert clustered(T,h,k,6,w)[1]['lost_start_measure']<=m
                binary+=1
sample={k:compare(10,s,9) for k,s in [('alternating',[0,4]*4),('clustered',[0]*4+[4]*4)]}
print(json.dumps(dict(variable_schedules_checked=variable,binary_schedules_checked=binary,example=sample),indent=2))