def diversity(first_front, first, last):
 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

def diversity ( first_front , first , last ) : 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
given a pareto front first_front and the two extreme points of the optimal pareto front .