further performance improvements

This commit is contained in:
Jan Petykiewicz 2026-03-09 22:16:34 -07:00
commit c36bce9978

View file

@ -39,6 +39,7 @@ class CostEvaluator:
unit_length_cost: float = 1.0,
greedy_h_weight: float = 1.1,
congestion_penalty: float = 10000.0,
bend_penalty: float = 50.0,
) -> None:
"""
Initialize the Cost Evaluator.
@ -49,6 +50,7 @@ class CostEvaluator:
unit_length_cost: Cost multiplier per micrometer of path length.
greedy_h_weight: Heuristic weighting (A* greedy factor).
congestion_penalty: Multiplier for path overlaps in negotiated congestion.
bend_penalty: Base cost for 90-degree bends.
"""
self.collision_engine = collision_engine
self.danger_map = danger_map
@ -56,6 +58,7 @@ class CostEvaluator:
unit_length_cost=unit_length_cost,
greedy_h_weight=greedy_h_weight,
congestion_penalty=congestion_penalty,
bend_penalty=bend_penalty,
)
# Use config values
@ -63,6 +66,7 @@ class CostEvaluator:
self.greedy_h_weight = self.config.greedy_h_weight
self.congestion_penalty = self.config.congestion_penalty
def g_proximity(self, x: float, y: float) -> float:
"""
Get proximity cost from the Danger Map.
@ -86,14 +90,21 @@ class CostEvaluator:
Returns:
Heuristic cost estimate.
"""
dist = abs(current.x - target.x) + abs(current.y - target.y)
dx = abs(current.x - target.x)
dy = abs(current.y - target.y)
dist = dx + dy
# Orientation penalty if not aligned with target entry
# If we need to turn, the cost is at least min_bend_radius * pi/2
# But we also need to account for the physical distance required for the turn.
penalty = 0.0
if current.orientation != target.orientation:
penalty += 50.0 # Arbitrary high cost for mismatch
# 90-degree turn cost: radius 10 -> ~15.7 um + penalty
penalty += 15.7 + self.config.bend_penalty
# Add 1.5 multiplier for greediness (faster search)
return 1.5 * (dist + penalty)
return self.greedy_h_weight * (dist + penalty)
def evaluate_move(
self,
@ -104,6 +115,7 @@ class CostEvaluator:
start_port: Port | None = None,
length: float = 0.0,
dilated_geometry: list[Polygon] | None = None,
skip_static: bool = False,
) -> float:
"""
Calculate the cost of a single move (Straight, Bend, SBend).
@ -116,6 +128,7 @@ class CostEvaluator:
start_port: Port at the start of the move.
length: Physical path length of the move.
dilated_geometry: Pre-calculated dilated polygons.
skip_static: If True, bypass static collision checks (e.g. if already done).
Returns:
Total cost of the move, or 1e15 if invalid.
@ -131,11 +144,12 @@ class CostEvaluator:
for i, poly in enumerate(geometry):
dil_poly = dilated_geometry[i] if dilated_geometry else None
# Hard Collision (Static obstacles)
if self.collision_engine.check_collision(
poly, net_id, buffer_mode='static', start_port=start_port, end_port=end_port,
dilated_geometry=dil_poly
):
return 1e15
if not skip_static:
if self.collision_engine.check_collision(
poly, net_id, buffer_mode='static', start_port=start_port, end_port=end_port,
dilated_geometry=dil_poly
):
return 1e15
# Soft Collision (Negotiated Congestion)
overlaps = self.collision_engine.check_collision(