## A.2 Fitness Function

Fitness function is the function that determines the quality of single gene. It is constructed from basic elements (elementary functions, operators, variables and constants - see User's Guide - How to construct fitness expression for details).

### A.2.1 Initialization

In the beginning fitness function is stored in parameter file as an expression (fitness expression is a string of characters describing the function). This expression is checked for errors first. Then it is converted into postfix form and stored in expression stack. Each element in the expression stack has its type and value. Supported types and values are :

• number ... numeric value (integer or real number)
• variable ... index into the variable field (number of variable)
• named constant ... index into the constant field (number of constant)
• functor ... index of a functor (number of elementary function or operator)
• neural network ... neural network is used
• sum index ... index of the sum
• sum start delimiter ... says "here starts the sum"
• sum end delimiter ... says "here ends the sum"

Each variable is a vector, each constant is a n-dimensional field. In expression stack the variables and named constants are always preceeded by correct number of indexes (one when variable, n when constant).

### A.2.2 Computation

Gene evaluation is a process of fitness function computation for the given gene. Gene parts are used as variables of the function (see User's Guide - How to encode information into gene). The result is value from the range <0,1>. (the higher the value the better the gene). If the value is out of this range the result will be transfered into <0,1> by linear scaling mechanism using maximal and minimal value of the fitness (as given in parameter file). The value is computed using "method of rails". Method description:

input: postfix (expression stack) - in this stack all popped elements are not really removed, but they are only marked as used. They can be eventually put back (eg. it is possible to put back all the elements so the stack is would be in initial state).
output: value from the range <0,1>
local stack: help (expression stack) - this stack contains only elements of type number

algorithm steps :

```0) set postfix to the initial state (put back all "removed" elements)
1) get element from postfix
2) if type is:
a) number then put number into help.
b) variable then find appropriate vector of variables, get element from help and
use this new element as an index into the vector (this number is zero when variable
is single value) and put value of the indexed element into help.
c) named constant then find appropriate n-dimensional field of constants, get n elements
from help, use these elements as indexes into the field and put value of the indexed
element into help.
d) functor then get appropriate number of elements from help, count down the function
and put the result into help.
e) neural network then get appropriate number of elements from help and use them as
inputs for neural network recall. Put the result into help.
f) sum index then put actual index value into help.
g) sum start delimiter then if it is first run of the sum then put 0 into the help
else increase sum index.
h) sum end delimiter then get two elements from help and put their sum into help.
If index is in the range of sum go to the sum start delimiter in the postfix (put back
all elements up to sum start delimiter).
3) if postfix is empty then get element from help (there should be only one - if not error
message appears) and if necessary scale it into <0,1> (see previous text).
This value is fitness function result (fitness value).
```