sample program - gen = 0; % Generational Loop while gen...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
8 Appendix 1: Project list of Lab1.m % Lab1.m % % This script implements the Simple Genetic Algorithm for CASE 1 % Binary representation for the individuals is used. % NIND = 10; % Number of individuals per subpopulations MAXGEN = 100; % maximal Number of generations NVAR = 1; % Number of variables of objective function PRECI = 22; % Precision of binary representation of each variable in NVAR GGAP = .4; % Generation gap, how many new individuals are created % Build field description matrix FieldD = [rep([PRECI],[1, NVAR]); rep([-1;2],[1, NVAR]);. .. rep([0; 0; 1 ;1], [1, NVAR])]; % Initialize the first population Chrom = crtbp(NIND, NVAR*PRECI); % Convert into real number Pheno = bs2rv(Chrom, FieldD); % Evaluate the first population ObjV = obj1(Pheno); % reset count variables
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: gen = 0; % Generational Loop while gen < MAXGEN, % Assign Fitness values to entire population FitnV = ObjV; % Select individuals from population SelCh = select(‘rws’, Chrom, FitnV, GGAP); % Recombine selected individuals (crossover) SelCh= xovsp(SelCh, 0.9); % Mutate offspring SelCh = mut(SelCh,0.01); % Evaluate the objective values of offspring ObjVSel = obj1(bs2rv(SelCh, FieldD)); % Insert offspring in population replacing parents. % Rein is designed for minimization problem in the toolbox [Chrom ObjV] = reins(Chrom, SelCh, 1, 1, -ObjV, -ObjVSel); ObjV = -ObjV; % counter increment gen=gen+1; end; Appendix 2: obj1.m % % OBJ1.M (Objective function for CASE 1) % function ObjVal = obj1(Pheno); ObjVal = Pheno .* sin(10*pi*Pheno)+2.0;...
View Full Document

This note was uploaded on 05/01/2011 for the course ELECTRICAL EE5602 taught by Professor Xuequan during the Spring '11 term at City University of Hong Kong.

Ask a homework question - tutors are online