Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function
A crossover function for binary code
[Crossed_Indiv1, Crossed_Indiv2, mix] = crossover_ga_binary(Indiv1, Indiv2, param)
the first individual (here a binary code) to be crossed-over.
the second individual to be crossed-over.
a list of parameters.
"binary_length": an integer, the length of the binary code (default 8).
"multi_cross": a boolean. If
%Tthen we allow several cuts in the binary code (default
"multi_cross_nb": an integer, the number of cuts in the binary code. Only used when multi_cross is set to %T (default 2).
The first individual obtained by the cross-over function.
The second individual obtained by the cross-over function.
A vector of integers
The positions the crossover occurred.
This function implements a classical binary cross-over.
crossover_ga_binary(Indiv1, Indiv2) generates
the crossover between
by merging the characters from each string.
i is chosen randomly
between 1 and the length of the binary code.
are split in two parts:
i characters (the head),
and the remaining characters (the tail).
The crossover swaps the tails of the binary codes.
The following schema presents the crossover:
Indiv1=[H1 T1] Indiv2=[H2 T2] Crossed_Indiv1=[H1 T2] Crossed_Indiv2=[H2 T1]
The behaviour of the function can be modified with the use of
changes the minimal length of the binary code, by default 8 characters.
Binary code for
Indiv2of lower length are zero padded to the right to be of
max([length(Indiv1), length(Indiv2)])whichever is greater.
if set to
%Tmultiple crossovers can happen (default
the number of locations for crossovers. (default 2 if multi_cross is set to
%T, 1 otherwise)
Random number generator
crossover_ga_binary is based
for generating the random samples.
grand("setsd", seed) to change the seed
A = "11100000" B = "00011111" [A_crossed, B_crossed, mix] = crossover_ga_binary(A, B) C = dec2bin(2^16 - 1, 16) D = "0" param = init_param(); param = add_param(param, "binary_length", 16); // Code of length 16 param = add_param(param, "multi_cross", %T); // Multiple Crossover param = add_param(param, "multi_cross_nb", 3); // Occurs over 3 locations [C_crossed, D_crossed, mix] = crossover_ga_binary(C, D, param)
|Report an issue|
|<< coding_ga_identity||Utilities||crossover_ga_default >>|