class_docstr: A SFO class, inherited from Optimizer.
  
  This is the designed class to define SFO-related
  variables and methods.
  
  References:
      S. Shadravan, H. Naji and V. Bardsiri.
      The Sailfish Optimizer: A novel nature-inspired metaheuristic algorithm
      for solving constrained engineering optimization problems.
      Engineering Applications of Artificial Intelligence (2019).
class_docstr_tok: ["A","SFO","class",",","inherited","from","Optimizer",".","This","is","the","designed","class","to","define","SFO-related","variables","and","methods",".","References",":","S.","Shadravan",",","H.","Naji","and","V.","Bardsiri",".","The","Sailfish","Optimizer",":","A","novel","nature-inspired","metaheuristic","algorithm","for","solving","constrained","engineering","optimization","problems",".","Engineering","Applications","of","Artificial","Intelligence","(","2019",")","."]
docstr: Wraps Sailfish Optimizer over all agents and variables.
  
  Args:
      space: Space containing agents and update-related information.
      function: A Function object that will be used as the objective function.
      iteration: Current iteration.
docstr_tok: ["Wraps","Sailfish","Optimizer","over","all","agents","and","variables",".","Args",":","space",":","Space","containing","agents","and","update-related","information",".","function",":","A","Function","object","that","will","be","used","as","the","objective","function",".","iteration",":","Current","iteration","."]
code: def update(
      self, space: Space, function: Function, iteration: int
  ) -> None:
      """Wraps Sailfish Optimizer over all agents and variables.
  
      Args:
          space: Space containing agents and update-related information.
          function: A Function object that will be used as the objective function.
          iteration: Current iteration.
  
      """
  
      best_sardine = self.sardines[0]
  
      n_sailfishes = len(space.agents)
      n_sardines = len(self.sardines)
      n_variables = space.agents[0].n_variables
  
      for agent in space.agents:
          lambda_i = self._calculate_lambda_i(n_sailfishes, n_sardines)
  
          agent.position = self._update_sailfish(
              agent, space.best_agent, best_sardine, lambda_i
          )
          agent.clip_by_bound()
  
          agent.fit = function(agent.position)
  
      # Calculates the attack power (eq. 10)
      AP = np.fabs(self.A * (1 - 2 * iteration * self.e))
  
      if AP < 0.5:
          # Calculates the number of sardines possible replacements (eq. 11)
          alpha = int(len(self.sardines) * AP)
  
          # Calculates the number of variables possible replacements (eq. 12)
          beta = int(n_variables * AP)
  
          selected_sardines = r.generate_integer_random_number(
              0, n_sardines, size=alpha
          )
  
          for i in selected_sardines:
              selected_vars = r.generate_integer_random_number(
                  0, n_variables, size=beta
              )
  
              for j in selected_vars:
                  r1 = r.generate_uniform_random_number()
  
                  # Updates the sardine's position (eq. 9)
                  self.sardines[i].position[j] = r1 * (
                      space.best_agent.position[j]
                      - self.sardines[i].position[j]
                      + AP
                  )
              self.sardines[i].clip_by_bound()
  
              self.sardines[i].fit = function(self.sardines[i].position)
      else:
          for sardine in self.sardines:
              # Updates the sardine's position (eq. 9)
              r1 = r.generate_uniform_random_number()
              sardine.position = r1 * (
                  space.best_agent.position - sardine.position + AP
              )
              sardine.clip_by_bound()
  
              # Re-calculates its fitness
              sardine.fit = function(sardine.position)
  
      space.agents.sort(key=lambda x: x.fit)
      self.sardines.sort(key=lambda x: x.fit)
  
      for agent in space.agents:
          for sardine in self.sardines:
              # If agent is worse than sardine (eq. 13)
              if agent.fit > sardine.fit:
                  agent = copy.deepcopy(sardine)
                  break
  
imports: import copy
  from typing import Any, Dict, List, Optional
  import numpy
  import opytimizer.math.random
  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 14 for calling the SFO obj's underlying member method code with example usage: obj.update(space, function, iteration) without return types