clean up magic numbers, enable arbitrary gridding, add cache invalidatino
This commit is contained in:
parent
a77ae781a7
commit
519dd48131
19 changed files with 574 additions and 358 deletions
|
|
@ -1,8 +1,6 @@
|
|||
from shapely.geometry import Polygon
|
||||
|
||||
from inire.geometry.collision import CollisionEngine
|
||||
from inire.geometry.primitives import Port
|
||||
from inire.router.astar import AStarContext, AStarMetrics, route_astar
|
||||
from inire.router.astar import AStarContext, AStarMetrics
|
||||
from inire.router.cost import CostEvaluator
|
||||
from inire.router.danger_map import DangerMap
|
||||
from inire.router.pathfinder import PathFinder
|
||||
|
|
@ -13,43 +11,44 @@ def main() -> None:
|
|||
print("Running Example 01: Simple Route...")
|
||||
|
||||
# 1. Setup Environment
|
||||
# Define the routing area bounds (minx, miny, maxx, maxy)
|
||||
# We define a 100um x 100um routing area
|
||||
bounds = (0, 0, 100, 100)
|
||||
|
||||
|
||||
# Clearance of 2.0um between waveguides
|
||||
engine = CollisionEngine(clearance=2.0)
|
||||
|
||||
# Precompute DangerMap for heuristic speedup
|
||||
danger_map = DangerMap(bounds=bounds)
|
||||
danger_map.precompute([]) # No obstacles yet
|
||||
|
||||
# Add a simple rectangular obstacle
|
||||
obstacle = Polygon([(30, 20), (70, 20), (70, 40), (30, 40)])
|
||||
engine.add_static_obstacle(obstacle)
|
||||
|
||||
# Precompute the danger map (distance field) for heuristics
|
||||
danger_map.precompute([obstacle])
|
||||
|
||||
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
|
||||
# 2. Configure Router
|
||||
evaluator = CostEvaluator(engine, danger_map)
|
||||
context = AStarContext(evaluator, snap_size=1.0, bend_radii=[10.0])
|
||||
pf = PathFinder(context)
|
||||
metrics = AStarMetrics()
|
||||
pf = PathFinder(context, metrics)
|
||||
|
||||
# 2. Define Netlist
|
||||
# Route from (10, 10) to (90, 50)
|
||||
# The obstacle at y=20-40 blocks the direct path.
|
||||
# 3. Define Netlist
|
||||
# Start at (10, 50) pointing East (0 deg)
|
||||
# Target at (90, 50) pointing East (0 deg)
|
||||
netlist = {
|
||||
"simple_net": (Port(10, 10, 0), Port(90, 50, 0)),
|
||||
"net1": (Port(10, 50, 0), Port(90, 50, 0)),
|
||||
}
|
||||
net_widths = {"simple_net": 2.0}
|
||||
net_widths = {"net1": 2.0}
|
||||
|
||||
# 3. Route
|
||||
# 4. Route
|
||||
results = pf.route_all(netlist, net_widths)
|
||||
|
||||
# 4. Check Results
|
||||
if results["simple_net"].is_valid:
|
||||
# 5. Check Results
|
||||
res = results["net1"]
|
||||
if res.is_valid:
|
||||
print("Success! Route found.")
|
||||
print(f"Path collisions: {results['simple_net'].collisions}")
|
||||
print(f"Path collisions: {res.collisions}")
|
||||
else:
|
||||
print("Failed to route.")
|
||||
print("Failed to find route.")
|
||||
|
||||
# 5. Visualize
|
||||
fig, ax = plot_routing_results(results, [obstacle], bounds, netlist=netlist)
|
||||
# 6. Visualize
|
||||
# plot_routing_results takes a dict of RoutingResult objects
|
||||
fig, ax = plot_routing_results(results, [], bounds)
|
||||
fig.savefig("examples/01_simple_route.png")
|
||||
print("Saved plot to examples/01_simple_route.png")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue