示例#1
0
 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;
 }
示例#2
0
 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;
 }
示例#3
0
 public void Copy(Individual otherInd)
 {
     Genome.Copy(otherInd.Genome);
     Objective = otherInd.Objective;
     Fitness = otherInd.Fitness;
 }
示例#4
0
 public void add(Individual individual)
 {
     individual.setFittness(home);
     indi.Add(individual);
 }
示例#5
0
文件: ga.cs 项目: rustynoob/GA
        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);
            }
        }