From 2a18f032ca0f3dcd199beaaa2127b358cf9cb3b9 Mon Sep 17 00:00:00 2001 From: isk75 Date: Thu, 11 Oct 2018 16:11:57 +0300 Subject: [PATCH 1/2] edge sortrank --- lib/order/index.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/order/index.js b/lib/order/index.js index 9d3f3622..152a447b 100644 --- a/lib/order/index.js +++ b/lib/order/index.js @@ -71,9 +71,23 @@ function sweepLayerGraphs(layerGraphs, biasRight) { } function assignOrder(g, layering) { - _.forEach(layering, function(layer) { - _.forEach(layer, function(v, i) { - g.node(v).order = i; + var thisNode; + _.each(layering, function(layer, j) { + + layering[j] = _.sortBy(layer, function (v) { + + thisNode = g.node(v); + + if (thisNode.edgeLabel) { + return thisNode.edgeLabel.sortrank; + } else { + return thisNode.sortrank; + } + }); + + _.each(layering[j], function (v2, i) { + g.node(v2).order = i; }); }); } + From ce21f3818c436f0d7f9937556218c6d79be0032a Mon Sep 17 00:00:00 2001 From: isk75 Date: Tue, 16 Oct 2018 12:21:04 +0300 Subject: [PATCH 2/2] deep ordering --- lib/order/index.js | 52 +++++++++++++++++++++++----------------------- lib/version.js | 2 +- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/order/index.js b/lib/order/index.js index 152a447b..ee8f345e 100644 --- a/lib/order/index.js +++ b/lib/order/index.js @@ -1,13 +1,13 @@ "use strict"; var _ = require("../lodash"), - initOrder = require("./init-order"), - crossCount = require("./cross-count"), - sortSubgraph = require("./sort-subgraph"), - buildLayerGraph = require("./build-layer-graph"), - addSubgraphConstraints = require("./add-subgraph-constraints"), - Graph = require("../graphlib").Graph, - util = require("../util"); + initOrder = require("./init-order"), + crossCount = require("./cross-count"), + sortSubgraph = require("./sort-subgraph"), + buildLayerGraph = require("./build-layer-graph"), + addSubgraphConstraints = require("./add-subgraph-constraints"), + Graph = require("../graphlib").Graph, + util = require("../util"); module.exports = order; @@ -27,43 +27,43 @@ module.exports = order; * algorithm. */ function order(g) { - var maxRank = util.maxRank(g), + var bestCC = Number.POSITIVE_INFINITY, + best; + for (var j = 0; j < 4; j++) { + var maxRank = util.maxRank(g), downLayerGraphs = buildLayerGraphs(g, _.range(1, maxRank + 1), "inEdges"), upLayerGraphs = buildLayerGraphs(g, _.range(maxRank - 1, -1, -1), "outEdges"); - var layering = initOrder(g); - assignOrder(g, layering); - - var bestCC = Number.POSITIVE_INFINITY, - best; + var layering = initOrder(g); + assignOrder(g, layering); - for (var i = 0, lastBest = 0; lastBest < 4; ++i, ++lastBest) { - sweepLayerGraphs(i % 2 ? downLayerGraphs : upLayerGraphs, i % 4 >= 2); + for (var i = 0, lastBest = 0; lastBest < 4; ++i, ++lastBest) { + sweepLayerGraphs(i % 2 ? downLayerGraphs : upLayerGraphs, i % 4 >= 2); - layering = util.buildLayerMatrix(g); - var cc = crossCount(g, layering); - if (cc < bestCC) { - lastBest = 0; - best = _.cloneDeep(layering); - bestCC = cc; + layering = util.buildLayerMatrix(g); + var cc = crossCount(g, layering); + if (cc < bestCC) { + lastBest = 0; + best = _.cloneDeep(layering); + bestCC = cc; + } } } - assignOrder(g, best); } function buildLayerGraphs(g, ranks, relationship) { - return _.map(ranks, function(rank) { + return _.map(ranks, function (rank) { return buildLayerGraph(g, rank, relationship); }); } function sweepLayerGraphs(layerGraphs, biasRight) { var cg = new Graph(); - _.forEach(layerGraphs, function(lg) { + _.forEach(layerGraphs, function (lg) { var root = lg.graph().root; var sorted = sortSubgraph(lg, root, cg, biasRight); - _.forEach(sorted.vs, function(v, i) { + _.forEach(sorted.vs, function (v, i) { lg.node(v).order = i; }); addSubgraphConstraints(lg, cg, sorted.vs); @@ -72,7 +72,7 @@ function sweepLayerGraphs(layerGraphs, biasRight) { function assignOrder(g, layering) { var thisNode; - _.each(layering, function(layer, j) { + _.each(layering, function (layer, j) { layering[j] = _.sortBy(layer, function (v) { diff --git a/lib/version.js b/lib/version.js index dec155cb..c640f4e6 100644 --- a/lib/version.js +++ b/lib/version.js @@ -1 +1 @@ -module.exports = "0.8.3-pre"; +module.exports = "0.8.4-pre";