import { Graph } from '../graph/graph'; import { Path } from '../types/algorithm-results'; import { ExtractionError } from '../types/errors'; import { Edge, Node } from '../types/graph'; import { Option } from '../types/option'; import { Result } from '../types/result'; /** * Direction for reachability analysis. * - 'forward': Follow outgoing edges (what can be reached from source) * - 'backward': Follow incoming edges (what can reach the source) */ export type ReachabilityDirection = "forward" | "backward"; /** * Finds the shortest path between two nodes in a graph. * * Uses BFS for unweighted graphs (all edges have weight 1) and Dijkstra's algorithm * for weighted graphs. Automatically selects the appropriate algorithm based on * edge weights. * * Time Complexity: * - BFS: O(V + E) for unweighted graphs * - Dijkstra: O((V + E) log V) for weighted graphs * * Space Complexity: O(V) * @param graph - The graph to search * @param sourceId - Starting node ID * @param targetId - Destination node ID * @returns Result containing Option or ExtractionError * - Ok(Some(path)) if path exists * - Ok(None) if no path exists * - Err(error) if inputs are invalid * @example * ```typescript * // Find citation path between papers * const result = findShortestPath(graph, 'P123', 'P456'); * if (result.ok && result.value.some) { * console.log('Path length:', result.value.value.nodes.length); * console.log('Total citations:', result.value.value.edges.length); * } * ``` */ export declare const findShortestPath: (graph: Graph, sourceId: string, targetId: string) => Result>, ExtractionError>; /** * Extracts a subgraph containing all nodes reachable from a source node. * * Performs a breadth-first traversal to find all nodes that can be reached * from the source within an optional maximum depth. Supports both forward * (following outgoing edges) and backward (following incoming edges) traversal. * * Time Complexity: O(V + E) where V, E are in the reachable subgraph * Space Complexity: O(V) * @param graph - The graph to extract from * @param sourceId - Starting node ID * @param direction - 'forward' for outgoing edges, 'backward' for incoming edges * @param maxDepth - Optional maximum depth to traverse (undefined = unlimited) * @returns Result containing extracted subgraph or ExtractionError * @example * ```typescript * // Extract all papers cited by P123 (forward) * const cited = extractReachabilitySubgraph(graph, 'P123', 'forward'); * * // Extract all papers that cite P123 (backward) * const citing = extractReachabilitySubgraph(graph, 'P123', 'backward'); * * // Extract citation network within 2 hops * const local = extractReachabilitySubgraph(graph, 'P123', 'forward', 2); * ``` */ export declare const extractReachabilitySubgraph: (graph: Graph, sourceId: string, direction: ReachabilityDirection, maxDepth?: number) => Result, ExtractionError>; //# sourceMappingURL=path.d.ts.map