private void initialize(final LGraph graph) {
    layeredGraph = graph;
    int layerCount = graph.getLayers().size();
    bestNodeOrder = new LNode[layerCount][];
    currentNodeOrder = new LNode[layerCount][];
    originalNodeOrder = new LNode[layerCount][];

    ListIterator<Layer> layerIter = graph.getLayers().listIterator();
    while (layerIter.hasNext()) {
      Layer layer = layerIter.next();

      int layerNodeCount = layer.getNodes().size();
      assert layerNodeCount > 0;

      int layerIndex = layerIter.previousIndex();
      bestNodeOrder[layerIndex] = new LNode[layerNodeCount];
      currentNodeOrder[layerIndex] = new LNode[layerNodeCount];
      originalNodeOrder[layerIndex] = new LNode[layerNodeCount];

      ListIterator<LNode> nodeIter = layer.getNodes().listIterator();
      int id = 0;
      while (nodeIter.hasNext()) {
        LNode node = nodeIter.next();
        node.id = id++;

        currentNodeOrder[layerIndex][nodeIter.previousIndex()] = node;
        bestNodeOrder[layerIndex][nodeIter.previousIndex()] = node;
        originalNodeOrder[layerIndex][nodeIter.previousIndex()] = node;
      }
    }
    crossingCounter = new AllCrossingsCounter(currentNodeOrder);
    if (greedySwitchType.useHyperedgeCounter()) {
      crossingCounter.useHyperedgeCounter();
    }
  }
 private void sweepOneSidedOrTwoSided() {
   if (greedySwitchType.isOneSided()) {
     oneSidedLayerSweep();
   } else {
     twoSidedlayerSweep();
   }
 }
  /** {@inheritDoc} */
  public void process(final LGraph graph, final IElkProgressMonitor progressMonitor) {
    progressMonitor.begin("Greedy switch crossing reduction", 1);

    greedySwitchType = graph.getProperty(Properties.GREEDY_SWITCH_TYPE);

    int layerCount = graph.getLayers().size();
    if (layerCount < 2 || greedySwitchType == GreedySwitchType.OFF) {
      progressMonitor.done();
      return;
    }

    initialize(graph);

    if (greedySwitchType.useBestOfUpOrDown()) {
      compareSweepingUpwardOrDownward();
    } else {
      sweepOneSidedOrTwoSided();
    }

    setAsGraph(bestNodeOrder);

    progressMonitor.done();
  }
 private int getCrossingCount() {
   return greedySwitchType.isOneSided() ? currentCrossings : countCurrentNumberOfCrossings();
 }