Neighborhood Operators

The pycellga.neighborhoods module provides various neighborhood structures that define how individuals interact with their neighbors in the cellular genetic algorithm (CGA). These neighborhood operators are essential for managing the flow of information and maintaining diversity within the population. Each neighborhood module defines a specific spatial structure. Depending on the problem and the desired interaction level, users can select different neighborhood sizes and arrangements.

Linear 5

Defines a linear neighborhood where each individual interacts with 5 neighbors arranged in a line. This structure is suitable for problems where limited, sequential interaction is beneficial.

class Linear5(position, n_rows, n_cols)[source]

Bases: object

Linear5 calculates the positions of the 4 neighbors in a 2D grid for a given position, considering wrapping at the grid edges.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

__init__(position, n_rows, n_cols)[source]

Initialize the Linear5 object.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

calculate_neighbors_positions() list[source]

Calculate the positions of the 4 neighbors for the given position in the grid.

The neighbors are determined by considering wrapping at the grid edges.

Returns:

A list of tuples representing the positions of the 4 neighbors.

Return type:

list

Linear 9

A linear arrangement with 9 neighbors, encouraging a higher level of information flow along a line. This structure is ideal for applications that require extended sequential interactions.

class Linear9(position, n_rows, n_cols)[source]

Bases: object

Linear9 calculates the positions of the 8 neighbors in a 2D grid for a given position, considering wrapping at the grid edges.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

__init__(position, n_rows, n_cols)[source]

Initialize the Linear9 object.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

calculate_neighbors_positions() list[source]

Calculate the positions of the 8 neighbors for the given position in the grid.

The neighbors are determined by considering wrapping at the grid edges.

Returns:

A list of tuples representing the positions of the 8 neighbors.

Return type:

list

Compact 9

A compact neighborhood structure with 9 neighbors. This layout offers dense interaction among individuals, facilitating rapid convergence while maintaining diversity.

class Compact9(position, n_rows, n_cols)[source]

Bases: object

Compact9 calculates the positions of the 8 neighbors in a 2D grid for a given position, considering wrapping at the grid edges.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

__init__(position, n_rows, n_cols)[source]

Initialize the Compact9 object.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

calculate_neighbors_positions() list[source]

Calculate the positions of the 8 neighbors for the given position in the grid.

The neighbors are determined by considering wrapping at the grid edges.

Returns:

A list of tuples representing the positions of the 8 neighbors.

Return type:

list

Compact 13

Defines a compact neighborhood structure where each individual interacts with its immediate and extended neighbors in a 13 grid. This structure allows moderate information sharing across neighboring cells.

class Compact13(position, n_rows, n_cols)[source]

Bases: object

Compact13 calculates the positions of the 12 neighbors in a 2D grid for a given position, considering wrapping at the grid edges.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

__init__(position, n_rows, n_cols)[source]

Initialize the Compact13 object.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

calculate_neighbors_positions() list[source]

Calculate the positions of the 12 neighbors for the given position in the grid.

The neighbors are determined by considering wrapping at the grid edges.

Returns:

A list of tuples representing the positions of the 12 neighbors.

Return type:

list

Compact 21

Provides a compact arrangement where individuals have a 21 neighborhood structure. This layout encourages local exploration and is useful in tightly clustered populations.

class Compact21(position, n_rows, n_cols)[source]

Bases: object

Compact21 calculates the positions of the 20 neighbors in a 2D grid for a given position, considering wrapping at the grid edges.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

__init__(position, n_rows, n_cols)[source]

Initialize the Compact21 object.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

calculate_neighbors_positions() list[source]

Calculate the positions of the 20 neighbors for the given position in the grid.

The neighbors are determined by considering wrapping at the grid edges.

Returns:

A list of tuples representing the positions of the 20 neighbors.

Return type:

list

Compact 25

An extended compact neighborhood that includes more neighbors, with a 25 structure. This layout promotes broader information sharing, enhancing convergence in larger populations.

class Compact25(position, n_rows, n_cols)[source]

Bases: object

Compact25 calculates the positions of the 24 neighbors in a 2D grid for a given position, considering wrapping at the grid edges.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

__init__(position, n_rows, n_cols)[source]

Initialize the Compact25 object.

Parameters:
  • position (tuple) – The (x, y) position of the point whose neighbors are to be calculated.

  • n_rows (int) – The number of rows in the grid.

  • n_cols (int) – The number of columns in the grid.

calculate_neighbors_positions() list[source]

Calculate the positions of the 24 neighbors for the given position in the grid.

The neighbors are determined by considering wrapping at the grid edges.

Returns:

A list of tuples representing the positions of the 24 neighbors.

Return type:

list