Posted By

a2-hopewell on 03/21/14


Tagged


Versions (?)

SimpleGa


 / Published in: Java
 

Simple Genetic Algorithm

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package simplega;
  6.  
  7. import classification.Rule;
  8. import java.io.IOException;
  9.  
  10. /**
  11.  *
  12.  * @author Andee
  13.  */
  14. public class SimpleGA {
  15.  
  16. final static int generations = 50;
  17.  
  18. /**
  19.   * @param args the command line arguments
  20.   */
  21. public static void main(String[] args) throws IOException {
  22.  
  23. Population pop = new Population();
  24. Rule rule = new Rule();
  25. Gene[] postCycle;
  26. Gene dataset = rule.readFile("F:\\AiAI\\SimpleGA\\src\\classification\\data1.txt");
  27.  
  28. System.out.print(" 1) ");
  29. pop.generatePop(dataset);
  30. pop.getBestFitness(pop.initialPopulation);
  31. pop.getMeanFitness();
  32. pop.tournament(pop.initialPopulation);
  33. pop.uniform();
  34. postCycle = pop.mutation();
  35.  
  36. for(int n = 1; n < generations; n++)
  37. {
  38. if(n < 9)
  39. System.out.print(" " + (n+1) + ") ");
  40. else
  41. System.out.print((n+1) + ") ");
  42. pop.total = 0;
  43. pop.newOffspring(dataset);
  44. pop.getBestFitness(postCycle);
  45. pop.getMeanFitness();
  46. pop.tournament(postCycle);
  47. pop.uniform();
  48. postCycle = pop.mutation();
  49. }
  50.  
  51. System.out.println();
  52. }
  53. }

Report this snippet  

You need to login to post a comment.