metaheuristic_designer.operators.branch_operator module#
Operator that randomly applies one operator from a list to each individual.
- class BranchOperator(op_list, random_pick=True, name=None, encoding=None, rng=None, weights=None, p=None, **kwargs)[source]#
Bases:
OperatorOperator that stochastically selects among several operators.
For each individual, one operator from op_list is chosen according to the configured method (random with given probability, or manually picked). This allows e.g. applying mutation with a certain probability while leaving the rest untouched.
- Parameters:
- op_listlist of Operator
The candidate operators.
- random_pickbool, optional
Whether to pick an operator at random or by specifying an index (default True).
- namestr, optional
Display name; defaults to
"method(op_names)".- encodingEncoding, optional
Encoding applied to the genotype.
- rngRNGLike, optional
Random number generator.
- weights: VectorLike, optional
Weights of each operator when choosing at random.
- pfloat, optional
Probability of selecting the first operator (default 0.5). Only applied when
op_listhas length 2 and no weights are specified.- **kwargs
Additional keyword arguments stored as schedulable parameters.
- Attributes:
paramsAccess parameter values by attribute-style lookup.
- Parameters:
Methods
__call__(population)Shorthand for
evolve().choose_index(idx)Manually chooses the operator to use next
evolve(population)Apply a random operator to each individual according to the branch method.
Collect parameters from this operator and all sub-operators.
get_params()Return a copy of the current parameter dictionary.
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 a random operator to each individual according to the branch method.
- Return type:
- Parameters:
- populationPopulation
The current population.
- Returns:
- Population
The modified population.
- Parameters:
population (Population)
- choose_index(idx)[source]#
Manually chooses the operator to use next
- Parameters:
- idxint
Index of the operator in the list.
- Parameters:
idx (ndarray[tuple[int], floating] | ndarray[tuple[int], integer] | ndarray[tuple[int], uint8 | bool] | number | float | int)