metaheuristic_designer.encoding module#
Base class for the Encoding module.
This module implements a way to have a different representation in the inner working of the algorithm and the result of the procedure.
- class Encoding(decode_as_array=False, name=None, **kwargs)[source]#
Bases:
ParametrizableMixin,ABCTranslate between internal genotypes and problem-specific phenotypes.
An
Encodingis responsible for converting a population matrix (the internal representation used by operators) into a collection of solutions that the objective function understands, and vice versa.- Parameters:
- decode_as_arraybool, optional
If
True,decode()returns a NumPy array instead of an iterable of arbitrary objects. DefaultFalse.- namestr, optional
Display name for this encoding.
- **kwargs
Additional keyword arguments stored as schedulable parameters.
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
decode_as_array (bool)
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.
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
- abstract 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)
- abstract 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])
- class DefaultEncoding(decode_as_array=True)[source]#
Bases:
EncodingIdentity encoding - the internal genotype is used directly.
No transformation is applied;
encode()anddecode()return their arguments unchanged. This is the encoding used when no other is specified.- Parameters:
- decode_as_arraybool, optional
See
Encoding. DefaultTrue.
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
decode_as_array (bool)
Methods
decode(population)Decodes a population matrix into a list/array of solutions.
encode(solution)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(solution)[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:
solution (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])
- class EncodingFromLambda(encode_fn, decode_fn, **kwargs)[source]#
Bases:
EncodingEncoding built from two callables.
- Parameters:
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
encode_fn (Callable)
decode_fn (Callable)
Methods
decode(population)Decodes a population matrix into a list/array of solutions.
encode(solution)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(solution)[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:
solution (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])