docstr: Initialize the swarm
  
  Attributes
  ----------
  n_particles : int
      number of particles in the swarm.
  dimensions : int
      number of dimensions in the space.
  options : dict with keys :code:`{'c1', 'c2', 'w'}` or :code:`{'c1',
          'c2', 'w', 'k', 'p'}`
      a dictionary containing the parameters for the specific
      optimization technique.
          * c1 : float
              cognitive parameter
          * c2 : float
              social parameter
          * w : float
              inertia parameter
          if used with the :code:`Ring`, :code:`VonNeumann` or
          :code:`Random` topology the additional parameter k must be
          included
          * k : int
              number of neighbors to be considered. Must be a positive
              integer less than :code:`n_particles`
          if used with the :code:`Ring` topology the additional
          parameters k and p must be included
          * p: int {1,2}
              the Minkowski p-norm to use. 1 is the sum-of-absolute
              values (or L1 distance) while 2 is the Euclidean (or L2)
              distance.
          if used with the :code:`VonNeumann` topology the additional
          parameters p and r must be included
          * r: int
              the range of the VonNeumann topology.  This is used to
              determine the number of neighbours in the topology.
  topology : pyswarms.backend.topology.Topology
      a :code:`Topology` object that defines the topology to use in the
      optimization process. The currently available topologies are:
          * Star
              All particles are connected
          * Ring (static and dynamic)
              Particles are connected to the k nearest neighbours
          * VonNeumann
              Particles are connected in a VonNeumann topology
          * Pyramid (static and dynamic)
              Particles are connected in N-dimensional simplices
          * Random (static and dynamic)
              Particles are connected to k random particles
          Static variants of the topologies remain with the same
          neighbours over the course of the optimization. Dynamic
          variants calculate new neighbours every time step.
  bounds : tuple of numpy.ndarray, optional
      a tuple of size 2 where the first entry is the minimum bound while
      the second entry is the maximum bound. Each array must be of shape
      :code:`(dimensions,)`.
  oh_strategy : dict, optional, default=None(constant options)
      a dict of update strategies for each option.
  bh_strategy : str
      a strategy for the handling of out-of-bounds particles.
  velocity_clamp : tuple, optional
      a tuple of size 2 where the first entry is the minimum velocity and
      the second entry is the maximum velocity. It sets the limits for
      velocity clamping.
  vh_strategy : str
      a strategy for the handling of the velocity of out-of-bounds particles.
  center : list (default is :code:`None`)
      an array of size :code:`dimensions`
  ftol : float
      relative error in objective_func(best_pos) acceptable for
      convergence. Default is :code:`-np.inf`
  ftol_iter : int
      number of iterations over which the relative error in
      objective_func(best_pos) is acceptable for convergence.
      Default is :code:`1`
  init_pos : numpy.ndarray, optional
      option to explicitly set the particles' initial positions. Set to
      :code:`None` if you wish to generate the particles randomly.
docstr_tok: ["Initialize","the","swarm","Attributes","--","--","--","--","--","n_particles",":","int","number","of","particles","in","the","swarm",".","dimensions",":","int","number","of","dimensions","in","the","space",".","options",":","dict","with","keys",":","code",":","`","{","'c1","'",",","'c2","'",",","'","w","'","}","`","or",":","code",":","`","{","'c1","'",",","'c2","'",",","'","w","'",",","'","k","'",",","'","p","'","}","`","a","dictionary","containing","the","parameters","for","the","specific","optimization","technique",".","*","c1",":","float","cognitive","parameter","*","c2",":","float","social","parameter","*","w",":","float","inertia","parameter","if","used","with","the",":","code",":","`","Ring","`",",",":","code",":","`","VonNeumann","`","or",":","code",":","`","Random","`","topology","the","additional","parameter","k","must","be","included","*","k",":","int","number","of","neighbors","to","be","considered",".","Must","be","a","positive","integer","less","than",":","code",":","`","n_particles","`","if","used","with","the",":","code",":","`","Ring","`","topology","the","additional","parameters","k","and","p","must","be","included","*","p",":","int","{","1,2","}","the","Minkowski","p-norm","to","use",".","1","is","the","sum-of-absolute","values","(","or","L1","distance",")","while","2","is","the","Euclidean","(","or","L2",")","distance",".","if","used","with","the",":","code",":","`","VonNeumann","`","topology","the","additional","parameters","p","and","r","must","be","included","*","r",":","int","the","range","of","the","VonNeumann","topology",".","This","is","used","to","determine","the","number","of","neighbours","in","the","topology",".","topology",":","pyswarms.backend.topology.Topology","a",":","code",":","`","Topology","`","object","that","defines","the","topology","to","use","in","the","optimization","process",".","The","currently","available","topologies","are",":","*","Star","All","particles","are","connected","*","Ring","(","static","and","dynamic",")","Particles","are","connected","to","the","k","nearest","neighbours","*","VonNeumann","Particles","are","connected","in","a","VonNeumann","topology","*","Pyramid","(","static","and","dynamic",")","Particles","are","connected","in","N-dimensional","simplices","*","Random","(","static","and","dynamic",")","Particles","are","connected","to","k","random","particles","Static","variants","of","the","topologies","remain","with","the","same","neighbours","over","the","course","of","the","optimization",".","Dynamic","variants","calculate","new","neighbours","every","time","step",".","bounds",":","tuple","of","numpy.ndarray",",","optional","a","tuple","of","size","2","where","the","first","entry","is","the","minimum","bound","while","the","second","entry","is","the","maximum","bound",".","Each","array","must","be","of","shape",":","code",":","`","(","dimensions",",",")","`",".","oh_strategy",":","dict",",","optional",",","default=None","(","constant","options",")","a","dict","of","update","strategies","for","each","option",".","bh_strategy",":","str","a","strategy","for","the","handling","of","out-of-bounds","particles",".","velocity_clamp",":","tuple",",","optional","a","tuple","of","size","2","where","the","first","entry","is","the","minimum","velocity","and","the","second","entry","is","the","maximum","velocity",".","It","sets","the","limits","for","velocity","clamping",".","vh_strategy",":","str","a","strategy","for","the","handling","of","the","velocity","of","out-of-bounds","particles",".","center",":","list","(","default","is",":","code",":","`","None","`",")","an","array","of","size",":","code",":","`","dimensions","`","ftol",":","float","relative","error","in","objective_func","(","best_pos",")","acceptable","for","convergence",".","Default","is",":","code",":","`","-np.inf","`","ftol_iter",":","int","number","of","iterations","over","which","the","relative","error","in","objective_func","(","best_pos",")","is","acceptable","for","convergence",".","Default","is",":","code",":","`","1","`","init_pos",":","numpy.ndarray",",","optional","option","to","explicitly","set","the","particles","'","initial","positions",".","Set","to",":","code",":","`","None","`","if","you","wish","to","generate","the","particles","randomly","."]
code: def __init__(
      self,
      n_particles,
      dimensions,
      options,
      topology,
      bounds=None,
      oh_strategy=None,
      bh_strategy="periodic",
      velocity_clamp=None,
      vh_strategy="unmodified",
      center=1.00,
      ftol=-np.inf,
      ftol_iter=1,
      init_pos=None,
  ):
      """Initialize the swarm
  
      Attributes
      ----------
      n_particles : int
          number of particles in the swarm.
      dimensions : int
          number of dimensions in the space.
      options : dict with keys :code:`{'c1', 'c2', 'w'}` or :code:`{'c1',
              'c2', 'w', 'k', 'p'}`
          a dictionary containing the parameters for the specific
          optimization technique.
              * c1 : float
                  cognitive parameter
              * c2 : float
                  social parameter
              * w : float
                  inertia parameter
              if used with the :code:`Ring`, :code:`VonNeumann` or
              :code:`Random` topology the additional parameter k must be
              included
              * k : int
                  number of neighbors to be considered. Must be a positive
                  integer less than :code:`n_particles`
              if used with the :code:`Ring` topology the additional
              parameters k and p must be included
              * p: int {1,2}
                  the Minkowski p-norm to use. 1 is the sum-of-absolute
                  values (or L1 distance) while 2 is the Euclidean (or L2)
                  distance.
              if used with the :code:`VonNeumann` topology the additional
              parameters p and r must be included
              * r: int
                  the range of the VonNeumann topology.  This is used to
                  determine the number of neighbours in the topology.
      topology : pyswarms.backend.topology.Topology
          a :code:`Topology` object that defines the topology to use in the
          optimization process. The currently available topologies are:
              * Star
                  All particles are connected
              * Ring (static and dynamic)
                  Particles are connected to the k nearest neighbours
              * VonNeumann
                  Particles are connected in a VonNeumann topology
              * Pyramid (static and dynamic)
                  Particles are connected in N-dimensional simplices
              * Random (static and dynamic)
                  Particles are connected to k random particles
              Static variants of the topologies remain with the same
              neighbours over the course of the optimization. Dynamic
              variants calculate new neighbours every time step.
      bounds : tuple of numpy.ndarray, optional
          a tuple of size 2 where the first entry is the minimum bound while
          the second entry is the maximum bound. Each array must be of shape
          :code:`(dimensions,)`.
      oh_strategy : dict, optional, default=None(constant options)
          a dict of update strategies for each option.
      bh_strategy : str
          a strategy for the handling of out-of-bounds particles.
      velocity_clamp : tuple, optional
          a tuple of size 2 where the first entry is the minimum velocity and
          the second entry is the maximum velocity. It sets the limits for
          velocity clamping.
      vh_strategy : str
          a strategy for the handling of the velocity of out-of-bounds particles.
      center : list (default is :code:`None`)
          an array of size :code:`dimensions`
      ftol : float
          relative error in objective_func(best_pos) acceptable for
          convergence. Default is :code:`-np.inf`
      ftol_iter : int
          number of iterations over which the relative error in
          objective_func(best_pos) is acceptable for convergence.
          Default is :code:`1`
      init_pos : numpy.ndarray, optional
          option to explicitly set the particles' initial positions. Set to
          :code:`None` if you wish to generate the particles randomly.
      """
      super(GeneralOptimizerPSO, self).__init__(
          n_particles,
          dimensions=dimensions,
          options=options,
          bounds=bounds,
          velocity_clamp=velocity_clamp,
          center=center,
          ftol=ftol,
          ftol_iter=ftol_iter,
          init_pos=init_pos,
      )
      if oh_strategy is None:
          oh_strategy = {}
      # Initialize logger
      self.rep = Reporter(logger=logging.getLogger(__name__))
      # Initialize the resettable attributes
      self.reset()
      # Initialize the topology and check for type
      if not isinstance(topology, Topology):
          raise TypeError(
              "Parameter `topology` must be a Topology object"
          )
      else:
          self.top = topology
      self.bh = BoundaryHandler(strategy=bh_strategy)
      self.vh = VelocityHandler(strategy=vh_strategy)
      self.oh = OptionsHandler(strategy=oh_strategy)
      self.name = __name__
  
file_path: pyswarms/pyswarms/single/general_optimizer.py
imports: import logging
  import numpy
  import multiprocessing
  from collections import deque
  from ..backend.operators import compute_pbest, compute_objective_function
  from ..backend.topology import Topology
  from ..backend.handlers import BoundaryHandler, VelocityHandler, OptionsHandler
  from ..base import SwarmOptimizer
  from ..utils.reporter import Reporter
label_desc: Use image node_id 1 to create a new GeneralOptimizerPSO object from inherited base classes: SwarmOptimizer with example: obj = GeneralOptimizerPSO(n_particles, dimensions, options, topology, bounds, oh_strategy, bh_strategy, velocity_clamp, vh_strategy, center, ftol, ftol_iter, init_pos)