geneticengine.solutions

Submodules

Package Contents

Classes

TreeNode

Base class for protocol classes.

Individual

Abstract base class for generic types.

Attributes

__ALL__

class geneticengine.solutions.TreeNode

Bases: Protocol

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto(Protocol[T]):
    def meth(self) -> T:
        ...
gengy_labeled: bool
gengy_distance_to_term: int
gengy_nodes: int
gengy_weighted_nodes: int
gengy_types_this_way: dict[type, list[Any]]
gengy_init_values: tuple[Any]
class geneticengine.solutions.Individual(genotype, representation, metadata=None)

Bases: Generic[G, P]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
Parameters:
genotype: G
representation: geneticengine.representations.api.Representation[G, P]
phenotype: P | None
fitness_store: weakref.WeakKeyDictionary[geneticengine.problems.Problem, geneticengine.problems.Fitness]
metadata: dict[str, Any]
get_phenotype()
has_fitness(problem)
Parameters:

problem (geneticengine.problems.Problem)

Return type:

bool

set_fitness(problem, fitness)
Parameters:
get_fitness(problem=None)
Parameters:

problem (geneticengine.problems.Problem | None)

Return type:

geneticengine.problems.Fitness

ensure_fitness(problem)
Parameters:

problem (geneticengine.problems.Problem)

static key_function(problem)
Parameters:

problem (geneticengine.problems.Problem)

__str__()

Return str(self).

Return type:

str

geneticengine.solutions.__ALL__