code: def sweepB(best, worst, front):
      """Adjust the rank number of the worst fitnesses according to
      the best fitnesses on the first two objectives using a sweep
      procedure.
      """
      stairs, fstairs = [], []
      iter_best = iter(best)
      next_best = next(iter_best, False)
      for h in worst:
          while next_best and h[:2] <= next_best[:2]:
              insert = True
              for i, fstair in enumerate(fstairs):
                  if front[fstair] == front[next_best]:
                      if fstair[1] > next_best[1]:
                          insert = False
                      else:
                          del stairs[i], fstairs[i]
                      break
              if insert:
                  idx = bisect.bisect_right(stairs, -next_best[1])
                  stairs.insert(idx, -next_best[1])
                  fstairs.insert(idx, next_best)
              next_best = next(iter_best, False)
  
          idx = bisect.bisect_right(stairs, -h[1])
          if 0 < idx <= len(stairs):
              fstair = max(fstairs[:idx], key=front.__getitem__)
              front[h] = max(front[h], front[fstair] + 1)
  
imports: import bisect
  from collections import defaultdict, namedtuple
  from itertools import chain
  import math
  from operator import attrgetter, itemgetter
  import random
  import numpy
label_desc: Use image node_id 14 for calling a global function with example usage: sweepB(best, worst, front) without return types