// Represents an edge from source to sink with capacity var Edge = function(source, sink, capacity) { this.source = source; this.sink = sink; this.capacity = capacity; }; // Main class to manage the network var Graph = function() { this.edges = {}; this.nodes = []; this.nodeMap = {}; // Add a node to the graph this.addNode = function(node) { this.nodes.push(node); this.nodeMap[node] = this.nodes.length-1; this.edges[node] = []; }; // Add an edge from source to sink with capacity this.addEdge = function(source, sink, capacity) { // Create the two edges = one being the reverse of the other this.edges[source].push(new Edge(source, sink, capacity)); this.edges[sink].push(new Edge(sink, source, capacity)); }; // Does edge from source to sink exist? this.edgeExists = function(source, sink) { if(this.edges[source] !== undefined) for(var i=0;iResult'); document.write(result);