#!/usr/bin/env python3 """Job #4551 (route 1 step check): the price of the five-event step, and the chordal-graph census. Exact pieces, no experiment: (1) the width-2 chordal graphs on 5 labelled vertices = the family the step's B2 maximises over, enumerated exhaustively (all 2^10 graphs), with the number of clique terms (edges + triangles) each Dohmen clique-sum budget of the served four-event shape B(G) = first + sum_{e in E(G)} pair[e] - sum_{3-cliques of G} tri needs. The four-event source's own family is the six maximal ones on 4 vertices (K4 minus an edge). (2) the price in CPU hours at the only served rate (#1841's recipe: the L = 813 four-event screen, 22,256 classes x 392,863 phases, "~150 s on 4 cores"). Writes: price.json """ import itertools import json import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) N4, N5 = 4, 5 Q4 = (19, 23, 29, 31) Q5 = 37 EDGES5 = list(itertools.combinations(range(N5), 2)) EDGES4 = list(itertools.combinations(range(N4), 2)) def adj_of(edges, mask, n): adj = [[False] * n for _ in range(n)] for i in range(len(edges)): if mask >> i & 1: u, v = edges[i] adj[u][v] = adj[v][u] = True return adj def is_chordal(adj, n): """No induced cycle of length >= 4 (brute force, n <= 5).""" for k in range(4, n + 1): for cyc in itertools.permutations(range(n), k): if cyc[0] != min(cyc): continue if not all(adj[cyc[i]][cyc[(i + 1) % k]] for i in range(k)): continue if not any(adj[cyc[i]][cyc[j]] for i in range(k) for j in range(i + 1, k) if (j - i) % k not in (1, k - 1)): return False return True def clique_number(adj, n): for k in range(n, 1, -1): for sub in itertools.combinations(range(n), k): if all(adj[u][v] for u, v in itertools.combinations(sub, 2)): return k return 1 def width2(adj, n): return is_chordal(adj, n) and clique_number(adj, n) <= 3 def triangles(adj, n): return [c for c in itertools.combinations(range(n), 3) if all(adj[u][v] for u, v in itertools.combinations(c, 2))] def census(edges, n): fam, maximal = [], [] for mask in range(1 << len(edges)): adj = adj_of(edges, mask, n) if not width2(adj, n): continue rec = {"edges": bin(mask).count("1"), "triangles": len(triangles(adj, n))} fam.append(rec) if not any(width2(adj_of(edges, mask | (1 << i), n), n) for i in range(len(edges)) if not mask >> i & 1): maximal.append(rec) return fam, maximal def main(): fam5, max5 = census(EDGES5, N5) fam4, max4 = census(EDGES4, N4) work5 = sum(f["edges"] + f["triangles"] for f in fam5) workm5 = sum(f["edges"] + f["triangles"] for f in max5) work4 = sum(f["edges"] + f["triangles"] for f in max4) # the served C code's own six candidates max4_shape = all(f["edges"] == 5 and f["triangles"] == 2 for f in max4) p4 = 1 for q in Q4: p4 *= q p5 = p4 * Q5 classes = 50 + 8 + 86 total5 = classes * p5 total4 = 22256 * p4 rate = total4 / (150 * 4) # #1841's recipe: ~150 s wall on 4 cores for the L = 813 screen price = { "width2_chordal_labelled_5": len(fam5), "width2_maximal_labelled_5": len(max5), "maximal_5_all_seven_edges": all(f["edges"] == 7 for f in max5), "clique_terms_full_family_5": work5, "clique_terms_maximal_family_5": workm5, "width2_chordal_labelled_4": len(fam4), "width2_maximal_labelled_4": len(max4), "clique_terms_family_4": work4, "maximal_4_is_the_served_six_K4_minus_edge": max4_shape and len(max4) == 6, "multiplier_maximal_5_over_served_4": workm5 / work4, "multiplier_full_5_over_served_4": work5 / work4, "phases_per_class_4": p4, "phases_per_class_5": p5, "classes_step": classes, "phases_step_total": total5, "phases_4event_screen_total": total4, "served_rate_phases_per_core_s": rate, "cpu_hours_step_maximal_family": total5 * (workm5 / work4) / rate / 3600, "cpu_hours_step_full_family": total5 * (work5 / work4) / rate / 3600, "cpu_hours_step_at_1x": total5 / rate / 3600, "declared_cpu_hours": 2, "wall_minutes_maximal_family_4cores": total5 * (workm5 / work4) / rate / 4 / 60, "wall_minutes_full_family_4cores": total5 * (work5 / work4) / rate / 4 / 60, } with open(os.path.join(HERE, "price.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(price, fh, indent=1) print(json.dumps(price, indent=1)) return 0 if __name__ == "__main__": sys.exit(main())