Esempio n. 1
0
 protected void sortVertices() {
   layerPartition =
       new DefaultLayerPartition(digraph, rankFunction, vertexShape, subgraphPartition);
   layerPartition.breadthFirstSort();
   int crossingCount = layerPartition.countCrossings();
   Map orderSnapshot = layerPartition.makeOrderSnapshot();
   boolean lastIsBest = true;
   for (int i = 0; i < sortIterationCount; i++) {
     if (i % 2 == 0) layerPartition.sortDownByMedian();
     else layerPartition.sortUpByMedian();
     int newCrossingCount = layerPartition.countCrossings();
     if (newCrossingCount < crossingCount) {
       crossingCount = newCrossingCount;
       orderSnapshot = layerPartition.makeOrderSnapshot();
       lastIsBest = true;
     } else if (newCrossingCount > crossingCount) lastIsBest = false;
   }
   if (!lastIsBest) layerPartition.restoreOrder(orderSnapshot);
   layerPartition.refreshIndices();
 }