/*
Runs the order phase with the specified `graph, `maxSweeps`, and
`debugLevel`. If `maxSweeps` is not specified we use `DEFAULT_MAX_SWEEPS`.
If `debugLevel` is not set we assume 0.
function order(g, maxSweeps) {
  if (arguments.length < 2) {
    maxSweeps = DEFAULT_MAX_SWEEPS;
  }

  var layerGraphs = initLayerGraphs(g);
  // TODO: remove this when we add back support for ordering clusters
  layerGraphs.forEach(function(lg) {
    lg = lg.filterNodes(function(u) { return !g.children(u).length; });
  });

  initOrder(g);

  util.log(2, 'Order phase start cross count: ' + g.graph().orderInitCC);

  var i, lastBest;
  for (i = 0, lastBest = 0; lastBest < 4 && i < maxSweeps; ++i, ++lastBest) {
    sweep(g, layerGraphs, i);
    if (saveBest(g)) {
      lastBest = 0;
    }
    util.log(3, 'Order phase iter ' + i + ' cross count: ' + g.graph().orderCC);
  }

  restoreBest(g);

  util.log(2, 'Order iterations: ' + i);
  util.log(2, 'Order phase best cross count: ' + g.graph().orderCC);
}