Please note that the recommended version of Scilab is 6.1.0. This page might be outdated.

See the recommended documentation of this function

# crossover_ga_binary

A crossover function for binary code

### Calling Sequence

[Crossed_Indiv1, Crossed_Indiv2, mix] = crossover_ga_binary(Indiv1, Indiv2, param)

### Arguments

- Indiv1
A string

the first individual (here a binary code) to be crossed-over.

- Indiv2
A string

the second individual to be crossed-over.

- param
a list of parameters.

`"binary_length"`

: an integer, the length of the binary code (default 8).`"multi_cross"`

: a boolean. If`%T`

then we allow several cuts in the binary code (default`%F`

).`"multi_cross_nb"`

: an integer, the number of cuts in the binary code. Only used when multi_cross is set to %T (default 2).

- Crossed_Indiv1
A string

The first individual obtained by the cross-over function.

- Crossed_Indiv2
A string

The second individual obtained by the cross-over function.

- mix
A vector of integers

The positions the crossover occurred.

### Description

This function implements a classical binary cross-over.

`crossover_ga_binary(Indiv1, Indiv2)`

generates
the crossover between `Indiv1`

and `Indiv2`

by merging the characters from each string.

A position `i`

is chosen randomly
between 1 and the length of the binary code.

Then `Indiv1`

and `Indiv2`

are split in two parts:
the first `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 `param`

:

- binary_length
changes the minimal length of the binary code, by default 8 characters.

Binary code for

`Indiv1`

or`Indiv2`

of lower length are zero padded to the right to be of`binary_length`

length or`max([length(Indiv1), length(Indiv2)])`

whichever is greater.- multi_cross
if set to

`%T`

multiple crossovers can happen (default`%F`

)- multi_cross_nb
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
on grand
for generating the random samples.
Use `grand("setsd", seed)`

to change the seed
for `crossover_ga_binary`

.

### Examples

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)

### See Also

- crossover_ga_binary — A crossover function for binary code
- crossover_ga_default — A crossover function for continuous variable functions
- mutation_ga_binary — A function which performs binary mutation
- optim_ga — A flexible genetic algorithm
- grand — 乱数生成器

## Comments

Add a comment:Please login to comment this page.