reV.bespoke.gradient_free.GeneticAlgorithm

class GeneticAlgorithm(bits, bounds, variable_type, objective_function, max_generation=100, population_size=0, crossover_rate=0.1, mutation_rate=0.01, tol=1e-06, convergence_iters=5, max_time=3600)[source]

Bases: object

a simple genetic algorithm used to select bespoke turbine locations

Parameters:
  • bits (array of ints) – The number of bits assigned to each of the design variables. The number of discretizations for each design variables will be 2^n where n is the number of bits assigned to that variable.

  • bounds (array of tuples) – The bounds for each design variable. This parameter looks like: np.array([(lower, upper), (lower, upper)…])

  • variable_type (array of strings (‘int’ or ‘float’)) – The type of each design variable (int or float).

  • objective_function (function handle for the objective that is to be) – minimized. Should take a single variable as an input which is a list/array of the design variables.

  • max_generation (int, optional) – The maximum number of generations that will be run in the genetic algorithm.

  • population_size (int, optional) – The population size in the genetic algorithm.

  • crossover_rate (float, optional) – The probability of crossover for a single bit during the crossover phase of the genetic algorithm.

  • mutation_rate (float, optional) – The probability of a single bit mutating during the mutation phase of the genetic algorithm.

  • tol (float, optional) – The absolute tolerance to determine convergence.

  • convergence_iters (int, optional) – The number of generations to determine convergence.

  • max_time (float) – The maximum time (in seconds) to run the genetic algorithm.

Methods

chromosome_2_variables(chromosome)

convert the binary chromosomes to design variable values

crossover()

perform crossover between individual parents

initialize_bits()

determine the total number of bits

initialize_design_variables()

initialize the design variables from the randomly initialized population

initialize_fitness()

initialize the fitness of member of the parent population

initialize_population()

randomly initialize the parent and offspring populations

mutate()

randomly mutate bits of each chromosome

optimize_ga()

run the genetic algorithm

initialize_design_variables()[source]

initialize the design variables from the randomly initialized population

initialize_bits()[source]

determine the total number of bits

initialize_population()[source]

randomly initialize the parent and offspring populations

initialize_fitness()[source]

initialize the fitness of member of the parent population

chromosome_2_variables(chromosome)[source]

convert the binary chromosomes to design variable values

crossover()[source]

perform crossover between individual parents

mutate()[source]

randomly mutate bits of each chromosome

optimize_ga()[source]

run the genetic algorithm