diff --git a/lib/adj.js b/lib/adj.js index ae269da..3663eb4 100644 --- a/lib/adj.js +++ b/lib/adj.js @@ -7,6 +7,14 @@ Object.defineProperty(exports, "__esModule", { var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); exports.default = adj; + +/** + * Constructs the adjacency list for an undirected unweighted connected + * loopless multigraph G given as a list of edges. + * + * @param {Iterable} edges The edges of G. + * @returns {Map} The adjacency list G. + */ function adj(edges) { var G = new Map(); var _iteratorNormalCompletion = true; @@ -44,4 +52,4 @@ function adj(edges) { return G; } -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9hZGouanMiXSwibmFtZXMiOlsiYWRqIiwiZWRnZXMiLCJHIiwiTWFwIiwidSIsInYiLCJoYXMiLCJzZXQiLCJnZXQiLCJwdXNoIl0sIm1hcHBpbmdzIjoiOzs7Ozs7OztrQkFDd0JBLEc7QUFBVCxTQUFTQSxHQUFULENBQWVDLEtBQWYsRUFBdUI7QUFDckMsS0FBTUMsSUFBSSxJQUFJQyxHQUFKLEVBQVY7QUFEcUM7QUFBQTtBQUFBOztBQUFBO0FBRXJDLHVCQUF5QkYsS0FBekIsOEhBQWlDO0FBQUE7O0FBQUE7O0FBQUEsT0FBbkJHLENBQW1CO0FBQUEsT0FBZkMsQ0FBZTs7QUFDaEMsT0FBSyxDQUFDSCxFQUFFSSxHQUFGLENBQU1GLENBQU4sQ0FBTixFQUFpQkYsR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W5jdGlvbiBhZGogKCBlZGdlcyApIHtcblx0Y29uc3QgRyA9IG5ldyBNYXAoKTtcblx0Zm9yICggY29uc3QgWyB1ICwgdiBdIG9mIGVkZ2VzICkge1xuXHRcdGlmICggIUcuaGFzKHUpICkgRy5zZXQodSwgW10pIDtcblx0XHRHLmdldCh1KS5wdXNoKHYpO1xuXHRcdGlmICggIUcuaGFzKHYpICkgRy5zZXQodiwgW10pIDtcblx0XHRHLmdldCh2KS5wdXNoKHUpO1xuXHR9XG5cdHJldHVybiBHO1xufVxuIl19 \ No newline at end of file diff --git a/lib/maxback/_contract.js b/lib/maxback/_contract.js index d96c623..ff7f4cb 100644 --- a/lib/maxback/_contract.js +++ b/lib/maxback/_contract.js @@ -7,31 +7,40 @@ exports.default = _contract; var _jsItertools = require('@aureooms/js-itertools'); +/** + * Given G and some ordering, computes the graph H obtained from G by + * contracting all edges between the last two vertices of the ordering. + * + * @param {Map} G + * @param {Array} ordering + * @returns {Map} + */ function _contract(G, ordering) { - var x = ordering[ordering.length - 2]; - var y = ordering[ordering.length - 1]; + var u = ordering[ordering.length - 2]; + var v = ordering[ordering.length - 1]; var H = new Map(); + // replace each edge xv by the edge xu, x != u ^ x != v var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = (0, _jsItertools.head)(ordering, -2)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var u = _step.value; + var x = _step.value; var n = []; - H.set(u, n); + H.set(x, n); var _iteratorNormalCompletion4 = true; var _didIteratorError4 = false; var _iteratorError4 = undefined; try { - for (var _iterator4 = G.get(u)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var _v2 = _step4.value; - n.push(_v2 === y ? x : _v2); + for (var _iterator4 = G.get(x)[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var y = _step4.value; + n.push(y === v ? u : y); } } catch (err) { _didIteratorError4 = true; @@ -64,16 +73,17 @@ function _contract(G, ordering) { } var nx = []; - H.set(x, nx); + H.set(u, nx); + // keep all edges ux with, x != v (x != u is implied because G is loopless) var _iteratorNormalCompletion2 = true; var _didIteratorError2 = false; var _iteratorError2 = undefined; try { - for (var _iterator2 = G.get(x)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var v = _step2.value; - if (v !== y) nx.push(v); - } + for (var _iterator2 = G.get(u)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var _x = _step2.value; + if (_x !== v) nx.push(_x); + } // replace each edge vx by the edge ux, x != u ^ x != v } catch (err) { _didIteratorError2 = true; _iteratorError2 = err; @@ -94,9 +104,9 @@ function _contract(G, ordering) { var _iteratorError3 = undefined; try { - for (var _iterator3 = G.get(y)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var _v = _step3.value; - if (_v !== x && _v !== y) nx.push(_v); + for (var _iterator3 = G.get(v)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var _x2 = _step3.value; + if (_x2 !== u && _x2 !== v) nx.push(_x2); } } catch (err) { _didIteratorError3 = true; @@ -115,4 +125,4 @@ function _contract(G, ordering) { return H; } -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYXhiYWNrL19jb250cmFjdC5qcyJdLCJuYW1lcyI6WyJfY29udHJhY3QiLCJHIiwib3JkZXJpbmciLCJ4IiwibGVuZ3RoIiwieSIsIkgiLCJNYXAiLCJ1IiwibiIsInNldCIsImdldCIsInYiLCJwdXNoIi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RoLCB4ICE9IHYgKHggIT0gdSBpcyBpbXBsaWVkIGJlY2F1c2UgRyBpcyBsb29wbGVzcylcblx0Zm9yICggY29uc3QgeCBvZiBHLmdldCh1KSApIGlmICggeCAhPT0gdiApIG54LnB1c2goeCk7XG5cdC8vIHJlcGxhY2UgZWFjaCBlZGdlIHZ4IGJ5IHRoZSBlZGdlIHV4LCB4ICE9IHUgXiB4ICE9IHZcblx0Zm9yICggY29uc3QgeCBvZiBHLmdldCh2KSApIGlmICggeCAhPT0gdSAmJiB4ICE9PSB2ICkgbngucHVzaCh4KTtcblx0cmV0dXJuIEg7XG5cbn1cbiJdfQ== \ No newline at end of file diff --git a/lib/maxback/_order.js b/lib/maxback/_order.js index a40d9fd..88e4f08 100644 --- a/lib/maxback/_order.js +++ b/lib/maxback/_order.js @@ -11,6 +11,13 @@ var _jsPairingHeap = require('@aureooms/js-pairing-heap'); var _marked = /*#__PURE__*/regeneratorRuntime.mark(_order); +/** + * Lists the vertices of an undirected unweighted connected loopless multigraph + * G in max-back order. + * + * @param {Map} G The adjacency list of G. + * @returns {Iterable} The vertices of G in max-back order. + */ function _order(G) { var heap, refs, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, v, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _, max, u, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, _v, ref; @@ -18,7 +25,7 @@ function _order(G) { while (1) { switch (_context.prev = _context.next) { case 0: - heap = new _jsPairingHeap.PairingHeap((0, _jsCompare.attr)(_jsCompare.decreasing, 'key')); + heap = new _jsPairingHeap.PairingHeap((0, _jsCompare.attr)(_jsCompare.decreasing, 'weight')); refs = new Map(); _iteratorNormalCompletion = true; _didIteratorError = false; @@ -28,7 +35,7 @@ function _order(G) { for (_iterator = G.keys()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { v = _step.value; - refs.set(v, heap.push({ key: 0, value: v })); + refs.set(v, heap.push({ weight: 0, vertex: v })); }_context.next = 13; break; @@ -77,9 +84,9 @@ function _order(G) { _ = _step2.value; max = heap.pop(); - u = max.value; + u = max.vertex; _context.next = 32; - return [u, max.key]; + return [u, max.weight]; case 32: refs.delete(u); @@ -108,11 +115,11 @@ function _order(G) { case 42: ref = refs.get(_v); - // max heap so decrease-key is used for + + // max heap so decrease-weight is used for + heap.decreasekey(ref, { - key: ref.value.key + 1, - value: ref.value.value + weight: ref.value.weight + 1, + vertex: ref.value.vertex }); case 44: @@ -200,4 +207,4 @@ function _order(G) { } }, _marked, this, [[5, 9, 13, 21], [14,, 16, 20], [24, 66, 70, 78], [36, 49, 53, 61], [54,, 56, 60], [71,, 73, 77]]); } -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYXhiYWNrL19vcmRlci5qcyJdLCJuYW1lcyI6WyJfb3JkZXIiLCJHIiwiaGVhcCIsInJlZnMiLCJNYXAiLCJrZXlzIiwidiIsInNldCIsInB1c2giLCJrZXkiLCJ2YWx1ZSIsIl8iLCJtYXgiLCJwb3AiLCJ1IiwiZGVsZXRlIiwiZ2V0IiwiaGFzIiwicmVmIiwiZGVjcmVhc2VrZXkiXSwibWFwcGluZ3MiOiI7Ozs7O2tCQUd5QkEsTTs7QUFIekI7O0FBQ0E7O21EQUV5QkEsTTs7QUFBVixTQUFVQSxNQUFWLENBQW1CQyxDQUFuQjtBQUFBOztBQUFBO0FBQUE7QUFBQTtBQUFBO0FBRVJDLFNBRlEsR0FFRCwrQkFBaUIsNENBQW1CLEtBQW5CLENBQWpCLENBRkM7QUFHUkMsU0FIUSxHQUdELElBQUlDLEdBQUosRUFIQztBQUFBO0FBQUE7QUFBQTtBQUFBOzs7QUFLZCxzQkFBaUJILEVBQUVJLElBQUYsRUFBakI7QUFBWUMsT0FBWjtBQUE0QkgsV0FBS0ksR0FBTCxDQUFTRCxDQUF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IG9mIEcgaW4gbWF4LWJhY2sgb3JkZXIuXG4gKi9cbmV4cG9ydCBkZWZhdWx0IGZ1bmN0aW9uKiBfb3JkZXIgKCBHICkge1xuXG5cdGNvbnN0IGhlYXAgPSBuZXcgUGFpcmluZ0hlYXAoIGF0dHIoIGRlY3JlYXNpbmcgLCAnd2VpZ2h0JyApICk7XG5cdGNvbnN0IHJlZnMgPSBuZXcgTWFwKCk7XG5cblx0Zm9yICggY29uc3QgdiBvZiBHLmtleXMoKSApIHJlZnMuc2V0KHYsIGhlYXAucHVzaCh7IHdlaWdodCA6IDAgLCB2ZXJ0ZXggOiB2IH0pKSA7XG5cblx0Zm9yICggY29uc3QgXyBvZiBHICkge1xuXG5cdFx0Y29uc3QgbWF4ID0gaGVhcC5wb3AoKSA7XG5cdFx0Y29uc3QgdSA9IG1heC52ZXJ0ZXggO1xuXHRcdHlpZWxkIFsgdSAsIG1heC53ZWlnaHQgXSA7XG5cdFx0cmVmcy5kZWxldGUodSk7XG5cblx0XHQvLyB1cGRhdGUga2V5c1xuXHRcdGZvciAoIGNvbnN0IHYgb2YgRy5nZXQodSkgKSB7XG5cdFx0XHRpZiAoIXJlZnMuaGFzKHYpKSBjb250aW51ZTtcblx0XHRcdGNvbnN0IHJlZiA9IHJlZnMuZ2V0KHYpO1xuXHRcdFx0Ly8gbWF4IGhlYXAgc28gZGVjcmVhc2Utd2VpZ2h0IGlzIHVzZWQgZm9yICtcblx0XHRcdGhlYXAuZGVjcmVhc2VrZXkocmVmLCB7XG5cdFx0XHRcdHdlaWdodCA6IHJlZi52YWx1ZS53ZWlnaHQgKyAxICxcblx0XHRcdFx0dmVydGV4IDogcmVmLnZhbHVlLnZlcnRleFxuXHRcdFx0fSApO1xuXHRcdH1cblxuXHR9XG5cbn1cbiJdfQ== \ No newline at end of file diff --git a/lib/maxback/_smallcuts.js b/lib/maxback/_smallcuts.js index 694bdde..0846fdb 100644 --- a/lib/maxback/_smallcuts.js +++ b/lib/maxback/_smallcuts.js @@ -22,6 +22,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de var _marked = /*#__PURE__*/regeneratorRuntime.mark(_smallcuts); +/** + * Yields the small cuts of undirected unweighted connected loopless multigraph G. + * At least one of them must be a minimum cut. + * + * @param {Map} G The adjacency list of G. + * @returns {Iterable} The small cuts of G. + */ function _smallcuts(G) { var H, id, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, v, ordering, _ordering, x, _ordering2, y, cutsize; @@ -78,15 +85,17 @@ function _smallcuts(G) { break; } - ordering = (0, _jsItertools.list)((0, _order3.default)(H)); + ordering = (0, _jsItertools.list)((0, _order3.default)(H)); // compute the max-back order + _ordering = _slicedToArray(ordering[ordering.length - 2], 1), x = _ordering[0]; _ordering2 = _slicedToArray(ordering[ordering.length - 1], 2), y = _ordering2[0], cutsize = _ordering2[1]; _context.next = 27; return [new Set(id.get(y)), cutsize]; case 27: + // yield a small cut with its size - id.set(x, id.get(x).concat(id.get(y))); + id.set(x, id.get(x).concat(id.get(y))); // associate the last vertex with the penultimate one H = (0, _contract3.default)(H, (0, _jsItertools.list)((0, _jsItertools.map)(function (_ref) { var _ref2 = _slicedToArray(_ref, 2), @@ -94,7 +103,7 @@ function _smallcuts(G) { _ = _ref2[1]; return u; - }, ordering))); + }, ordering))); // contract all edges between those two vertices _context.next = 21; break; @@ -106,4 +115,4 @@ function _smallcuts(G) { } }, _marked, this, [[5, 9, 13, 21], [14,, 16, 20]]); } -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYXhiYWNrL19zbWFsbGN1dHMuanMiXSwibmFtZXMiOlsiX3NtYWxsY3V0cyIsIkciLCJIIiwiaWQiLCJNYXAiLCJrZXlzIiwidiIsInNldCIsInNpemUiLCJvcmRlcmluZyIsImxlbmd0aCIsIngiLCJ5IiwiY3V0c2l6ZSIsIlNldCIsImdldCIsImNvbmNhdCIsInUiLCJf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SCwgbGlzdChtYXAoKFt1LF9dKSA9PiB1ICwgb3JkZXJpbmcpKSk7IC8vIGNvbnRyYWN0IGFsbCBlZGdlcyBiZXR3ZWVuIHRob3NlIHR3byB2ZXJ0aWNlc1xuXG5cdH1cblxufVxuIl19 \ No newline at end of file diff --git a/lib/maxback/maxback.js b/lib/maxback/maxback.js index 652b7e5..b686d5b 100644 --- a/lib/maxback/maxback.js +++ b/lib/maxback/maxback.js @@ -23,10 +23,10 @@ var _outgoingedges2 = _interopRequireDefault(_outgoingedges); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** - * Nagamochi-Ibaraki poly-time algorithm. + * Convenience wrapper around Nagamochi-Ibaraki poly-time algorithm. * - * @param edges List of edges of a undirected unweighted connected loopless multigraph G. - * @returns {Array} A minimum cut of G. + * @param {Iterable} edges List of edges of an undirected unweighted connected loopless multigraph G. + * @returns {Iterable} An iterable over the edges of a minimum cut of G. */ function maxback(edges) { var G = (0, _adj2.default)(edges); @@ -37,4 +37,4 @@ function maxback(edges) { return (0, _outgoingedges2.default)(G, U); } -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYXhiYWNrL21heGJhY2suanMiXSwibmFtZXMiOlsibWF4YmFjayIsImVkZ2VzIiwiRyIsIlUiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7O2tCQVV3QkEsTzs7QUFWeEI7Ozs7QUFDQTs7OztBQUNBOzs7Ozs7QUFFQTs7Ozs7O0FBTWUsU0FBU0EsT0FBVCxDQUFtQkMsS0FBbkIsRUFBMkI7QUFDekMsTUFBTUMsSUFBSSxtQkFBS0QsS0FBTCxDQUFWOztBQUR5QyxZQUUzQixrQkFBSUMsQ0FBSixDQUYyQjtBQUFBO0FBQUEsTUFFakNDLENBRmlDOztBQUd6QyxTQUFPLDZCQUFlRCxDQUFmLEVBQW1CQyxDQUFuQixDQUFQO0FBQ0EiLCJm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DQUFmLEVBQW1CQyxDQUFuQixDQUFQO0FBQ0EiLCJmaWxlIjoibWF4YmFjay5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBhZGogZnJvbSAnLi4vYWRqJztcbmltcG9ydCBtYiBmcm9tICcuL21iJztcbmltcG9ydCBvdXRnb2luZ2VkZ2VzIGZyb20gJy4uL291dGdvaW5nZWRnZXMnO1xuXG4vKipcbiAqIENvbnZlbmllbmNlIHdyYXBwZXIgYXJvdW5kIE5hZ2Ftb2NoaS1JYmFyYWtpIHBvbHktdGltZSBhbGdvcml0aG0uXG4gKlxuICogQHBhcmFtIHtJdGVyYWJsZX0gZWRnZXMgTGlzdCBvZiBlZGdlcyBvZiBhbiB1bmRpcmVjdGVkIHVud2VpZ2h0ZWQgY29ubmVjdGVkIGxvb3BsZXNzIG11bHRpZ3JhcGggRy5cbiAqIEByZXR1cm5zIHtJdGVyYWJsZX0gQW4gaXRlcmFibGUgb3ZlciB0aGUgZWRnZXMgb2YgYSBtaW5pbXVtIGN1dCBvZiBHLlxuICovXG5leHBvcnQgZGVmYXVsdCBmdW5jdGlvbiBtYXhiYWNrICggZWRnZXMgKSB7XG5cdGNvbnN0IEcgPSBhZGooIGVkZ2VzICkgO1xuXHRjb25zdCBbIFUgXSA9IG1iKCBHICkgO1xuXHRyZXR1cm4gb3V0Z29pbmdlZGdlcyggRyAsIFUgKSA7XG59XG4iXX0= \ No newline at end of file diff --git a/lib/maxback/mb.js b/lib/maxback/mb.js index 2c6decf..afcd5ca 100644 --- a/lib/maxback/mb.js +++ b/lib/maxback/mb.js @@ -1,7 +1,7 @@ 'use strict'; Object.defineProperty(exports, "__esModule", { - value: true + value: true }); exports.default = mb; @@ -15,7 +15,13 @@ var _smallcuts3 = _interopRequireDefault(_smallcuts2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +/** + * Nagamochi-Ibaraki poly-time algorithm. + * + * @param {Map} G The adjacency list of an undirected unweighted connected loopless multigraph G. + * @returns {Array} A pair [U,cutsize] reprensenting a minimum cut of G. + */ function mb(G) { - return (0, _jsItertools.min)((0, _jsCompare.attr)(_jsCompare.increasing, 1), (0, _smallcuts3.default)(G), undefined); + return (0, _jsItertools.min)((0, _jsCompare.attr)(_jsCompare.increasing, 1), (0, _smallcuts3.default)(G), undefined); } -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYXhiYWNrL21iLmpzIl0sIm5hbWVzIjpbIm1iIiwiRyIsInVuZGVmaW5lZCJdLCJtYXBwaW5ncyI6Ijs7Ozs7a0JBS3dCQSxFOztBQUx4Qjs7QUFDQTs7QUFFQTs7Ozs7O0FBRWUsU0FBU0EsRUFBVCxDQUFjQyxDQUFkLEVBQWtCO0FBQ2hDLFFBQU8sc0JBQUssNENBQW1CLENBQW5CLENBQUwsRUFBOEIseUJBQVdBLENBQVgsQ0FBOUIsRUFBOENDLFNBQTlDLENBQVA7QUFDQSIsImZpbGUiOiJtYi5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IG1pbiB9IGZyb20gJ0BhdXJlb29tcy9qcy1pdGVydG9vbHMnIDtcbmltcG9ydCB7IGF0dHIgLCBpbmNyZWFzaW5nIH0gZnJvbSAnQGF1cmVvb21zL2pzLWNvbXBhcmUnIDtcblxuaW1wb3J0IF9zbWFsbGN1dHMgZnJvbSAnLi9fc21hbGxjdXRzJyA7XG5cbmV4cG9ydCBkZWZhdWx0IGZ1bmN0aW9uIG1iICggRyApIHtcblx0cmV0dXJuIG1pbiggYXR0ciggaW5jcmVhc2luZyAsIDEgKSAsIF9zbWFsbGN1dHMoRykgLCB1bmRlZmluZWQgKSA7XG59XG4iXX0= \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tYXhiYWNrL21iLmpzIl0sIm5hbWVzIjpbIm1iIiwiRyIsInVuZGVmaW5lZCJdLCJtYXBwaW5ncyI6Ijs7Ozs7a0JBV3dCQSxFOztBQVh4Qjs7QUFDQTs7QUFFQTs7Ozs7O0FBRUE7Ozs7OztBQU1lLFNBQVNBLEVBQVQsQ0FBY0MsQ0FBZCxFQUFrQjtBQUNoQyxTQUFPLHNCQUFLLDRDQUFtQixDQUFuQixDQUFMLEVBQThCLHlCQUFXQSxDQUFYLENBQTlCLEVBQThDQyxTQUE5QyxDQUFQO0FBQ0EiLCJmaWxlIjoibWIuanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBtaW4gfSBmcm9tICdAYXVyZW9vbXMvanMtaXRlcnRvb2xzJyA7XG5pbXBvcnQgeyBhdHRyICwgaW5jcmVhc2luZyB9IGZyb20gJ0BhdXJlb29tcy9qcy1jb21wYXJlJyA7XG5cbmltcG9ydCBfc21hbGxjdXRzIGZyb20gJy4vX3NtYWxsY3V0cycgO1xuXG4vKipcbiAqIE5hZ2Ftb2NoaS1JYmFyYWtpIHBvbHktdGltZSBhbGdvcml0aG0uXG4gKlxuICogQHBhcmFtIHtNYXB9IEcgVGhlIGFkamFjZW5jeSBsaXN0IG9mIGFuIHVuZGlyZWN0ZWQgdW53ZWlnaHRlZCBjb25uZWN0ZWQgbG9vcGxlc3MgbXVsdGlncmFwaCBHLlxuICogQHJldHVybnMge0FycmF5fSBBIHBhaXIgPGNvZGU+W1UsY3V0c2l6ZV08L2NvZGU+IHJlcHJlbnNlbnRpbmcgYSBtaW5pbXVtIGN1dCBvZiBHLlxuICovXG5leHBvcnQgZGVmYXVsdCBmdW5jdGlvbiBtYiAoIEcgKSB7XG5cdHJldHVybiBtaW4oIGF0dHIoIGluY3JlYXNpbmcgLCAxICkgLCBfc21hbGxjdXRzKEcpICwgdW5kZWZpbmVkICkgO1xufVxuIl19 \ No newline at end of file diff --git a/lib/mincut.js b/lib/mincut.js index 6f70f7e..ce49621 100644 --- a/lib/mincut.js +++ b/lib/mincut.js @@ -10,5 +10,8 @@ var _maxback2 = _interopRequireDefault(_maxback); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +/** + * Default to the maxback algorithm. + */ exports.default = _maxback2.default; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9taW5jdXQuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEiLCJmaWxlIjoibWluY3V0LmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IG1heGJhY2sgZnJvbSAnLi9tYXhiYWNrJyA7XG5cbmV4cG9ydCBkZWZhdWx0IG1heGJhY2sgO1xuIl19 \ No newline at end of file +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9taW5jdXQuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUE7Ozs7OztBQUVBIiwiZmlsZSI6Im1pbmN1dC5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBtYXhiYWNrIGZyb20gJy4vbWF4YmFjaycgO1xuXG4vKipcbiAqIERlZmF1bHQgdG8gdGhlIG1heGJhY2sgYWxnb3JpdGhtLlxuICovXG5leHBvcnQgZGVmYXVsdCBtYXhiYWNrIDtcbiJdfQ== \ No newline at end of file diff --git a/lib/outgoingedges.js b/lib/outgoingedges.js index 7188389..929d8c1 100644 --- a/lib/outgoingedges.js +++ b/lib/outgoingedges.js @@ -1,137 +1,146 @@ "use strict"; Object.defineProperty(exports, "__esModule", { - value: true + value: true }); exports.default = outgoingedges; var _marked = /*#__PURE__*/regeneratorRuntime.mark(outgoingedges); +/** + * Yields all edges of an undirected unweighted connected loopless multigraph G + * that have one endpoint inside some vertex subset U and that have the other + * endpoint inside of V = V(G) \ U. + * + * @param {Map} G The input undirected unweighted connected loopless multigraph. + * @param {Set} U The subset of edges. + * @returns {Iterable} The edges of G going from U to V(G) \ U. + */ function outgoingedges(G, U) { - var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, u, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, v; - - return regeneratorRuntime.wrap(function outgoingedges$(_context) { - while (1) { - switch (_context.prev = _context.next) { - case 0: - _iteratorNormalCompletion = true; - _didIteratorError = false; - _iteratorError = undefined; - _context.prev = 3; - _iterator = U[Symbol.iterator](); - - case 5: - if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { - _context.next = 37; - break; - } - - u = _step.value; - _iteratorNormalCompletion2 = true; - _didIteratorError2 = false; - _iteratorError2 = undefined; - _context.prev = 10; - _iterator2 = G.get(u)[Symbol.iterator](); - - case 12: - if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { - _context.next = 20; - break; - } - - v = _step2.value; - - if (U.has(v)) { - _context.next = 17; - break; - } - - _context.next = 17; - return [u, v]; - - case 17: - _iteratorNormalCompletion2 = true; - _context.next = 12; - break; - - case 20: - _context.next = 26; - break; - - case 22: - _context.prev = 22; - _context.t0 = _context["catch"](10); - _didIteratorError2 = true; - _iteratorError2 = _context.t0; - - case 26: - _context.prev = 26; - _context.prev = 27; - - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); - } - - case 29: - _context.prev = 29; - - if (!_didIteratorError2) { - _context.next = 32; - break; - } - - throw _iteratorError2; - - case 32: - return _context.finish(29); - - case 33: - return _context.finish(26); - - case 34: - _iteratorNormalCompletion = true; - _context.next = 5; - break; - - case 37: - _context.next = 43; - break; - - case 39: - _context.prev = 39; - _context.t1 = _context["catch"](3); - _didIteratorError = true; - _iteratorError = _context.t1; - - case 43: - _context.prev = 43; - _context.prev = 44; - - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - - case 46: - _context.prev = 46; - - if (!_didIteratorError) { - _context.next = 49; - break; - } - - throw _iteratorError; - - case 49: - return _context.finish(46); - - case 50: - return _context.finish(43); - - case 51: - case "end": - return _context.stop(); - } - } - }, _marked, this, [[3, 39, 43, 51], [10, 22, 26, 34], [27,, 29, 33], [44,, 46, 50]]); + var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, u, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, v; + + return regeneratorRuntime.wrap(function outgoingedges$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _iteratorNormalCompletion = true; + _didIteratorError = false; + _iteratorError = undefined; + _context.prev = 3; + _iterator = U[Symbol.iterator](); + + case 5: + if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { + _context.next = 37; + break; + } + + u = _step.value; + _iteratorNormalCompletion2 = true; + _didIteratorError2 = false; + _iteratorError2 = undefined; + _context.prev = 10; + _iterator2 = G.get(u)[Symbol.iterator](); + + case 12: + if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { + _context.next = 20; + break; + } + + v = _step2.value; + + if (U.has(v)) { + _context.next = 17; + break; + } + + _context.next = 17; + return [u, v]; + + case 17: + _iteratorNormalCompletion2 = true; + _context.next = 12; + break; + + case 20: + _context.next = 26; + break; + + case 22: + _context.prev = 22; + _context.t0 = _context["catch"](10); + _didIteratorError2 = true; + _iteratorError2 = _context.t0; + + case 26: + _context.prev = 26; + _context.prev = 27; + + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + + case 29: + _context.prev = 29; + + if (!_didIteratorError2) { + _context.next = 32; + break; + } + + throw _iteratorError2; + + case 32: + return _context.finish(29); + + case 33: + return _context.finish(26); + + case 34: + _iteratorNormalCompletion = true; + _context.next = 5; + break; + + case 37: + _context.next = 43; + break; + + case 39: + _context.prev = 39; + _context.t1 = _context["catch"](3); + _didIteratorError = true; + _iteratorError = _context.t1; + + case 43: + _context.prev = 43; + _context.prev = 44; + + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + + case 46: + _context.prev = 46; + + if (!_didIteratorError) { + _context.next = 49; + break; + } + + throw _iteratorError; + + case 49: + return _context.finish(46); + + case 50: + return _context.finish(43); + + case 51: + case "end": + return _context.stop(); + } + } + }, _marked, this, [[3, 39, 43, 51], [10, 22, 26, 34], [27,, 29, 33], [44,, 46, 50]]); } -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9vdXRnb2luZ2VkZ2VzLmpzIl0sIm5hbWVzIjpbIm91dGdvaW5nZWRnZXMiLCJHIiwiVSIsInUiLCJnZXQiLCJ2IiwiaGFzIl0sIm1hcHBpbmdzIjoiOzs7OztrQkFBeUJBLGE7O21EQUFBQSxhOztBQUFWLFNBQVVBLGFBQVYsQ0FBMEJDLENBQTFCLEVBQThCQyxDQUE5QjtBQUFBOztBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQSxpQkFDR0EsQ0FESDs7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBOztBQUNGQyxNQURFO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQSxrQkFDd0JGLEVBQUVHLEdBQUYsQ0FBTUQsQ0FBTixDQUR4Qjs7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBOztBQUNtQkUsTUFEbkI7O0FBQUEsU0FDeUNILEVBQUVJLEdBQUYsQ0FBTUQsQ0FBTixDQUR6QztBQUFBO0FBQUE7QUFBQTs7QUFBQTtBQUFBLFlBQzBELENBQUVGLENBQUYsRUFBTUUsQ0FBTixDQUQxRDs7QUFBQTtBQUFBO0FBQUE7QUFBQTs7QUFBQTtBQUFBO0FBQUE7O0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTs7QUFBQTtBQUFBO0FBQUE7O0FBQUE7QUFBQTtBQUFBOztBQUFBO0FBQUE7O0FBQUE7QUFBQTtBQUFBO0FBQUE7O0FBQUE7O0FBQUE7QUFBQTs7QUFBQTtBQUFBOztBQUFBO0FBQUE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YXBoLlxuICogQHBhcmFtIHtTZXR9IFUgVGhlIHN1YnNldCBvZiBlZGdlcy5cbiAqIEByZXR1cm5zIHtJdGVyYWJsZX0gVGhlIGVkZ2VzIG9mIEcgZ29pbmcgZnJvbSBVIHRvIFYoRykgXFwgVS5cbiAqL1xuZXhwb3J0IGRlZmF1bHQgZnVuY3Rpb24qIG91dGdvaW5nZWRnZXMgKCBHICwgVSApIHtcblx0Zm9yICggY29uc3QgdSBvZiBVICkge1xuXHRcdGZvciAoIGNvbnN0IHYgb2YgRy5nZXQodSkgKSB7XG5cdFx0XHRpZiAoICFVLmhhcyh2KSApIHlpZWxkIFsgdSAsIHYgXSA7XG5cdFx0fVxuXHR9XG59XG4iXX0= \ No newline at end of file diff --git a/package.json b/package.json index f8df1c6..96b865c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "esdoc-inject-script-plugin": "^1.0.0", "esdoc-inject-style-plugin": "^1.0.0", "esdoc-standard-plugin": "^1.0.0", - "np": "^2.19.0", + "np": "^2.20.0", "nyc": "^11.4.1" }, "homepage": "https://aureooms.github.io/js-mincut", diff --git a/src/adj.js b/src/adj.js index a25b47c..5261cde 100644 --- a/src/adj.js +++ b/src/adj.js @@ -1,4 +1,11 @@ +/** + * Constructs the adjacency list for an undirected unweighted connected + * loopless multigraph G given as a list of edges. + * + * @param {Iterable} edges The edges of G. + * @returns {Map} The adjacency list G. + */ export default function adj ( edges ) { const G = new Map(); for ( const [ u , v ] of edges ) { diff --git a/src/maxback/_contract.js b/src/maxback/_contract.js index eb41fa8..466a0aa 100644 --- a/src/maxback/_contract.js +++ b/src/maxback/_contract.js @@ -1,22 +1,33 @@ import { head } from '@aureooms/js-itertools' ; +/** + * Given G and some ordering, computes the graph H obtained from G by + * contracting all edges between the last two vertices of the ordering. + * + * @param {Map} G + * @param {Array} ordering + * @returns {Map} + */ export default function _contract ( G, ordering ) { - const x = ordering[ordering.length-2]; - const y = ordering[ordering.length-1]; + const u = ordering[ordering.length-2]; + const v = ordering[ordering.length-1]; const H = new Map(); - for ( const u of head( ordering , -2 ) ) { + // replace each edge xv by the edge xu, x != u ^ x != v + for ( const x of head( ordering , -2 ) ) { const n = []; - H.set(u, n); - for ( const v of G.get(u) ) n.push(v === y ? x : v); + H.set(x, n); + for ( const y of G.get(x) ) n.push(y === v ? u : y); } const nx = []; - H.set(x,nx); - for ( const v of G.get(x) ) if ( v !== y ) nx.push(v); - for ( const v of G.get(y) ) if ( v !== x && v !== y ) nx.push(v); + H.set(u,nx); + // keep all edges ux with, x != v (x != u is implied because G is loopless) + for ( const x of G.get(u) ) if ( x !== v ) nx.push(x); + // replace each edge vx by the edge ux, x != u ^ x != v + for ( const x of G.get(v) ) if ( x !== u && x !== v ) nx.push(x); return H; } diff --git a/src/maxback/_order.js b/src/maxback/_order.js index 1ab2652..481ee9e 100644 --- a/src/maxback/_order.js +++ b/src/maxback/_order.js @@ -1,28 +1,35 @@ import { attr , decreasing } from '@aureooms/js-compare' ; import { PairingHeap } from '@aureooms/js-pairing-heap' ; +/** + * Lists the vertices of an undirected unweighted connected loopless multigraph + * G in max-back order. + * + * @param {Map} G The adjacency list of G. + * @returns {Iterable} The vertices of G in max-back order. + */ export default function* _order ( G ) { - const heap = new PairingHeap( attr( decreasing , 'key' ) ); + const heap = new PairingHeap( attr( decreasing , 'weight' ) ); const refs = new Map(); - for ( const v of G.keys() ) refs.set(v, heap.push({ key : 0 , value : v })) ; + for ( const v of G.keys() ) refs.set(v, heap.push({ weight : 0 , vertex : v })) ; for ( const _ of G ) { const max = heap.pop() ; - const u = max.value ; - yield [ u , max.key ] ; + const u = max.vertex ; + yield [ u , max.weight ] ; refs.delete(u); // update keys for ( const v of G.get(u) ) { if (!refs.has(v)) continue; const ref = refs.get(v); - // max heap so decrease-key is used for + + // max heap so decrease-weight is used for + heap.decreasekey(ref, { - key : ref.value.key + 1 , - value : ref.value.value + weight : ref.value.weight + 1 , + vertex : ref.value.vertex } ); } diff --git a/src/maxback/_smallcuts.js b/src/maxback/_smallcuts.js index ef47cf0..70a5de0 100644 --- a/src/maxback/_smallcuts.js +++ b/src/maxback/_smallcuts.js @@ -3,6 +3,13 @@ import { list , map , head , filter , chain } from '@aureooms/js-itertools' ; import _order from './_order' ; import _contract from './_contract' ; +/** + * Yields the small cuts of undirected unweighted connected loopless multigraph G. + * At least one of them must be a minimum cut. + * + * @param {Map} G The adjacency list of G. + * @returns {Iterable} The small cuts of G. + */ export default function* _smallcuts ( G ) { let H = G; @@ -11,15 +18,15 @@ export default function* _smallcuts ( G ) { while ( H.size >= 2 ) { - const ordering = list(_order(H)); + const ordering = list(_order(H)); // compute the max-back order const [ x ] = ordering[ordering.length-2]; const [ y , cutsize ] = ordering[ordering.length-1]; - yield [ new Set(id.get(y)) , cutsize ] ; + yield [ new Set(id.get(y)) , cutsize ] ; // yield a small cut with its size - id.set(x, id.get(x).concat(id.get(y))); + id.set(x, id.get(x).concat(id.get(y))); // associate the last vertex with the penultimate one - H = _contract(H, list(map(([u,_]) => u , ordering))); + H = _contract(H, list(map(([u,_]) => u , ordering))); // contract all edges between those two vertices } diff --git a/src/maxback/maxback.js b/src/maxback/maxback.js index b446ddf..36e1ef8 100644 --- a/src/maxback/maxback.js +++ b/src/maxback/maxback.js @@ -3,10 +3,10 @@ import mb from './mb'; import outgoingedges from '../outgoingedges'; /** - * Nagamochi-Ibaraki poly-time algorithm. + * Convenience wrapper around Nagamochi-Ibaraki poly-time algorithm. * - * @param edges List of edges of a undirected unweighted connected loopless multigraph G. - * @returns {Array} A minimum cut of G. + * @param {Iterable} edges List of edges of an undirected unweighted connected loopless multigraph G. + * @returns {Iterable} An iterable over the edges of a minimum cut of G. */ export default function maxback ( edges ) { const G = adj( edges ) ; diff --git a/src/maxback/mb.js b/src/maxback/mb.js index c5d1f94..da77301 100644 --- a/src/maxback/mb.js +++ b/src/maxback/mb.js @@ -3,6 +3,12 @@ import { attr , increasing } from '@aureooms/js-compare' ; import _smallcuts from './_smallcuts' ; +/** + * Nagamochi-Ibaraki poly-time algorithm. + * + * @param {Map} G The adjacency list of an undirected unweighted connected loopless multigraph G. + * @returns {Array} A pair [U,cutsize] reprensenting a minimum cut of G. + */ export default function mb ( G ) { return min( attr( increasing , 1 ) , _smallcuts(G) , undefined ) ; } diff --git a/src/mincut.js b/src/mincut.js index 3eb4276..658ad0a 100644 --- a/src/mincut.js +++ b/src/mincut.js @@ -1,3 +1,6 @@ import maxback from './maxback' ; +/** + * Default to the maxback algorithm. + */ export default maxback ; diff --git a/src/outgoingedges.js b/src/outgoingedges.js index 8cb80c2..262f4e8 100644 --- a/src/outgoingedges.js +++ b/src/outgoingedges.js @@ -1,3 +1,16 @@ +/** + * Yields all edges of an undirected unweighted connected loopless multigraph G + * that have one endpoint inside some vertex subset U and that have the other + * endpoint inside of V = V(G) \ U. + * + * @param {Map} G The input undirected unweighted connected loopless multigraph. + * @param {Set} U The subset of edges. + * @returns {Iterable} The edges of G going from U to V(G) \ U. + */ export default function* outgoingedges ( G , U ) { - for ( const u of U ) for ( const v of G.get(u) ) if ( !U.has(v) ) yield [ u , v ] ; + for ( const u of U ) { + for ( const v of G.get(u) ) { + if ( !U.has(v) ) yield [ u , v ] ; + } + } }