[planner] try bends=2 before bends=(2, 4)
This commit is contained in:
parent
b6c222cdc2
commit
54c4cd9a4a
2 changed files with 108 additions and 11 deletions
|
|
@ -50,6 +50,7 @@ from .interface import (
|
|||
PreparedRouteResult,
|
||||
RoutePlanningError,
|
||||
RoutePortContext,
|
||||
route_error_is_fatal,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -908,6 +909,12 @@ class RoutingPlanner:
|
|||
|
||||
TRACE_INTO_MAX_BENDS: int = 4
|
||||
|
||||
def trace_into_bend_budgets(self, family: PrimitiveKind) -> tuple[int, ...]:
|
||||
"""Return staged trace_into bend budgets for the route rotation parity."""
|
||||
if family == 'bend':
|
||||
return tuple(budget for budget in (1, 3) if budget <= self.TRACE_INTO_MAX_BENDS)
|
||||
return tuple(budget for budget in (2, 4) if budget <= self.TRACE_INTO_MAX_BENDS)
|
||||
|
||||
def plan_leg(
|
||||
self,
|
||||
family: PrimitiveKind,
|
||||
|
|
@ -1197,17 +1204,30 @@ class RoutingPlanner:
|
|||
desired.rotation = port_dst.rotation - pi
|
||||
desired.ptype = out_ptype
|
||||
family, length, jog, ccw = self.trace_into_spec(context_src.port, desired)
|
||||
leg = self.plan_leg(
|
||||
family,
|
||||
context_src,
|
||||
length=length,
|
||||
jog=jog,
|
||||
ccw=ccw,
|
||||
plug_into=portspec_dst if plug_destination else None,
|
||||
constrain_jog=family == 'bend',
|
||||
max_bends=self.TRACE_INTO_MAX_BENDS,
|
||||
**(dict(kwargs) | {'out_ptype': out_ptype}),
|
||||
)
|
||||
leg = None
|
||||
last_error: Exception | None = None
|
||||
for max_bends in self.trace_into_bend_budgets(family):
|
||||
try:
|
||||
leg = self.plan_leg(
|
||||
family,
|
||||
context_src,
|
||||
length=length,
|
||||
jog=jog,
|
||||
ccw=ccw,
|
||||
plug_into=portspec_dst if plug_destination else None,
|
||||
constrain_jog=family == 'bend',
|
||||
max_bends=max_bends,
|
||||
**(dict(kwargs) | {'out_ptype': out_ptype}),
|
||||
)
|
||||
break
|
||||
except (BuildError, NotImplementedError) as err:
|
||||
if route_error_is_fatal(err):
|
||||
raise
|
||||
last_error = err
|
||||
if leg is None:
|
||||
if last_error is not None:
|
||||
raise last_error
|
||||
raise BuildError('No legal primitive offer for trace_into route')
|
||||
renames = ((thru, context_src.portspec),) if thru is not None else ()
|
||||
return self.prepared_result_from_legs(
|
||||
(leg,),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue