Learn R Programming

windfarmGA (version 2.3.0)

mutation: Mutation Method

Description

Mutate the genes of every chromosome or individual with low probability.

Usage

mutation(a, p, seed = NULL)

Arguments

a

The binary matrix of all individuals.

p

The mutation rate.

seed

Set a seed for comparability. Default is NULL

Value

Returns a binary matrix with mutated genes.

See Also

Other Genetic Algorithm Functions: crossover(), fitness(), genetic_algorithm(), init_population(), selection(), trimton(), windfarmGA()

Examples

Run this code
# NOT RUN {
## Create 4 random individuals with binary values
a <- cbind(bin=sample(c(0,1),20,replace=TRUE,prob = c(70,30)),
        bin.1=sample(c(0,1),20,replace=TRUE,prob = c(30,70)),
        bin.2=sample(c(0,1),20,replace=TRUE,prob = c(30,70)),
        bin.3=sample(c(0,1),20,replace=TRUE,prob = c(30,70)))
a

## Mutate the individuals with a low percentage
aMut <- mutation(a,0.1, NULL)
## Check which values are not like the originals
a==aMut

## Mutate the individuals with a high percentage
aMut <- mutation(a,0.4, NULL)
## Check which values are not like the originals
a==aMut

# }

Run the code above in your browser using DataLab