public Individual(Individual Twin) { genes = new int[Twin.size()]; for (int i = 0; i < genes.Length; i++) { genes[i] = Twin.get(i); } fittness = 0; dead = Twin.dead; }
public double fittness(Individual path) { double dist = 0.0; int b = path.get(0); for (int i = 1; i < x.Length; i++) { int a = b; int dx = x[a] - x[b]; dx = dx > 0 ? dx : -dx; int dy = y[a] - y[b]; dy = dy > 0 ? dy : -dy; b = path.get(i); dist += (Math.Sqrt((double)((dx*dx)+(dy*dy)))); } return dist; }
public void Copy(Individual otherInd) { Genome.Copy(otherInd.Genome); Objective = otherInd.Objective; Fitness = otherInd.Fitness; }
public void add(Individual individual) { individual.setFittness(home); indi.Add(individual); }
public void reproduce() { pop.sort(); for (int i = pop.indi.Count; i > 0; i--) { if (i < r.Next(pop.indi.Count) && !pop.indi[i].dead ) { Individual individual = new Individual(pop.get(i)); individual.mutate(r.Next(maxGeneration-generation)/mutationFactor ); pop.add(individual); } } while (pop.size() < targetSize) { Individual individual = new Individual(pop.get(r.Next(pop.size()))); individual.mutate(mutationFactor); pop.add(individual); } }