navicatGA.float_solver

Attributes

Classes

FloatGenAlgSolver

Example child solver class for the GA.

Functions

Module Contents

Bases: navicatGA.base_solver.GenAlgSolver

Example child solver class for the GA. This child solver class is an example meant for a particular purpose, which in this case is optimizing a numerical function with float parameters. It might require heavy modification for other particular usages. Only the parameters specific for this child class are covered here.

Parameters: :param chromosome_to_array: object that when called returns a function that can take a chromosome and generate a np.array :type chromosome_to_array: object :param variables_limits: limits for each variable [(x1_min, x1_max), (x2_min, x2_max), …] :type variables_limits: tuple, list of tuples :param base_kwargs: any GenAlgSolver parameter (max_gen, pop_size, mutation_rate, …); see GenAlgSolver for the full list and defaults

Creates an offspring from 2 parents. It performs the crossover according the following rule: p_new = first_parent[crossover_pt] + beta * (first_parent[crossover_pt] - sec_parent[crossover_pt]) offspring = [first_parent[:crossover_pt], p_new, sec_parent[crossover_pt + 1:] where beta is a random number between 0 and 1, and can be either positive or negative depending on if it’s the first or second offspring http://index-of.es/z0ro-Repository-3/Genetic-Algorithm/R.L.Haupt,%20S.E.Haupt%20-%20Practical%20Genetic%20Algorithms.pdf

Parameters: :param first_parent: first parent’s chromosome :param sec_parent: second parent’s chromosome :param crossover_pt: point(s) at which to perform the crossover :param offspring_number: whether it’s the first or second offspring from a pair of parents.

Returns: :return: the resulting offspring.

Retrieves random crossover points :return: a numpy array with the crossover points

Initializes the population of the problem according to the population size and number of genes and according to the problem type (either integers or floats).

Returns: :return: a numpy array with a randomized initialized population

Mutates the population by randomizing specific positions of the population individuals.

Parameters: :param population: the population at a given iteration :param n_mutations: number of mutations to be performed

Returns: :return: the mutated population