Source:
private static void computeLinearOrderingMarks(final List<HyperEdgeSegment> segments, final LinkedList<HyperEdgeSegment> sources, final LinkedList<HyperEdgeSegment> sinks, final boolean criticalOnly, final Random random) { Set<HyperEdgeSegment> unprocessed = Sets.newTreeSet(segments); List<HyperEdgeSegment> maxSegments = new ArrayList<HyperEdgeSegment>(); int markBase = segments.size(); int nextRight = markBase - 1; int nextLeft = markBase + 1; while (!unprocessed.isEmpty()) { while (!sinks.isEmpty()) { HyperEdgeSegment sink = sinks.removeFirst(); unprocessed.remove(sink); sink.mark = nextRight--; updateNeighbors(sink, sources, sinks, criticalOnly); } while (!sources.isEmpty()) { HyperEdgeSegment source = sources.removeFirst(); unprocessed.remove(source); source.mark = nextLeft++; updateNeighbors(source, sources, sinks, criticalOnly); } int maxOutflow = Integer.MIN_VALUE; for (HyperEdgeSegment segment : unprocessed) { if (!criticalOnly && segment.getCriticalOutWeight() > 0 && segment.getCriticalInWeight() <= 0) { maxSegments.clear(); maxSegments.add(segment); break; } int outflow = segment.getOutWeight() - segment.getInWeight(); if (outflow >= maxOutflow) { if (outflow > maxOutflow) { maxSegments.clear(); maxOutflow = outflow; } maxSegments.add(segment); } } if (!maxSegments.isEmpty()) { HyperEdgeSegment maxNode = maxSegments.get(random.nextInt(maxSegments.size())); unprocessed.remove(maxNode); maxNode.mark = nextLeft++; updateNeighbors(maxNode, sources, sinks, criticalOnly); maxSegments.clear(); } } int shiftBase = segments.size() + 1; for (HyperEdgeSegment node : segments) { if (node.mark < markBase) { node.mark = node.mark + shiftBase; } } }

Target:
private static void computeLinearOrderingMarks(final List<HyperEdgeSegment> segments, final LinkedList<HyperEdgeSegment> sources, final LinkedList<HyperEdgeSegment> sinks, final boolean criticalOnly, final Random random) { Set<HyperEdgeSegment> unprocessed = Sets.newTreeSet(segments); List<HyperEdgeSegment> maxSegments = new ArrayList<HyperEdgeSegment>(); int markBase = segments.size(); int nextSinkMark = markBase - 1; int nextSourceMark = markBase + 1; while (!unprocessed.isEmpty()) { while (!sinks.isEmpty()) { HyperEdgeSegment sink = sinks.removeFirst(); unprocessed.remove(sink); sink.mark = nextSinkMark--; updateNeighbors(sink, sources, sinks, criticalOnly); } while (!sources.isEmpty()) { HyperEdgeSegment source = sources.removeFirst(); unprocessed.remove(source); source.mark = nextSourceMark++; updateNeighbors(source, sources, sinks, criticalOnly); } int maxOutflow = Integer.MIN_VALUE; for (HyperEdgeSegment segment : unprocessed) { if (!criticalOnly && segment.getCriticalOutWeight() > 0 && segment.getCriticalInWeight() <= 0) { maxSegments.clear(); maxSegments.add(segment); break; } int outflow = segment.getOutWeight() - segment.getInWeight(); if (outflow >= maxOutflow) { if (outflow > maxOutflow) { maxSegments.clear(); maxOutflow = outflow; } maxSegments.add(segment); } } if (!maxSegments.isEmpty()) { HyperEdgeSegment maxNode = maxSegments.get(random.nextInt(maxSegments.size())); unprocessed.remove(maxNode); maxNode.mark = nextSourceMark++; updateNeighbors(maxNode, sources, sinks, criticalOnly); maxSegments.clear(); } } int shiftBase = segments.size() + 1; for (HyperEdgeSegment node : segments) { if (node.mark < markBase) { node.mark = node.mark + shiftBase; } } }