randomselection.java
来自「这是多目标进化算法包」· Java 代码 · 共 38 行
JAVA
38 行
/** * RandomSelection.java * @author Juan J. Durillo * @version 1.0 */package jmetal.base.operator.selection;import jmetal.base.*;import jmetal.util.PseudoRandom;/** * This class implements a random selection operator used for selecting two * random parents */public class RandomSelection extends Operator { /** * Performs the operation * @param object Object representing a SolutionSet. * @return an object representing an array with the selected parents */ public Object execute(Object object) { SolutionSet population = (SolutionSet)object; int pos1, pos2; pos1 = PseudoRandom.randInt(0,population.size()-1); pos2 = PseudoRandom.randInt(0,population.size()-1); while ((pos1 == pos2) && (population.size()>1)) { pos2 = PseudoRandom.randInt(0,population.size()-1); } Solution [] parents = new Solution[2]; parents[0] = population.get(pos1); parents[1] = population.get(pos2); return parents; } // Execute } // RandomSelection
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?