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

📄 selectsinglegreatestfitness.java

📁 遗传算法源代码,实现了选择操作、交叉操作和变异操作
💻 JAVA
字号:
/*--- formatted by Jindent 2.1, (www.c-lab.de/~jindent) ---*//** * SelectionAlgorithm Class * * location: net.openai.ai.ga.selection.SelectionAlgorithm * */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>SelectGreatestFitness</code> is a <code>SelectionAlgorithm</code> * that will return a portion of the passed <code>Population</code> that * have the greatest fitness. It will choose either a fixed number or a * percentage. * * @author	Jared Grubb * @version	%I%, %G% * @since	JDK1.3 */public class SelectSingleGreatestFitness implements SelectionAlgorithm {    /**     * Creates a new <code>SelectSingleGreatestFitness</code> object for     * choosing a single <code>Cell</code> out of the specified <code>     * Population</code> who has the greatest fitness.     */    public SelectSingleGreatestFitness() {    }    /**     * Chooses the <code>Cell</code> in the specified <code>Population</code>     * with the greatest fitness.     *     * The returned population is guaranteed to return the cell of the     * specified population such that there are no other members in that     * population who are greater than that returned. This means that cells     * who tie the highest are ignored. For example, if     * the fitness of a population was {1,1,2,3,3,3,4,5,5} then only one cell     * of fitness 5 will be returned.     *     * @param pop  the <code>Population</code> to choose from     * @returns a selected <code>Population</code> of one cell     */    public Population selectFromPopulation(Population pop) {        Population output = new Population();        Cell tempCell=null;        double tempFitness;        Cell bestCell = null;        double bestFitness = Double.NEGATIVE_INFINITY;        for(Iterator i=pop.getCellIterator(); i.hasNext(); ) {            tempCell = (Cell) i.next();            tempFitness = tempCell.getFitness();            if (tempFitness>=bestFitness) {               bestFitness = tempFitness;               bestCell = tempCell;            }        }        output.addCell(bestCell);        return output;    }}/*--- formatting done in "Sun Java Convention" style on 12-28-2000 ---*/

⌨️ 快捷键说明

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