2026-03-10 21:55:54 -07:00
|
|
|
from shapely.geometry import Polygon
|
2026-03-11 09:37:54 -07:00
|
|
|
|
2026-03-30 15:32:29 -07:00
|
|
|
from inire import CongestionOptions, NetSpec, ObjectiveWeights, RoutingOptions, RoutingProblem, RoutingResult, SearchOptions, route
|
2026-03-10 21:55:54 -07:00
|
|
|
from inire.geometry.primitives import Port
|
|
|
|
|
from inire.utils.visualization import plot_routing_results
|
|
|
|
|
|
|
|
|
|
|
2026-03-30 15:32:29 -07:00
|
|
|
def _run_request(
|
|
|
|
|
bounds: tuple[float, float, float, float],
|
|
|
|
|
bend_collision_type: object,
|
|
|
|
|
net_id: str,
|
|
|
|
|
start: Port,
|
|
|
|
|
target: Port,
|
|
|
|
|
) -> dict[str, RoutingResult]:
|
|
|
|
|
problem = RoutingProblem(
|
|
|
|
|
bounds=bounds,
|
|
|
|
|
nets=(NetSpec(net_id, start, target, width=2.0),),
|
|
|
|
|
)
|
|
|
|
|
options = RoutingOptions(
|
|
|
|
|
search=SearchOptions(
|
|
|
|
|
bend_radii=(10.0,),
|
|
|
|
|
bend_collision_type=bend_collision_type,
|
|
|
|
|
sbend_radii=(),
|
|
|
|
|
),
|
|
|
|
|
objective=ObjectiveWeights(
|
|
|
|
|
bend_penalty=50.0,
|
|
|
|
|
sbend_penalty=150.0,
|
|
|
|
|
),
|
|
|
|
|
congestion=CongestionOptions(use_tiered_strategy=False),
|
|
|
|
|
)
|
|
|
|
|
return route(problem, options=options).results_by_net
|
2026-03-29 18:27:03 -07:00
|
|
|
|
|
|
|
|
|
2026-03-11 09:37:54 -07:00
|
|
|
def main() -> None:
|
|
|
|
|
print("Running Example 08: Custom Bend Geometry...")
|
|
|
|
|
|
2026-03-10 21:55:54 -07:00
|
|
|
bounds = (0, 0, 150, 150)
|
2026-03-30 15:32:29 -07:00
|
|
|
start = Port(20, 20, 0)
|
|
|
|
|
target = Port(100, 100, 90)
|
2026-03-10 21:55:54 -07:00
|
|
|
|
2026-03-11 09:37:54 -07:00
|
|
|
print("Routing with standard arc...")
|
2026-03-30 15:32:29 -07:00
|
|
|
results_std = _run_request(bounds, "arc", "custom_bend", start, target)
|
2026-03-10 21:55:54 -07:00
|
|
|
|
2026-03-29 18:27:03 -07:00
|
|
|
custom_poly = Polygon([(0, -11), (11, -11), (11, 0), (9, 0), (9, -9), (0, -9)])
|
2026-03-27 23:29:36 -07:00
|
|
|
|
2026-03-29 18:27:03 -07:00
|
|
|
print("Routing with custom bend geometry...")
|
2026-03-30 15:32:29 -07:00
|
|
|
results_custom = _run_request(bounds, custom_poly, "custom_model", start, target)
|
2026-03-10 21:55:54 -07:00
|
|
|
|
2026-03-11 09:37:54 -07:00
|
|
|
all_results = {**results_std, **results_custom}
|
2026-03-30 15:32:29 -07:00
|
|
|
fig, _ax = plot_routing_results(
|
|
|
|
|
all_results,
|
|
|
|
|
[],
|
|
|
|
|
bounds,
|
|
|
|
|
netlist={
|
|
|
|
|
"custom_bend": (start, target),
|
|
|
|
|
"custom_model": (start, target),
|
|
|
|
|
},
|
|
|
|
|
)
|
2026-03-10 21:55:54 -07:00
|
|
|
fig.savefig("examples/08_custom_bend_geometry.png")
|
|
|
|
|
print("Saved plot to examples/08_custom_bend_geometry.png")
|
|
|
|
|
|
2026-03-11 09:37:54 -07:00
|
|
|
|
2026-03-10 21:55:54 -07:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|