code: def test_fast_non_dominated_sort() -> None:
      # Single objective.
      directions = [StudyDirection.MINIMIZE]
      trials = [
          _create_frozen_trial(0, [10]),
          _create_frozen_trial(1, [20]),
          _create_frozen_trial(2, [20]),
          _create_frozen_trial(3, [30]),
      ]
      population_per_rank = (
          multi_objective.samplers._nsga2._fast_non_dominated_sort(
              trials, directions
          )
      )
      assert [
          {t.number for t in population}
          for population in population_per_rank
      ] == [
          {0},
          {1, 2},
          {3},
      ]
  
      # Two objective.
      directions = [StudyDirection.MAXIMIZE, StudyDirection.MAXIMIZE]
      trials = [
          _create_frozen_trial(0, [10, 30]),
          _create_frozen_trial(1, [10, 10]),
          _create_frozen_trial(2, [20, 20]),
          _create_frozen_trial(3, [30, 10]),
          _create_frozen_trial(4, [15, 15]),
      ]
      population_per_rank = (
          multi_objective.samplers._nsga2._fast_non_dominated_sort(
              trials, directions
          )
      )
      assert [
          {t.number for t in population}
          for population in population_per_rank
      ] == [
          {0, 2, 3},
          {4},
          {1},
      ]
  
      # Three objective.
      directions = [
          StudyDirection.MAXIMIZE,
          StudyDirection.MAXIMIZE,
          StudyDirection.MINIMIZE,
      ]
      trials = [
          _create_frozen_trial(0, [5, 5, 4]),
          _create_frozen_trial(1, [5, 5, 5]),
          _create_frozen_trial(2, [9, 9, 0]),
          _create_frozen_trial(3, [5, 7, 5]),
          _create_frozen_trial(4, [0, 0, 9]),
          _create_frozen_trial(5, [0, 9, 9]),
      ]
      population_per_rank = (
          multi_objective.samplers._nsga2._fast_non_dominated_sort(
              trials, directions
          )
      )
      assert [
          {t.number for t in population}
          for population in population_per_rank
      ] == [
          {2},
          {0, 3, 5},
          {1},
          {4},
      ]
  
file_path: optuna/tests/multi_objective_tests/samplers_tests/test_nsga2.py
imports: from collections import Counter
  from typing import List
  from typing import Tuple
  from unittest.mock import patch
  import pytest
  import optuna
  from optuna import multi_objective
  from optuna.study._study_direction import StudyDirection
label_desc: Use image node_id 5 for calling a global function with example usage: test_fast_non_dominated_sort() without return types