inire/examples/03_locked_paths.py

47 lines
1.6 KiB
Python
Raw Normal View History

2026-03-08 14:40:36 -07:00
from inire.geometry.collision import CollisionEngine
from inire.geometry.primitives import Port
from inire.router.astar import AStarContext, AStarMetrics
2026-03-08 14:40:36 -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-11 09:37:54 -07:00
print("Running Example 03: Locked Paths...")
2026-03-08 14:40:36 -07:00
# 1. Setup Environment
bounds = (0, -50, 100, 50)
2026-03-08 14:40:36 -07:00
engine = CollisionEngine(clearance=2.0)
danger_map = DangerMap(bounds=bounds)
2026-03-11 09:37:54 -07:00
danger_map.precompute([])
2026-03-08 14:40:36 -07:00
evaluator = CostEvaluator(engine, danger_map)
context = AStarContext(evaluator, snap_size=1.0, bend_radii=[10.0])
metrics = AStarMetrics()
pf = PathFinder(context, metrics)
2026-03-08 14:40:36 -07:00
# 2. Route Net A and 'Lock' it
# Net A is a straight path blocking the direct route for Net B
2026-03-11 09:37:54 -07:00
print("Routing initial net...")
netlist_a = {"netA": (Port(10, 0, 0), Port(90, 0, 0))}
results_a = pf.route_all(netlist_a, {"netA": 2.0})
2026-03-11 09:37:54 -07:00
# Locking prevents Net A from being removed or rerouted during NC iterations
engine.lock_net("netA")
print("Initial net locked as static obstacle.")
2026-03-08 14:40:36 -07:00
# 3. Route Net B (forced to detour)
2026-03-11 09:37:54 -07:00
print("Routing detour net around locked path...")
netlist_b = {"netB": (Port(50, -20, 90), Port(50, 20, 90))}
results_b = pf.route_all(netlist_b, {"netB": 2.0})
2026-03-08 14:40:36 -07:00
# 4. Visualize
results = {**results_a, **results_b}
fig, ax = plot_routing_results(results, [], bounds)
2026-03-08 23:34:18 -07:00
fig.savefig("examples/03_locked_paths.png")
print("Saved plot to examples/03_locked_paths.png")
2026-03-08 14:40:36 -07:00
if __name__ == "__main__":
main()