UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

50 lines 1.67 kB
/** * A* pathfinding algorithm * Finds the shortest path from start to goal using a heuristic function * * @param graph - The graph represented as an adjacency list * @param start - The starting node * @param goal - The goal node * @param heuristic - Heuristic function that estimates distance from node to goal * @returns Object containing the shortest path and its cost, or null if no path exists * * Time Complexity: O(E) with good heuristic, O(b^d) worst case * Space Complexity: O(V) */ export declare function astar<T>(graph: Map<T, Map<T, number>>, start: T, goal: T, heuristic: (node: T, goal: T) => number): { path: T[]; cost: number; } | null; /** * A* pathfinding with path reconstruction details * Returns detailed information about the search process */ export declare function astarWithDetails<T>(graph: Map<T, Map<T, number>>, start: T, goal: T, heuristic: (node: T, goal: T) => number): { path: T[] | null; cost: number; visited: Set<T>; gScores: Map<T, number>; fScores: Map<T, number>; }; /** * Common heuristic functions for A* */ export declare const heuristics: { /** * Manhattan distance heuristic for grid-based graphs */ manhattan: (a: [number, number], b: [number, number]) => number; /** * Euclidean distance heuristic */ euclidean: (a: [number, number], b: [number, number]) => number; /** * Chebyshev distance heuristic (diagonal movement allowed) */ chebyshev: (a: [number, number], b: [number, number]) => number; /** * Zero heuristic (makes A* behave like Dijkstra) */ zero: <T>(_a: T, _b: T) => number; }; //# sourceMappingURL=astar.d.ts.map