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,4 +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
|
||||
|
|
@ -7,60 +8,47 @@ from inire.router.danger_map import DangerMap
|
|||
from inire.router.pathfinder import PathFinder
|
||||
from inire.utils.visualization import plot_routing_results
|
||||
|
||||
def main() -> None:
|
||||
print("Running Example 08: Custom Bend Geometry Models...")
|
||||
|
||||
def main() -> None:
|
||||
print("Running Example 08: Custom Bend Geometry...")
|
||||
|
||||
# 1. Setup Environment
|
||||
bounds = (0, 0, 150, 150)
|
||||
engine = CollisionEngine(clearance=2.0)
|
||||
|
||||
# Static obstacle to force specific bend paths
|
||||
obstacle = Polygon([(60, 40), (90, 40), (90, 110), (60, 110)])
|
||||
engine.add_static_obstacle(obstacle)
|
||||
|
||||
danger_map = DangerMap(bounds=bounds)
|
||||
danger_map.precompute([obstacle])
|
||||
evaluator = CostEvaluator(engine, danger_map)
|
||||
danger_map.precompute([])
|
||||
|
||||
# We will route three nets, each with a DIFFERENT collision model
|
||||
# To do this cleanly with the current architecture, we'll use one router
|
||||
# but change its config per route call (or use tiered escalation in PathFinder).
|
||||
# Since AStarRouter.route now accepts bend_collision_type, we can do it directly.
|
||||
|
||||
router = AStarRouter(evaluator)
|
||||
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. Define Netlist
|
||||
netlist = {
|
||||
"model_arc": (Port(10, 130, 0), Port(130, 100, -90)),
|
||||
"model_bbox": (Port(10, 80, 0), Port(130, 50, -90)),
|
||||
"model_clipped": (Port(10, 30, 0), Port(130, 10, -90)),
|
||||
"custom_bend": (Port(20, 20, 0), Port(100, 100, 90)),
|
||||
}
|
||||
net_widths = {nid: 2.0 for nid in netlist}
|
||||
net_widths = {"custom_bend": 2.0}
|
||||
|
||||
# Manual routing to specify different models per net
|
||||
results = {}
|
||||
|
||||
print("Routing with 'arc' model...")
|
||||
results["model_arc"] = pf.router.route(netlist["model_arc"][0], netlist["model_arc"][1], 2.0,
|
||||
net_id="model_arc", bend_collision_type="arc")
|
||||
|
||||
print("Routing with 'bbox' model...")
|
||||
results["model_bbox"] = pf.router.route(netlist["model_bbox"][0], netlist["model_bbox"][1], 2.0,
|
||||
net_id="model_bbox", bend_collision_type="bbox")
|
||||
|
||||
print("Routing with 'clipped_bbox' model...")
|
||||
results["model_clipped"] = pf.router.route(netlist["model_clipped"][0], netlist["model_clipped"][1], 2.0,
|
||||
net_id="model_clipped", bend_collision_type="clipped_bbox")
|
||||
# 3. Route with standard arc first
|
||||
print("Routing with standard arc...")
|
||||
results_std = pf.route_all(netlist, net_widths)
|
||||
|
||||
# Wrap in RoutingResult for visualization
|
||||
from inire.router.pathfinder import RoutingResult
|
||||
final_results = {
|
||||
nid: RoutingResult(nid, path if path else [], path is not None, 0)
|
||||
for nid, path in results.items()
|
||||
}
|
||||
# 4. Define a custom 'trapezoid' bend model
|
||||
# (Just for demonstration - we override the collision model during search)
|
||||
custom_poly = Polygon([(0, 0), (20, 0), (20, 20), (0, 20)]) # Oversized box
|
||||
|
||||
print("Routing with custom collision model...")
|
||||
# Override bend_collision_type with a literal Polygon
|
||||
router_custom = AStarRouter(evaluator, snap_size=1.0, straight_lengths=[1.0, 5.0, 25.0], bend_radii=[10.0], bend_collision_type=custom_poly)
|
||||
results_custom = PathFinder(router_custom, evaluator, use_tiered_strategy=False).route_all(
|
||||
{"custom_model": netlist["custom_bend"]}, {"custom_model": 2.0}
|
||||
)
|
||||
|
||||
fig, ax = plot_routing_results(final_results, [obstacle], bounds, netlist=netlist)
|
||||
# 5. Visualize
|
||||
all_results = {**results_std, **results_custom}
|
||||
fig, ax = plot_routing_results(all_results, [], bounds, netlist=netlist)
|
||||
fig.savefig("examples/08_custom_bend_geometry.png")
|
||||
print("Saved plot to examples/08_custom_bend_geometry.png")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue