geneticengine.grammar.metahandlers.lists
Attributes
Classes
Create a collection of name/value pairs. |
|
ListSizeBetween(a,b) restricts lists to be of length between a and b and |
Module Contents
- geneticengine.grammar.metahandlers.lists.T
- class geneticengine.grammar.metahandlers.lists.VariationType
Bases:
enum.EnumCreate a collection of name/value pairs.
Example enumeration:
>>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3
Access them by:
attribute access:
>>> Color.RED <Color.RED: 1>
value lookup:
>>> Color(1) <Color.RED: 1>
name lookup:
>>> Color['RED'] <Color.RED: 1>
Enumerations can be iterated over, and know how many members they have:
>>> len(Color) 3
>>> list(Color) [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.
- REPLACEMENT = 1
- INSERTION = 2
- DELETION = 3
- class geneticengine.grammar.metahandlers.lists.ListSizeBetween(min, max)
Bases:
geneticengine.grammar.metahandlers.base.MetaHandlerGeneratorListSizeBetween(a,b) restricts lists to be of length between a and b and implements a special list mutation.
- The list of options can be dynamically altered before the grammar extraction
Set.__annotations__[“set”] = Annotated[List[Type], ListSizeBetween(c,d)].
- The special list mutation entails three different alterations to the list in question: deletion of a random element;
addition of a random element; and replacement of a random element.
- min
- max
- validate(v)
- Return type:
bool
- generate(random, grammar, base_type, rec, dependent_values, parent_values)
Generates an instance of type base_type, according to some criterion.
- Parameters:
r (Source) – Random source for generation
g (Grammar) – Grammar to follow in the generation :param Callable[[int, Type], Any] rec: The method to generate a new instance of type and maximum depth d
depth (int) – the current depth budget
base_type (Type) – The inner type being annotated
argname (str) – The name of the field of the parent object which is being generated :param Dict[str, Type] context: The names and types of all fields in the parent object :param Dict[str, Type] dependent_values: The names and values of all previous fields in the parent object
grammar (geneticengine.grammar.grammar.Grammar)
rec (Callable[[type[T]], T])
dependent_values (dict[str, Any])
parent_values (list[dict[str, Any]])
- mutate(random, g, random_node, base_type, current_node)
- Parameters:
- crossover(r, g, options, arg, list_type, current_node)
- Parameters:
- 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])
- classmethod __class_getitem__(args)
- __repr__()