code: def diversity(first_front, first, last):
      """Given a Pareto front `first_front` and the two extreme points of the
      optimal Pareto front, this function returns a metric of the diversity
      of the front as explained in the original NSGA-II article by K. Deb.
      The smaller the value is, the better the front is.
      """
      df = hypot(
          first_front[0].fitness.values[0] - first[0],
          first_front[0].fitness.values[1] - first[1],
      )
      dl = hypot(
          first_front[-1].fitness.values[0] - last[0],
          first_front[-1].fitness.values[1] - last[1],
      )
      dt = [
          hypot(
              first.fitness.values[0] - second.fitness.values[0],
              first.fitness.values[1] - second.fitness.values[1],
          )
          for first, second in zip(first_front[:-1], first_front[1:])
      ]
  
      if len(first_front) == 1:
          return df + dl
  
      dm = sum(dt) / len(dt)
      di = sum(abs(d_i - dm) for d_i in dt)
      delta = (df + dl + di) / (df + dl + len(dt) * dm)
      return delta
  
imports: from math import hypot, sqrt
  from functools import wraps
  from itertools import repeat
label_desc: Use image node_id 1 for calling a global function with example usage: diversity(first_front, first, last) and returns: delta, unknown