Genome.crossover constructor

Genome.crossover(
  1. Genome fittest,
  2. Genome weak
)

Implementation

factory Genome.crossover(Genome fittest, Genome weak) {
  var child = Genome.clone(fittest);
  for (var fitLink in child.connections) {
    if (weak.connections.any((l) => l.identifier == fitLink.identifier)) {
      var weakLink = weak.connections.singleWhere((l) => l.identifier == fitLink.identifier);
      List<Connection> choices = [weakLink, fitLink];
      choices.shuffle();
      var choice = choices.first;
      if (choice != fitLink) {
        fitLink.weight = weakLink.weight;
        fitLink.enabled = weakLink.enabled;
      }
    }
  }
  return child;
}