geneticengine.grammar.metahandlers.parent
Classes
The Parent(variable_names, func) function allows you to access the first |
|
The Parents(variable_names, func) function allows you to access all the |
Module Contents
- class geneticengine.grammar.metahandlers.parent.Parent
Bases:
geneticengine.grammar.metahandlers.base.MetaHandlerGeneratorThe Parent(variable_names, func) function allows you to access the first matched value of variables from other classes based on the specified variable_names.
Example
- Class A:
value_small : Annotated[int, IntRange(-100,0)] value_big : Annotated[int, IntRange(0,100)] value : B
- Class B:
x : Annotated[int, Parent(‘value_small,value_big’, lambda small, big: IntRange(small, big))]
In this example, the variable x is accessing variables of the Class A by parent Metahandler. You can specify multiple names at the same time by separating them with commas. If no matching variable is found, that value will be None. In func, you must ensure that None is handled or guarantee that the result will never be None. If there are multiples parent classes matched it will choose the closest one.
- name: str
- callable: Callable[[Any], type]
- validate(v)
- Return type:
bool
- generate(random, grammar, base_type, rec, dependent_values, parent_values)
- Parameters:
grammar (geneticengine.grammar.grammar.Grammar)
base_type (type)
rec (Any)
dependent_values (dict[str, Any])
parent_values (list[dict[str, Any]])
- iterate(base_type, combine_lists, rec, dependent_values)
- Parameters:
base_type (type)
combine_lists (Callable[[list[type]], Generator[Any, Any, Any]])
rec (Any)
dependent_values (dict[str, Any])
- __hash__()
- get_parents()
- class geneticengine.grammar.metahandlers.parent.Parents
Bases:
geneticengine.grammar.metahandlers.base.MetaHandlerGeneratorThe Parents(variable_names, func) function allows you to access all the matched values of variables from other classes based on the specified variable_names, returning them in a list.
Example
- Class A:
value_small : Annotated[int, IntRange(-100,0)] value_big : Annotated[int, IntRange(0,100)] value : B
- Class B:
x : Annotated[int, Parents(‘value_small,value_big’, lambda small, big: IntRange(small[0], big[0]))]
In this example, the variable x is accessing variables of the Class A by parents Metahandler. You can specify multiple names at the same time by separating them with commas. If no matching variable is found, that value will be a empty list. In func, you must ensure that empty list is handled or guarantee that the result will never be a empty list.
- name: str
- callable: Callable[[Any], type]
- validate(v)
- Return type:
bool
- generate(random, grammar, base_type, rec, dependent_values, parent_values)
- Parameters:
grammar (geneticengine.grammar.grammar.Grammar)
base_type (type)
rec (Any)
dependent_values (dict[str, Any])
parent_values (list[dict[str, Any]])
- iterate(base_type, combine_lists, rec, dependent_values)
- Parameters:
base_type (type)
combine_lists (Callable[[list[type]], Generator[Any, Any, Any]])
rec (Any)
dependent_values (dict[str, Any])
- __hash__()
- get_parents()