geneticengine.problems

Submodules

Attributes

P

__ALL__

Exceptions

InvalidFitnessException

Common base class for all non-exit exceptions.

Classes

Fitness

Problem

Represents the Optimization Problem being solved.

SequentialObjectiveProblem

SequentialObjectiveProblem is defined by a list of objectives that are intended to be either maximized/minimized in order.

SingleObjectiveProblem

A problem that is characterized by a single value.

MultiObjectiveProblem

Represents the Optimization Problem being solved.

LazyMultiObjectiveProblem

LazyMultiObjectiveProblem is used for problems whose number of objectives is not known a-priori.

Package Contents

exception geneticengine.problems.InvalidFitnessException

Bases: Exception

Common base class for all non-exit exceptions.

Initialize self. See help(type(self)) for accurate signature.

class geneticengine.problems.Fitness

Bases: NamedTuple

fitness_components: list[float]
valid: bool = True
__str__()
geneticengine.problems.P
class geneticengine.problems.Problem(fitness_function, minimize, target=None)

Bases: abc.ABC, Generic[P]

Represents the Optimization Problem being solved.

Parameters:
  • fitness_function (Callable[[P], list[float]])

  • minimize (list[bool])

  • target (Optional[list[float]])

minimize: list[bool]
target: list[float] | None
ff
evaluate(phenotype)
Parameters:

phenotype (P)

Return type:

Fitness

abstractmethod is_better(a, b)

Returns whether the first fitness is better than the second.

Parameters:
Return type:

bool

get_invalid_fitness()

Returns an invalid fitness.

Return type:

Fitness

number_of_objectives()
Return type:

int

is_solved(fitness)
Parameters:

fitness (Fitness)

Return type:

bool

class geneticengine.problems.SequentialObjectiveProblem(fitness_function, minimize, target=None)

Bases: Problem[P]

SequentialObjectiveProblem is defined by a list of objectives that are intended to be either maximized/minimized in order.

Parameters:
  • fitness_function (Callable[[P], list[float]])

  • minimize (list[bool])

  • target (Optional[list[float]])

is_better(a, b)

Returns whether the first fitness is better than the second.

Parameters:
Return type:

bool

class geneticengine.problems.SingleObjectiveProblem(fitness_function, minimize=False, target=None)

Bases: SequentialObjectiveProblem[P]

A problem that is characterized by a single value.

Parameters:
  • fitness_function (Callable[[P], float])

  • minimize (bool)

  • target (Optional[float])

class geneticengine.problems.MultiObjectiveProblem(fitness_function, minimize, target=None)

Bases: Problem[P]

Represents the Optimization Problem being solved.

Parameters:
  • fitness_function (Callable[[P], list[float]])

  • minimize (list[bool])

  • target (Optional[list[float]])

is_better(a, b)

Returns whether the first fitness is better than the second.

Parameters:
Return type:

bool

class geneticengine.problems.LazyMultiObjectiveProblem(fitness_function, minimize=False, target=None)

Bases: MultiObjectiveProblem

LazyMultiObjectiveProblem is used for problems whose number of objectives is not known a-priori.

Parameters:
  • fitness_function (Callable[[P], list[float]])

  • minimize (bool)

  • target (Optional[float])

initialized = False
future_minimize = False
future_target = None
evaluate(phenotype)
Parameters:

phenotype (object)

Return type:

Fitness

number_of_objectives()
Return type:

int

geneticengine.problems.__ALL__