Learn R Programming

inlmisc (version 0.5.5)

EncodeChromosome: Encode and Decode an Integer Chromosome

Description

Functions for encoding and decoding a chromosome represented by integer values. Where a chromosome is a set of numbers that defines a proposed solution to the problem that a genetic algorithm is trying to solve.

Usage

EncodeChromosome(x, n)

DecodeChromosome(y, n)

Arguments

x

'integer' vector. Integer representation of chromosome.

n

'integer' count. Maximum permissible number in the integer chromosome, used to calculate the bit width of a binary string.

y

'integer' vector. Binary representation of chromosome, a vector of 0s and 1s.

Value

EncodeChromosome returns a 'numeric' vector of 0s and 1s.

DecodeChromosome returns a 'numeric' vector of integers.

See Also

FindOptimalSubset, binary2decimal

Examples

Run this code
# NOT RUN {
x <- c(41, 796, 382)
y <- EncodeChromosome(x, 1000)
print(y)
x <- DecodeChromosome(y, 1000)
print(x)

# }

Run the code above in your browser using DataLab