Skip to content

bloqade.lanes.arch.path.PathFinder

← Module overview

classPathFindersource

bloqade.lanes.arch.path.PathFinder

class PathFinder(spec: ArchSpec)

Parameters

NameTypeDescription
specArchSpec

Attributes

NameTypeDefaultDescription
specArchSpecrequired
metricsMoveMetricCalculatorfield(init=False)
site_graphnx.PyDiGraphfield(init=False, default_factory=(nx.PyDiGraph))Graph representing all sites and edges as lanes.
physical_addresseslist[LocationAddress]field(init=False, default_factory=list)Map from graph node index to (zone_id, word_id, site_id) tuple.
physical_address_mapdict[LocationAddress, int]field(init=False, default_factory=dict)Map from (zone_id, word_id, site_id) tuple to graph node index.
end_points_cachedict[LaneAddress, tuple[LocationAddress, LocationAddress]]field(init=False, default_factory=dict)

methodextract_lanes_from_pathsource

bloqade.lanes.arch.path.PathFinder.extract_lanes_from_path

def extract_lanes_from_path(path: list[int]) -> tuple[LaneAddress, ...]

Given a path as node indices, extract the lane addresses.

Parameters

NameTypeDescription
pathlist[int]

Returns

tuple[LaneAddress, ...]

source

methodextract_locations_from_pathsource

bloqade.lanes.arch.path.PathFinder.extract_locations_from_path

Signature
def extract_locations_from_path(path: list[int]) -> tuple[LocationAddress, ...]

Given a path as node indices, extract the location addresses.

Parameters

NameTypeDescription
pathlist[int]

Returns

tuple[LocationAddress, ...]

source

methodget_lanesource

bloqade.lanes.arch.path.PathFinder.get_lane

Signature
def get_lane(start: LocationAddress, end: LocationAddress) -> LaneAddress | None

Get the LaneAddress connecting two LocationAddress sites.

Parameters

NameTypeDescription
startLocationAddress
endLocationAddress

Returns

LaneAddress | None

source

methodget_endpointssource

bloqade.lanes.arch.path.PathFinder.get_endpoints

def get_endpoints(lane: LaneAddress)

Get the start and end LocationAddress for a given LaneAddress.

Parameters

NameTypeDescription
laneLaneAddress
source

methodfind_pathsource

bloqade.lanes.arch.path.PathFinder.find_path

Signature
def find_path(start: LocationAddress, end: LocationAddress, occupied: frozenset[LocationAddress] = frozenset(), path_heuristic: Callable[[tuple[LaneAddress, ...], tuple[LocationAddress, ...]], float] = lambda _, __: 0.0, edge_weight: Callable[[LaneAddress], float] | None = None) -> tuple[tuple[LaneAddress, ...], tuple[LocationAddress, ...]] | None

Find a weighted shortest path from start to end.

Parameters

NameTypeDefaultDescription
startLocationAddressrequiredThe starting location.
endLocationAddressrequiredThe ending location.
occupiedfrozenset[LocationAddress]frozenset()Locations to exclude when searching for a path. If this excludes `start` or `end`, no path is returned.
path_heuristicCallable[[tuple[LaneAddress, ...], tuple[LocationAddress, ...]], float]lambda _, __: 0.0A tie-breaker over candidate shortest paths, evaluated on the candidate location sequence.
edge_weightCallable[[LaneAddress], float] | NoneNoneOptional edge weight function used for shortest-path costs. Defaults to `Metrics.get_lane_duration_us` when not provided.

Returns

(tuple[tuple[LaneAddress, ...], tuple[LocationAddress, ...]] | None, tuple[tuple[LaneAddress, ...], tuple[LocationAddress, ...]] | None)A tuple containing: - The selected path as `LaneAddress` values. - The same path as `LocationAddress` values (including start and end). Returns `None` when no valid path exists.

source