metaheuristic_designer.encodings.type_cast_encoding module#

Encoding that converts between data types (e.g., float ↔ int ↔ bool).

class TypeCastEncoding(encoded_dtype=<class 'int'>, decoded_dtype=<class 'float'>, **kwargs)[source]#

Bases: Encoding

Encoding that converts the population to a different NumPy dtype.

During encoding, the solutions are cast to encoded_dtype (the type used internally by operators). During decoding, they are cast to decoded_dtype (the type expected by the objective function).

Parameters:
encoded_dtypeNumPy dtype, optional

The dtype used for the internal genotype (default int).

decoded_dtypeNumPy dtype, optional

The dtype used for the decoded phenotype (default float).

**kwargs

Forwarded to Encoding.

Attributes:
params

Access parameter values by attribute-style lookup.

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])