Skip to content

Enable constrained Delaunay triangulation for convex via regions#78

Closed
zalo wants to merge 2 commits intotscircuit:mainfrom
zalo:euclidean-distance-g-cost
Closed

Enable constrained Delaunay triangulation for convex via regions#78
zalo wants to merge 2 commits intotscircuit:mainfrom
zalo:euclidean-distance-g-cost

Conversation

@zalo
Copy link

@zalo zalo commented Feb 24, 2026

Summary

Bump @tscircuit/find-convex-regions to 0.0.9 and enable useConstrainedDelaunay: true in generateConvexViaTopologyRegions. CDT produces better triangulations that improve solve rate on the 1000-sample convex via benchmark (48% -> 49%).

Changes

File Change
package.json @tscircuit/find-convex-regions ^0.0.7 -> ^0.0.9
generateConvexViaTopologyRegions.ts Add useConstrainedDelaunay: true to ConvexRegionsSolver input

Benchmark (100-sample subset)

Before (v0.0.36) After (CDT)
Solved 48/100 (48%) 49/100 (49%)
Iterations (median) 27,194 21,512
Iterations (mean) 71,306 62,447

Test plan

  • bun test — 48 pass, 2 skip (pre-existing), 0 fail
  • All solver correctness assertions pass
  • Only via-graph-convex-dataset02 snapshot changes (expected — different triangulation)

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 24, 2026 21:32
@vercel
Copy link

vercel bot commented Feb 24, 2026

@zalo is attempting to deploy a commit to the tscircuit Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves A* route search performance by adding a weighted Euclidean edge-length component to the g-cost, and auto-disabling it for through-jumper topologies where it can cause rip cascades.

Changes:

  • Add distanceCostWeight, auto-detection (computeDistanceCostWeight()), and edge-length cost (computeDistanceCost()) to HyperGraphSolver and integrate into computeG().
  • Initialize distanceCostWeight in ViaGraphSolver and JumperGraphSolver constructors; minor cleanup in BFS hop-distance maps.
  • Add a benchmark-style test and update SVG snapshots to reflect the new scoring/ordering; remove an unused skipped-test snapshot.

Reviewed changes

Copilot reviewed 4 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/HyperGraphSolver.ts Adds Euclidean distance g-cost and auto-detected weight selection.
lib/ViaGraphSolver/ViaGraphSolver.ts Computes distance-cost weight during solver construction; minor cleanup.
lib/JumperGraphSolver/JumperGraphSolver.ts Computes distance-cost weight during solver construction; removes unused import; minor cleanup.
tests/benchmark-heuristic.test.ts Adds benchmark assertion comparing iterations with/without distance g-cost.
tests/via-graph-solver/__snapshots__/via-graph-solver01.snap.svg Snapshot updated for new candidate ordering/scoring.
tests/via-graph-solver/__snapshots__/via-graph-solver02.snap.svg Snapshot updated for new candidate ordering/scoring.
tests/via-graph-solver/__snapshots__/via-graph-solver03.snap.svg Snapshot updated for new candidate ordering/scoring.
tests/via-graph-solver/__snapshots__/via-graph-solver04.snap.svg Snapshot updated for new candidate ordering/scoring.
tests/jumper-graph-solver/__snapshots__/jumper-graph-solver07.snap.svg Snapshot removed (associated test is skipped).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a couple changes bundled into this PR (constrained delauney + a change to distance cost), and a proper benchmark script result isn't run afaik (there are full benchmark suites that can be used, looking at individual tests isn't a good idea since there's a dataset of 1000 samples)

I could be wrong, but we should never modify the distance cost because it is the "grounded value", you can change scale other parameters but never distance, otherwise all other units lose their semantic meaning (i.e. a hyperparameter that specifies a penalty is 0.75 no longer means 0.75mm, it now refers to a "arbitrary cost", keeping one grounded value is desirable)

@seveibar
Copy link
Contributor

/benchmark

@github-actions
Copy link

github-actions bot commented Feb 24, 2026

Benchmark Failed

Benchmark run failed. View workflow run

@seveibar
Copy link
Contributor

yea so i guess the benchmark will fail until main is merged into this branch 🤷 it also takes a while to run which is not great (i think it takes an hour or two)

Bump @tscircuit/find-convex-regions to 0.0.9 and enable
useConstrainedDelaunay in generateConvexViaTopologyRegions.
CDT produces better triangulations that improve solve rate
on the 1000-sample convex via benchmark (48% -> 49%).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@zalo zalo force-pushed the euclidean-distance-g-cost branch from c9d6ed3 to 88cb9a9 Compare February 25, 2026 00:08
@zalo zalo changed the title Add Euclidean distance g-cost to reduce A* iterations Enable constrained Delaunay triangulation for convex via regions Feb 25, 2026
@zalo
Copy link
Author

zalo commented Feb 25, 2026

From just the fuller via test, the benefit from ambiguous to bad...

@zalo
Copy link
Author

zalo commented Feb 25, 2026

/benchmark

@github-actions
Copy link

github-actions bot commented Feb 25, 2026

Benchmark Results

PR results
Graph size (vertical): 10.4x11.0mm
Graph size (horizontal): 11.0x10.4mm
Benchmark: 2x2 1206x4 Jumper Grid Solver (Both Orientations)
==================================================
Testing 2-30 connections with 100 samples each

Crossings:  2 | Success: 100/100 | Rate: 100.0%   Med iters: 754   P95: 2065, P99: 2605   Med time: 4.9ms
Crossings:  3 | Success: 100/100 | Rate: 100.0%   Med iters: 704   P95: 2099, P99: 2704   Med time: 4.4ms
Crossings:  4 | Success: 100/100 | Rate: 100.0%   Med iters: 1461   P95: 6374, P99: 10148   Med time: 8.9ms
Crossings:  5 | Success: 100/100 | Rate: 100.0%   Med iters: 1527   P95: 4478, P99: 14977   Med time: 9.7ms
Crossings:  6 | Success: 100/100 | Rate: 100.0%   Med iters: 1516   P95: 4728, P99: 17021   Med time: 9.7ms
Crossings:  7 | Success: 100/100 | Rate: 100.0%   Med iters: 2608   P95: 17495, P99: 20695   Med time: 18.2ms
Crossings:  8 | Success: 100/100 | Rate: 100.0%   Med iters: 2965   P95: 14347, P99: 19142   Med time: 20.4ms
Crossings:  9 | Success: 100/100 | Rate: 100.0%   Med iters: 3184   P95: 15613, P99: 22698   Med time: 22.4ms
Crossings: 10 | Success:  99/100 | Rate:  99.0%   Med iters: 5111   P95: 18134, P99: 27262   Med time: 48.1ms
Crossings: 11 | Success:  98/100 | Rate:  98.0%   Med iters: 7138   P95: 29117, P99: 36849   Med time: 60.4ms
Crossings: 12 | Success:  98/100 | Rate:  98.0%   Med iters: 8950   P95: 28070, P99: 39752   Med time: 93.1ms
Crossings: 13 | Success:  95/100 | Rate:  95.0%   Med iters: 9767   P95: 30763, P99: 39437   Med time: 111.8ms
Crossings: 14 | Success:  93/100 | Rate:  93.0%   Med iters: 9698   P95: 32881, P99: 44086   Med time: 169.6ms
Crossings: 15 | Success:  80/100 | Rate:  80.0%   Med iters: 17900   P95: 40391, P99: 45435   Med time: 263.8ms
Crossings: 16 | Success:  64/100 | Rate:  64.0%   Med iters: 14666   P95: 39773, P99: 42027   Med time: 216.0ms
Crossings: 17 | Success:  50/100 | Rate:  50.0%   Med iters: 18086   P95: 36393, P99: 40033   Med time: 347.5ms
Crossings: 18 | Success:  33/100 | Rate:  33.0%   Med iters: 20850   P95: 42097, P99: 54758   Med time: 395.6ms
Crossings: 19 | Success:  21/100 | Rate:  21.0%   Med iters: 22342   P95: 45613, P99: 45613   Med time: 445.6ms
Crossings: 20 | Success:  18/100 | Rate:  18.0%   Med iters: 28448   P95: 57781, P99: 57781   Med time: 523.7ms
Crossings: 21 | Success:   7/100 | Rate:   7.0%   Med iters: 16765   P95: 50348, P99: 50348   Med time: 597.3ms
Crossings: 22 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 23 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 24 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 25 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 26 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 27 | Success:   1/100 | Rate:   1.0%   Med iters: 66510   P95: 66510, P99: 66510   Med time: 633.3ms
Crossings: 28 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 29 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 30 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A

==================================================
Summary:
==================================================
Average success rate: 53.7%
Crossing counts with 100% success: 8
Crossing counts with 0% success: 8
Main branch results (baseline)
Graph size (vertical): 10.4x11.0mm
Graph size (horizontal): 11.0x10.4mm
Benchmark: 2x2 1206x4 Jumper Grid Solver (Both Orientations)
==================================================
Testing 2-30 connections with 100 samples each

Crossings:  2 | Success: 100/100 | Rate: 100.0%   Med iters: 754   P95: 2065, P99: 2605   Med time: 5.1ms
Crossings:  3 | Success: 100/100 | Rate: 100.0%   Med iters: 704   P95: 2099, P99: 2704   Med time: 4.2ms
Crossings:  4 | Success: 100/100 | Rate: 100.0%   Med iters: 1461   P95: 6374, P99: 10148   Med time: 8.9ms
Crossings:  5 | Success: 100/100 | Rate: 100.0%   Med iters: 1527   P95: 4478, P99: 14977   Med time: 9.3ms
Crossings:  6 | Success: 100/100 | Rate: 100.0%   Med iters: 1516   P95: 4728, P99: 17021   Med time: 9.7ms
Crossings:  7 | Success: 100/100 | Rate: 100.0%   Med iters: 2608   P95: 17495, P99: 20695   Med time: 17.7ms
Crossings:  8 | Success: 100/100 | Rate: 100.0%   Med iters: 2965   P95: 14347, P99: 19142   Med time: 20.0ms
Crossings:  9 | Success: 100/100 | Rate: 100.0%   Med iters: 3184   P95: 15613, P99: 22698   Med time: 23.0ms
Crossings: 10 | Success:  99/100 | Rate:  99.0%   Med iters: 5111   P95: 18134, P99: 27262   Med time: 47.8ms
Crossings: 11 | Success:  98/100 | Rate:  98.0%   Med iters: 7138   P95: 29117, P99: 36849   Med time: 59.1ms
Crossings: 12 | Success:  98/100 | Rate:  98.0%   Med iters: 8950   P95: 28070, P99: 39752   Med time: 93.4ms
Crossings: 13 | Success:  95/100 | Rate:  95.0%   Med iters: 9767   P95: 30763, P99: 39437   Med time: 108.5ms
Crossings: 14 | Success:  93/100 | Rate:  93.0%   Med iters: 9698   P95: 32881, P99: 44086   Med time: 170.0ms
Crossings: 15 | Success:  80/100 | Rate:  80.0%   Med iters: 17900   P95: 40391, P99: 45435   Med time: 251.8ms
Crossings: 16 | Success:  64/100 | Rate:  64.0%   Med iters: 14666   P95: 39773, P99: 42027   Med time: 217.3ms
Crossings: 17 | Success:  50/100 | Rate:  50.0%   Med iters: 18086   P95: 36393, P99: 40033   Med time: 348.4ms
Crossings: 18 | Success:  33/100 | Rate:  33.0%   Med iters: 20850   P95: 42097, P99: 54758   Med time: 390.1ms
Crossings: 19 | Success:  21/100 | Rate:  21.0%   Med iters: 22342   P95: 45613, P99: 45613   Med time: 452.3ms
Crossings: 20 | Success:  18/100 | Rate:  18.0%   Med iters: 28448   P95: 57781, P99: 57781   Med time: 498.2ms
Crossings: 21 | Success:   7/100 | Rate:   7.0%   Med iters: 16765   P95: 50348, P99: 50348   Med time: 596.6ms
Crossings: 22 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 23 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 24 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 25 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 26 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 27 | Success:   1/100 | Rate:   1.0%   Med iters: 66510   P95: 66510, P99: 66510   Med time: 620.6ms
Crossings: 28 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 29 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A
Crossings: 30 | Success:   0/100 | Rate:   0.0%   Med iters: N/A   P95: N/A, P99: N/A   Med time: N/A

==================================================
Summary:
==================================================
Average success rate: 53.7%
Crossing counts with 100% success: 8
Crossing counts with 0% success: 8

View workflow run

@zalo
Copy link
Author

zalo commented Feb 26, 2026

Duplicate of #91 it seems 😅

The polyanya graph merging should help a lot with speed coming down the pipeline... Though, I think I might have to make its usage of cdtjs handle self-intersecting obstacles better.

@zalo zalo closed this Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants