comparative analysis of genetic algorithm implementations · introduction to genetic algorithms...

36
SIGAda 2004 1 1/4/2005 Comparative Analysis of Genetic Algorithm Implementations Robert Soricone Dr. Melvin Neville Department of Computer Science Northern Arizona University Flagstaff, Arizona

Upload: others

Post on 16-Oct-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 11/4/2005

Comparative Analysis of GeneticAlgorithm Implementations

Robert SoriconeDr. Melvin Neville

Department of Computer ScienceNorthern Arizona University

Flagstaff, Arizona

Page 2: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 21/4/2005

Outline

Introduction to Genetic Algorithms (GA)Problems solved with GA in Ada95GA toolkit for MatlabCompare implementation and performanceRefactoring the Ada95 GAApplication using the Ada95 GA

Page 3: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 31/4/2005

Genetic Algorithms

Search method based on principles of evolution and heredity Apply principle of Survival of the Fittest to a set of possible solutionsGoal: produce (hopefully) produce better approximations to solutionGA process leads to evolution of solutions

Page 4: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 41/4/2005

Chromosomes

Encodes a solution to the problemClassical GA uses bit strings

Alternatives: real values, permutation, decision trees

0101001101

Page 5: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 51/4/2005

Apply GA Operators

Population Offspring

Genetic Algorithms

Reinsertion

Page 6: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 61/4/2005

Genetic OperatorsCrossover

Exchange information between selected parentsRecombined genetic material used to produce offspringNumber of segments and length of segments depends on crossover implementationExample: single point crossover

11010110100110101101

1101001101

Page 7: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 71/4/2005

Genetic Operators

MutationCompliments the crossover operationExample: Arbitrary swapping of 2 or more values within the chromosomeHelp introduce variability into the population

jIHGFEDCBA

jIBGFEDCHA

Page 8: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 81/4/2005

Structure of a GAProcedure Genetic_Alg isBegin

generation = 0initialize Populationevaluate Populationloop

generation ++select individualsapply genetic operatorsevaluate new individualsreplace original populationexit when criteria met

end loopEnd Genetic_Alg

Page 9: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 91/4/2005

Evolution of Coefficients

Coefficients of the power series that represents the sine function are evolved. Beginning with the fundamental series:

sin(x) = a0 x0 + a1 x1 + a2 x2 + a3 x3 + a4 x4 + …

Actual answer is known to be:sin(x) = x1 /1! - x3 /3! + x5 /5! - x7/7! +…

Page 10: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 101/4/2005

Evolution of Coefficients

Chromosomes encoded with long floatCrossover accomplished by swapping of sequences between chromosomesMutation implemented by increasing/decreasing random array index valuesLed to functions that could perform within 0.25% of the actual sine values in the range 0 – 90 degrees

sin(x) = a0 x0 + a1 x1 + a2 x2 + a3 x3 + a4 x4 + a5 x5 + a6 x6

Chromosome

Page 11: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 111/4/2005

Maximization of a Function

Maximization of a function of one variable Function:

f(x) = x * sin(10 * π * x) + 1.0

Page 12: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 121/4/2005

Maximization of a Function

Chromosomes encoded as bit stringsCrossover is a swap of two equal-length substrings between two chromosomes Mutation is the flipping of the gene’s value from one binary value to the other problem was immediately and accurately solved

Page 13: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 131/4/2005

Traveling Salesman ProblemTSP starts with a graph of fully interconnected nodes or towns, where the distances between the towns are measured (a “weighted graph”) The problem lies in finding the best route in which each town is visited once and only once in a tour which begins and ends with the same node “Best” here is in the sense of lowest total distance measured along the final route

Page 14: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 141/4/2005

TSP Chromosome EncodingNatural value correspond to node IDRepresents a particular tour of the given graph“Order” crossover operatorMutation: swapping random elements in chromosome

52431

1 2

3

4

5

Chromosome

Page 15: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 151/4/2005

TSP: Chromosome Value

.849.6336.343.198665.23

.873.6521.3431.9863.023

.876.656.347.9223.023

.874.658.344.5861.923

.876.651.343.9841.023

Distance Matrix

52431

Chromosome

Value of Chromosome: Sum of distances along path

1 2 3 4 5

1

2

3

4

5

Page 16: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 161/4/2005

TSP: 225 Node Tour

Starting tour length: 1,575,904.000000 Final tour length: 126445.9336

Page 17: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 171/4/2005

TSP: 237 Node Tour

Starting tour length: 11969.209961 Final tour length: 1069.562134

Page 18: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 181/4/2005

TSP: 662 Node Tour

Starting tour length: 53434.769531 Final tour length: 2729.069580

Page 19: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 191/4/2005

GA in Ada95: Main Data Structures

Population: Linked list of list nodesEach node holds an access to chromosome typeMembers selected from list processed by genetic operators

Chromosome Chromosome Chromosome Chromosome

Page 20: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 201/4/2005

Priority queue (binary heap) holds new offspringSort key for the priority queue is the value of the chromosomeProvide convenient access to best performers of the generation

GA in Ada95: Main Data Structures

Parent Chromosome

Left Child ChromosomeRight Child Chromosome

Page 21: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 211/4/2005

Core PackagesFormal package allows for the composition of multiple generic packagesOne package is used as a parameter of another package to maintain a consistent hierarchy

Chromosome is generic with respect to array type (chromosome encoding)Nodes for the list and heap are instantiated with chromosome packageLists/heap instantiated with the new nodesGA instantiates all of the above packages

Chromo Pkg

Chromo

Node Pkg

Node

List/Heap Pkg

List/Heap

Chromo

Node

List/Heap

GenAlg Pkg

Page 22: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 221/4/2005

Problem-Specific PackagesCrossover and mutation packages are also instantiatedCrossover and mutation operators are tightly coupled with interpretation of chromosomeCurrent design requires rewriting operators for new problems Search for GA “toolkit” that may simplify changing problems

Crossover Pkg

Crossover

Mutate Pkg

Mutate

Objective F(x). Pkg

Objective F.

Chromosome

Node

List/Heap

GenAlg Pkg

Crossover

Mutate

Obj. F(n)

Page 23: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 231/4/2005

MatlabNumerical scripting languagePart of integrated computing environment: graphics, visualization tools and the Matlab scripting languageData structures & operations pre-made for matrices, linear algebraToolboxes added later for specific problem domains

Page 24: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 241/4/2005

Natural Selection TSP Demo

www.natural-selection.comExample of using GA to solve TSPPopulation, node distances held in matrixChromosomes encoded with integer values for node ID

Page 25: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 251/4/2005

225 Node Graph Comparison

01Optimal03Less than 1%121Less than 5%840Less than 10%

2240Less than 15%

Matlab GAAda95 GADistance from optimal

Page 26: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 261/4/2005

TSP Demo: 225 Node Tour

Final tour length: 130480.0

Page 27: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 271/4/2005

Matlab GA ToolboxUniversity of Sheffield

http://www.shef.ac.uk/~gaipp/ga-toolbox/ Collection of m-files (Matlab script) which implement functions in a GAToolbox developed for control engineering applicationsProvides framework for experimenting with GA

Page 28: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 281/4/2005

Toolbox Data Structures

Matlab essentially supports only one data type: rectangular matrix of real or imaginary numbersChromosome population contained in matrix, each row corresponding to unique individual

Chromosome 1

Chromosome 2.

.

.

Chromosome n

Page 29: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 291/4/2005

Test Functions

f(x) = x2 f(x) = |x| f(x) = x2- 10*Cos(2πx)

Page 30: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 301/4/2005

Test Function Results

.12/.0411.93/.14

8.85/2.6813.6/5.12

#3: Ada#3: Matlab

.11/.0214.37/.15

11.9/2.2728.05/8.9

#2: Ada#2: Matlab

.13/0.014.32/.22

3.8/.9528.75/9.68

#1: Ada#1:Matlab

Avg. Time/SDAvg. Bouts/SDGA

Page 31: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 311/4/2005

Matlab Conclusions

ImplementationOther chromosome encoding schemes possible User provides algorithm, crossover, mutationLess work involved in writing new procedures

PerformanceMatlab script is interpreted, Ada95 compiledAda95 GA better equipped to escape locally optimal solutions

Page 32: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 321/4/2005

Flexible GA

Ada95 GA provides same abstractions as Matlab GA

Data structures, utility packages providedUser implements chromosome, crossover, mutation, objective function

Generics allow for change of chromosome encoding through instantiationThree problems already implemented, user can extend existing types for new problemshttp://astrogeology.usgs.gov/Projects/flexible_ga

Page 33: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 331/4/2005

GIS TSP Module

Page 34: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 341/4/2005

GIS TSP Module

Page 35: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 351/4/2005

GIS TSP Module

Page 36: Comparative Analysis of Genetic Algorithm Implementations · Introduction to Genetic Algorithms (GA) Problems solved with GA in Ada95 GA toolkit for Matlab Compare implementation

SIGAda 2004 361/4/2005

GIS TSP Module