IMSL C Stat Library
ga_individual
Creates an Imsls_f_individual data structure from user supplied phenotypes.
Synopsis
#include <imsls.h>
Imsls_f_individual  *imsls_f_ga_individual (Imsls_f_chromosome *chromosome, ..., 0)
The type double function is imsls_d_ga_individual.
Required Arguments
Imsls_f_chromosome  *chromosome (Input)
A chromosome data structure created by imsls_f_ga_chromosome. This structure is cloned and stored in the Imsls_f_individual data structure.
Return Value
The function imsls_f_ga_individual returns an Imsls_f_individual data structure, which is required input to imsls_f_ga_population. The memory allocated to this data structure can be freed using imsls_f_ga_free_individual.
Synopsis with Optional Arguments
#include <imsls.h>
Imsls_f_individual *imsls_f_ga_individual (Imsls_f_chromosome *chromosome,
IMSLS_PRINT,
IMSLS_GRAY_ENCODING,
IMSLS_BINARY, int  binaryPhenotype[],
IMSLS_NOMINAL, int nominalPhenotype[],
IMSLS_INTEGER, int intPhenotype[],
IMSLS_REAL, float realPhenotype[],
0)
Optional Arguments
IMSLS_PRINT, (Input)
By default, intermediate results are not printed. This option turns on printing of intermediate results.
IMSLS_GRAY_ENCODING, (Input)
Specifies whether alleles are encoded using Base-2 or Gray encoding for integer and real phenotypes.
Default: Base-2 encoding.
IMSLS_BINARY, int binaryPhenotype[] (Input)
An array of length chromosome->n_binary containing the integer values for any binary phenotypes. This is a required argument when chromosome->n_binary> 0.
IMSLS_NOMINAL, int nominalPhenotype[] (Input)
An array of length chromosome>n_nominal containing the integer values for any nominal phenotypes. This is a required argument when chromosome>n_nominal is greater than zero. The value of nominalPhenotype[i] must be one of the integers 0, 1, …, chromosome > n_categories[i]-1.
IMSLS_INTEGER, int integerPhenotype[] (Input)
An array of length chromosome>n_integer containing the integer values for any integer phenotypes. This is a required argument when chromosome>n_integer>0. The value of integerPhenotype[i] must conform to the inequality:
chromosome>i_bounds[2*i]  integerPhenotype[i]  chromosome>i_bounds[2*i+1]
IMSLS_REAL, float realPhenotype[] (Input)
An array of length chromosome>n_real containing the floating point values for any real phenotypes. This is a required argument when chromosome>n_real is greater than zero. The value of realPhenotype[i] must conform to the inequality:
chromosome>r_bounds[2*i] realPhenotype[i] <chromosome>r_bounds[2*i+1]
Description
The imsls_f_genetic_algorithm operates on a population of individuals. Individuals can be created automatically using ga_random_population or systematically using imsls_f_ga_population. If the initial population is created using randomly selected individuals, then this function is not needed. However, if the initial population is to be constructed systematically, then the individuals for that population must first be created using this function.
This function takes the phenotype values in the optional arguments and creates an Imsls_f_individual data structure. This structure contains a chromosome created by encoding the phenotypes into their respective allele representations using the chromosome map described in Imsls_f_chromosome.
It also allows for incorporating parentage information for the individual, although this is typically not done for the individuals in the initial population.
Memory allocated for this data structure is released using imsls_f_ga_free_individual. The chromosome data structure passed to this function is copied into the individual and left unaltered. Hence, releasing memory using imsls_f_ga_free_individual does not release memory allocated to the original chromosome. The original chromosome can be released using imsls_free.
Example
This example creates an individual using a chromosome with 1 binary, 2 nominals, 3 integers and 2 real phenotypes. The IMSLS_PRINT argument is used to print a description of the data structure. By default, Base-2 encoding is used for encoding integer and real phenotypes.
Note that imsls_f_ga_free_individual frees the Imsls_f_chromosome data structure within the individual.
 
#include <imsls.h>
int main(){
int n_binary=1, n_nominal=2, n_integer=3, n_real=2;
/* binary phenotype */
int binaryPhenotype[] = {1};
/* number of categories for nomial phenotypes */
int n_categories[] = {2, 3};
/* nominal phenotype values */
int nominalPhenotype[] = {1, 2};
/* number of intervals and boundaries for integer */
/* phenotypes */
int i_intervals[] = {16, 16, 16};
int i_bounds[] = {0, 1000, -10, 10, -20, 0};
/* integer phenotype values */
int integerPhenotype[] = {200, -5, -5};
/* number of intervals and boundaries for real */
/* phenotypes */
int r_intervals[] = {512, 1024};
float r_bounds[] = {0.0, 20.0, -20.0, 20.0};
/* real phenotype values */
float realPhenotype[] = {19.9, 19.9};
/* Chromosome Data Structure */
Imsls_f_chromosome* chromosome;
/* Individual Data Structure */
Imsls_f_individual* individual;
 
chromosome = imsls_f_ga_chromosome(
IMSLS_BINARY, n_binary,
IMSLS_NOMINAL, n_nominal, n_categories,
IMSLS_INTEGER, n_integer, i_intervals, i_bounds,
IMSLS_REAL, n_real, r_intervals, r_bounds, 0);
/* Create individual data structure */
individual = imsls_f_ga_individual(chromosome,
IMSLS_BINARY, binaryPhenotype,
IMSLS_NOMINAL, nominalPhenotype,
IMSLS_INTEGER, integerPhenotype,
IMSLS_REAL, realPhenotype,
IMSLS_PRINT, 0);
imsls_free(chromosome);
imsls_f_ga_free_individual(individual);
}
Output
The IMSLS_PRINT option produced the following description of the individual. Summary starts with a detailed description of the chromosome. It consists of 34 alleles split among the phenotypes. The actual encoding of the phenotypes into alleles is shown below.
Bits assigned to binary phenotypes are not encoded. They are mapped directly into the first n_binary bits of the chromosome. In this case there is only one binary phenotype. It gets mapped into bit zero.
Following the binary phenotype are the nominal phenotypes. Each of these is also mapped into a single allele. However, unlike binary phenotypes, the alleles can assume values other than zero and one.
The integer and real phenotypes are discretized into sixteen interval values. These are then encoded into 4 bit Base2 representations of the integers 015.
 
*******************************
**** INDIVIDUAL STRUCTURE *****
Number of Parents: 2
Encoding: BASE-2
*******************************
**** CHROMOSOME STRUCTURE *****
 
Chromosome length: 34 Bits
 
*****BIT ASSIGNMENTS***********
Binary: 0 - 0 n_binary = 1
Nominal: 1 - 2 n_nominal= 2
Integer: 3 - 14 n_integer= 3
Real: 15 - 33 n_real = 2
*******************************
 
 
********PHENOTYPES*************
BINARY*************************
Variable 0: 1
*******************************
NOMINAL************************
Variable 0: 1
Variable 1: 2
*******************************
INTEGER************************
Variable 0: 200
Variable 1: -5
Variable 2: -5
*******************************
REAL***************************
Variable 0: 19.9
Variable 1: 19.9
*******************************
 
**********CHROMOSOME**************************************
BINARY BITS: 1
NOMINAL ALLELES: 1 2
INTEGER BITS: 0 0 1 1 0 1 0 0 1 1 0 0
 
REAL BITS: 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1
**********************************************************