settings.py

Since the evolutionary framework requires several settings for each of the modules being used, a separate file is used to specify the correct settings for a run of an evolution.

This file contains functions, each of which generates a specific set of settings to run evolution on a specific problem

Fields

All fields have to be set with some value or other. There are no default values in this framework, by design

algorithm

The evolutionary algorithm to be run (defined in GA.py)

testmode

Set this to true to run in-function assert statements that check contracts. False otherwise

maxGens

The maximum number of generations for which evolution shall be run after which it will be stopped even if an optimal solution has not yet been discovered

targetscore

The known optimal fitness score of the problem. Setting this to None or '' will simulate negative and positive infinity, respectively

popsize

The number of individuals in the population during evolution

numCrossovers

The number of crossover operations per generation

SCORES

A dictionary that remembers the fitness values of all individuals. This is used as an optimization. Usually, this is an empty dictionary This can be deactivated by changing Individual.__hash__ to something that will be unique to each individual, regardless of genetic makeup

genfunc

The function that generates the initial population

genparams

A tuple containing the parameters to send to genfunc in the correct order

scorefunc

The function that returns the fitness evaluation of an individual. By default this is set to fitness.score. .. note:

It is advisable to leave this as ``fitness.score``, especially for multi-chromosome individuals.

scoreparams

This is a 3-tuple

Index Type Description
0 list of functions the i th function listed here will be used to compute the fitness of the i th chromosome of the individuals
1 list of tuples the i th tuple listed here contains the parameters (in the correct order) for the i th function in the list in index 0
2 dictionary SCORES

Warning

The parameters listed do NOT include any reference to the individual whose fitness will be computed. The individual will be supplied by the main evolution function itself. This is because the individual is chosen by the selection function and therefore cannot be known at the time of making these settings

selectfunc

The selection function by which individuals will be selected for crossover

selectparams

A tuple of parameters (in the correct order) for the selection function

Warning

The parameters listed do NOT include any reference to the population from which individuals will be selected. The population will be supplied by the main evolution function itself. This is because the population keeps changing over time and therefore cannot be known at the time of making these settings

crossfunc

The function that performs crossover between two individuals. This is usually either oneChildCrossover or twoChildCrossover. These crossover functions return 1 or 2 children as the result of crossover, respectively.

crossfuncs

A list of crossover functions. The i``th function in this list will be used (along with the ``i``th tuple of parameters from ``crossparams) to crossover the ``i``th pair of corresponding chromosomes of two individuals.

crossparams

A tuple of parameters (in the correct order) for the crossover function

Warning

The parameters listed do NOT include any reference to the individuals to be crossed over. These individuals will be supplied by the main evolution function itself. This is because the individuals are chosen by the selection function and therefore cannot be known at the time of making these settings

mutfunc

The function that will mutate a given individual

mutparams

A tuple of parameters (in the correct order) for the crossover function

Warning

The parameters listed do NOT include any reference to the individual to be mutated. This individual will be supplied by the main evolution function itself. This is because the individual is chosen at random (with probability) and therefore cannot be known at the time of making these settings

crossprob

The probability of crossover occurring. Represented as a float in [0, 1]

mutprob

The probability of mutation occurring. Represented as a float in [0, 1]

rouletteWheelRequireres

A set of functions that require a roulette wheel. This is used later in the automated computation some settings

getWheel

A bool that determines whether the evolutionary algorithm must compute a roulette wheel for selection

Warning

This is an automatically set parameter. Do not alter it.

visualize

A boolean flag that determines if visualization is enabled

screenWidth

The width of the screen created for visualization

screenHeight

The height of the screen created for visualization

makeScreenParams

A tuple of parameters (in the correct order) required to make the screen on which the visualization will be drawn

drawParams

A tuple of parameters (in the correct order) required to draw the visualization on the screen

fon

The font with which any text should be written on screen during visualization

fontParams

The parameters for rendering font as a tuple 9in the correct order)

labelParams

A tuple of parameters (in the correct order) required to place any text in the correct place on screen during visualization

sanity

A list of parameter names that should be present in the settings. The settings are checked for the entries in sanity before any evolution is run, to ensure that all parameters are provided

answer

A dictionary of the settings to run evolution

Warning

It is generally a bad idea to alter statements that are not assignment statements. This is because they are automations that generate some settings, thus taking the responsibility of generating those settings away from the programmer. Altering them may have unintended side-effects

Warning

It is generally a bad idea to alter statements that are inside the if visualize block. This is a block that automates the inclusion of settings (both into the returned settings and the sanity) for visualization if it is enabled