code: function order(g) {
    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;
  
    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;
      }
    }
  
    assignOrder(g, best);
  }
docs: /*
  Applies heuristics to minimize edge crossings in the graph and sets the best
  order solution as an order attribute on each node.
  
  Pre-conditions:
  
  1. Graph must be DAG
  2. Graph nodes must be objects with a "rank" attribute
  3. Graph edges must have the "weight" attribute
  
  Post-conditions:
  
  1. Graph nodes will have an "order" attribute based on the results of the
  algorithm.