java - 交叉算法实现

标签 java genetic-algorithm

我开始在这里深入研究 GA 进行研究,但我似乎无法找到交叉生成断点的答案。例如,如果我从 parent 开始:
Father = [A,B,B,A,C]<br/> Mother = [D,D,B,A,A]

我什么时候可以合法地停止生育 child 以证明所有可能的组合都已用尽?代码如下:

void reproduce(String[] father, String[] mother) {<br/> double choice = Math.random() * 100;<br/> if((int) choice % 10 < 2){<br/> //start at father[1] and swap.<br/> //Continue for other choices

这是关于我正在使用的逻辑的一小部分。所以我的问题又回到了,我如何合法地确定何时停止生育 child ?或者这只是一个数学问题,我应该只看一个直接的排列生成器而暂时忽略 GA?

最佳答案

首先,这应该是从 parent 那里生出 child 的一个不错的方法。这是单点交叉。

public String[] reproduce(String[] father, String[] mother) {
  int[] child=new String[father.length];
  int crossPoint = Math.random()*father.length;//make a crossover point
  for (int i=0;i<father.length;++i)
  {
    if (i<crossPoint)
      child[i]=father[i];
    else
      child[i]=mother[i];
  }
  return child;
}

没有咖啡,所以不能保证。您可能需要检查是否存在差一错误。

关于java - 交叉算法实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3852074/

相关文章:

java - 对象模拟不起作用(其 null)并在方法调用时返回 NullPointerException

java - android中已弃用类的现有等价物

php - 我的 GAHelloWorld 实现逻辑有什么问题?

java - 从密码字段获取文本

java - Java 日志记录、Log4J、Logback 的性能和内存占用

java - Zulu Server JDK 和 Zulu Client JDK for Windows 有什么区别?

java - 从现有列表创建元素列表

python - 使用 Pyevolve 进行帕累托排序

genetic-algorithm - 为什么这个遗传算法停滞不前?

algorithm - 如何解决这个组合算法问题