⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectmaturityrange.java

📁 遗传算法源代码,实现了选择操作、交叉操作和变异操作
💻 JAVA
字号:
/*--- formatted by Jindent 2.1, (www.c-lab.de/~jindent) ---*//** * SelectLeastMaturity Class * * location: net.openai.ai.ga.selection.common.SelectLeastMaturity * */package net.openai.ai.ga.selection.common;import net.openai.ai.ga.selection.*;import net.openai.ai.ga.population.*;import net.openai.ai.ga.cell.*;import java.util.Iterator;/** * <code>SelectMaturityRange</code> is a <code>SelectionAlgorithm</code> * that will return a portion of the passed <code>Population</code> that * have a maturity in the given range. * * @author	Jared Grubb * @version	%I%, %G% * @since	JDK1.3 */public class SelectMaturityRange implements SelectionAlgorithm {    private int lowerBound, upperBound;    private boolean lowerExclusive, upperExclusive;    /**     * Creates a new <code>SelectMaturityRange</code> object for choosing     * the <code>Cell</code>s out of the specified <code>Population</code> who     * have a maturity in the specified range, inclusive. (Equilivant to     * <code>SelectMaturityRange(lowerBound, false, upperBound, false)</code>).     *     * @param lowerBound the lower bound of the maturity range to allow, inclusive     * @param upperBound the upper bound of the maturity range to allow, inclusive     * @throws <code>ArithmeticException</code> on lowerBound>upperBound     */    public SelectMaturityRange(int lowerBound, int upperBound) {        this(lowerBound, false, upperBound, false);    }    /**     * Creates a new <code>SelectMaturityRange</code> object for choosing     * the <code>Cell</code>s out of the specified <code>Population</code> who     * have a maturity in the specified range, specified with whether each     * bound is treated inclusive or exclusive.     *     * @param lowerBound the lower bound of the maturity range to allow     * @param lowerExclusive <code>false</code> lowerBound is inclusive     *                       <code>true</code> lowerBound is exclusive     * @param upperBound the upper bound of the maturity range to allow     * @param upperExclusive <code>false</code> upperBound is inclusive     *                       <code>true</code> upperrBound is exclusive     * @throws <code>ArithmeticException</code> on lowerBound>upperBound     */    public SelectMaturityRange(int lowerBound, boolean lowerExclusive,                              int upperBound, boolean upperExclusive) {        if (lowerBound>upperBound)            throw new ArithmeticException(                "SelectMaturityRange: lowerBound exceeds upperBound, "+lowerBound+">"+upperBound);        this.lowerBound = lowerBound;        this.lowerExclusive = lowerExclusive;        this.upperBound = upperBound;        this.upperExclusive = upperExclusive;    }    /**     * Chooses the <code>Cell</code>s in the specified <code>Population</code>     * with maturity in a given range. There is no limit to the number of     * members returned; it is possible that no cells are returned (when none     * meet the range requirements) or that all the cells are returned (when     * they all meet the requirements).     *     * @param pop  the <code>Population</code> to choose from     * @return a selected <code>Population</code> in arbitrary order     */    public Population selectFromPopulation(Population pop) {        Population output = new Population();        Cell tempCell;        int tempMaturity;        for(Iterator i=pop.getCellIterator(); i.hasNext(); ) {            tempCell = (Cell) i.next();            tempMaturity = tempCell.getMaturity();            if (tempMaturity>this.upperBound || tempMaturity<this.lowerBound)                continue;            if (lowerExclusive && tempMaturity==this.lowerBound)                continue;            if (upperExclusive && tempMaturity==this.upperBound)                continue;            output.addCell(tempCell);        }        return output;    }}/*--- formatting done in "Sun Java Convention" style on 12-28-2000 ---*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -