Objects of anyflo type genetic are used to define populations managed by genetic algorithms.
Each gene is composed of individuals, called particles, constructed from a certain alphabet.
Each gene may receive an evaluation function..
A new population can be generated by selection, crossover and mutation (favoring individuals of maximum assessment).
Genetic type object
Defines the genetic id.id.
Builds genetic number 1.
Builds the genetic name G.
Individuals of a population are constructed from an alphabet, which by default is reduced to two characters 0 and 1.
Defines the alphabet ABC on the genetic id.
An initial population can be defined randomly:
generate alea particle(100,12)genetic(1);
Randomly generate 100 individuals size 12 from the alphabet of genetic 1.
Defines a new individual.
Redefines individual p of genetic id.
All individuals of the same genetic must be character strings of the same size:
Population evolves by:
1) Selection of individuals for reproduction. They are chosen optimal in that they maximize a certain evaluation function.
2) Crossing two such individuals by randomly cutting and constructing a new individual by taking
the first part of the 1st and 2nd part of the 2nd.
3) Mutation (low probability) arbitrarily changing one or more elements.
The evaluation can be done in different ways:
1) Written anyflo language anyflo.:
This function must be of the form:
x=normalized avaluation of particue p (between 0.0 and 1.0)
g = number of the evluated genetic.
num = number of the evaluated individual.
p = value of this individual.
2) Written C language function:
num is the number passed to function
(of utilb.c), it will change, then it will link anyflo.
Runs genetic id, ie computes the returnss of the evaluation function for each individual
of population id.
scale particle genetic(g);
Returns these values.
Cross overs are stored in
cut genetic in the form:
ind,p1,p2 with ind=index of cut, p1 et p2 = number of the particles crossed.
Returns ind,p1,p2 for individual n.
(This command is a purely didactic).
Returns the first element of cut.
Edits genetic id.
edit particle genetic(id);
Edits individuals of genetic id.
Removes genetic id.
Deletes all genetics.
Regeneration of a population
Regenerates the genetic id by selection, crossover and mutation of its individuals,
favoring individuals of maximum evaluation.
Regenerates n times the genetic id..
Population improves as we regenerate it.
the evaluation values of individuals are stored in:
scale particle genetic;
edit scale particle genetic(1);
Edits the evaluations.
$scale particle(1) genetic(1);
Prints the evaluation of individual 1.
scale particle(1) genetic(1)=0.1;
Changes the evaluation of individual 1.
Recomputes the evaluations of individuals of genetic id.
Recomputes the evaluations of individuals of all genetics.
validate particle(n) genetic(id);
Recomputes the evaluations of individual n of genetic id.
For a simple example showing the resolution of a problem by a genetic algorithm