def sweepB(best, worst, front):
 (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))

def sweepB ( best , worst , front ) : ( 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 ) )
adjust the rank number of the worst fitnesses according to the best fitnesses on the first two objectives using a sweep procedure .