Add conflict tracing and pair-local repair
This commit is contained in:
parent
71e263c527
commit
42e46c67e0
1 changed files with 6981 additions and 142 deletions
|
|
@ -15,6 +15,7 @@ from inire import (
|
|||
RoutingOptions,
|
||||
RoutingProblem,
|
||||
RoutingResult,
|
||||
RoutingRunResult,
|
||||
SearchOptions,
|
||||
)
|
||||
from inire.geometry.collision import RoutingWorld
|
||||
|
|
@ -34,6 +35,7 @@ _OBJECTIVE_FIELDS = set(ObjectiveWeights.__dataclass_fields__)
|
|||
ScenarioOutcome = tuple[float, int, int, int]
|
||||
ScenarioRun = Callable[[], ScenarioOutcome]
|
||||
ScenarioSnapshotRun = Callable[[], "ScenarioSnapshot"]
|
||||
TraceScenarioRun = Callable[[], RoutingRunResult]
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
|
|
@ -79,6 +81,19 @@ def _make_snapshot(
|
|||
)
|
||||
|
||||
|
||||
def _make_run_result(
|
||||
results: dict[str, RoutingResult],
|
||||
pathfinder: PathFinder,
|
||||
) -> RoutingRunResult:
|
||||
return RoutingRunResult(
|
||||
results_by_net=results,
|
||||
metrics=pathfinder.metrics.snapshot(),
|
||||
expanded_nodes=tuple(pathfinder.accumulated_expanded_nodes),
|
||||
conflict_trace=tuple(pathfinder.conflict_trace),
|
||||
frontier_trace=tuple(pathfinder.frontier_trace),
|
||||
)
|
||||
|
||||
|
||||
def _sum_metrics(metrics_list: tuple[RouteMetrics, ...]) -> RouteMetrics:
|
||||
metric_names = RouteMetrics.__dataclass_fields__
|
||||
return RouteMetrics(
|
||||
|
|
@ -318,6 +333,24 @@ def run_example_05() -> ScenarioOutcome:
|
|||
return snapshot_example_05().as_outcome()
|
||||
|
||||
|
||||
def trace_example_05() -> RoutingRunResult:
|
||||
netlist = {
|
||||
"u_turn": (Port(50, 50, 0), Port(50, 70, 180)),
|
||||
"loop": (Port(100, 100, 90), Port(100, 80, 270)),
|
||||
"zig_zag": (Port(20, 150, 0), Port(180, 150, 0)),
|
||||
}
|
||||
widths = dict.fromkeys(netlist, 2.0)
|
||||
_, _, _, pathfinder = _build_routing_stack(
|
||||
bounds=(0, 0, 200, 200),
|
||||
netlist=netlist,
|
||||
widths=widths,
|
||||
evaluator_kwargs={"bend_penalty": 50.0},
|
||||
request_kwargs={"bend_radii": [20.0], "capture_conflict_trace": True, "capture_frontier_trace": True},
|
||||
)
|
||||
results = pathfinder.route_all()
|
||||
return _make_run_result(results, pathfinder)
|
||||
|
||||
|
||||
def snapshot_example_06() -> ScenarioSnapshot:
|
||||
bounds = (-20, -20, 170, 170)
|
||||
obstacles = [
|
||||
|
|
@ -391,6 +424,14 @@ def snapshot_example_07_no_warm_start() -> ScenarioSnapshot:
|
|||
)
|
||||
|
||||
|
||||
def trace_example_07() -> RoutingRunResult:
|
||||
return _trace_example_07_variant(warm_start_enabled=True)
|
||||
|
||||
|
||||
def trace_example_07_no_warm_start() -> RoutingRunResult:
|
||||
return _trace_example_07_variant(warm_start_enabled=False)
|
||||
|
||||
|
||||
def _snapshot_example_07_variant(
|
||||
name: str,
|
||||
*,
|
||||
|
|
@ -454,6 +495,68 @@ def _snapshot_example_07_variant(
|
|||
return _make_snapshot(name, results, t1 - t0, pathfinder.metrics.snapshot())
|
||||
|
||||
|
||||
def _trace_example_07_variant(
|
||||
*,
|
||||
warm_start_enabled: bool,
|
||||
) -> RoutingRunResult:
|
||||
bounds = (0, 0, 1000, 1000)
|
||||
obstacles = [
|
||||
box(450, 0, 550, 400),
|
||||
box(450, 600, 550, 1000),
|
||||
]
|
||||
num_nets = 10
|
||||
start_x = 50
|
||||
start_y_base = 500 - (num_nets * 10.0) / 2.0
|
||||
end_x = 950
|
||||
end_y_base = 100
|
||||
end_y_pitch = 800.0 / (num_nets - 1)
|
||||
|
||||
netlist = {}
|
||||
for index in range(num_nets):
|
||||
sy = int(round(start_y_base + index * 10.0))
|
||||
ey = int(round(end_y_base + index * end_y_pitch))
|
||||
netlist[f"net_{index:02d}"] = (Port(start_x, sy, 0), Port(end_x, ey, 0))
|
||||
widths = dict.fromkeys(netlist, 2.0)
|
||||
_, evaluator, metrics, pathfinder = _build_routing_stack(
|
||||
bounds=bounds,
|
||||
netlist=netlist,
|
||||
widths=widths,
|
||||
clearance=6.0,
|
||||
obstacles=obstacles,
|
||||
evaluator_kwargs={
|
||||
"greedy_h_weight": 1.5,
|
||||
"unit_length_cost": 0.1,
|
||||
"bend_penalty": 100.0,
|
||||
"sbend_penalty": 400.0,
|
||||
},
|
||||
request_kwargs={
|
||||
"node_limit": 2000000,
|
||||
"bend_radii": [50.0],
|
||||
"sbend_radii": [50.0],
|
||||
"bend_clip_margin": 10.0,
|
||||
"max_iterations": 15,
|
||||
"base_penalty": 100.0,
|
||||
"multiplier": 1.4,
|
||||
"net_order": "shortest",
|
||||
"capture_expanded": True,
|
||||
"capture_conflict_trace": True,
|
||||
"capture_frontier_trace": True,
|
||||
"shuffle_nets": True,
|
||||
"seed": 42,
|
||||
"warm_start_enabled": warm_start_enabled,
|
||||
},
|
||||
)
|
||||
|
||||
def iteration_callback(idx: int, current_results: dict[str, RoutingResult]) -> None:
|
||||
_ = current_results
|
||||
new_greedy = max(1.1, 1.5 - ((idx + 1) / 10.0) * 0.4)
|
||||
evaluator.greedy_h_weight = new_greedy
|
||||
metrics.reset_per_route()
|
||||
|
||||
results = pathfinder.route_all(iteration_callback=iteration_callback)
|
||||
return _make_run_result(results, pathfinder)
|
||||
|
||||
|
||||
def run_example_07() -> ScenarioOutcome:
|
||||
return snapshot_example_07().as_outcome()
|
||||
|
||||
|
|
@ -557,6 +660,15 @@ PERFORMANCE_SCENARIO_SNAPSHOTS: tuple[tuple[str, ScenarioSnapshotRun], ...] = (
|
|||
("example_07_large_scale_routing_no_warm_start", snapshot_example_07_no_warm_start),
|
||||
)
|
||||
|
||||
TRACE_SCENARIO_RUNS: tuple[tuple[str, TraceScenarioRun], ...] = (
|
||||
("example_05_orientation_stress", trace_example_05),
|
||||
("example_07_large_scale_routing", trace_example_07),
|
||||
)
|
||||
|
||||
TRACE_PERFORMANCE_SCENARIO_RUNS: tuple[tuple[str, TraceScenarioRun], ...] = (
|
||||
("example_07_large_scale_routing_no_warm_start", trace_example_07_no_warm_start),
|
||||
)
|
||||
|
||||
|
||||
def capture_all_scenario_snapshots() -> tuple[ScenarioSnapshot, ...]:
|
||||
return tuple(run() for _, run in SCENARIO_SNAPSHOTS)
|
||||
|
|
|
|||
Loading…
Reference in a new issue