/sigmah/src/test/java/org/sigmah/server/report/generator/map/GeneticTracer.java

http://sigma-h.googlecode.com/ · Java · 42 lines · 24 code · 7 blank · 11 comment · 1 complexity · e10cb395d1f7b13f06b9a48033692da7 MD5 · raw file

  1. /*
  2. * All Sigmah code is released under the GNU General Public License v3
  3. * See COPYRIGHT.txt and LICENSE.txt.
  4. */
  5. package org.sigmah.server.report.generator.map;
  6. /*
  7. * @author Alex Bertram
  8. */
  9. public class GeneticTracer implements GeneticSolver.Tracer {
  10. public void breeding(GeneticSolver solver, int i, int j) {
  11. System.out.println(String.format("Breeding phenotypes %d and %d", i, j));
  12. }
  13. public void evolved(GeneticSolver solver, int generation, int stagnationCount) {
  14. System.out.println(String.format("Generation %d evolved, fitness = %f", generation,
  15. solver.getFittest().getFitness()));
  16. }
  17. private String phenotypeToString(int[] p) {
  18. StringBuilder sb = new StringBuilder();
  19. for(int i = 0; i!=p.length; ++i) {
  20. String value = Integer.toString(p[i]);
  21. int len = value.length();
  22. while(len++ < 3) {
  23. sb.append(' ');
  24. }
  25. sb.append(value);
  26. }
  27. return sb.toString();
  28. }
  29. public void crossover(GeneticSolver solver, int[] p1, int[] p2, int xoverPoint, int[] c1, int[] c2) {
  30. // System.out.println("Parent 1 = " + phenotypeToString(p1));
  31. // System.out.println("Parent 2 = " + phenotypeToString(p2));
  32. // System.out.println("Child 1 = " + phenotypeToString(c1));
  33. // System.out.println("Child 2 = " + phenotypeToString(c2));
  34. }
  35. }