fp-search-algorithms
Version:
Functional Programming Style Search Algorithms and Unordered Containers
81 lines (80 loc) • 4.21 kB
TypeScript
/**
* Generator function that lazily iterates through each visit of an A* search.
* If you want just the found path and totalCost to the solution, use `aStarAssoc`
*
* Each yield is an object `{ cost: number; path: T[] }`
*
* Notes:
* * The first yield will be the initialState with a cost of 0
* * Specific states may be visited multiple time, but through different costs and paths
* * If the solved state is found, that will be the final yield, otherwise the final yield will happen once all possible states are visited
* * Generator `return` value (at `done: true`) will be the found solution or undefined
*
* @category AStar
* @param getNextStates - a function to generate list of neighboring states with associated transition costs given the current state
* @param estimateRemainingCost - a heuristic function to determine remaining cost
* @param determineIfFound - a function to determine if solution found
* @param initial - initial state
*/
export declare const generateAStarAssoc: <T>(getNextStates: (state: T) => [state: T, cost: number][], estimateRemainingCost: (state: T) => number, determineIfFound: (state: T) => boolean, initial: T) => Generator<{
cost: number;
path: T[];
}, {
cost: number;
path: T[];
} | undefined>;
/**
* Generator function that lazily iterates through each visit of an A* search.
* If you want just the found path and totalCost to the solution, use `aStar`
*
* Each yield is an object `{ cast: number; path: T[] }`
*
* Notes:
* * The first yield will be the initialState with a cost of 0
* * Specific states may be visited multiple time, but through different costs and paths
* * If the solved state is found, that will be the final yield, otherwise the final yield will happen once all possible states are visited
* * The return value is the total cost and path, or undefined if path to solved state is not possible
*
* @category AStar
* @param getNextStates - a function to generate list of neighboring states given the current state
* @param getCost - a function to generate transition costs between neighboring states
* @param estimateRemainingCost - a heuristic function to determine remaining cost
* @param determineIfFound - a function to determine if solution found
* @param initial - initial state
*/
export declare const generateAStar: <T>(getNextStates: (state: T) => T[], getCost: (from: T, to: T) => number, estimateRemainingCost: (state: T) => number, determineIfFound: (state: T) => boolean, initial: T) => Generator<{
cost: number;
path: T[];
}, {
cost: number;
path: T[];
} | undefined>;
/**
* Performs a best-first search using the A* search algorithm
*
* @category AStar
* @param getNextStates - a function to generate list of neighboring states with associated transition costs given the current state
* @param estimateRemainingCost - a heuristic function to determine remaining cost
* @param determineIfFound - a function to determine if solution found
* @param initial - initial state
* @returns an object with `totalCost` and the `path` with costs between states, or `undefined` if no path found
*/
export declare const aStarAssoc: <T>(getNextStates: (state: T) => [state: T, cost: number][], estimateRemainingCost: (state: T) => number, determineIfFound: (state: T) => boolean, initial: T) => {
cost: number;
path: T[];
} | undefined;
/**
* Performs a best-first search using the A* search algorithm
*
* @category AStar
* @param getNextStates - a function to generate list of neighboring states given the current state
* @param getCost - a function to generate transition costs between neighboring states
* @param estimateRemainingCost - a heuristic function to determine remaining cost
* @param determineIfFound - a function to determine if solution found
* @param initial - initial state
* @returns an object with `totalCost` and the `path` with costs between states, or `undefined` if no path found
*/
export declare const aStar: <T>(getNextStates: (state: T) => T[], getCost: (from: T, to: T) => number, estimateRemainingCost: (state: T) => number, determineIfFound: (state: T) => boolean, initial: T) => {
cost: number;
path: T[];
} | undefined;