def sortNDHelperA(fitnesses, obj, front):
 if (len(fitnesses) < 2):
  return
 elif (len(fitnesses) == 2):
  (s1, s2) = (fitnesses[0], fitnesses[1])
  if isDominated(s2[:(obj + 1)], s1[:(obj + 1)]):
   front[s2] = max(front[s2], (front[s1] + 1))
 elif (obj == 1):
  sweepA(fitnesses, front)
 elif (len(frozenset(map(itemgetter(obj), fitnesses))) == 1):
  sortNDHelperA(fitnesses, (obj - 1), front)
 else:
  (best, worst) = splitA(fitnesses, obj)
  sortNDHelperA(best, obj, front)
  sortNDHelperB(best, worst, (obj - 1), front)
  sortNDHelperA(worst, obj, front)

def sortNDHelperA ( fitnesses , obj , front ) : if ( len ( fitnesses ) < 2 ) : return elif ( len ( fitnesses ) == 2 ) : ( s1 , s2 ) = ( fitnesses [ 0 ] , fitnesses [ 1 ] ) if isDominated ( s2 [ : ( obj + 1 ) ] , s1 [ : ( obj + 1 ) ] ) : front [ s2 ] = max ( front [ s2 ] , ( front [ s1 ] + 1 ) ) elif ( obj == 1 ) : sweepA ( fitnesses , front ) elif ( len ( frozenset ( map ( itemgetter ( obj ) , fitnesses ) ) ) == 1 ) : sortNDHelperA ( fitnesses , ( obj - 1 ) , front ) else : ( best , worst ) = splitA ( fitnesses , obj ) sortNDHelperA ( best , obj , front ) sortNDHelperB ( best , worst , ( obj - 1 ) , front ) sortNDHelperA ( worst , obj , front )
create a non-dominated sorting of s on the first m objectives .