001: /*
002: * This file is part of JGAP.
003: *
004: * JGAP offers a dual license model containing the LGPL as well as the MPL.
005: *
006: * For licensing information please see the file license.txt included with JGAP
007: * or have a look at the top of class org.jgap.Chromosome which representatively
008: * includes the JGAP license policy applicable for any file delivered with JGAP.
009: */
010: package org.jgap;
011:
012: import java.io.*;
013: import org.jgap.util.*;
014:
015: /**
016: * Interface for chromosomes.
017: * Normally, you would start using BaseChromosome which implements this
018: * interface to build your own chromosome classes.
019: *
020: * @author Klaus Meffert
021: * @since 2.6
022: */
023: public interface IChromosome extends Comparable, ICloneable,
024: Serializable {
025: /** String containing the CVS revision. Read out via reflection!*/
026: final static String CVS_REVISION = "$Revision: 1.13 $";
027:
028: /**
029: * Constants for toString()
030: */
031: public final static String S_FITNESS_VALUE = "Fitness value";
032:
033: public final static String S_ALLELES = "Alleles";
034:
035: public final static String S_APPLICATION_DATA = "Application data";
036:
037: public final static String S_SIZE = "Size";
038:
039: /**
040: * Returns the Gene at the given index (locus) within the Chromosome. The
041: * first gene is at index zero and the last gene is at the index equal to
042: * the size of this Chromosome - 1.
043: *
044: * @param a_desiredLocus index of the gene value to be returned
045: * @return Gene at the given index
046: *
047: * @author Neil Rotstan
048: * @author Klaus Meffert
049: * @since 2.6
050: */
051: Gene getGene(int a_desiredLocus);
052:
053: /**
054: * Retrieves the set of genes that make up this Chromosome. This method
055: * exists primarily for the benefit of GeneticOperators that require the
056: * ability to manipulate Chromosomes at a low level.
057: *
058: * @return an array of the Genes contained within this Chromosome
059: *
060: * @author Neil Rotstan
061: * @author Klaus Meffert
062: * @since 2.6
063: */
064: Gene[] getGenes();
065:
066: /**
067: * Sets the genes for the chromosome.
068: * @param a_genes the genes to set for the chromosome
069: *
070: * @throws InvalidConfigurationException in case constraint checker is
071: * provided
072: *
073: * @author Klaus Meffert
074: * @since 2.6
075: */
076: void setGenes(Gene[] a_genes) throws InvalidConfigurationException;
077:
078: /**
079: * Returns the size of this Chromosome (the number of genes it contains).
080: * A Chromosome's size is constant and will not change, until setGenes(...)
081: * is used.
082: *
083: * @return number of genes contained within this Chromosome instance
084: *
085: * @author Klaus Meffert
086: * @author Neil Rotstan
087: * @since 2.6
088: */
089: int size();
090:
091: /**
092: * Sets the fitness value of this Chromosome. This method is for use
093: * by bulk fitness functions and should not be invokved from anything
094: * else (except test cases).
095: *
096: * @param a_newFitnessValue a positive integer representing the fitness
097: * of this Chromosome
098: *
099: * @author Neil Rotstan
100: * @since 2.6
101: */
102: void setFitnessValue(double a_newFitnessValue);
103:
104: /**
105: * Sets the fitness value of this Chromosome directly without any
106: * constraint checks, conversions or checks. Only use if you know what
107: * you do.
108: *
109: * @param a_newFitnessValue a positive integer representing the fitness
110: * of this Chromosome
111: *
112: * @author Klaus Meffert
113: * @since 2.6
114: */
115: void setFitnessValueDirectly(double a_newFitnessValue);
116:
117: /**
118: * Retrieves the fitness value of this Chromosome, as determined by the
119: * active fitness function. If a bulk fitness function is in use and
120: * has not yet assigned a fitness value to this Chromosome, then -1 is
121: * returned.<p>
122: * Attention: should not be called from toString() as the fitness value would
123: * be computed if it was initial!
124: *
125: * @return a positive double value representing the fitness of this
126: * Chromosome, or -1 if a bulk fitness function is in use and has not yet
127: * assigned a fitness value to this Chromosome
128: *
129: * @author Neil Rotstan
130: * @author Klaus Meffert
131: * @since 2.6
132: */
133: double getFitnessValue();
134:
135: /**
136: * @return the lastly computed fitness value, or FitnessFunction.NO_FITNESS_VALUE
137: * in case no value has been computed yet.
138: *
139: * @author Klaus Meffert
140: * @since 2.6
141: */
142: double getFitnessValueDirectly();
143:
144: /**
145: * Sets whether this Chromosome has been selected by the natural selector
146: * to continue to the next generation or manually (e.g. via an add-method).
147: *
148: * @param a_isSelected true if this Chromosome has been selected, false
149: * otherwise
150: *
151: * @author Neil Rotstan
152: * @author Klaus Meffert
153: * @since 2.6
154: */
155: void setIsSelectedForNextGeneration(boolean a_isSelected);
156:
157: /**
158: * Retrieves whether this Chromosome has been selected by the natural
159: * selector to continue to the next generation.
160: *
161: * @return true if this Chromosome has been selected, false otherwise
162: *
163: * @author Neil Rotstan
164: * @author Klaus Meffert
165: * @since 2.6
166: */
167: boolean isSelectedForNextGeneration();
168:
169: /**
170: * Sets the constraint checker to be used for this gene whenever method
171: * setAllele(Object) is called.
172: *
173: * @param a_constraintChecker the constraint checker to be set
174: * @throws InvalidConfigurationException
175: *
176: * @author Klaus Meffert
177: * @since 2.6
178: */
179: void setConstraintChecker(IGeneConstraintChecker a_constraintChecker)
180: throws InvalidConfigurationException;
181:
182: /**
183: * This sets the application-specific data that is attached to this
184: * Chromosome. Attaching application-specific data may be useful for
185: * some applications when it comes time to evaluate this Chromosome
186: * in the fitness function.
187: *
188: * @param a_newData the new application-specific data to attach to this
189: * Chromosome. Should be an instance of IApplicationData
190: *
191: * @author Neil Rotstan
192: * @author Klaus Meffert
193: * @since 2.6
194: */
195: void setApplicationData(Object a_newData);
196:
197: /**
198: * Retrieves the application-specific data that is attached to this
199: * Chromosome. Attaching application-specific data may be useful for
200: * some applications when it comes time to evaluate this Chromosome
201: * in the fitness function. JGAP ignores this data functionally.
202: *
203: * @return the application-specific data previously attached to this
204: * Chromosome, or null if there is no data attached
205: *
206: * @author Neil Rotstan
207: * @author Klaus Meffert
208: * @since 2.6
209: */
210: Object getApplicationData();
211:
212: /**
213: * Invoked when this Chromosome is no longer needed and should perform
214: * any necessary cleanup. Note that this method will attempt to release
215: * this Chromosome instance to the active ChromosomePool, if any.
216: *
217: * @author Neil Rotstan
218: * @author Klaus Meffert
219: * @since 2.6
220: */
221: void cleanup();
222:
223: /**
224: * @return the configuration set
225: *
226: * @author Klaus Meffert
227: * @since 3.0
228: */
229: Configuration getConfiguration();
230:
231: /**
232: * Increases the number of evolutionary rounds of chromosome in which it has
233: * not been changed by one.
234: *
235: * @author Klaus Meffert
236: * @since 3.2
237: */
238: void increaseAge();
239:
240: /**
241: * Reset age of chromosome because it has been changed.
242: *
243: * @author Klaus Meffert
244: * @since 3.2
245: */
246: void resetAge();
247:
248: /**
249: * @return 0: Chromosome newly created in this generation. This means it
250: * does not need being crossed over with another newly created one
251: *
252: * @author Klaus Meffert
253: * @since 3.2
254: */
255: int getAge();
256:
257: /**
258: * Increase information of number of genetic operations performed on
259: * chromosome in current evolution round.
260: *
261: * @author Klaus Meffert
262: * @since 3.2
263: */
264: void increaseOperatedOn();
265:
266: /**
267: * Resets the information of how many genetic operators have been performed
268: * on the chromosome in the current round of evolution.
269: *
270: * @author Klaus Meffert
271: * @since 3.2
272: *
273: */
274: void resetOperatedOn();
275:
276: /**
277: * @return number of genetic operations performed on chromosome in current
278: * evolution round
279: *
280: * @author Klaus Meffert
281: * @since 3.2
282: */
283: int operatedOn();
284: }
|