|
GALib-Parallel
Header-only C++ library for parallel evolutionary algorithms
|
A population organized in a 2D grid structure. More...
#include <GridPopulation.h>
Public Member Functions | |
| GridPopulation (std::size_t rows, std::size_t cols, std::size_t num_genes) | |
| Constructs a grid population with specified dimensions. | |
| void | initialize (GeneType lower, GeneType upper) |
| Randomly initializes all individuals in the grid. | |
| std::size_t | size () const |
| Returns the total number of individuals in the grid. | |
| const Individual< GeneType > & | getBestIndividual () const |
| Returns the best individual found in the entire grid. | |
| std::size_t | index (std::size_t row, std::size_t col) const |
| Converts 2D grid coordinates to a 1D linear index. | |
| Individual< GeneType > & | at (std::size_t row, std::size_t col) |
| Accesses an individual at specific grid coordinates. | |
| const Individual< GeneType > & | at (std::size_t row, std::size_t col) const |
| Accesses an individual at specific grid coordinates (const version). | |
| std::size_t | rows () const |
| Returns the number of rows. | |
| std::size_t | cols () const |
| Returns the number of columns. | |
| std::size_t | getNumGenes () const |
| Returns the number of genes for individuals in this population. | |
| Individual< GeneType > & | linearAt (std::size_t index) |
| Accesses an individual via its linear index. | |
| const Individual< GeneType > & | linearAt (std::size_t index) const |
| Accesses an individual via its linear index (const version). | |
| bool | empty () const |
| Checks if the population is empty. | |
| std::vector< std::pair< std::size_t, std::size_t > > | getNeighbors (std::size_t row, std::size_t col) const |
| Retrieves the 4-neighborhood (Up, Down, Left, Right) of a cell. | |
A population organized in a 2D grid structure.
Primarily used by Cellular Genetic Algorithms where spatial locality and neighborhood relationships are important for selection.
| GeneType | The type of the genes. |
Definition at line 23 of file GridPopulation.h.
|
inline |
Constructs a grid population with specified dimensions.
| rows | Number of rows in the grid. |
| cols | Number of columns in the grid. |
| num_genes | Number of genes each individual should have. |
| std::invalid_argument | if dimensions are zero. |
Definition at line 37 of file GridPopulation.h.
References galib::GridPopulation< GeneType >::cols(), and galib::GridPopulation< GeneType >::rows().
|
inline |
Accesses an individual at specific grid coordinates.
| row | Grid row. |
| col | Grid column. |
Definition at line 92 of file GridPopulation.h.
References galib::GridPopulation< GeneType >::index().
|
inline |
Accesses an individual at specific grid coordinates (const version).
| row | Grid row. |
| col | Grid column. |
Definition at line 102 of file GridPopulation.h.
References galib::GridPopulation< GeneType >::index().
|
inline |
Returns the number of columns.
Definition at line 110 of file GridPopulation.h.
Referenced by galib::GridPopulation< GeneType >::GridPopulation().
|
inline |
Checks if the population is empty.
Definition at line 145 of file GridPopulation.h.
References galib::Population< GeneType >::empty().
|
inline |
Returns the best individual found in the entire grid.
Definition at line 68 of file GridPopulation.h.
References galib::Population< GeneType >::getBestIndividual().
|
inline |
Retrieves the 4-neighborhood (Up, Down, Left, Right) of a cell.
Uses periodic (toroidal) boundary conditions.
| row | Cell row. |
| col | Cell column. |
Definition at line 159 of file GridPopulation.h.
|
inline |
Returns the number of genes for individuals in this population.
Definition at line 116 of file GridPopulation.h.
References galib::Population< GeneType >::getNumGenes().
|
inline |
Converts 2D grid coordinates to a 1D linear index.
| row | Grid row. |
| col | Grid column. |
| std::out_of_range | if coordinates are invalid. |
Definition at line 79 of file GridPopulation.h.
Referenced by galib::GridPopulation< GeneType >::at(), galib::GridPopulation< GeneType >::at(), galib::GridPopulation< GeneType >::linearAt(), and galib::GridPopulation< GeneType >::linearAt().
|
inline |
Randomly initializes all individuals in the grid.
| lower | Lower bound for genes. |
| upper | Upper bound for genes. |
Definition at line 52 of file GridPopulation.h.
References galib::Population< GeneType >::initialize().
|
inline |
Accesses an individual via its linear index.
| index | Linear index. |
Definition at line 125 of file GridPopulation.h.
References galib::GridPopulation< GeneType >::index(), and galib::Population< GeneType >::size().
|
inline |
Accesses an individual via its linear index (const version).
| index | Linear index. |
Definition at line 137 of file GridPopulation.h.
References galib::GridPopulation< GeneType >::index(), and galib::Population< GeneType >::size().
|
inline |
Returns the number of rows.
Definition at line 107 of file GridPopulation.h.
Referenced by galib::GridPopulation< GeneType >::GridPopulation().
|
inline |
Returns the total number of individuals in the grid.
Definition at line 60 of file GridPopulation.h.
References galib::Population< GeneType >::size().