KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > IChromosome


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap;
11
12 import java.io.*;
13 import org.jgap.util.*;
14
15 /**
16  * Interface for chromosomes.
17  *
18  * @author Klaus Meffert
19  * @since 2.6
20  */

21 public interface IChromosome
22     extends Comparable JavaDoc, ICloneable, Serializable {
23   /** String containing the CVS revision. Read out via reflection!*/
24   final static String JavaDoc CVS_REVISION = "$Revision: 1.10 $";
25
26   /**
27    * Constants for toString()
28    */

29   public final static String JavaDoc S_FITNESS_VALUE = "Fitness value";
30
31   public final static String JavaDoc S_ALLELES = "Alleles";
32
33   public final static String JavaDoc S_APPLICATION_DATA = "Application data";
34
35   public final static String JavaDoc S_SIZE = "Size";
36
37   /**
38    * Returns the Gene at the given index (locus) within the Chromosome. The
39    * first gene is at index zero and the last gene is at the index equal to
40    * the size of this Chromosome - 1.
41    *
42    * @param a_desiredLocus index of the gene value to be returned
43    * @return Gene at the given index
44    *
45    * @author Neil Rotstan
46    * @author Klaus Meffert
47    * @since 2.6
48    */

49   Gene getGene(int a_desiredLocus);
50
51   /**
52    * Retrieves the set of genes that make up this Chromosome. This method
53    * exists primarily for the benefit of GeneticOperators that require the
54    * ability to manipulate Chromosomes at a low level.
55    *
56    * @return an array of the Genes contained within this Chromosome
57    *
58    * @author Neil Rotstan
59    * @author Klaus Meffert
60    * @since 2.6
61    */

62   Gene[] getGenes();
63
64   /**
65    * Sets the genes for the chromosome.
66    * @param a_genes the genes to set for the chromosome
67    *
68    * @throws InvalidConfigurationException in case constraint checker is
69    * provided
70    *
71    * @author Klaus Meffert
72    * @since 2.6
73    */

74   void setGenes(Gene[] a_genes)
75       throws InvalidConfigurationException;
76
77   /**
78    * Returns the size of this Chromosome (the number of genes it contains).
79    * A Chromosome's size is constant and will not change, until setGenes(...)
80    * is used.
81    *
82    * @return number of genes contained within this Chromosome instance
83    *
84    * @author Klaus Meffert
85    * @author Neil Rotstan
86    * @since 2.6
87    */

88   int size();
89
90   /**
91    * Sets the fitness value of this Chromosome. This method is for use
92    * by bulk fitness functions and should not be invokved from anything
93    * else (except test cases).
94    *
95    * @param a_newFitnessValue a positive integer representing the fitness
96    * of this Chromosome
97    *
98    * @author Neil Rotstan
99    * @since 2.6
100    */

101   void setFitnessValue(double a_newFitnessValue);
102
103   /**
104    * Sets the fitness value of this Chromosome directly without any
105    * constraint checks, conversions or checks. Only use if you know what
106    * you do.
107    *
108    * @param a_newFitnessValue a positive integer representing the fitness
109    * of this Chromosome
110    *
111    * @author Klaus Meffert
112    * @since 2.6
113    */

114   void setFitnessValueDirectly(double a_newFitnessValue);
115
116   /**
117    * Retrieves the fitness value of this Chromosome, as determined by the
118    * active fitness function. If a bulk fitness function is in use and
119    * has not yet assigned a fitness value to this Chromosome, then -1 is
120    * returned.<p>
121    * Attention: should not be called from toString() as the fitness value would
122    * be computed if it was initial!
123    *
124    * @return a positive double value representing the fitness of this
125    * Chromosome, or -1 if a bulk fitness function is in use and has not yet
126    * assigned a fitness value to this Chromosome
127    *
128    * @author Neil Rotstan
129    * @author Klaus Meffert
130    * @since 2.6
131    */

132   double getFitnessValue();
133
134   /**
135    * @return the lastly computed fitness value, or FitnessFunction.NO_FITNESS_VALUE
136    * in case no value has been computed yet.
137    *
138    * @author Klaus Meffert
139    * @since 2.6
140    */

141   double getFitnessValueDirectly();
142
143   /**
144    * Sets whether this Chromosome has been selected by the natural selector
145    * to continue to the next generation or manually (e.g. via an add-method).
146    *
147    * @param a_isSelected true if this Chromosome has been selected, false
148    * otherwise
149    *
150    * @author Neil Rotstan
151    * @author Klaus Meffert
152    * @since 2.6
153    */

154   void setIsSelectedForNextGeneration(boolean a_isSelected);
155
156   /**
157    * Retrieves whether this Chromosome has been selected by the natural
158    * selector to continue to the next generation.
159    *
160    * @return true if this Chromosome has been selected, false otherwise
161    *
162    * @author Neil Rotstan
163    * @author Klaus Meffert
164    * @since 2.6
165    */

166   boolean isSelectedForNextGeneration();
167
168   /**
169    * Sets the constraint checker to be used for this gene whenever method
170    * setAllele(Object) is called.
171    *
172    * @param a_constraintChecker the constraint checker to be set
173    * @throws InvalidConfigurationException
174    *
175    * @author Klaus Meffert
176    * @since 2.6
177    */

178   void setConstraintChecker(IGeneConstraintChecker a_constraintChecker)
179       throws InvalidConfigurationException;
180
181   /**
182    * This sets the application-specific data that is attached to this
183    * Chromosome. Attaching application-specific data may be useful for
184    * some applications when it comes time to evaluate this Chromosome
185    * in the fitness function.
186    *
187    * @param a_newData the new application-specific data to attach to this
188    * Chromosome. Should be an instance of IApplicationData
189    *
190    * @author Neil Rotstan
191    * @author Klaus Meffert
192    * @since 2.6
193    */

194   void setApplicationData(Object JavaDoc a_newData);
195
196   /**
197    * Retrieves the application-specific data that is attached to this
198    * Chromosome. Attaching application-specific data may be useful for
199    * some applications when it comes time to evaluate this Chromosome
200    * in the fitness function. JGAP ignores this data functionally.
201    *
202    * @return the application-specific data previously attached to this
203    * Chromosome, or null if there is no data attached
204    *
205    * @author Neil Rotstan
206    * @author Klaus Meffert
207    * @since 2.6
208    */

209   Object JavaDoc getApplicationData();
210
211   /**
212    * Invoked when this Chromosome is no longer needed and should perform
213    * any necessary cleanup. Note that this method will attempt to release
214    * this Chromosome instance to the active ChromosomePool, if any.
215    *
216    * @author Neil Rotstan
217    * @author Klaus Meffert
218    * @since 2.6
219    */

220   void cleanup();
221
222   /**
223    * @return the configuration set
224    *
225    * @author Klaus Meffert
226    * @since 3.0
227    */

228   public Configuration getConfiguration();
229 }
230
Popular Tags