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,49 +11,34 @@ def main() -> None:
|
|||
print("Running Example 03: Locked Paths...")
|
||||
|
||||
# 1. Setup Environment
|
||||
bounds = (0, 0, 100, 100)
|
||||
bounds = (0, -50, 100, 50)
|
||||
engine = CollisionEngine(clearance=2.0)
|
||||
danger_map = DangerMap(bounds=bounds)
|
||||
danger_map.precompute([])
|
||||
|
||||
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
|
||||
evaluator = CostEvaluator(engine, danger_map)
|
||||
context = AStarContext(evaluator, snap_size=1.0, bend_radii=[10.0])
|
||||
metrics = AStarMetrics()
|
||||
pf = PathFinder(context, metrics)
|
||||
|
||||
# 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)
|
||||
|
||||
# 2. Route Net A and 'Lock' it
|
||||
# Net A is a straight path blocking the direct route for Net B
|
||||
print("Routing initial net...")
|
||||
res_fixed = route_astar(fixed_start, fixed_target, net_width=2.0, context=context, metrics=metrics)
|
||||
netlist_a = {"netA": (Port(10, 0, 0), Port(90, 0, 0))}
|
||||
results_a = pf.route_all(netlist_a, {"netA": 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)),
|
||||
}
|
||||
net_widths = {"detour_net": 2.0}
|
||||
# Locking prevents Net A from being removed or rerouted during NC iterations
|
||||
engine.lock_net("netA")
|
||||
print("Initial net locked as static obstacle.")
|
||||
|
||||
# 3. Route Net B (forced to detour)
|
||||
print("Routing detour net around locked path...")
|
||||
results = pf.route_all(netlist, net_widths)
|
||||
netlist_b = {"netB": (Port(50, -20, 90), Port(50, 20, 90))}
|
||||
results_b = pf.route_all(netlist_b, {"netB": 2.0})
|
||||
|
||||
# 5. Visualize
|
||||
# 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)
|
||||
# 4. Visualize
|
||||
results = {**results_a, **results_b}
|
||||
fig, ax = plot_routing_results(results, [], bounds)
|
||||
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