Presentation is loading. Please wait.

Presentation is loading. Please wait.

GAlib A C++ Library of Genetic Algorithm Components Vanessa Herves Gómez Department of Computer Architecture and Technology,

Similar presentations


Presentation on theme: "GAlib A C++ Library of Genetic Algorithm Components Vanessa Herves Gómez Department of Computer Architecture and Technology,"— Presentation transcript:

1 GAlib A C++ Library of Genetic Algorithm Components Vanessa Herves Gómez vherves@fi.upm.esvherves@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 hierarchya) Scaling hierarchya) Selection hierarchy

12 Class Hierarchy (II) d) Genome Hierarchy

13 The form of a typical optimization problem #include 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::TerminateUponCo nvergence); genome.crossover(GA2DBinaryStringGenome::OnePoi ntCrossover); genome.mutator(GA2DBinaryStringGenome::FlipMutat or); 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={c 1, c 2, …, c n } 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 CityXY 111 242 323 414 5126 ……… N -1293 N1720

21 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. 10 3 5 9 2 7 4 1 6 8

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 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: 10 3 5 9 2 7 4 1 6 810 3 5 4 2 7 9 1 6 8 Before mutation After mutation ≥


Download ppt "GAlib A C++ Library of Genetic Algorithm Components Vanessa Herves Gómez Department of Computer Architecture and Technology,"

Similar presentations


Ads by Google