Skip to content

Hex router: prefer open-space candidates when backtracking equal-length paths #6

Description

@jamesbowman

Problem

HexBoard.hex_route() performs a breadth-first search, then reconstructs the route by taking the first neighboring cell whose distance is n - 1. When several equally short predecessors exist, the fixed direction order makes the selected geometry arbitrary and dependent on which terminal is passed as the source.

This appeared while routing the four td2f serial signals. Routing DTR from GPIO12 to the header selected a shortest path that blocked a later signal. Calling the same route with its endpoints reversed selected another equally short DTR path and allowed DTR, RX, TX, and RTS all to route. Copper is electrically directionless, so argument order should ideally have less influence on route quality.

Proposed heuristic

During backtracking, collect all neighboring cells whose distance is n - 1 and rank them by:

  1. Greater local clearance, initially the number of unblocked cells among the six hex neighbors.
  2. Optionally, distance from existing copper and keepouts using a clearance/distance field.
  3. Continuing in the current direction to avoid unnecessary turns.
  4. A stable coordinate tie-breaker so builds remain deterministic.

The clearance score must use the original board blockage map (self.blocked[layer]). The local blocked array used by the breadth-first search has been mutated to mark every visited cell and cannot measure physical openness.

Tests / acceptance criteria

  • Add a small synthetic grid test with multiple equal-length paths and verify that the route chooses the higher-clearance path.
  • Verify deterministic output across repeated builds.
  • Check whether swapping source and target produces equivalent or at least equally useful geometry.
  • Use td2f's DTR/RX/TX/RTS routing as a regression case; ideally all four should route without requiring the DTR call to be reversed.
  • Confirm existing board output invariants where applicable.

This is still a local greedy heuristic; global congestion handling or rip-up/reroute would be a separate enhancement.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions