metaheuristic_designer.encodings.matrix_encoding module#

Encoding that reshapes vectors into matrices.

class MatrixEncoding(shape, **kwargs)[source]#

Bases: Encoding

Encoding that reshapes flat genotype vectors into 2-D matrices.

Each individual is reshaped according to the given shape.

Parameters:
shapetuple of int

(rows, cols) of the resulting matrix.

**kwargs

Forwarded to Encoding.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:

shape (Tuple[int, int])

Methods

decode(population)

Decodes a population matrix into a list/array of solutions.

encode(solutions)

Encodes a list of solutions to our problem to an population matrix.

gather_params()

Overridable thin wrapper around get_params

get_params()

Return a copy of the current parameter dictionary.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Re-evaluate all stored parameters at the current progress.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

get_state

encode(solutions)[source]#

Encodes a list of solutions to our problem to an population matrix.

Return type:

ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool]

Parameters:
solutions: Iterable

Solutions that should be encoded.

Returns:
population: ndarray

Population array.

Parameters:

solutions (Iterable)

decode(population)[source]#

Decodes a population matrix into a list/array of solutions.

Return type:

Iterable

Parameters:
population: ndarray

Population that should be decoded.

Returns:
solutions: Iterable

List/array of solutions.

Parameters:

population (ndarray[tuple[int, int], floating] | ndarray[tuple[int, int], integer] | ndarray[tuple[int, int], uint8 | bool])