inire/examples/02_congestion_resolution.py

44 lines
1.5 KiB
Python
Raw Normal View History

2026-03-30 15:32:29 -07:00
from inire import CongestionOptions, NetSpec, ObjectiveWeights, Port, RoutingOptions, RoutingProblem, SearchOptions, route
2026-03-08 14:40:36 -07:00
from inire.utils.visualization import plot_routing_results
def main() -> None:
2026-03-08 23:03:07 -07:00
print("Running Example 02: Congestion Resolution (Triple Crossing)...")
2026-03-08 14:40:36 -07:00
bounds = (0, 0, 100, 100)
netlist = {
"horizontal": (Port(10, 50, 0), Port(90, 50, 0)),
2026-03-08 23:03:07 -07:00
"vertical_up": (Port(45, 10, 90), Port(45, 90, 90)),
"vertical_down": (Port(55, 90, 270), Port(55, 10, 270)),
2026-03-08 14:40:36 -07:00
}
2026-03-30 15:32:29 -07:00
problem = RoutingProblem(
bounds=bounds,
nets=tuple(NetSpec(net_id, start, target, width=2.0) for net_id, (start, target) in netlist.items()),
)
options = RoutingOptions(
search=SearchOptions(
bend_radii=(10.0,),
sbend_radii=(10.0,),
greedy_h_weight=1.5,
),
objective=ObjectiveWeights(
2026-03-30 23:40:29 -07:00
bend_penalty=50.0,
sbend_penalty=150.0,
2026-03-30 15:32:29 -07:00
),
congestion=CongestionOptions(base_penalty=1000.0),
)
2026-03-08 14:40:36 -07:00
2026-03-30 15:32:29 -07:00
run = route(problem, options=options)
all_valid = all(result.is_valid for result in run.results_by_net.values())
2026-03-08 14:40:36 -07:00
if all_valid:
2026-03-08 23:03:07 -07:00
print("Success! Congestion resolved for all nets.")
2026-03-08 14:40:36 -07:00
else:
print("Failed to resolve congestion for some nets.")
2026-03-08 14:40:36 -07:00
2026-03-30 15:32:29 -07:00
fig, _ax = plot_routing_results(run.results_by_net, [], bounds, netlist=netlist)
2026-03-08 23:34:18 -07:00
fig.savefig("examples/02_congestion_resolution.png")
print("Saved plot to examples/02_congestion_resolution.png")
2026-03-08 14:40:36 -07:00
if __name__ == "__main__":
main()