consistency and speed

This commit is contained in:
Jan Petykiewicz 2026-03-09 02:26:27 -07:00
commit c9bb8d6469

View file

@ -74,31 +74,23 @@ class CostEvaluator:
_ = net_width # Unused
total_cost = length * self.unit_length_cost
# 1. Hard Collision & Boundary Check
# We buffer by the full clearance to ensure distance >= clearance
hard_dilation = self.collision_engine.clearance
for poly in geometry:
dilated_poly = poly.buffer(hard_dilation)
# Boundary Check: Physical edges must stay within design bounds
minx, miny, maxx, maxy = dilated_poly.bounds
if not (self.danger_map.is_within_bounds(minx, miny) and
self.danger_map.is_within_bounds(maxx, maxy)):
return 1e15 # Out of bounds is impossible
# 1. Boundary Check (Centerline based for compatibility)
if not self.danger_map.is_within_bounds(end_port.x, end_port.y):
return 1e15
if self.collision_engine.is_collision_prebuffered(dilated_poly, start_port=start_port, end_port=end_port):
return 1e15 # Impossible cost for hard collisions
# 2. Soft Collision check (Negotiated Congestion)
# We buffer by clearance/2 because both paths are buffered by clearance/2
soft_dilation = self.collision_engine.clearance / 2.0
# 2. Collision Check
for poly in geometry:
dilated_poly = poly.buffer(soft_dilation)
overlaps = self.collision_engine.count_congestion_prebuffered(dilated_poly, net_id)
if overlaps > 0:
# Hard Collision (Static obstacles)
if self.collision_engine.check_collision(
poly, net_id, buffer_mode="static", start_port=start_port, end_port=end_port
):
return 1e15
# Soft Collision (Negotiated Congestion)
overlaps = self.collision_engine.check_collision(poly, net_id, buffer_mode="congestion")
if isinstance(overlaps, int) and overlaps > 0:
total_cost += overlaps * self.congestion_penalty
# 3. Proximity cost from Danger Map
total_cost += self.g_proximity(end_port.x, end_port.y)
return total_cost