Skip to content

Commit 612728b

Browse files
committed
fix(gen): prioritize tree generator over planar for acyclic graphs
When both planar and acyclic constraints specified, the tree generator must take precedence. Tree constraint (m = n-1) is stricter than planar (m ≤ 3n-6). Changes: - Skip planar generation when cycles.kind === 'acyclic' - Trees are always planar, so fall through to Phase 1 tree generator
1 parent bd9cd5d commit 612728b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/generation/generators/edge-generator.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,20 @@ const generateBaseStructure = (nodes: TestNode[], spec: GraphSpec, _config: Grap
351351
return edges;
352352
}
353353

354-
if (spec.planar?.kind === "planar") {
354+
// Only use planar generator if not also constrained to be acyclic (tree)
355+
// Tree constraint (m = n-1) is stricter than planar (m ≤ 3n-6)
356+
if (spec.planar?.kind === "planar" && spec.cycles.kind !== "acyclic") {
355357
generatePlanarEdges(nodes, edges, spec, rng);
356358
return edges;
357359
}
358360

361+
// Handle planar + acyclic combination by using tree generator
362+
// Trees are always planar, so we defer to the tree generator from Phase 1
363+
if (spec.planar?.kind === "planar" && spec.cycles.kind === "acyclic") {
364+
// Skip planar generation - let Phase 1 tree generator handle it
365+
// Fall through to default generation
366+
}
367+
359368
if (spec.hamiltonian?.kind === "hamiltonian") {
360369
generateHamiltonianEdges(nodes, edges, spec, rng);
361370
return edges;

0 commit comments

Comments
 (0)