Gravitational Search Algorithm.

class opytimizer.optimizers.science.gsa.GSA(params: Optional[Dict[str, Any]] = None)

A GSA class, inherited from Optimizer.

This is the designed class to define GSA-related variables and methods.


E. Rashedi, H. Nezamabadi-Pour and S. Saryazdi. GSA: a gravitational search algorithm. Information Sciences (2009).

__init__(params: Optional[Dict[str, Any]] = None) → None

Initialization method.

Parameters:params – Contains key-value parameters to the meta-heuristics.

Initial gravity.


Array of velocities.

compile(space: opytimizer.core.space.Space) → None

Compiles additional information that is used by this optimizer.

Parameters:space – A Space object containing meta-information.
_calculate_mass(agents: List[opytimizer.core.agent.Agent]) → float

Calculates agents’ mass (eq. 16).

Parameters:agents – List of agents.
Returns:The agents’ mass.
Return type:(float)
_calculate_force(agents: List[opytimizer.core.agent.Agent], mass: numpy.ndarray, gravity: float) → float

Calculates agents’ force (eq. 7-9).

  • agents – List of agents.
  • mass – An array of agents’ mass.
  • gravity – Current gravity value.

The attraction force between all agents.

Return type:


update(space: opytimizer.core.space.Space, iteration: int) → None

Wraps Gravitational Search Algorithm over all agents and variables.

  • space – Space containing agents and update-related information.
  • iteration – Current iteration.