Welcome to Genetic’s documentation!¶
Contents:
Required Installations¶
Python 2.7¶
This package requires python 2.7 and will not work with python 2.6. It can easily be transformed into python 2.6 compliant code. Most of the incompatibilities come from list/dict comprehension expressions
PyGame (and all its dependencies)¶
Used in visualization of the included TSP solver
pycontract¶
Used for contract checking (only when testmode is True; see the documentation for settings.py)
Overview - How to use this Framework¶
If you are making your own evolutionary algorithm, there are several files that you should edit
individual.py¶
This file defines what an individual is (in a class). Generically, an individual
is simply an ordered collection of chromosomes. The original implementation treats each chromosome differently. Therefore, all the chromosomes of an individual are maintained in a list
as opposed to a set
.
Also implemented in this file are methods to the individual
class that help identify an individual, define its hash
, test its equality to another individual
instance, etc
population.py¶
This file contains the functions that define population generation.
The important function defined here is genPop()
, which may be used as an interface to creating unique individuals.
-
genPop
(N, chromGenfuncs, chromGenParams)¶ Parameters: - N (int) – the number of individuals in the population
- chromGenfuncs (list of tuples) – a list of functions. The ith function is responsible for generating the ith chromosome for the individual. The length of this list is exactly the number of chromosomes in each individual
- chromGenfuncs – list of params for the functions in chromGenfuncs. The ith function in chromGenfuncs is called with the parameters held in the ith tuple of this list
Return type: list of unique individuals. Uniqueness is defined by
Individual.__eq__
chromGenfuncs¶
chromGenfuncs is a list of functions. The idea here is that each individual in the population is made up of C chromosomes. These C chromosomes are generated independently of each other for each individual in the initial population. Therefore, there must be exactly C functions listed in chromGenfuncs. The i
th function in chromGenfuncs will be used to generate the i
th chromosome of each individual
chromGenParams¶
chromGenParams is a list of tuples. There should be exactly as many tuples in this list, as there are functions in chromGenfuncs. To generate the ith chromosome for each individual in the population, the ith function in chromGenfuncs is called with the parameters in the ith tuple of chromGenParams as follows:
chromGenfuncs[i](*chromGenParams[i])
Though that is the general idea behind how genPop()
works, it actually performs this call in a for loop over a zip()
of chromGenfuncs and chromGenParams
fitness.py¶
This file contains all selection functions for evaluating the fitness of any individual of the population. The main function in this file is called score()
.
-
score
(p, scorefuncs, scorefuncparams, SCORES)¶ Parameters: - p (instance of individual) – the individual being evaluated
- scorefuncs (list of functions) – a list of functions - one to evaluate each chromosome in the individual
- scorefuncparams – a list of tuples containing the parameters for each of the functions in scorefuncs. Each function will be called by calling scorefuncs[i](p, *scorefuncparams[i])
- SCORES (dict {Individual : number}) – a dict mapping instances of Individual to their fitness
Return type: number (the fitness of the individual)
Note
if the individual being evaluated by this function (p
) was not in SCORES
before the function is executed, it will be inserted into SCORES
by this function. Thus, SCORES
is modified in-place by this function as required.
selection.py¶
This file contains all selection functions for selecting individuals from a population for any purpose.
There are three important functions already implemented:
tournamentSelect()
¶
-
tournamentSelect
(pop, T, w, n, scorefunc, scoreparams)¶ Parameters: - pop (list of Individuals) – the population to select from
- T (int) – the number of contestants in each tournament (must be smaller than len(pop))
- w (int) – the number of winners in each tournament (must be smaller than T)
- n (int) – the number of Individuals to be selected from the population by Tournament Selection (n%w should be 0)
- scorefunc (function) – the function used to evaluate the fitness of individuals, to determine the winner(s) of a tournament
- scoreparams (tuple) – the parameters that scorefunc requires, other than the individual itself. The individual is provided along with the unpacked list of params
Return type: list of individuals
rouletteWheelSelect()
¶
-
rouletteWheelSelect
(wheel, s=None)¶ Parameters: - wheel (a list of 3-tuples. Each tuple consists of the individual, the lower bound (float) of its section of the roulette wheel, and the upper bound (float) of its section of the roulette wheel.) – a roulette wheel
- s (float) – the random number on which the roulette ball lands on the roulette wheel. This is not provided when calling the function (though it may be if desired). Using this, a binary search is performed to find the Individual that bet on a section of the roulette wheel containing this number
Return type: single individual
getRouletteWheel()
¶
-
getRouletteWheel
(pop, SCORES)¶ Parameters: - pop (list of instances of Individual) – the population for which a roulette wheel must be made
- SCORES (dict {Individual:number}) – a dictionary that maps instances of Individual to their fitnesses
Return type: list of 3-tuples (Individual, lowerBound, UpperBound)
crossover.py¶
All functions that have to do with crossing over chromosomes between individuals are defined here. There is no generic driver function here as crossovers are defined per GA.
mutation.py¶
All functions that have to do with mutating chromosomes between individuals are defined here. There is no generic driver function here as mutations are defined per GA
individual.py¶
Define an individual to be used for evolution.
Instance variables¶
id
¶
A trackable identifier for the individual
chromosomes
¶
An ordered collection of the genetic material of this individual. Maintained as a list
Methods¶
__eq__(self, other)
¶
Return True if all chromosomes of self and other are equal (and in the same order). Else, return False
__hash__(self)
¶
Return the hash of the tuple version of all chromosomes
__len__(self)
Return the number of chromosomes self
is made of.
__getitem__(self, i)
¶
Return the i th individual
__setitem__(self, index, obj)
¶
Set obj as the index`th chromosome of ``self`
__contains__(self, chromosome)
¶
Return True if chromosome
is a member of self.chromosomes
.
Else return False
__repr__(self)
¶
Return self.id
as a string
append(self, chrom)
¶
Append chrom
to self.chromosomes
count(self, sub, chrom)
Return the number of occurrences of sub
in the chrom
th chromosome of self
population.py¶
genPop(N, chromGenfuncs, chromGenParams)¶
Return a population (list) of N unique individuals. Each individual has len(chromgGenFuncs) chromosomes. For each individual, chromosome_i is generated by calling chromGenFuncs_i(chromeGenParams_i)
genCharsChrom(l, chars)¶
Return a chromosome (list) of length l
, each of which is made up of the characters from chars.
genTour(numCities)¶
This is the chromosome generation function for the traveling salesman problem. This function returns a list of ints. This list is a permeation of {0, 1, 2, …, numCities-1} and represents a tour that the traveling salesman would take
fitness.py¶
score(p, scorefuncs, scorefuncparams, SCORES)¶
Return the sum of the fitness of each chromosome of individual p and store the result in SCORES (mapped under p) The score of the chromosome_i is determined by the call scorefunc[i](p.chromosomes[i], *scorefuncparams[i])
scoreOnes(p)¶
Return the number of ‘1’s in the chromosome p
scoreTSP(tour, DIST)¶
Return the total distance of tour
, a list of ints, representing a tour (each int is a city ID).
DIST
is a dictionary: {source_city_id : {destination_city_id : distance between source_city and desitantion_city} }
selection.py¶
getRouletteWheel(pop, SCORES)¶
Return a fitness proportional roulette wheel. A roulette wheel is a list of 3-tuples structured as follows: (indiv, low, high) where indiv is the individual that bets on the section of the roulette wheel between low and high
rouletteWheelSelect(wheel, s=None)¶
Perform roulette wheel selection. A wheel is a fitness proportional roulette wheel as returned by the makeRouletteWheel function. The parameter s is not required thought not disallowed at the time of calling by the evolutionary algorithm. If it is not supplied, it will be set as a random float between 0 and 1. This function returns the individual that bet on the section of the roulette wheel that contains s
tournamentSelect(pop, T, w, n, scorefunc, scoreparams)¶
Return a list of n indivuduals. Each of these individuals has been selected by conducting tournaments of size T. Each tournament may have exactly w winners Winners of the tournament are the fittest individuals in the tournament as determined by scorefunc
crossover.py¶
crossOnes(p1, p2)¶
Take two chromosomes (p1
and p2
).
Cross them over.
Return two new child chromosomes
injectionco(p1, p2, chrom)¶
Take two chromosomes p1
and p2
.
Crossover them over as follows:
- Select distinct points A < B between 0 and
len(p1.chromosomes[chrom])
- Make an empty child chromosome of length
len(p1.chromosomes[chrom])
- Copy over the genes of
p1
from A to (but not including) B into the corresponding genes of the child - Fill in the rest of the genes of the child with the genes from
p2
, in the order in which they appear inp2
, making sure not to include alleles that already exist in the child
Return the child chromosome
twoChildCrossover(p1,p2, crossfuncs, crossparams)¶
Take two parents, p1
and p2
.
Assume that crossfuncs
and crossparams
are of equal length
Make two empty individuals to be returned as the answer
For each i``th pair of corresponding chromosomes in ``p1
and p2
, cross them over with the corresponding i``th function in ``crossfuncs
(and pass in the i``th tuple of parameters from ``crossparams
)
It is assumed that each function in crossparams
returns two child chromosomes.
When crossover on each pair of chromosomes is complete, add the first child chromosome to the first child individual to be returned and the second child chromosome to the second child individual to be returned.
When all crossover operations are complete, return the two child individuals as the product of crossing over p1
and p2
.
oneChildCrossover(p1, p2, crossfuncs, crossparams)¶
Take two parents, p1
and p2
.
Assume that crossfuncs
and crossparams
are of equal length
Make an empty individual to be returned as the answer
For each i``th pair of corresponding chromosomes in ``p1
and p2
, cross them over with the corresponding i``th function in ``crossfuncs
(and pass in the i``th tuple of parameters from ``crossparams
)
It is assumed that each function in crossparams
returns one child chromosome
When crossover on each pair of chromosomes is complete, add the child chromosome to the child individual to be returned
When all crossover operations are complete, return the child individual as the product of crossing over p1
and p2
.
mutaion.py¶
mutateSingleAllele(p, chrom, chars)¶
Return a new individual, which is the same as p
, but with the chrom
th chromosome changed as follows:
Select a random gene and change its value to something from the choices in chars
swapmut(p, chrom)
¶
Get the chrom
th individual in p. Select two random elements in that chromosome and swap their positions in that chromosome
Return a new individual that is the same as p
, but with the above change made to its chrom
th chromosome
revmut(p, chrom)
¶
Get the chrom
th individual in p. Select two random elements in that chromosome and reverse the order of genes between those two elements in that chromosome
Return a new individual that is the same as p
, but with the above change made to its chrom
th chromosome
shufflemut(p, chrom)
¶
Get the chrom
th individual in p. Shuffle that chromosome with random.shuffle
Return a new individual that is the same as p
, but with the above change made to its chrom
th chromosome
GA.py¶
runTSPGA(kwargs)¶
Run a GA that solves the Traveling Salesman Problem with the settings generated in settings.py
runGA(kwargs)¶
Run a simple fitness-maximizing GA that solves any applicable problem. At the time of writing this document, it was applied to the One-Max problem
run(kwargs)¶
This is the main driver function that runs the required evolutionary algorithm. But before it does that, it also checks the sanity and makes sure to import PyContract if required (as indicated by the testmode
flag)
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
visualization.py¶
This module handles all the visualization for any evolution.
The current implementation uses pygame
makeScreen(W, H)¶
Make an empty screen of width W
and height H
normalize(point, (olow, ohigh), (low, high))¶
This is a helper function. It takes a value for point
, originally measured in the scale [olow, ohigh].
The returned value is the corresponding value of point
on the scale [low, high]
draw(tour, window, W, H, SCORES, COORDS)¶
Draws a tour of a traveling salesman, and writes the score of the tour on the window.
Each city in the tour is represented as a red dot, with white lines connecting them.
COORDS
is a dictionary that contains the coordinates of the various cities.
The fitness score of tour
is also written to window
killscreen()¶
This function cleans up pygame and destroys the window and the screen; to be called at the end of evolution.
Contracts¶
Contracts are used to check the pre and post conditions of functions to make sure that the evolutionary algorithm remains constrained within the solution space.
All contracts used by all functions are listed here. It is highly recommended that similar functions that are implemented in the future implement similar contracts. This will be explained further as each contract is explaioned.
GA.py¶
The main GA driver has the following contracts. It is highly recommended that any GA implemented to maximize the fitness score should implement these contracts.
The main GA runner¶
Preconditions¶
kwargs
should be suppliedkwargs
is a dict mapping argument names (strings) to argument values- The maximum number of generations allowed is greater than 0
Postconditions¶
kwargs
should not be changed- At least one of the following two conditions must hold
- the fitness of the fittest individual (being returned) is at least
targetscore
- the current generation count is equal to the maximum number of generations allowed
- the fitness of the fittest individual (being returned) is at least
the maximum number of generations allowed is greater than 0
Individual.py¶
The following contracts must be followed for any implementation of the Individual
class
Individual.__hash__(self, other)
¶
Preconditions¶
None
Postconditions¶
- an
int
should be returned self
should not be changed
In addition to these, the current implementation has the following methods implemented:
Individual.__eq__(self, other)
¶
Preconditions¶
other
should be an instance ofIndividual
Postconditions¶
other
should not be changedself
should not be changed
Individual.__setitem__(self, index, obj)
¶
Preconditions¶
- Exactly one of the following two conditions must be satisfied:
- 0 <=
index
<= len(self.chromosomes) - len(self.chromosomes)*-1 >= index >= -1
- 0 <=
Postconditions¶
- The object at
self.chromosomes[index]
should beobj
Individual.__contains__(self, chromosome)
¶
Preconditions¶
None
Postconditions¶
self
should not be changedchromosome
should not be changed
population.py¶
The following contracts are applied to the functions in population.py
genPop(N, chromGenfuncs, chromGenParams)
¶
Preconditions¶
- N >= 0
chromGenfuncs
is a list- Every entry in
chromGenfuncs
is a function chromGenParamss
is a list- The lengths of
chromGenfuncs
andchromGenParams
are equal
Postconditions¶
- The inputs are unchanged
- Function returns a list
- The length of the returned list is
N
- The returned list contains exactly 1 of each item i.e. no two items in the returned list are equal
genCharsChrom(l, chars)
¶
Preconditions¶
l
is an integerchars
is an instance of some class that implements__getitem__
chars
is an instance of some class that implements__len__
len(chars)
is greater than 0
Postconditions¶
- The inputs are unchanged
- Function returns a list
- The length of the returned list is
l
- Every element in the returned list exists in
chars
score.py¶
score(p, scorefuncs, scorefuncparams, SCORES)
¶
Preconditions¶
p
is an instance ofIndividual
scorefuncs
is a list of functionsscorefuncparams
is a list of tuples- The lengths of
scorefuncs
andscorefuncparams
are equal SCORES
is a dictionary
Postconditions¶
The inputs are unchanged
p
is inSCORES
- Exactly one of the following two conditions are met:
p
was inSCORES
before this function was called and the number of entries inSCORES
has not changedp
was not inSCORES
before this function was called and the number of entries inSCORES
has increased by exactly 1
scoreOnes(p)
¶
Preconditions¶
p
is list- All elements in
p
are strings of length exactly 1 - All elements in
p
are either ‘0’ or ‘1’
Postconditions¶
p
is unchaged- An integer is returned
- The value returned is at least 0
scoreTSP(tour, DIST)¶
- post:
- isinstance(__return__, float)
- post[tour, DIST]:
- __old__.tour == tour __old__.DIST == DIST
Preconditions¶
tour
is a listDIST
is a dictionary- All elements in
tour
are integers - All keys in
DIST
are integers - All values in
DIST
are dictionaries - Every key in every value of
DIST
is an integer - Every value in every value of
DIST
is a float
Loop Invariant¶
answer
(the value to be returned is at most 0 and monotonously decreases
Postconditions¶
- The inputs are unchanged
- The function returns a float
getRouletteWheel(pop, SCORES)¶
Preconditions¶
pop
is a list of instances ofIndividual
SCORES
is a dictionary- Every element in
pop
is a key inSCORES
Postconditions¶
- The inputs are unchanged
- A list of 3-tuples of type (Individual, float, float) is returned
- The length of the returned list is equal to the length of
pop
- The first element of every tuple in the returned list exists in
pop
- The second float is smaller than the third float in every tuple in the returned list
rouletteWheelSelect(wheel, s=None)¶
Preconditions¶
wheel
is a list of 3-tuples which satisfy all the following conditions- The first element is an instance of
Individual
- The last two elements are floats
- The first float is smaller than the second
- The first element is an instance of
- Exactly one of the following two conditions are met:
s
is a floats
is None
Postconditions:¶
- The inputs are unchanged
- An instance of
Individual
is returned
tournamentSelect(pop, T, w, n, scorefunc, scoreparams)¶
Preconditions¶
pop
is a list of instances ofIndividual
T
is an integerw
is an integern
is an integerw
is at mostn
n%w
is exactly 0n
is at mostT
scoreparams
is a tuple
Postconditions¶
- The inputs are unchanged
- A list of
n
instances ofIndividual
is returned
crossover.py¶
The following contracts are implemented for the crossover functions.
crossOnes(p1, p2, chrom)¶
injectionco(p1, p2, chrom)¶
twoChildCrossover(p1,p2, crossfuncs, crossparams)¶
Preconditions¶
p1
andp2
are instances ofIndividual
p1
andp2
are of exactly equal length- The number of elements in
crossfuncs
is exactly equal to the length ofp1
(and therefore ofp2
) - The number of elements in
crossfuncs
is exactly equal to the number of elements incrossparams
- Every element in
crossparams
is a tuple
Postconditions¶
- The inputs are unchanged
- A tuple of two elements of type
Individual
is returned - Each of the returned children has the same number of chromosomes as the parents
- Each chromosome in each of the children has the same length as the corresponding chromosome of both parents
oneChildCrossover(p1,p2, crossfuncs, crossparams)¶
Preconditions¶
p1
andp2
are instances ofIndividual
p1
andp2
are of exactly equal length- The number of elements in
crossfuncs
is exactly equal to the length ofp1
(and therefore ofp2
) - The number of elements in
crossfuncs
is exactly equal to the number of elements incrossparams
- Every element in
crossparams
is a tuple
Postconditions¶
- The inputs are unchanged
- A tuple of one element of type
Individual
is returned - The returned child has the same number of chromosomes as the parents
- Each chromosome in the child has the same length as the corresponding chromosome of both parents
muatation.py¶
mutateSingleAllele(p, chrom, chars)¶
Preconditions¶
p
is an instance ofIndividual
chrom
is an integerThe value of each gene in the
chrom
th chromosome ofp
exists inchars
- Exactly one of the following two conditions must be satisfied:
- 0 <=
index
<= len(self.chromosomes) - len(self.chromosomes)*-1 >= index >= -1
- 0 <=
Postconditions¶
- The inputs are unchanged
- A new instance of
Individual
is returned - The
chrom
th chromosome of the returned individual is not equal to thechrom
th chromosome ofp
- All other chromosomes of the returned individual are exactly the same as the corresponding chromosome of
p
swapmut(p, chrom)¶
Preconditions¶
p
is an instance ofIndividual
chrom
is an integer- Exactly one of the following two conditions are satisfied:
- 0 <=
chrom
<=len(p.chromosomes)
len(self.chromosomes)*-1
>=index
>= -1
- 0 <=
Postconditions¶
- The inputs are unchaged
- An instance of
Individual
is returned - All values in the
chrom
th chromosome ofp
are present in thechrom
th chromosome of the output individual - The
chrom
th chromosomes of the output individual andp
are not equal - There are exactly two genes in the
chrom
th chromome ofp
and the returned individual, whose values differ
revmut(p, chrom)¶
Preconditions¶
p
is an instance ofIndividual
chrom
is an integer- Exactly one of the following two conditions are satisfied:
- 0 <=
chrom
<=len(p.chromosomes)
len(self.chromosomes)*-1
>=index
>= -1
- 0 <=
Postconditions¶
- The inputs are unchaged
- An instance of
Individual
is returned - All values in the
chrom
th chromosome ofp
are present in the`chrom
th chromosome of the output individual - The
chrom
th chromosomes of the output individual andp
are not equal
shufflemut(p, chrom)¶
- post[p, chrom]:
- __old__.p == p __old__.chrom == chrom isinstance(__return__, Individual) __return__.chromosomes[chrom] != p.chromosomes[chrom] forall(p.chromosomes[chrom], lambda e: e in __return__.chromosomes[chrom]) forall(__return__.chromosomes[chrom], lambda e: e in p.chromosomes[chrom])
Preconditions¶
p
is an instance ofIndividual
chrom
is an integer- Exactly one of the following two conditions are satisfied:
- 0 <=
chrom
<=len(p.chromosomes)
len(self.chromosomes)*-1
>=index
>= -1
- 0 <=
Postconditions¶
- The inputs are unchaged
- An instance of
Individual
is returned - All values in the
chrom
th chromosome ofp
are present in the`chrom
th chromosome of the output individual - The
chrom
th chromosomes of the output individual andp
are not equal - The length of the
chrom
th chromosome of the returned individual is exactly equal to the length of thechrom
th chromosome ofp
Download the PDF¶
lorem ipsum