📄 abstractcell.java
字号:
/*--- formatted by Jindent 2.1, (www.c-lab.de/~jindent) ---*//** * AbstractCell Class * * location: net.openai.ai.ga.cell.AbstractCell * */package net.openai.ai.ga.cell;import net.openai.ai.ga.environment.*;import net.openai.ai.ga.population.*;/** * The <code>AbstractCell</code> class is an encapsulation of data that will * be used to try to solve a problem (<code>Environment</code>). This class * provides a skeletal implementation to minimize the effort needed to implement * a simple <code>Cell</code> interface. * * <p>The following functions <b>must be implemented</b> in the derived class: * <ul> * <li><code>double evaluateFitness(Environment)</code> * <li><code>Cell combine(Population)</code> * </ul> * The following functions have <i>basic functionality</i>: * <ul> * <li><code>double getFitness()</code> * <li><code>int getMaturity()</code> * <li><code>void mature()</code> * </ul> * The following functions are <i>stubbed</i>: * <ul> * <li><code>void condemn()</code> * <li><code>void mutate()</code> * </ul> * @author Jared Grubb * @version %I%, %G% * @since JDK1.3 */public abstract class AbstractCell implements Cell { /** * The last evaluated fitness for the cell is stored here and is used for * the <code>getFitness</code> calls. */ protected double cellFitness; /** * The maturity of the cell is stored here and is used for the <code> * getMaturity</code>. */ protected int cellMaturity; /** * Return the fitness of the <code>Cell</code>. This call does not * neccessarily require that a new evaluation is performed, only that * the last fitness generated is desired. This is the preferred method * for any function curious about the cell's fitness as it should not * require any complex calculations. The fitness must be quantifiable * as an integer. * * <p>This skeletal implementation returns the value of the <code> * cellFitness</code> member. * * @return a <code>double</code> representing the fitness of this * <code>Cell</code> */ public double getFitness() {return cellFitness;} /** * Return the fitness of the <code>Cell</code>. This call asks that a new * evaluation is performed. This method is called during every iteration * of a <code>Population</code>. The implementation must determine whether * a new evaluation is required or whether the last returned value will * suffice. The fitness must be quantifiable as an integer. This function * should only be called if there is reason to ask for a new value, but * should be generally avoided since it may require extra overhead. * * <p>There is no implementation in this skeletal implementation and must * be provided by the derived class. * * @param env the <code>Environment</code> to evaluate against * @return a <code>double</code> representing the fitness of this * <code>Cell</code> */ public abstract double evaluateFitness(Environment env); /** * Returns the maturity of the <code>Cell</code>. * * <p>This skeletal implementation returns the value of the <code> * cellMaturity</code> member. * * @return the maturity of this <code>Cell</code> */ public int getMaturity() {return cellMaturity;} /** * Tells the cell that it has been condemned to die. This allows for any * extra clean-up necessary or for record-keeping of cells that are * removed from a population. It is not required that the Cell destroy * itself or any objects, but is provided as notification that the Cell * will be removed from the population. * * <p>This skeletal implementation is a stub <code>{}</code>. */ public void condemn() {} /** * Tells the cell that it has been chosen to mutate. * * This skeletal implementation is a stub <code>{}</code>. */ public void mutate() {} /** * Tells the cell to mature. This function is called before evaluation * on the cells. Outside calling of this function should be avoided as it * may cause over-maturation of a cell. This function may also be as * simple as incrementing the age of the cell. * * <p>This skeletal implementation increments the cellMaturity member by 1. */ public void mature() {this.cellMaturity++;} /** * Tells the cell to create new offspring, which will be placed in * the population. The offspring should be new <code>Cell</code> created * by some combination of the parents and should also be initialized with * data. The instance of <code>Cell</code> called is the first Cell in the * <code>Population</code>. * * @param parents the chosen <code>Population</code> of parents for * the new cell * @return a new <code>Population</code> to be added into the population */ public abstract Population combine(Population parents); /** * Returns a string showing the fitness and maturity of this cell. Returned * as "(fitness,maturity)". * * @return a <code>String</code> containing the fitness and maturity */ public String toString() {return "("+this.getFitness()+ ","+this.getMaturity()+")";}}/*--- formatting done in "Sun Java Convention" style on 12-28-2000 ---*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -