From b46c76ce9a18efc8fd8d70d87fdff61be8e6da0c Mon Sep 17 00:00:00 2001 From: x Date: Thu, 3 Dec 2026 22:23:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(spatial):=20=E8=BF=91=E8=B4=B4=E5=90=88?= =?UTF-8?q?=E5=AE=B6=E6=97=8F=E4=B8=8E=E5=AE=B9=E5=B7=AE=E6=89=AB=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 稳定性家族加 clearance 参数(把上块抬离底座 0/1/2/4 格,1 格 = 0.25mm), 新增 area.gap1/2/4。extract 加 tol 子命令:对每个间隙扫容差,问两件事——会不会 提取出一条不存在的 T-P 接触,以及这条假边会不会被检查器接受为有效凭证。 --- spatial/extract.py | 43 ++++++++++++++++++++++++++++++++++++++++++- spatial/generator.py | 21 +++++++++++++++++---- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/spatial/extract.py b/spatial/extract.py index af03aab..28b4dd4 100644 --- a/spatial/extract.py +++ b/spatial/extract.py @@ -178,9 +178,50 @@ def report(n: int = 32) -> None: print("余隙 = 互不接触的零件表面之间的最小距离,说明容差有没有被真正考验") +GAP_FAMILIES = (("area.sup2", 0), ("area.gap1", 1), ("area.gap2", 2), ("area.gap4", 4)) + + +def report_tolerance(n: int = 8) -> None: + """Does the distance tolerance decide anything, and what does it cost. + + For every clearance the upper block sits at, sweep the tolerance and ask two + questions: does an edge between the block and its (absent) pedestal appear, + and if so does the checker accept that edge as a certificate. A tolerance + that fuses two parts 0.25mm apart does not merely add noise -- it forges a + support that validates. + """ + tols = (0.0, 0.5, 1.0, 2.0, 4.0) + print(f"{'family':10s} {'间隙':>4s} " + " ".join(f"{t:>9.1f}" for t in tols)) + print("-" * 68) + for fam, gap in GAP_FAMILIES: + cells = [] + for tol in tols: + got = forged = total = 0 + for i in range(n): + sc = generator.make(fam, seed=7, index=i) + edges = extract_edges(sc.obs.entities, tol=tol) + world = FullState(entities=list(sc.obs.entities), edges=edges) + tp = [e for e in edges if {e.a, e.b} == {"T", "P"}] + total += 1 + if tp: + got += 1 + forged += int(checker.validate_evidence( + world, Query(kind="stability", a="T"), [tp[0].eid])) + mark = "ok" if gap == 0 else ("!" if forged else " ") + cells.append(f"{got:2d}/{total} {mark:2s}") + print(f"{fam:10s} {gap:4d} " + " ".join(f"{c:>9s}" for c in cells)) + print() + print("单元格 = 提取到 T-P 边的样本数 / 总数;ok = 该边合法(间隙为 0,本来就贴着)") + print("! = 该边被检查器当成有效凭证,但零件其实没有接触 —— 容差过大伪造了支撑") + print("间隙单位 0.25mm;真实装配的余隙是 0.2mm 级,即 1 格") + + def main(argv=None) -> int: argv = list(sys.argv[1:] if argv is None else argv) - report(int(argv[0]) if argv else 32) + if argv and argv[0] == "tol": + report_tolerance(int(argv[1]) if len(argv) > 1 else 8) + else: + report(int(argv[0]) if argv else 32) return 0 diff --git a/spatial/generator.py b/spatial/generator.py index f235812..c1f5e02 100644 --- a/spatial/generator.py +++ b/spatial/generator.py @@ -32,6 +32,9 @@ FAMILIES = { "area.free": {"domain": "stability", "n_blocks": 2, "hidden": 0, "free": 1}, "area.sup3h": {"domain": "stability", "n_blocks": 3, "hidden": 1}, "area.sup2d": {"domain": "stability", "n_blocks": 2, "hidden": 0, "notch": 1}, + "area.gap1": {"domain": "stability", "n_blocks": 2, "hidden": 0, "clearance": 1}, + "area.gap2": {"domain": "stability", "n_blocks": 2, "hidden": 0, "clearance": 2}, + "area.gap4": {"domain": "stability", "n_blocks": 2, "hidden": 0, "clearance": 4}, "dof.c6": {"domain": "freedom", "n_cons": 6, "hidden": 0}, "dof.c6r": {"domain": "freedom", "n_cons": 7, "hidden": 0}, "dof.c6h": {"domain": "freedom", "n_cons": 6, "hidden": 1}, @@ -129,7 +132,8 @@ def _build_connection(rng, n_paths: int, hidden: int): # stability: stacked blocks, optional hidden pedestal -def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0, notch: int = 0): +def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0, notch: int = 0, + clearance: int = 0): if free: # the minimal pair against area.sup2h: here T has exactly one contact and # that contact leads to a block which itself hangs in the air. Nothing @@ -156,16 +160,22 @@ def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0, notch: int # is exactly what the report kept showing. dx = rng.choice((-13, -6, 0, 3, 6, 13)) dy = rng.choice((-9, 0, 0, 0, 9)) + # clearance lifts the upper block off its pedestal by a few grid units (one + # grid unit is 0.25mm). At 0 the two surfaces touch exactly; at 1 they are + # 0.25mm apart, which is the regime real assemblies live in and the regime a + # distance tolerance actually has to decide. + cl = int(clearance) ents = [Entity("G", "ground", attrs={"plane": 0}), Entity("P", "block", attrs={"box": [40, 40, 0, 60, 60, 20]}), - Entity("T", "block", attrs={"box": [42 + dx, 42 + dy, 20, 58 + dx, 58 + dy, 36]}), + Entity("T", "block", attrs={"box": [42 + dx, 42 + dy, 20 + cl, + 58 + dx, 58 + dy, 36 + cl]}), Entity("D", "block", attrs={"box": [80, 40, 0, 100, 60, 16]})] edges = [Edge("kPG", "contact", "P", "G"), Edge("kPT", "contact", "T", "P"), Edge("kDG", "contact", "D", "G")] top = None if n_blocks >= 3: ents.append(Entity("U", "block", - attrs={"box": [44 + dx, 44 + dy, 36, 56 + dx, 56 + dy, 48]})) + attrs={"box": [44 + dx, 44 + dy, 36 + cl, 56 + dx, 56 + dy, 48 + cl]})) edges.append(Edge("kTU", "contact", "U", "T")) top = "U" vis_edges = {e.eid for e in edges} @@ -195,6 +205,8 @@ def _build_stability(rng, n_blocks: int, hidden: int, free: int = 0, notch: int # that removes P, so "removed something" no longer implies "answer false" query = Query(kind="stability", a="T") r = rng.random() + if clearance: + return ents, edges, query, vis_edges, vis_ents, layers, ["front", "iso"], {"length": "mm", "per_unit": 1} if not hidden: harmless = top or "D" if r < 0.4: @@ -264,7 +276,8 @@ def _build_freedom(rng, n_cons: int, hidden: int, no_edit: int = 0, notch: int = _BUILDERS = { "connection": lambda rng, spec: _build_connection(rng, spec["n_paths"], spec["hidden"]), "stability": lambda rng, spec: _build_stability(rng, spec["n_blocks"], spec["hidden"], - spec.get("free", 0), spec.get("notch", 0)), + spec.get("free", 0), spec.get("notch", 0), + spec.get("clearance", 0)), "freedom": lambda rng, spec: _build_freedom(rng, spec["n_cons"], spec["hidden"], spec.get("no_edit", 0), spec.get("notch", 0)), }