rework structure of everything
This commit is contained in:
parent
dcc4d6436c
commit
941d3e01df
64 changed files with 3819 additions and 3559 deletions
|
|
@ -1,59 +1,61 @@
|
|||
from shapely.geometry import Polygon
|
||||
|
||||
from inire.geometry.collision import CollisionEngine
|
||||
from inire import CongestionOptions, NetSpec, ObjectiveWeights, RoutingOptions, RoutingProblem, RoutingResult, SearchOptions, route
|
||||
from inire.geometry.primitives import Port
|
||||
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
|
||||
from inire.utils.visualization import plot_routing_results
|
||||
|
||||
|
||||
def _route_with_context(
|
||||
context: AStarContext,
|
||||
metrics: AStarMetrics,
|
||||
netlist: dict[str, tuple[Port, Port]],
|
||||
net_widths: dict[str, float],
|
||||
) -> dict[str, object]:
|
||||
return PathFinder(context, metrics, use_tiered_strategy=False).route_all(netlist, net_widths)
|
||||
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
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print("Running Example 08: Custom Bend Geometry...")
|
||||
|
||||
# 1. Setup Environment
|
||||
bounds = (0, 0, 150, 150)
|
||||
start = Port(20, 20, 0)
|
||||
target = Port(100, 100, 90)
|
||||
|
||||
# 2. Define Netlist
|
||||
netlist = {
|
||||
"custom_bend": (Port(20, 20, 0), Port(100, 100, 90)),
|
||||
}
|
||||
net_widths = {"custom_bend": 2.0}
|
||||
|
||||
def build_context(bend_collision_type: object = "arc") -> tuple[AStarContext, AStarMetrics]:
|
||||
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)
|
||||
return AStarContext(evaluator, bend_radii=[10.0], bend_collision_type=bend_collision_type, sbend_radii=[]), AStarMetrics()
|
||||
|
||||
# 3. Route with standard arc first
|
||||
print("Routing with standard arc...")
|
||||
context_std, metrics_std = build_context()
|
||||
results_std = _route_with_context(context_std, metrics_std, netlist, net_widths)
|
||||
results_std = _run_request(bounds, "arc", "custom_bend", start, target)
|
||||
|
||||
# 4. Define a custom Manhattan 90-degree bend proxy in bend-local coordinates.
|
||||
# The polygon origin is the bend center. It is mirrored for CW bends and
|
||||
# rotated with the bend orientation before being translated into place.
|
||||
custom_poly = Polygon([(0, -11), (11, -11), (11, 0), (9, 0), (9, -9), (0, -9)])
|
||||
|
||||
print("Routing with custom bend geometry...")
|
||||
context_custom, metrics_custom = build_context(custom_poly)
|
||||
results_custom = _route_with_context(context_custom, metrics_custom, {"custom_model": netlist["custom_bend"]}, {"custom_model": 2.0})
|
||||
results_custom = _run_request(bounds, custom_poly, "custom_model", start, target)
|
||||
|
||||
# 5. Visualize
|
||||
all_results = {**results_std, **results_custom}
|
||||
fig, ax = plot_routing_results(all_results, [], bounds, netlist=netlist)
|
||||
fig, _ax = plot_routing_results(
|
||||
all_results,
|
||||
[],
|
||||
bounds,
|
||||
netlist={
|
||||
"custom_bend": (start, target),
|
||||
"custom_model": (start, target),
|
||||
},
|
||||
)
|
||||
fig.savefig("examples/08_custom_bend_geometry.png")
|
||||
print("Saved plot to examples/08_custom_bend_geometry.png")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue