Learn R Programming

gena (version 1.0.0)

gena.constr: Constraints

Description

Impose constraints on chromosomes.

Usage

gena.constr(population, method = "bounds", par, iter)

Value

The function returns a list with the following elements:

  • population - matrix which rows are chromosomes after constraints have been imposed.

  • constr.ind - matrix of logical values which (i, j)-th elements equals TRUE (FALSE otherwise) if j-th jene of i-th chromosome is a subject to constraint.

Arguments

population

numeric matrix which rows are chromosomes i.e. vectors of parameters values.

method

method used to impose constraints.

par

additional parameters to be passed depending on the method.

iter

iteration number of the genetic algorithm.

Details

If method = "bounds" then chromosomes will be bounded between par$lower and par$upper.

Examples

Run this code
# Randomly initialize population
set.seed(123)
population <- gena.population(pop.n = 10,
                              lower = c(-5, -5), 
                              upper = c(5, 5))
                           
# Impose lower and upper bounds constraints
pop.constr <- gena.constr(population, 
                          method = "bounds",
                          par = list(lower = c(-1, 2),
                                     upper = c(1, 5)))
print(pop.constr)

Run the code above in your browser using DataLab