1 / 23

GAlib A C++ Library of Genetic Algorithm Components

GAlib A C++ Library of Genetic Algorithm Components. Vanessa Herves Gómez vherves@fi.upm.es Department of Computer Architecture and Technology, Technical University of Madrid, Spain. Types of genetic algorithms (GAs). The library contains four types of genetic algorithms:

jemima
Download Presentation

GAlib A C++ Library of Genetic Algorithm Components

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GAlibA C++ Library of Genetic Algorithm Components Vanessa Herves Gómez vherves@fi.upm.es Department of Computer Architecture and Technology, Technical University of Madrid, Spain

  2. Types of genetic algorithms (GAs) • The library contains four types of genetic algorithms: • Simple genetic algorithm • Steady state genetic algorithm • Incremental genetic algorithm • Deme genetic algorithm.

  3. Scheme of a genetic algorithm

  4. Resolve a problem with GAs • In order to solve a problem using a genetic algorithm you must do three things: • Define a representation • Define the genetic operators • Define the objective function → Defined by you • To generate new individuals the genetic algorithm uses: • Genetic operators • Selection/replacement strategies

  5. Representation • A single solution to the problem is represented in a single data structure called genome. • The library contains four types of genomes: • GAListGenome • GATreeGenome • GAArrayGenome • GABinaryStringGenome

  6. The Genetic Operators • Built into the genome. • Each genome have three primary operators: • Initialization • Mutation • Crossover • GAlib comes whith these operators pre-defined for each genome type. • You can customize any of them. • Each genome must also contain an objective function and may also contain a comparator.

  7. Selection strategies • Is defined in the population. • It is use by the genetic algorithms to choose which individuals should mate. • The library contains the following selection strategies: • GARankSelector • GARouletteWheelSelector • GATournamentSelector • GADSSelector • GASRSSelector • GAUniformSelector

  8. Objective Functions and Fitness Scaling (I) • Given a single solution to a problem, the objective function provides a measure of how good is it. • The objective score is the value returned by your objective function. • The fitness score is a possibly-transformed rating used by the GA to determinate the fitness of individuals for mating. • The genetic algoritm uses the fitness score to do selection.

  9. Objective Functions and Fitness Scaling (II) • GAlib contains the following scaling scheme: • GANoScaling • GALinearScaling • GASigmaTruncationScaling • GaPowerLawScaling • GASharing

  10. Stopping criterion • You must tell the algorithm when to stop. • The library contains the following stopping criterion: • TerminateUponGeneration • TerminateUponConvergence • TerminateUponPopConvergence

  11. Class Hierarchy (I) a) GA hierarchy a) Scaling hierarchy a) Selection hierarchy

  12. Class Hierarchy (II) d) Genome Hierarchy

  13. The form of a typical optimization problem #include <ga/GASimpleGA.h> #include <ga/GA1DBinStrGenome.h> float Objective(GAGenome &); main(int argc, char **argv){ int length = 10; GA1DBinaryStringGenome genome(length, Objective); //create a genome GASimpleGA ga(genome); //create the genetic algorithm ga.evolve(); //do the evolution cout << ga.statistics() << endl; //print out the results } float Objective(GAGenome & g) { GA1DBinaryStringGenome & genome = (GA1DBinaryStringGenome &)g; //put here your objective function }

  14. Parameters names (I)

  15. Parameters names (II)

  16. Change the behaviour of the GA (I) • By setting various parameters: ga.populationSize(popsize); ga.nGenerations(ngen); ga.pMutation(pmut); ga.pCrossover(pcross); • Parameters in comand line: GAParameterList params; GASimpleGA::registerDefaultParameters(params); params.set(gaNnGenerations, 2000); params.parse(argc, argv, gaFalse); GA1DBinaryStringGenome genome(length, Objective); GASimpleGA ga(genome); ga.parameters(params);

  17. Change the behaviour of the GA (II) • GASigmaTruncationScaling scale; Ga.scaling(scale); • GARankSelector scheme; ga.selector(scheme); • ga.terminator(GAGeneticAlgorithm::TerminateUponConvergence); • genome.crossover(GA2DBinaryStringGenome::OnePointCrossover); • genome.mutator(GA2DBinaryStringGenome::FlipMutator); • ga.replacement(GAIncrementalGA::RANDOM);

  18. Define our own operators int MyMutator(GAGenome&, float); void MyInitializer(GAGenome&); float MyComparator(const GAGenome&, const GAGenome&); int MyCrossover(const GAGenome&, const GAGenome&, GAGenome*, GAGenome*); GA1DBinaryStringGenome genome(20); genome.initializer(MyInitializer); genome.mutator(MyMutator); genome.comparator(MyComparator); genome.crossover(MyCrossover);

  19. Traveling Salesman Problem (TSP) • Given a finite set of cities C={c1, c2, …, cn} and a distance d(ci,cj), i≠j, between each pair, the TSP asks for finding a tour through all of the cities, visiting each exactly once, and returning to the originating city such that the total distance traveled is minimized.

  20. Format of the file that contains cities

  21. 10 3 5 9 2 7 4 1 6 8 Genome and Initializer • To resolve this problem: • Use GAListGenome. The cities are listed in the order in which they are visited. • Define your own Initializer • Use GARandomInt(int, int); • Use a vector in which are stored the visited cities.

  22. Crossover • Define your own crossover: • This crossover selects the first city of one parent, compares the cities leaving that city in both parents, and chooses the closer one to extend the tour. If one city has already appeared in the tour, we choose the other city. If both cities have already appeared, we randomly select a non-selected city."

  23. 10 3 5 9 2 7 4 1 6 8 10 3 5 4 2 7 9 1 6 8 Mutator • Define your own mutator • This mutator randomly select two cities from one chromosome and swap them if the new (swapped) tour length is shorter than the old one. • Example: Before mutation ≥ After mutation

More Related