spawner.java

来自「CHC (基因算法)基因算法(GeneticAlgorithm简称GA)是人工智」· Java 代码 · 共 40 行

JAVA
40
字号
package chc;import shared.LogOptions;import java.util.*;  public class Spawner {  private int attrselectionsize;  private LogOptions logOptions = new LogOptions("WRAPPER");  private Random rand;  public Spawner(int attrselsize) {    if (attrselsize < 1) {      logOptions.ERR(0, "Atribute attrselectionsize cannot be zero.");    }    attrselectionsize = attrselsize;    rand = new Random(System.currentTimeMillis());  }  public Hypothesis[] spawnPopulation(int number, int generation) {    logOptions.LOG(3, "Spawning"+CHC.ENDL);      Hypothesis[] result = new Hypothesis[number];      for (int i = 0; i < number; i++) {        result[i] = newHypo(generation);      }    return result;  }  public Hypothesis newHypo(int generation) {      int[] newint = new int[attrselectionsize];      for (int j = 0; j < attrselectionsize; j++) {        newint[j] = rand.nextInt(2);      }    Hypothesis newhypo = new Hypothesis(generation, newint);    return newhypo;  }    }

⌨️ 快捷键说明

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