1 / 14

GA implementaatiot

GA implementaatiot. Oskar Norrback q86033. 10-vuotinen historia, ~130k LoC, TDD(96%) natural, best chromosomes, roulette wheel selection Crossover, averaging crossover, mutation, gaussian mutation, reproduction operator Integer- , double, boolean- ja fixed binary geenit Grid computing

afram
Download Presentation

GA implementaatiot

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. GA implementaatiot Oskar Norrback q86033

  2. 10-vuotinen historia, ~130k LoC, TDD(96%) • natural, best chromosomes, roulette wheel selection • Crossover, averaging crossover, mutation, gaussian mutation, reproduction operator • Integer- , double, boolean- ja fixed binary geenit • Grid computing • Supergeenit, Pareto • Käytetty jonkin verran GA aiheisissa julkaisuissa

  3. JGAP / TSP • Löytyy valmis abstrakti Salesman luokka • Implementaatio yksinkertaista(~40 LoC)

  4. public class TravelingSalesMan extends Salesman { private static final long serialVersionUID = 6645643570553239308L; public static final intCITIES = 10; @Override public IChromosome createSampleChromosome(Object arg0) { try { //set up sample genes for the sample chromosome Gene[] sampleGenes = new Gene[10]; for(int i=0;i<10;i++) { sampleGenes[i] = new IntegerGene(getConfiguration(),1,CITIES); sampleGenes[i].setAllele(i+1); //create 1,2,3... Example solution for JGAP } Chromosome c = new Chromosome(getConfiguration(),sampleGenes); return c; } catch(Exception x) { throw new RuntimeException(x); } } @Override public double distance(Gene arg0, Gene arg1) { IntegerGene from = (IntegerGene)arg0; IntegerGene to = (IntegerGene)arg1; return DistanceMatrix.getDistance(from.intValue(), to.intValue()); } }

  5. public class DistanceMatrix { private static int[][] _distances = new int[][] { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10}, { 1, 0, 6, 5, 7, 9, 2, 5, 3, 4, 1}, { 2, 5, 0, 2, 4, 4, 4, 7, 9, 6, 3}, { 3, 7, 1, 0, 3, 4, 4, 3, 8, 7, 5}, { 4, 8, 7, 6, 0, 3, 5, 4, 5, 9, 7}, { 5, 4, 4, 7, 2, 0, 9, 7, 2, 4, 9}, { 6,11, 7, 8, 1, 6, 0, 6, 2, 2, 2}, { 7, 3, 7, 3, 5, 7, 9, 0, 6, 3, 4}, { 8, 5, 7, 3, 5, 4, 6, 1, 0, 5, 6}, { 9, 6, 2, 5, 3, 1, 9,11, 5, 0, 8}, {10, 6, 5, 8, 4, 7, 3, 6, 5, 5, 0}}; public static intgetDistance(int from, int to) { return _distances[from][to]; } }

  6. public class TSPMain { public static void main(String[] args) throws Exception { TravelingSalesMan t = new TravelingSalesMan(); IChromosome optimal = t.findOptimalPath(null); System.out.println("Optimal solution: "+optimal); } }

  7. AForge.NET(C#) • 3-vuotinen historia, ~190k LoC • Suuri tekoälyyn ja signaalien käsittelyyn liittyvä koodikirjasto: imaging, vision, video, neuro,genetic, fuzzy, robotics, machinelearning • elite, roulette wheel ja rank selection • binary, short array, double array geenit

  8. AForge / TSP • Ei yhtä helppoa kuin JGAPilla, mutta löytyy valmis PermutationChromosome pohjaksi • Crossoveria pitäisi luultavasti viilata, esiintyy paljon samoja ratkaisuja • C#:llä helpompi tehdä interaktiivinen sovellus kuin Javalla

  9. class TSPFitnessfunction : AForge.Genetic.IFitnessFunction { #region IFitnessFunction Members public double Evaluate(AForge.Genetic.IChromosome chromosome) { int roundTrip = 0; PermutationChromosome pc = (PermutationChromosome)chromosome; for(int i=0;i<pc.Length-1;i++) { ushort from = pc.Value[i]; ushort to = pc.Value[i + 1]; roundTrip += DistanceMatrix.getDistance(from+1, to+1); } return 100-roundTrip; } #endregion public double getRoundTrip(IChromosome chromosome) { double fitness = Evaluate(chromosome); return 100-fitness; } }

  10. class TSPController { public Population _pop { get; set; } private TSPFitnessfunction _tff; public int generation { get; set; } private int POP_SIZE=25; public TSPController() { init(); } private void init() { PermutationChromosome pc = new PermutationChromosome(9); _tff = new TSPFitnessfunction(); RouletteWheelSelection rws = new RouletteWheelSelection(); _pop = new Population(POP_SIZE, pc, _tff, rws); } public void evolve() { generation++; _pop.RunEpoch(); } .... }

  11. Evolving Objects(C++) • 10-vuotinen historia, ~90k LoC • ”create your own stochastic optimization algorithms insanely fast” • Perustuu STL templateihin • Binary string, permutaatio, vektori kromosomit • Rank, roulette wheel, elitism selection • Joitakin julkaisuja

  12. EO / TSP • ??!%¤#%&% • Suuria ongelmia saada edes esimerkkejä kääntymään(MinGW-GCC / MSVC++) • Osa ongelmaa todennäköisesti allekirjoittaneen vähäinen C++ kokemus, mutta EO vaikuttaa kolmikosta vaikeimmaltaalustalta

  13. Lähteet • http://jgap.sourceforge.net/ • http://www.aforgenet.com/framework/ • http://eodev.sourceforge.net/ • http://www.ohloh.net/

More Related