Operators

Crossovers, mutations and selections operations.

Crossovers

gefest.core.opt.operators.crossovers.crossover_structures(structure1: Structure, structure2: Structure, domain: Domain, operations: list[Callable], operation_chance: float, operations_probs: list[int], **kwargs) tuple[Structure][source]

Applys random crossover from given list for pair of structures.

Parameters:
  • structure1 (Structure) – First parent.

  • structure1 – Second parent.

  • domain (Domain) – Task domain.

  • operations (list[Callable]) – List of crossovers operations to choose.

  • operation_chance (float) – Chance of crossover.

  • operations_probs (list[int]) – Probablilites of each crossover operation.

Returns:

Сhildren.

Return type:

tuple[Structure]

gefest.core.opt.operators.crossovers.panmixis(pop: list[Structure]) list[tuple[Structure, Structure]][source]

Default pair selection strategy.

gefest.core.opt.operators.crossovers.structure_level_crossover(s1: Structure, s2: Structure, domain: Domain, **kwargs)[source]

Exchanges points of two polygons.

gefest.core.opt.operators.crossovers.polygon_level_crossover(s1: Structure, s2: Structure, domain: Domain, **kwargs)[source]

Exchanges points of two nearest polygons in structure.

class gefest.core.opt.operators.crossovers.CrossoverTypes(value)[source]

Bases: Enum

Enumerates all crossover functions.

structure_level(*args, **kwargs) = functools.partial(<function structure_level_crossover>)
polygon_level(*args, **kwargs) = functools.partial(<function polygon_level_crossover>)

Mutations

gefest.core.opt.operators.mutations.mutate_structure(structure: Structure, domain: Domain, operations: list[Callable], operation_chance: float, operations_probs: list[float], **kwargs) Structure[source]

Applys random mutation from given list for each polygon in structure.

Parameters:
  • structure (Structure) – Structure to mutate.

  • domain (Domain) – Task domain.

  • mutations (list[Callable]) – List of mutation operations to choose.

  • mutation_chance (float) – Chance to mutate polygon.

  • mutations_probs (list[int]) – Probablilites of each mutation operation.

Returns:

Mutated structure. It is not guaranteed

that the resulting structure will be valid or changed.

Return type:

Structure

gefest.core.opt.operators.mutations.rotate_poly_mutation(new_structure: Structure, domain: Domain, idx_: int = None, **kwargs) Structure[source]

Rotares polygon for random angle.

gefest.core.opt.operators.mutations.drop_poly_mutation(new_structure: Structure, domain: Domain, idx_: int = None, **kwargs) Structure[source]

Drops random polygon from structure.

gefest.core.opt.operators.mutations.add_poly_mutation(new_structure: Structure, domain: Domain, idx_: int = None, **kwargs) Structure[source]

Adds random polygon into structure using standard generator.

gefest.core.opt.operators.mutations.resize_poly_mutation(new_structure: Structure, domain: Domain, idx_: int = None, **kwargs) Structure[source]

Randomly resizes polygon.

gefest.core.opt.operators.mutations.pos_change_point_mutation(new_structure: Structure, domain: Domain, idx_: int = None, **kwargs) Structure[source]

Moves a random point without violating the geometry type specified in the domain.

gefest.core.opt.operators.mutations.add_point_mutation(new_structure: Structure, domain: Domain, idx_: int = None, **kwargs)[source]

Adds a random point without violating the geometry type specified in the domain.

gefest.core.opt.operators.mutations.drop_point_mutation(new_structure: Structure, domain: Domain, idx_: int = None, **kwargs)[source]

Drops random point from polygon.

class gefest.core.opt.operators.mutations.MutationTypes(value)[source]

Bases: Enum

enumerates all mutation functions.

rotate_poly(*args, **kwargs) = functools.partial(<function rotate_poly_mutation>)
resize_poly(*args, **kwargs) = functools.partial(<function resize_poly_mutation>)
add_point(*args, **kwargs) = functools.partial(<function add_point_mutation>)
drop_point(*args, **kwargs) = functools.partial(<function drop_point_mutation>)
add_poly(*args, **kwargs) = functools.partial(<function add_poly_mutation>)
drop_poly(*args, **kwargs) = functools.partial(<function drop_poly_mutation>)
pos_change_point(*args, **kwargs) = functools.partial(<function pos_change_point_mutation>)

Selections

gefest.core.opt.operators.selections.roulette_selection(pop: list[Structure], pop_size: int, **kwargs) list[Structure][source]

Selects the best ones from provided population.

Parameters:
  • pop (list[Structure]) – population

  • pop_size (int) – population size limit

Returns:

best individuals from pop

Return type:

list[Structure]

gefest.core.opt.operators.selections.tournament_selection(pop: list[Structure], pop_size: int, fraction: float = 0.1, **kwargs) list[Structure][source]

Selects the best ones from provided population.

Parameters:
  • pop (list[Structure]) – population

  • pop_size (int) – population size limit

  • fraction (float, optional) – best part size. Defaults to 0.1.

Returns:

The best individuals from given population.

Their number is equal to 'initial_number' * fraction

Return type:

list[Structure]

class gefest.core.opt.operators.selections.SelectionTypes(value)[source]

Bases: Enum

Enumerates all GEFEST selection functions.

roulette_selection(*args, **kwargs) = functools.partial(<function roulette_selection>)
tournament_selection(*args, **kwargs) = functools.partial(<function tournament_selection>)