examples work

This commit is contained in:
jan 2026-03-10 21:55:54 -07:00
commit 7b0dddfe45

View file

@ -40,6 +40,7 @@ class CostEvaluator:
greedy_h_weight: float = 1.1,
congestion_penalty: float = 10000.0,
bend_penalty: float = 50.0,
sbend_penalty: float = 150.0,
) -> None:
"""
Initialize the Cost Evaluator.
@ -51,6 +52,7 @@ class CostEvaluator:
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.
sbend_penalty: Base cost for parametric S-bends.
"""
self.collision_engine = collision_engine
self.danger_map = danger_map
@ -59,6 +61,7 @@ class CostEvaluator:
greedy_h_weight=greedy_h_weight,
congestion_penalty=congestion_penalty,
bend_penalty=bend_penalty,
sbend_penalty=sbend_penalty,
)
# Use config values
@ -102,8 +105,7 @@ class CostEvaluator:
# 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(
@ -116,6 +118,7 @@ class CostEvaluator:
length: float = 0.0,
dilated_geometry: list[Polygon] | None = None,
skip_static: bool = False,
penalty: float = 0.0,
) -> float:
"""
Calculate the cost of a single move (Straight, Bend, SBend).
@ -129,12 +132,13 @@ class CostEvaluator:
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).
penalty: Fixed cost penalty for the move type (bend, sbend).
Returns:
Total cost of the move, or 1e15 if invalid.
"""
_ = net_width # Unused
total_cost = length * self.unit_length_cost
total_cost = length * self.unit_length_cost + penalty
# 1. Boundary Check
if not self.danger_map.is_within_bounds(end_port.x, end_port.y):