@graphty/algorithms
Version:
Graph algorithms library for browser environments implemented in TypeScript
59 lines • 1.91 kB
TypeScript
import type { Graph } from "../core/graph.js";
/**
* 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][];
};
}
/**
* 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;
};
/**
* Ford-Fulkerson algorithm using DFS for finding augmenting paths
*
* @param graph - Adjacency list representation with capacities - accepts Graph class or Map
* @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: Graph, source: string, sink: string): MaxFlowResult;
/**
* Edmonds-Karp algorithm (Ford-Fulkerson with BFS)
* More efficient implementation with better time complexity
*
* @param graph - Adjacency list representation with capacities - accepts Graph class or Map
* @param source - Source node
* @param sink - Sink node
* @returns Maximum flow value and flow graph
*
* Time Complexity: O(V * E²)
*/
export declare function edmondsKarp(graph: Graph | Map<string, Map<string, number>>, source: string, sink: string): MaxFlowResult;
//# sourceMappingURL=ford-fulkerson.d.ts.map