EncodeChromosome: Encode and Decode an Integer Chromosome

View source: R/FindOptimalSubset.R

EncodeChromosomeR Documentation

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.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

See Also

FindOptimalSubset, binary2decimal

Examples

x <- c(41, 796, 382)
y <- EncodeChromosome(x, 1000)
print(y)
x <- DecodeChromosome(y, 1000)
print(x)


USGS-R/inlmisc documentation built on Sept. 17, 2022, 2:38 a.m.