geneticengine.grammar.metahandlers.vars

Attributes

T

Classes

VarRange

VarRange([a, b, c]) represents the alternative between a, b, and c.

VarRangeWithProbabilities

VarRangeWithProbabilities([a, b, c], [pa, pb, pc]) represents the

Module Contents

geneticengine.grammar.metahandlers.vars.T
class geneticengine.grammar.metahandlers.vars.VarRange(options)

Bases: geneticengine.grammar.metahandlers.base.MetaHandlerGenerator

VarRange([a, b, c]) represents the alternative between a, b, and c.

The list of options can be dynamically altered before the grammar extraction with something like Var.__init__.__annotations__[“name”] = Annotated[str, VarRange([d, e, f])]. The option list must not be empty.

Parameters:

options (list[T])

options
validate(v)
Return type:

bool

generate(random, grammar, base_type, rec, dependent_values, parent_values)
Parameters:
__repr__()
classmethod __class_getitem__(args)
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])

class geneticengine.grammar.metahandlers.vars.VarRangeWithProbabilities(options, probabilities)

Bases: geneticengine.grammar.metahandlers.base.MetaHandlerGenerator

VarRangeWithProbabilities([a, b, c], [pa, pb, pc]) represents the alternative between a, b, and c with the given probabilities.

The options list must not be empty and the probabilities list must have the same length as options. Probabilities can be any non-negative numbers and are interpreted as weights.

Parameters:
  • options (list[T])

  • probabilities (list[float])

options
probabilities
validate(v)
Return type:

bool

generate(random, grammar, base_type, rec, dependent_values, parent_values)
Parameters:
__repr__()
classmethod __class_getitem__(args)
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])