2026-03-08 20:18:53 -07:00
|
|
|
from inire.geometry.collision import CollisionEngine
|
|
|
|
|
from inire.geometry.primitives import Port
|
2026-03-21 22:50:45 -07:00
|
|
|
from inire.router.astar import AStarContext, route_astar
|
2026-03-08 20:18:53 -07:00
|
|
|
from inire.router.cost import CostEvaluator
|
|
|
|
|
from inire.router.danger_map import DangerMap
|
|
|
|
|
from inire.router.pathfinder import PathFinder
|
|
|
|
|
from inire.utils.visualization import plot_routing_results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None:
|
2026-03-21 22:50:45 -07:00
|
|
|
print("Running Example 04: SBends and Radii Strategy...")
|
2026-03-08 20:18:53 -07:00
|
|
|
|
|
|
|
|
# 1. Setup Environment
|
2026-03-08 22:02:07 -07:00
|
|
|
bounds = (0, 0, 100, 100)
|
2026-03-08 20:18:53 -07:00
|
|
|
engine = CollisionEngine(clearance=2.0)
|
|
|
|
|
danger_map = DangerMap(bounds=bounds)
|
2026-03-08 22:02:07 -07:00
|
|
|
danger_map.precompute([])
|
|
|
|
|
|
2026-03-21 22:50:45 -07:00
|
|
|
evaluator = CostEvaluator(engine, danger_map, bend_penalty=200.0, sbend_penalty=400.0)
|
|
|
|
|
|
|
|
|
|
# Define a custom router with multiple SBend radii and specific offsets
|
|
|
|
|
context = AStarContext(
|
2026-03-08 20:18:53 -07:00
|
|
|
evaluator,
|
2026-03-11 09:37:54 -07:00
|
|
|
snap_size=1.0,
|
2026-03-21 22:50:45 -07:00
|
|
|
bend_radii=[20.0, 50.0],
|
|
|
|
|
sbend_radii=[5.0, 10.0, 50.0],
|
|
|
|
|
sbend_offsets=[2.0, 5.0, 10.0, 20.0, 50.0]
|
2026-03-08 20:18:53 -07:00
|
|
|
)
|
2026-03-21 22:50:45 -07:00
|
|
|
pf = PathFinder(context)
|
2026-03-08 22:02:07 -07:00
|
|
|
|
2026-03-21 22:50:45 -07:00
|
|
|
# 2. Define Netlist
|
|
|
|
|
# High-density parallel nets with varying offsets
|
|
|
|
|
netlist = {}
|
|
|
|
|
for i in range(10):
|
|
|
|
|
# Starts at x=50, y=50+i*10. Targets at x=450, y=60+i*10.
|
|
|
|
|
# This forces small vertical jogs (SBends)
|
|
|
|
|
netlist[f"net_{i}"] = (Port(50, 50 + i * 10, 0), Port(450, 55 + i * 10, 0))
|
|
|
|
|
|
|
|
|
|
net_widths = {nid: 2.0 for nid in netlist}
|
2026-03-08 22:02:07 -07:00
|
|
|
|
2026-03-21 22:50:45 -07:00
|
|
|
# 3. Route
|
|
|
|
|
print(f"Routing {len(netlist)} nets with custom SBend strategy...")
|
|
|
|
|
results = pf.route_all(netlist, net_widths, shuffle_nets=True)
|
2026-03-08 20:18:53 -07:00
|
|
|
|
2026-03-21 22:50:45 -07:00
|
|
|
# 4. Visualize
|
2026-03-08 22:13:10 -07:00
|
|
|
fig, ax = plot_routing_results(results, [], bounds, netlist=netlist)
|
2026-03-08 23:34:18 -07:00
|
|
|
fig.savefig("examples/04_sbends_and_radii.png")
|
|
|
|
|
print("Saved plot to examples/04_sbends_and_radii.png")
|
2026-03-08 20:18:53 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|