navicatGA.float_solver¶
Attributes¶
Classes¶
Example child solver class for the GA. |
Functions¶
Module Contents¶
- class navicatGA.float_solver.FloatGenAlgSolver(chromosome_to_array=make_array(), variables_limits=None, n_genes: int = 1, fitness_function=None, excluded_genes: Sequence = None, **base_kwargs)¶
Bases:
navicatGA.base_solver.GenAlgSolverExample 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
- create_offspring(first_parent, sec_parent, crossover_pt, offspring_number)¶
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.
- get_crossover_points()¶
Retrieves random crossover points :return: a numpy array with the crossover points
- initialize_population()¶
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
- mutate_population(population, n_mutations)¶
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
- variables_limits = None¶
- navicatGA.float_solver.test_bohachevsky()¶
- navicatGA.float_solver.logger¶