geneticengine.grammar.metahandlers.lists ======================================== .. py:module:: geneticengine.grammar.metahandlers.lists Attributes ---------- .. autoapisummary:: geneticengine.grammar.metahandlers.lists.T Classes ------- .. autoapisummary:: geneticengine.grammar.metahandlers.lists.VariationType geneticengine.grammar.metahandlers.lists.ListSizeBetween Module Contents --------------- .. py:data:: T .. py:class:: VariationType Bases: :py:obj:`enum.Enum` Create a collection of name/value pairs. Example enumeration: >>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3 Access them by: - attribute access: >>> Color.RED - value lookup: >>> Color(1) - name lookup: >>> Color['RED'] Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [, , ] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details. .. py:attribute:: REPLACEMENT :value: 1 .. py:attribute:: INSERTION :value: 2 .. py:attribute:: DELETION :value: 3 .. py:class:: ListSizeBetween(min, max) Bases: :py:obj:`geneticengine.grammar.metahandlers.base.MetaHandlerGenerator` ListSizeBetween(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. .. py:attribute:: min .. py:attribute:: max .. py:method:: validate(v) .. py:method:: generate(random, grammar, base_type, rec, dependent_values, parent_values) Generates an instance of type base_type, according to some criterion. :param Source r: Random source for generation :param Grammar g: 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 :param int depth: the current depth budget :param Type base_type: The inner type being annotated :param str argname: 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 .. py:method:: mutate(random, g, random_node, base_type, current_node) .. py:method:: crossover(r, g, options, arg, list_type, current_node) .. py:method:: iterate(base_type, combine_lists, rec, dependent_values) .. py:method:: __class_getitem__(args) :classmethod: .. py:method:: __repr__()