In this section we are showing the interfaces that you need to follow when implementing your own objective functions and operators to solve a problem, and we illustrate them with examples.

## 1. Objective Functions

The objective functions receive a vector representing the evaluable part of a solution and return its ﬁtness for the problem under consideration. Our toolbox solves maximization problems, that is, it considers that a certain solution is better than another if it has a higher ﬁtness value. The interface for the objective functions is:

function y = objective(x) |

For example, if you want to solve the onemax problem, consisting in maximizing the number of ones in a binary string, you can implement the objective function shown below, which returns the sum of the vector that it has received as an argument:

function y = onemax(x) |

y = sum(x); |

The Frequency Modulation Sounds problem (FMS) consists in determining the 6 parameters
a_{1},ω_{1},a_{2},ω_{2},a_{3},ω_{3} of the FM Sound model represented by

_{1}· sin(ω

_{1}· t · θ + a

_{2}· sin(ω

_{2}· t · θ + a

_{3}· sin(ω

_{3}· t · θ)))

with θ = (2 · π · 100). The ﬁtness function is deﬁned as the summation of square errors between the evolved data and the model data, as follows:

f_{fms}(a

_{1},ω

_{1},a

_{2},ω

_{2},a

_{3},ω

_{3}) = ∑

_{t=0:100}(y(t) - y

_{0}(t))

^{2}

The model data are given by the following equation:

y

_{0}(t) = 1.0 · sin(5.0 · t · θ - 1.5 · sin(4.8 · t · θ + 2.0 · sin(4.9 · t · θ))).

Each parameter is in the range -6.4 to 6.35. This is a highly complex multimodal problem with a strong epistasis.

As our toolbox works solving maximization problems, the ﬁtness function implemented in MATLAB is the reverse of the ﬁtness function shown above. To avoid dividing by 0, we add 0.001 to the denominator, so the ﬁtness value of the global minimum is 1000. The code of this function is shown in Figure 1.

Figure 1: MATLAB function to solve the FMS problem

## 2.Operators

Because of the large amount of different operators that can be used, the interface for the MATLAB functions implementing them is very general. The data received by the functions depend strongly on the kind of operator we implement and the library we are using to solve the problem. The deﬁned interface is the following:

function res = operador(inds, props) |

where inds is a MATLAB structure with the following ﬁelds:

- popl: The population size.
- data: A 2-dimensional matrix with popl rows. Each row stores the evaluable part of an individual in the population.
- sigma: A 2-dimensional matrix with popl rows. This ﬁeld is only used in Evolutionary Strategies. Each row stores the standard deviations vector of one individual in the population.
- alpha: A 2-dimensional matrix with popl rows. This ﬁeld is only used in Evolutionary Strategies. Each row stores the angles vector of one individual in the population.
- ﬁt: A row vector with a length of popl containing the ﬁtness values of all the individuals in the population.
- n_ind: The number of individuals received by the operator.
- data_op: A 2-dimensional matrix with n_ind rows. Each row stores the evaluable part of one individual received by the operator.
- sigma_op: A 2-dimensional matrix with n_ind rows. This ﬁeld only makes sense in Evolutionary Strategies. Each row stores the standard deviations vector of one individual received by the operator.
- alpha_op: A 2-dimensional matrix with n_ind rows. This ﬁeld is only used in Evolutionary Strategies. Each row stores the angles vector of one individual received by the operator.
- ﬁt_op: A row vector with a length of n_ind containing the ﬁtness values of all the individuals received by the operator.

When using the MALLBA library, the only ﬁelds that may have a content are n_ind, data_op,
sigma_op y alpha_op. In the jEA library, all the ﬁelds can be used. The ssGA library does not
admit the addition of new operators.

props contains the operator parameters deﬁned by the user in the conﬁguration ﬁle, stored
in a 2-dimensional cell array with as many rows as the number of parameters of the operator,
and two columns: the ﬁrst one containing the name of the parameter and the second one its
value.

res must be a MATLAB structure with the following ﬁelds:

- n_ind: The number of individuals returned by the operator. Operators in the MALLBA library must return the same number of individuals they have received. There are no restrictions in the number of individuals returned by the operators in the jEA library.
- data: A 2-dimensional matrix with n_ind rows. Each ﬁle will store the evaluable part of one individual returned by the operator.
- sigma: A 2-dimensional matrix with n_ind rows. It is only used in Evolutionary Strategies. Each row will store the standard deviations vector of one individual returned by the operator.
- alpha: A 2-dimensional matrix with n_ind rows. It only makes sense in Evolutionary Strategies. Each row will contain the angles vector of one individual returned by the operator.
- ﬁt: A row vector with a length of n_ind, containing the ﬁtness values of all the individuals returned by the operator.

As an example, the code of a random selection operator is shown. This operator receives some individuals and returns as many as indicated by the select parameter, chosen at random. This function is shown in Figure 2.

Figure 2: Random Selection operator