class_docstr: A TWO class, inherited from Optimizer.
  
  This is the designed class to define TWO-related
  variables and methods.
  
  References:
      A. Kaveh. Tug of War Optimization.
      Advances in Metaheuristic Algorithms for Optimal Design of Structures (2016).
class_docstr_tok: ["A","TWO","class",",","inherited","from","Optimizer",".","This","is","the","designed","class","to","define","TWO-related","variables","and","methods",".","References",":","A.","Kaveh",".","Tug","of","War","Optimization",".","Advances","in","Metaheuristic","Algorithms","for","Optimal","Design","of","Structures","(","2016",")","."]
docstr: Wraps Tug of War Optimization 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.
      n_iterations: Maximum number of iterations.
docstr_tok: ["Wraps","Tug","of","War","Optimization","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",".","n_iterations",":","Maximum","number","of","iterations","."]
code: def update(
      self,
      space: Space,
      function: Function,
      iteration: int,
      n_iterations: int,
  ) -> None:
      """Wraps Tug of War Optimization 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.
          n_iterations: Maximum number of iterations.
  
      """
  
      space.agents.sort(key=lambda x: x.fit)
      best_fit, worst_fit = space.agents[0].fit, space.agents[-1].fit
  
      weights = [
          (agent.fit - worst_fit) / (best_fit - worst_fit + c.EPSILON)
          + 1
          for agent in space.agents
      ]
  
      temp_agents = copy.deepcopy(space.agents)
  
      mu_k = self.mu_k - (self.mu_k - 0.1) * (iteration / n_iterations)
  
      for i, temp1 in enumerate(temp_agents):
          delta = 0.0
  
          for j, temp2 in enumerate(temp_agents):
              if weights[i] < weights[j]:
                  # Calculates the residual force (eq. 6)
                  force = (
                      np.maximum(
                          weights[i] * self.mu_s, weights[j] * self.mu_s
                      )
                      - weights[i] * mu_k
                  )
  
                  # Calculates the gravitational acceleration (eq. 8)
                  g = temp2.position - temp1.position
  
                  # Calculates the acceleration (eq. 7)
                  acceleration = (force / (weights[i] * mu_k)) * g
  
                  r1 = r.generate_gaussian_random_number(
                      size=(temp1.n_variables, temp1.n_dimensions)
                  )
  
                  # Calculates the displacement (eq. 9-10)
                  delta += (
                      0.5 * acceleration * self.delta_t**2
                      + np.multiply(
                          self.alpha**iteration
                          * self.beta
                          * (
                              np.expand_dims(temp1.ub, -1)
                              - np.expand_dims(temp1.lb, -1)
                          ),
                          r1,
                      )
                  )
  
          # Updates the temporary agent's position (eq. 11)
          temp1.position += delta
  
      self._constraint_handle(
          temp_agents, space.best_agent, function, iteration + 1
      )
  
      for agent, temp in zip(space.agents, temp_agents):
          if temp.fit < agent.fit:
              agent.position = copy.deepcopy(temp.position)
              agent.fit = copy.deepcopy(temp.fit)
  
imports: import copy
  from typing import Any, Dict, List, Optional
  import numpy
  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 13 for calling the TWO obj's underlying member method code with example usage: obj.update(space, function, iteration, n_iterations) without return types