go to a tunable 5um grid
This commit is contained in:
parent
7b0dddfe45
commit
91256cbcf9
21 changed files with 222 additions and 233 deletions
|
|
@ -1,3 +1,5 @@
|
|||
from shapely.geometry import Polygon
|
||||
|
||||
from inire.geometry.collision import CollisionEngine
|
||||
from inire.geometry.primitives import Port
|
||||
from inire.router.astar import AStarRouter
|
||||
|
|
@ -8,63 +10,51 @@ from inire.utils.visualization import plot_routing_results
|
|||
|
||||
|
||||
def main() -> None:
|
||||
print("Running Example 03: Locked Paths (Incremental Routing - Bus Scenario)...")
|
||||
print("Running Example 03: Locked Paths...")
|
||||
|
||||
# 1. Setup Environment
|
||||
bounds = (0, 0, 120, 120)
|
||||
bounds = (0, 0, 100, 100)
|
||||
engine = CollisionEngine(clearance=2.0)
|
||||
danger_map = DangerMap(bounds=bounds)
|
||||
danger_map.precompute([]) # Start with empty space
|
||||
danger_map.precompute([])
|
||||
|
||||
evaluator = CostEvaluator(engine, danger_map, greedy_h_weight=1.2)
|
||||
router = AStarRouter(evaluator, node_limit=200000)
|
||||
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
|
||||
router = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0])
|
||||
pf = PathFinder(router, evaluator)
|
||||
|
||||
# 2. Phase 1: Route a "Bus" of 3 parallel nets
|
||||
# We give them a small jog to make the locked geometry more interesting
|
||||
netlist_p1 = {
|
||||
"bus_0": (Port(10, 40, 0), Port(110, 45, 0)),
|
||||
"bus_1": (Port(10, 50, 0), Port(110, 55, 0)),
|
||||
"bus_2": (Port(10, 60, 0), Port(110, 65, 0)),
|
||||
# 2. Add a 'Pre-routed' net and lock it
|
||||
# Net 'fixed' goes right through the middle
|
||||
fixed_start = Port(10, 50, 0)
|
||||
fixed_target = Port(90, 50, 0)
|
||||
|
||||
print("Routing initial net...")
|
||||
res_fixed = router.route(fixed_start, fixed_target, net_width=2.0)
|
||||
|
||||
if res_fixed:
|
||||
# 3. Lock this net! It now behaves like a static obstacle
|
||||
geoms = [comp.geometry[0] for comp in res_fixed]
|
||||
engine.add_path("locked_net", geoms)
|
||||
engine.lock_net("locked_net")
|
||||
print("Initial net locked as static obstacle.")
|
||||
|
||||
# Update danger map to reflect the new static obstacle
|
||||
danger_map.precompute(list(engine.static_geometries.values()))
|
||||
|
||||
# 4. Route a new net that must detour around the locked one
|
||||
netlist = {
|
||||
"detour_net": (Port(50, 10, 90), Port(50, 90, 90)),
|
||||
}
|
||||
print("Phase 1: Routing bus (3 nets)...")
|
||||
results_p1 = pf.route_all(netlist_p1, dict.fromkeys(netlist_p1, 2.0))
|
||||
net_widths = {"detour_net": 2.0}
|
||||
|
||||
# Lock all Phase 1 nets
|
||||
path_polys = []
|
||||
for nid, res in results_p1.items():
|
||||
if res.is_valid:
|
||||
print(f" Locking {nid}...")
|
||||
engine.lock_net(nid)
|
||||
path_polys.extend([p for comp in res.path for p in comp.geometry])
|
||||
else:
|
||||
print(f" Warning: {nid} failed to route correctly.")
|
||||
|
||||
# Update danger map with the newly locked geometry
|
||||
print("Updating DangerMap with locked paths...")
|
||||
danger_map.precompute(path_polys)
|
||||
|
||||
# 3. Phase 2: Route secondary nets that must navigate around the locked bus
|
||||
# These nets cross the bus vertically.
|
||||
netlist_p2 = {
|
||||
"cross_left": (Port(30, 10, 90), Port(30, 110, 90)),
|
||||
"cross_right": (Port(80, 110, 270), Port(80, 10, 270)), # Top to bottom
|
||||
}
|
||||
|
||||
print("Phase 2: Routing crossing nets around locked bus...")
|
||||
# We use a slightly different width for variety
|
||||
results_p2 = pf.route_all(netlist_p2, dict.fromkeys(netlist_p2, 1.5))
|
||||
|
||||
# 4. Check Results
|
||||
for nid, res in results_p2.items():
|
||||
status = "Success" if res.is_valid else "Failed"
|
||||
print(f" {nid:12}: {status}, collisions={res.collisions}")
|
||||
print("Routing detour net around locked path...")
|
||||
results = pf.route_all(netlist, net_widths)
|
||||
|
||||
# 5. Visualize
|
||||
all_results = {**results_p1, **results_p2}
|
||||
all_netlists = {**netlist_p1, **netlist_p2}
|
||||
|
||||
fig, ax = plot_routing_results(all_results, [], bounds, netlist=all_netlists)
|
||||
# Add the locked net back to results for display
|
||||
from inire.router.pathfinder import RoutingResult
|
||||
display_results = {**results, "locked_net": RoutingResult("locked_net", res_fixed or [], True, 0)}
|
||||
|
||||
fig, ax = plot_routing_results(display_results, list(engine.static_geometries.values()), bounds, netlist=netlist)
|
||||
fig.savefig("examples/03_locked_paths.png")
|
||||
print("Saved plot to examples/03_locked_paths.png")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue