class_docstr: An GA class, inherited from Optimizer.
  
  This is the designed class to define GA-related
  variables and methods.
  
  References:
      M. Mitchell. An introduction to genetic algorithms. MIT Press (1998).
class_docstr_tok: ["An","GA","class",",","inherited","from","Optimizer",".","This","is","the","designed","class","to","define","GA-related","variables","and","methods",".","References",":","M.","Mitchell",".","An","introduction","to","genetic","algorithms",".","MIT","Press","(","1998",")","."]
docstr: Performs a roulette selection on the population (p. 8).
  
  Args:
      n_agents: Number of agents allowed in the space.
      fitness: A fitness list of every agent.
  
  Returns:
      (List[int]): The selected indexes of the population.
docstr_tok: ["Performs","a","roulette","selection","on","the","population","(","p.","8",")",".","Args",":","n_agents",":","Number","of","agents","allowed","in","the","space",".","fitness",":","A","fitness","list","of","every","agent",".","Returns",":","(","List","[","int","]",")",":","The","selected","indexes","of","the","population","."]
code: def _roulette_selection(
      self, n_agents: int, fitness: List[float]
  ) -> List[int]:
      """Performs a roulette selection on the population (p. 8).
  
      Args:
          n_agents: Number of agents allowed in the space.
          fitness: A fitness list of every agent.
  
      Returns:
          (List[int]): The selected indexes of the population.
  
      """
  
      n_individuals = int(n_agents * self.p_selection)
      if n_individuals % 2 != 0:
          n_individuals += 1
  
      max_fitness = np.max(fitness)
  
      # Re-arrange the list of fitness by inverting it
      # Note that we apply a trick due to it being designed for minimization
      # f'(x) = f_max - f(x)
      inv_fitness = [max_fitness - fit + c.EPSILON for fit in fitness]
      total_fitness = np.sum(inv_fitness)
  
      probs = [fit / total_fitness for fit in inv_fitness]
  
      selected = d.generate_choice_distribution(
          n_agents, probs, n_individuals
      )
  
      return selected
  
imports: import copy
  from typing import Any, Dict, List, Optional, Tuple
  import numpy
  import opytimizer.math.distribution
  import opytimizer.math.general
  import opytimizer.math.random
  import opytimizer.utils.constant
  import opytimizer.utils.exception
  from opytimizer.core import Optimizer
  from opytimizer.core.agent import Agent
  from opytimizer.core.function import Function
  from opytimizer.core.space import Space
  from opytimizer.utils import logging
label_desc: Use image node_id 8 for calling the GA obj's underlying member method code with example usage: obj._roulette_selection(n_agents, fitness) and returns: selected