Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/app/tutorial3/MyStatistics.java @ 7611

Last change on this file since 7611 was 6152, checked in by bfarka, 14 years ago

added ecj and custom statistics to communicate with the okb services #1441

File size: 3.0 KB
Line 
1/*
2  Copyright 2006 by Sean Luke
3  Licensed under the Academic Free License version 3.0
4  See the file "LICENSE" for more information
5*/
6
7
8package ec.app.tutorial3;
9import ec.*;
10import ec.util.*;
11import java.io.*;
12import ec.vector.*;
13
14public class MyStatistics extends Statistics
15    {
16    // The parameter string and log number of the file for our readable population
17    public static final String P_POPFILE = "pop-file";
18    public int popLog;
19
20    // The parameter string and log number of the file for our best-genome-#3 individual
21    public static final String P_INFOFILE = "info-file";
22    public int infoLog;
23
24    public void setup(final EvolutionState state, final Parameter base)
25        {
26        // DO NOT FORGET to call super.setup(...) !!
27        super.setup(state,base);
28
29        // set up popFile
30        File popFile = state.parameters.getFile(
31            base.push(P_POPFILE),null);
32        if (popFile!=null) try
33                               {
34                               popLog = state.output.addLog(popFile,true);
35                               }
36            catch (IOException i)
37                {
38                state.output.fatal("An IOException occurred while trying to create the log " +
39                    popFile + ":\n" + i);
40                }
41
42        // set up infoFile
43        File infoFile = state.parameters.getFile(
44            base.push(P_INFOFILE),null);
45        if (infoFile!=null) try
46                                {
47                                infoLog = state.output.addLog(infoFile,true);
48                                }
49            catch (IOException i)
50                {
51                state.output.fatal("An IOException occurred while trying to create the log " +
52                    infoFile + ":\n" + i);
53                }
54
55        }
56
57    public void postEvaluationStatistics(final EvolutionState state)
58        {
59        // be certain to call the hook on super!
60        super.postEvaluationStatistics(state);
61
62        // write out a warning that the next generation is coming
63        state.output.println("-----------------------\nGENERATION " +
64            state.generation + "\n-----------------------", popLog);
65
66        // print out the population
67        state.population.printPopulation(state,popLog);
68
69        // print out best genome #3 individual in subpop 0
70        int best = 0;
71        double best_val = ((DoubleVectorIndividual)state.population.subpops[0].individuals[0]).genome[3];
72        for(int y=1;y<state.population.subpops[0].individuals.length;y++)
73            {
74            // We'll be unsafe and assume the individual is a DoubleVectorIndividual
75            double val = ((DoubleVectorIndividual)state.population.subpops[0].individuals[y]).genome[3];
76            if (val > best_val)
77                {
78                best = y;
79                best_val = val;
80                }
81            }
82        state.population.subpops[0].individuals[best].printIndividualForHumans(state,infoLog);
83        }
84    }
Note: See TracBrowser for help on using the repository browser.