metaheuristic_designer.operators.masked_operator module#

Operator that applies different operators to disjoint slices of the genotype.

class MaskedOperator(op_list, mask, name=None, **kwargs)[source]#

Bases: Operator

Operator that partitions the genotype and applies different operators.

A mask (integer array of length vec_size) specifies which operator (index into op_list) handles each gene. This is used internally by ExtendedOperator to separate the solution from auxiliary parameters.

Parameters:
op_listlist of Operator

Operators to apply, one per mask index.

maskarray of int

Array of length vec_size assigning each gene to an operator.

namestr, optional

Display name; defaults to "Split (op_names)".

**kwargs

Forwarded to Operator.

Attributes:
params

Access parameter values by attribute-style lookup.

Parameters:
  • op_list (Iterable[Operator])

  • mask (MaskLike)

  • name (str)

Methods

__call__(population)

Shorthand for evolve().

evolve(population)

Apply the appropriate operator to each slice of the genotype.

gather_params()

Collect parameters from this operator and all sub-operators.

get_params()

Return a copy of the current parameter dictionary.

get_state()

Gets the current state of the algorithm as a dictionary.

store_kwargs([progress])

Store keyword arguments and evaluate them at the given progress.

update(progress)

Update schedulable parameters and propagate to sub-operators.

update_kwargs([progress])

Add or replace parameters and immediately evaluate them.

gather_params()[source]#

Collect parameters from this operator and all sub-operators.

Return type:

dict

Returns:
dict

Flat dictionary with dotted keys.

evolve(population)[source]#

Apply the appropriate operator to each slice of the genotype.

Return type:

Population

Parameters:
populationPopulation

The current population.

Returns:
Population

The modified population.

Parameters:

population (Population)

update(progress)[source]#

Update schedulable parameters and propagate to sub-operators.

Parameters:
progressfloat

Current progress of the algorithm (0-1).

Parameters:

progress (float)

get_state()[source]#

Gets the current state of the algorithm as a dictionary.

Return type:

dict

Returns:
state: dict

The complete state of the operator.