PageRenderTime 31ms CodeModel.GetById 22ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 6package org.sigmah.server.report.generator.map;
 7/*
 8 * @author Alex Bertram
 9 */
10
11public class GeneticTracer implements GeneticSolver.Tracer {
12
13
14    public void breeding(GeneticSolver solver, int i, int j) {
15        System.out.println(String.format("Breeding phenotypes %d and %d", i, j));
16    }
17
18    public void evolved(GeneticSolver solver, int generation, int stagnationCount) {
19        System.out.println(String.format("Generation %d evolved, fitness = %f", generation,
20                solver.getFittest().getFitness()));
21    }
22
23    private String phenotypeToString(int[] p) {
24        StringBuilder sb = new StringBuilder();
25        for(int i = 0; i!=p.length; ++i) {
26            String value = Integer.toString(p[i]);
27            int len = value.length();
28            while(len++ < 3) {
29                sb.append(' ');
30            }
31            sb.append(value);
32        }
33        return sb.toString();
34    }
35
36    public void crossover(GeneticSolver solver, int[] p1, int[] p2, int xoverPoint, int[] c1, int[] c2) {
37//        System.out.println("Parent 1 = " + phenotypeToString(p1));
38//        System.out.println("Parent 2 = " + phenotypeToString(p2));
39//        System.out.println("Child  1 = " + phenotypeToString(c1));
40//        System.out.println("Child  2 = " + phenotypeToString(c2));
41    }
42}