A Generic Genetic Algorithm Using Phenotype Building Functions
A Generic Genetic Algorithm Using Phenotype Building Functions
Marc Tanti
Dept Artificial Intelligence
University of Malta
[email protected]
Clashes
avoid counting each attack twice as attacks are 15
symmetric (queen A attacks queen B means that 10
queen B attacks queen A). Overlapping queens 5
are counted 3 times, hence giving them a greater
0
penalty. The genetic algorithm minimizes the
1
43
85
127
169
211
253
295
337
379
421
463
number of attacks.
One of the 3 runs reached a solution to the
Generation
problem with no queens attacking others, the
other two only had one queen in the wrong place. Figure 3 Graph of best fitness vs generation of evolution
15 of time table scheduling.
10
4.4 Travelling Salesperson Problem
Attacks
Distance
150 to evolve an equation which has a graph that
passes through a given set of points with minimal
100
error. The points1 used are the duration of the
50 orbits of planets against their distance from the
0 sun. The goal is that of finding an equation
which describes the relationship between orbit
1
43
85
127
169
211
253
295
337
379
421
463
duration and radius.
Generation The equation to be evolved can consist of (any
number of the following) a constant made of 10
Figure 5 Graph of best fitness vs generation of evolution bits for the whole number and 10 bits for the
of TSP. fractional part, an input variable for the equation
(x), a square root, a plus, a times and a division.
4.5 Bin Packing Problem
In all there cannot be more than 50 operands and
In this problem, the genetic algorithm was used operators.
to evolve a solution to a bin packing problem Since evolving equations involves evolving
where the bin size is of 100 units and the items to expression trees, the builder function generates
bin are the numbers from 1 to 99. trees by using reverse polish notation. First, a
To make the example more interesting, it was queue of rational number constants of 10 bit
decided to solve this problem by finding a per- whole numbers and 10 bit fractional parts are
mutation of the list of items and adding them to evolved together with another queue of operands
the bins in order, fitting as many numbers as and operators, collectively called functions.
possible in the current bin and starting a new bin Functions are de-queued and pushed into a stack
when the next number doesn’t fit. where if a function is an operation, the right
As a permutation problem, the builder func- amount of functions are popped from the stack
tion generates permutations by swapping the and attached to the operation. Should there not
elements in the ordered list of numbers. In this be enough functions in the stack, the operation is
case, we shall use the concept used by selection ignored. If the function being pushed is a con-
sort, where we move through the list from first to stant, a rational number is de-queued and used as
last swapping each element with an element after the constant to be pushed into the stack. At the
it (or with itself in order to leave it in place). end only the tree found at the top of the stack is
Natural numbers are read to determine which used as the phenotype, which allows variation in
element to swap with. the size of the tree. If the stack is empty, the
The fitness function counts the number of bins phenotype will be the equation y = 0.
used. The genetic algorithm minimizes the num- The fitness function takes each point the equa-
ber of bins. tion is supposed to pass through and calculates
All 3 runs evolved a solution using 53 bins, 3 the mean square error for each point. The genetic
bins more than a greedy algorithm’s solution algorithm minimizes the error.
(binning 99 with 1, 98 with 2, etc). None of the 3 runs reached zero error, howev-
65 er they all came very close when considering that
a perfect fit might not exist within the constraints
60 imposed on the equation. The best fit had a max-
imum error of 48.4 and the graph of the equation
Bins
55
is:
50
45
1
43
85
127
169
211
253
295
337
379
421
463
Generation
5 Conclusion
We feel that the experiments demonstrated in
this report show that the concept described is
worth investigating further. Although we do not
claim that any problem can be efficiently
Figure 7 Equation evolved: y=(x + x) * sqrt(x /
evolved with this system, we believe that any
100.751953125) Turing computable candidate solution can be
described and evolved.
1.00E+10 From a cynical point of view, one might claim
Mean Square Error