metaheuristic_designer.parent_selection.parent_selection module#
Parent selection registry and factory.
- class ParentSelectionDef(selection_fn, params=<factory>, forced_params=<factory>)[source]#
Bases:
objectWrapper that turns a raw parent-selection function into a callable.
- Parameters:
- selection_fncallable
Function
(fitness, amount, rng, **kwargs) -> indices.- paramsdict, optional
Default keyword arguments merged with user-supplied ones.
- forced_paramsdict, optional
Keyword arguments that always override user-supplied ones.
- Parameters:
selection_fn (callable)
params (dict)
forced_params (dict)
Methods
__call__(population[, amount, rng])Call self as a function.
-
selection_fn:
callable#
-
params:
dict#
-
forced_params:
dict#
- create_parent_selection(method, name=None, amount=None, rng=None, **kwargs)[source]#
Create a parent selection method by name.
- Return type:
- Parameters:
- methodstr
Key into
parent_sel_map, or a null alias.- namestr, optional
Display name for the selection method.
- amountint, optional
Default number of parents to select.
- rngRNGLike, optional
Random number generator.
- **kwargs
Additional parameters forwarded to the selection function.
- Returns:
- ParentSelectionFromLambda or NullParentSelection
The wrapped selection method.
- Parameters:
method (str)
name (str | None)
amount (int | None)
rng (int | Generator | None)
- add_parent_selection_entry(selection_fn, selection_method_name)[source]#
Register a new parent selection method.
- Parameters:
- selection_fncallable
A function with the parent selection signature.
- selection_method_namestr
Name under which to register the method. If it already exists, a warning is logged.
- Parameters:
selection_fn (callable)
selection_method_name (str)