initial pass on examples
This commit is contained in:
parent
07d079846b
commit
82aaf066e2
19 changed files with 600 additions and 238 deletions
54
examples/02_congestion_resolution.py
Normal file
54
examples/02_congestion_resolution.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
from inire.geometry.collision import CollisionEngine
|
||||
from inire.geometry.primitives import Port
|
||||
from inire.router.astar import AStarRouter
|
||||
from inire.router.cost import CostEvaluator
|
||||
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 02: Congestion Resolution (Crossing)...")
|
||||
|
||||
# 1. Setup Environment (Open space)
|
||||
bounds = (0, 0, 100, 100)
|
||||
engine = CollisionEngine(clearance=2.0)
|
||||
danger_map = DangerMap(bounds=bounds)
|
||||
danger_map.precompute([])
|
||||
|
||||
evaluator = CostEvaluator(engine, danger_map)
|
||||
router = AStarRouter(evaluator)
|
||||
pf = PathFinder(router, evaluator)
|
||||
|
||||
# 2. Define Netlist
|
||||
# Two nets that MUST cross.
|
||||
# Since crossings are illegal in single-layer routing, one net must detour around the other.
|
||||
netlist = {
|
||||
"horizontal": (Port(10, 50, 0), Port(90, 50, 0)),
|
||||
"vertical": (Port(50, 10, 90), Port(50, 90, 90)),
|
||||
}
|
||||
net_widths = {"horizontal": 2.0, "vertical": 2.0}
|
||||
|
||||
# 3. Route with Negotiated Congestion
|
||||
# We increase the base penalty to encourage faster divergence
|
||||
pf.base_congestion_penalty = 500.0
|
||||
results = pf.route_all(netlist, net_widths)
|
||||
|
||||
# 4. Check Results
|
||||
all_valid = all(r.is_valid for r in results.values())
|
||||
if all_valid:
|
||||
print("Success! Congestion resolved (one net detoured).")
|
||||
else:
|
||||
print("Some nets failed or have collisions.")
|
||||
for nid, res in results.items():
|
||||
print(f" {nid}: valid={res.is_valid}, collisions={res.collisions}")
|
||||
|
||||
# 5. Visualize
|
||||
fig, ax = plot_routing_results(results, [], bounds)
|
||||
fig.savefig("examples/congestion.png")
|
||||
print("Saved plot to examples/congestion.png")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue