fixup! clean up magic numbers, enable arbitrary gridding, add cache invalidatino

This commit is contained in:
Jan Petykiewicz 2026-03-27 23:29:36 -07:00
commit 457451d3b2
6 changed files with 15 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 101 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 90 KiB

Before After
Before After

View file

@ -19,7 +19,7 @@ def main() -> None:
danger_map.precompute([]) danger_map.precompute([])
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0) evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
context = AStarContext(evaluator, snap_size=1.0, bend_radii=[10.0]) context = AStarContext(evaluator, snap_size=1.0, bend_radii=[10.0], sbend_radii=[])
metrics = AStarMetrics() metrics = AStarMetrics()
pf = PathFinder(context, metrics) pf = PathFinder(context, metrics)
@ -40,7 +40,7 @@ def main() -> None:
print("Routing with custom collision model...") print("Routing with custom collision model...")
# Override bend_collision_type with a literal Polygon # Override bend_collision_type with a literal Polygon
context_custom = AStarContext(evaluator, snap_size=1.0, bend_radii=[10.0], bend_collision_type=custom_poly) context_custom = AStarContext(evaluator, snap_size=1.0, bend_radii=[10.0], bend_collision_type=custom_poly, sbend_radii=[])
metrics_custom = AStarMetrics() metrics_custom = AStarMetrics()
results_custom = PathFinder(context_custom, metrics_custom, use_tiered_strategy=False).route_all( results_custom = PathFinder(context_custom, metrics_custom, use_tiered_strategy=False).route_all(
{"custom_model": netlist["custom_bend"]}, {"custom_model": 2.0} {"custom_model": netlist["custom_bend"]}, {"custom_model": 2.0}

View file

@ -433,7 +433,10 @@ def process_move(
else: else:
gx, gy, go = parent_state gx, gy, go = parent_state
abs_key = (parent_state, move_class, params, net_width, context.config.bend_collision_type, snap_to_grid) coll_type = context.config.bend_collision_type
coll_key = id(coll_type) if isinstance(coll_type, shapely.geometry.Polygon) else coll_type
abs_key = (parent_state, move_class, params, net_width, coll_key, snap_to_grid)
if abs_key in context.move_cache_abs: if abs_key in context.move_cache_abs:
res = context.move_cache_abs[abs_key] res = context.move_cache_abs[abs_key]
move_radius = params[0] if move_class == 'B' else (params[1] if move_class == 'SB' else None) move_radius = params[0] if move_class == 'B' else (params[1] if move_class == 'SB' else None)
@ -448,8 +451,14 @@ def process_move(
# Trigger periodic cache eviction check (only on Absolute cache misses) # Trigger periodic cache eviction check (only on Absolute cache misses)
context.check_cache_eviction() context.check_cache_eviction()
# Template Cache Key (Relative to Port 0,0,Ori)
# We snap the parameters to ensure template re-use
snapped_params = params
if move_class == 'SB':
snapped_params = (snap_search_grid(params[0], snap), params[1])
self_dilation = context.cost_evaluator.collision_engine.clearance / 2.0 self_dilation = context.cost_evaluator.collision_engine.clearance / 2.0
rel_key = (base_ori, move_class, params, net_width, context.config.bend_collision_type, self_dilation, snap_to_grid) rel_key = (base_ori, move_class, snapped_params, net_width, coll_key, self_dilation, snap_to_grid)
cache_key = (gx, gy, go, move_type, net_width) cache_key = (gx, gy, go, move_type, net_width)
if cache_key in context.hard_collision_set: if cache_key in context.hard_collision_set:
@ -465,7 +474,7 @@ def process_move(
elif move_class == 'B': elif move_class == 'B':
res_rel = Bend90.generate(p0, params[0], net_width, params[1], collision_type=context.config.bend_collision_type, clip_margin=context.config.bend_clip_margin, dilation=self_dilation, snap_to_grid=snap_to_grid, snap_size=snap) res_rel = Bend90.generate(p0, params[0], net_width, params[1], collision_type=context.config.bend_collision_type, clip_margin=context.config.bend_clip_margin, dilation=self_dilation, snap_to_grid=snap_to_grid, snap_size=snap)
elif move_class == 'SB': elif move_class == 'SB':
res_rel = SBend.generate(p0, params[0], params[1], net_width, collision_type=context.config.bend_collision_type, clip_margin=context.config.bend_clip_margin, dilation=self_dilation, snap_to_grid=snap_to_grid, snap_size=snap) res_rel = SBend.generate(p0, snapped_params[0], snapped_params[1], net_width, collision_type=context.config.bend_collision_type, clip_margin=context.config.bend_clip_margin, dilation=self_dilation, snap_to_grid=snap_to_grid, snap_size=snap)
else: else:
return return
context.move_cache_rel[rel_key] = res_rel context.move_cache_rel[rel_key] = res_rel

View file

@ -152,8 +152,6 @@ class CostEvaluator:
else: # 90 or 270 degree rotation else: # 90 or 270 degree rotation
penalty += 1 * bp penalty += 1 * bp
p1 = penalty
# 2. Side Check (Entry half-plane) # 2. Side Check (Entry half-plane)
v_dx = tx - current.x v_dx = tx - current.x
v_dy = ty - current.y v_dy = ty - current.y
@ -163,8 +161,6 @@ class CostEvaluator:
if side_proj < -0.1 or (side_proj < self._min_radius and perp_dist > 0.1): if side_proj < -0.1 or (side_proj < self._min_radius and perp_dist > 0.1):
penalty += 2 * bp penalty += 2 * bp
p2 = penalty - p1
# 3. Traveling Away # 3. Traveling Away
# Optimization: avoid np.radians/cos/sin if current_ori is standard 0,90,180,270 # Optimization: avoid np.radians/cos/sin if current_ori is standard 0,90,180,270
if curr_ori == 0: c_cos, c_sin = 1.0, 0.0 if curr_ori == 0: c_cos, c_sin = 1.0, 0.0
@ -179,15 +175,11 @@ class CostEvaluator:
if move_proj < -0.1: if move_proj < -0.1:
penalty += 2 * bp penalty += 2 * bp
p3 = penalty - p1 - p2
# 4. Jog Alignment # 4. Jog Alignment
if diff < 0.1: if diff < 0.1:
if perp_dist > 0.1: if perp_dist > 0.1:
penalty += 2 * bp penalty += 2 * bp
p4 = penalty - p1 - p2 - p3
return self.greedy_h_weight * (dist + penalty) return self.greedy_h_weight * (dist + penalty)