UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

53 lines 1.66 kB
/** * Ford-Fulkerson Algorithm for Maximum Flow * * Finds the maximum flow from source to sink in a flow network * using the method of augmenting paths. */ export interface FlowEdge { from: string; to: string; capacity: number; flow: number; } export interface FlowNetwork { nodes: Set<string>; edges: Map<string, Map<string, FlowEdge>>; } export interface MaxFlowResult { maxFlow: number; flowGraph: Map<string, Map<string, number>>; minCut?: { source: Set<string>; sink: Set<string>; edges: [string, string][]; }; } /** * Ford-Fulkerson algorithm using DFS for finding augmenting paths * * @param graph - Adjacency list representation with capacities * @param source - Source node * @param sink - Sink node * @returns Maximum flow value and flow graph * * Time Complexity: O(E * f) where f is the maximum flow * Space Complexity: O(V + E) */ export declare function fordFulkerson(graph: Map<string, Map<string, number>>, source: string, sink: string): MaxFlowResult; /** * Edmonds-Karp algorithm (Ford-Fulkerson with BFS) * More efficient implementation with better time complexity * * Time Complexity: O(V * E²) */ export declare function edmondsKarp(graph: Map<string, Map<string, number>>, source: string, sink: string): MaxFlowResult; /** * Utility function to create a flow network for bipartite matching */ export declare function createBipartiteFlowNetwork(leftNodes: string[], rightNodes: string[], edges: [string, string][]): { graph: Map<string, Map<string, number>>; source: string; sink: string; }; //# sourceMappingURL=ford-fulkerson.d.ts.map