code: def rank(
      population: tp.List[p.Parameter],
      n_selected: tp.Optional[int] = None,
  ) -> tp.Dict[str, tp.Tuple[int, int, float]]:
      """implements the multi-objective ranking function of NSGA-II."""
      frontier_ranker = FastNonDominatedRanking()
      density_estimator = CrowdingDistance()
      selected_pop: tp.Dict[str, tp.Tuple[int, int, float]] = {}
      frontiers = frontier_ranker.compute_ranking(population)
      count = 0
      next_rank = 0
      for front_i, p_frontier in enumerate(frontiers):
          count += len(p_frontier)
          if n_selected is None or count > n_selected:
              density_estimator.compute_distance(p_frontier)
              density_estimator.sort(p_frontier)
              n_dist_calc = (
                  n_selected - len(selected_pop)
                  if n_selected is not None
                  else len(p_frontier)
              )
              for c_i in range(0, n_dist_calc):
                  selected_pop[p_frontier[c_i].uid] = (
                      next_rank,
                      front_i,
                      p_frontier[c_i]._meta["crowding_distance"],
                  )
                  next_rank += 1
              if n_selected is not None:
                  break
          if n_selected is not None:
              for candidate in p_frontier:
                  selected_pop[candidate.uid] = (
                      next_rank,
                      front_i,
                      float("inf"),
                  )
              next_rank += 1
      return selected_pop
  
file_path: nevergrad/nevergrad/optimization/multiobjective/nsga2.py
imports: import logging
  import numpy
  import nevergrad.common.typing
  from nevergrad.parametrization import parameter
label_desc: Use image node_id 1 for calling a global function with example usage: rank(population, n_selected) and returns: selected_pop