lots more refactoring
This commit is contained in:
parent
941d3e01df
commit
bc218a416b
43 changed files with 1433 additions and 1694 deletions
|
|
@ -4,12 +4,10 @@ import heapq
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from inire.constants import TOLERANCE_LINEAR
|
||||
from inire.geometry.components import BendCollisionModel
|
||||
from inire.geometry.primitives import Port
|
||||
|
||||
from ._astar_moves import expand_moves as _expand_moves
|
||||
from ._astar_types import AStarContext, AStarMetrics, AStarNode as _AStarNode
|
||||
from .results import RouteMetrics
|
||||
from ._astar_types import AStarContext, AStarMetrics, AStarNode as _AStarNode, SearchRunConfig
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from inire.geometry.components import ComponentResult
|
||||
|
|
@ -29,21 +27,14 @@ def route_astar(
|
|||
target: Port,
|
||||
net_width: float,
|
||||
context: AStarContext,
|
||||
*,
|
||||
metrics: AStarMetrics | None = None,
|
||||
net_id: str = "default",
|
||||
bend_collision_type: BendCollisionModel | None = None,
|
||||
return_partial: bool = False,
|
||||
store_expanded: bool = False,
|
||||
skip_congestion: bool = False,
|
||||
max_cost: float | None = None,
|
||||
self_collision_check: bool = False,
|
||||
node_limit: int | None = None,
|
||||
config: SearchRunConfig,
|
||||
) -> list[ComponentResult] | None:
|
||||
if metrics is None:
|
||||
metrics = AStarMetrics()
|
||||
metrics.reset_per_route()
|
||||
search_options = context.options.search
|
||||
effective_bend_collision_type = bend_collision_type if bend_collision_type is not None else search_options.bend_collision_type
|
||||
|
||||
context.ensure_static_caches_current()
|
||||
context.cost_evaluator.set_target(target)
|
||||
|
|
@ -51,18 +42,21 @@ def route_astar(
|
|||
closed_set: dict[tuple[int, int, int], float] = {}
|
||||
congestion_cache: dict[tuple, int] = {}
|
||||
|
||||
start_node = _AStarNode(start, 0.0, context.cost_evaluator.h_manhattan(start, target))
|
||||
start_node = _AStarNode(
|
||||
start,
|
||||
0.0,
|
||||
context.cost_evaluator.h_manhattan(start, target, min_bend_radius=context.min_bend_radius),
|
||||
)
|
||||
heapq.heappush(open_set, start_node)
|
||||
best_node = start_node
|
||||
effective_node_limit = node_limit if node_limit is not None else search_options.node_limit
|
||||
nodes_expanded = 0
|
||||
|
||||
while open_set:
|
||||
if nodes_expanded >= effective_node_limit:
|
||||
return _reconstruct_path(best_node) if return_partial else None
|
||||
if nodes_expanded >= config.node_limit:
|
||||
return _reconstruct_path(best_node) if config.return_partial else None
|
||||
|
||||
current = heapq.heappop(open_set)
|
||||
if max_cost is not None and current.fh_cost[0] > max_cost:
|
||||
if config.max_cost is not None and current.fh_cost[0] > config.max_cost:
|
||||
metrics.pruned_cost += 1
|
||||
metrics.total_pruned_cost += 1
|
||||
continue
|
||||
|
|
@ -75,7 +69,7 @@ def route_astar(
|
|||
continue
|
||||
closed_set[state] = current.g_cost
|
||||
|
||||
if store_expanded:
|
||||
if config.store_expanded:
|
||||
metrics.last_expanded_nodes.append(state)
|
||||
|
||||
nodes_expanded += 1
|
||||
|
|
@ -95,18 +89,7 @@ def route_astar(
|
|||
context,
|
||||
metrics,
|
||||
congestion_cache,
|
||||
bend_collision_type=effective_bend_collision_type,
|
||||
max_cost=max_cost,
|
||||
skip_congestion=skip_congestion,
|
||||
self_collision_check=self_collision_check,
|
||||
config=config,
|
||||
)
|
||||
|
||||
return _reconstruct_path(best_node) if return_partial else None
|
||||
|
||||
|
||||
__all__ = [
|
||||
"AStarContext",
|
||||
"AStarMetrics",
|
||||
"RouteMetrics",
|
||||
"route_astar",
|
||||
]
|
||||
return _reconstruct_path(best_node) if config.return_partial else None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue