@Override public Hash<UUID, Rocket> evolve() { Tuple<Rocket> group = topHalfPerformers(); Tuple<Rocket> children = new Tuple<>(); int idx, idx2; for (int i = 0; i < group.size(); i++) { idx = Utility.rand(0, group.size() - 1); idx2 = Utility.rand(0, group.size() - 1); if (idx == i) idx = (idx + 1) % group.size(); if (idx2 == i) idx2 = (idx + 1) % group.size(); while (idx != idx2 && idx2 != i) idx2 = (idx + 1) % group.size(); children.add( new Rocket( tadd( group.get(i).getChromosome(), tsub(group.get(idx).getChromosome(), group.get(idx2).getChromosome())))); } for (int i = 0; i < group.size(); i++) { idx = Utility.rand(0, group.size() - 1); idx2 = Utility.rand(0, group.size() - 1); if (idx == i) idx = (idx + 1) % group.size(); if (idx2 == i) idx2 = (idx + 1) % group.size(); while (idx != idx2 && idx2 != i) idx2 = (idx + 1) % group.size(); children.add( new Rocket( tadd( group.get(i).getChromosome(), tsub(group.get(idx).getChromosome(), group.get(idx2).getChromosome())))); } Hash<UUID, Rocket> result = new Hash<>(); for (Rocket r : children) result.add(r.getId(), r); return result; }
// ===== CONSTRUCTOR public DifferentialEvolution(Hash<UUID, Rocket> generation) { this.generation = generation.values(); }