Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKBJavaConnector/ECJClient/src/ec/gp/GPSpecies.java @ 8614

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

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

File size: 3.3 KB
RevLine 
[6152]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.gp;
9import ec.*;
10import ec.util.*;
11import java.io.*;
12
13/*
14 * GPSpecies.java
15 *
16 * Created: Tue Aug 31 17:00:10 1999
17 * By: Sean Luke
18 */
19
20/**
21 * GPSpecies is a simple individual which is suitable as a species
22 * for GP subpopulations.  GPSpecies' individuals must be GPIndividuals,
23 * and often their pipelines are GPBreedingPipelines (at any rate,
24 * the pipelines will have to return members of GPSpecies!).
25 *
26 <p><b>Default Base</b><br>
27 gp.species
28
29 *
30 * @author Sean Luke
31 * @version 1.0
32 */
33
34public class GPSpecies extends Species
35    {
36    public static final String P_GPSPECIES = "species";
37
38    public Parameter defaultBase()
39        {
40        return GPDefaults.base().push(P_GPSPECIES);
41        }
42
43    public void setup(final EvolutionState state, final Parameter base)
44        {
45        super.setup(state,base);
46
47        // check to make sure that our individual prototype is a GPIndividual
48        if (!(i_prototype instanceof GPIndividual))
49            state.output.fatal("The Individual class for the Species " + getClass().getName() + " is must be a subclass of ec.gp.GPIndividual.", base );
50        }   
51
52    public Individual newIndividual(EvolutionState state, int thread)
53        {
54        GPIndividual newind = ((GPIndividual)(i_prototype)).lightClone();
55       
56        // Initialize the trees
57        for (int x=0;x<newind.trees.length;x++)
58            newind.trees[x].buildTree(state, thread);
59
60        // Set the fitness
61        newind.fitness = (Fitness)(f_prototype.clone());
62        newind.evaluated = false;
63
64        // Set the species to me
65        newind.species = this;
66               
67        // ...and we're ready!
68        return newind;
69        }
70
71
72    // A custom version of newIndividual() which guarantees that the
73    // prototype is light-cloned before readIndividual is issued
74    public Individual newIndividual(final EvolutionState state,
75        final LineNumberReader reader)
76        throws IOException
77        {
78        GPIndividual newind = ((GPIndividual)i_prototype).lightClone();
79               
80        // Set the fitness -- must be done BEFORE loading!
81        newind.fitness = (Fitness)(f_prototype.clone());
82        newind.evaluated = false; // for sanity's sake, though it's a useless line
83
84        // load that sucker
85        newind.readIndividual(state,reader);
86
87        // Set the species to me
88        newind.species = this;
89
90        // and we're ready!
91        return newind; 
92        }
93
94
95    // A custom version of newIndividual() which guarantees that the
96    // prototype is light-cloned before readIndividual is issued
97    public Individual newIndividual(final EvolutionState state,
98        final DataInput dataInput)
99        throws IOException
100        {
101        GPIndividual newind = ((GPIndividual)i_prototype).lightClone();
102       
103        // Set the fitness -- must be done BEFORE loading!
104        newind.fitness = (Fitness)(f_prototype.clone());
105        newind.evaluated = false; // for sanity's sake, though it's a useless line
106
107        // Set the species to me
108        newind.species = this;
109
110        // load that sucker
111        newind.readIndividual(state,dataInput);
112
113        // and we're ready!
114        return newind; 
115        }
116
117    }
Note: See TracBrowser for help on using the repository browser.