UNPKG

@cedoor/nfa

Version:

TypeScript implementation of some network flow algorithms.

43 lines (42 loc) 1.73 kB
import Graph from "./dataStructures/graph"; /** * Retrieves the path from a node of the graph to the source node * using the predecessors map. If there is a cycle return the cycle path. * Time complexity: O(n). * @param {Map<number, number>} The predecessor nodes. * @param {number} The node to start from. * @returns {number[]} The path from a node to the source node or a cycle path. */ export declare function retrievePath(predecessors: Map<number, number>, nodeId: number): number[]; /** * Converts a graph in a residual graph, in which the new arc flow * represent the residual capacity. * Time complexity: O(m). * @param {Graph} The original graph. * @returns {Graph} The residual graph. */ export declare function getResidualGraph(graph: Graph): Graph; /** * Returns the arc minimum residual capacity of the path. * Time complexity: O(n). * @param {Graph} Graph containing the path. * @param {number[]} The path of the nodes. * @returns {number} The minimum capacity. */ export declare function getResidualCapacity(graph: Graph, path: number[]): number; /** * Augments the path in the graph updating the flow of the arcs. * Time complexity: O(n). * @param {Graph} The graph containing the path. * @param {number[]} The path of the nodes. * @param {number} The flow to send in the path. */ export declare function sendFlow(graph: Graph, path: number[], flow: number): void; /** * Convert the residual graph in an optimal graph in which the * residual capacity is converted in flow. * Time complexity: O(m). * @param {Graph} The graph to update. * @returns {Graph} The optimal graph. */ export declare function getOptimalGraph(graph: Graph): Graph;