Ejemplo n.º 1
0
 //Evolve algorithm
 public void Evolve()
 {
     while (true)
     {
         generation++;
         if (Numbers.GenerationQuantity > 1)
         {
             var children = EvoManager.Crossover(Numbers.GenerationQuantity, parents.ElementAt(0), parents.ElementAt(1));
             EvoManager.Mutate(children, colorTable);
             children = (from child in children
                         orderby child.Fitness
                         select child).ToList();
             var mostFitChild = children.First();
             if (mostFitChild.NeedRepaint)
             {
                 if (fitness >= mostFitChild.Fitness)
                 {
                     childrenSelected++;
                     fitness = mostFitChild.Fitness;
                     parents = children;
                     lock (drawingData)
                     {
                         drawingData = mostFitChild;
                     }
                 }
             }
         }
         else
         {
             EvoDrawing child;
             lock (drawingData)
             {
                 child = drawingData.Clone();
             }
             child.Mutate();
             child.Fitness = EvoManager.Fitness(child, colorTable);
             if (child.NeedRepaint)
             {
                 if (fitness >= child.Fitness)
                 {
                     childrenSelected++;
                     fitness = child.Fitness;
                     //Keep possibility to come back
                     parents.Clear();
                     parents.Add(child.Clone());
                     parents.Add(child.Clone());
                     lock (drawingData)
                     {
                         drawingData = child;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 private void setupStart()
 {
     if (parents != null)
     {
         parents.Clear();
     }
     else
     {
         parents = new List <EvoDrawing>();
     }
     for (int i = 0; i < Numbers.GenerationQuantity; i++)
     {
         var adam = new EvoDrawing(Numbers.MinPointsPerShape, Numbers.MaxPointsPerShape, colorTable);
         parents.Add(adam.Clone());
     }
     generation       = 0;
     childrenSelected = 0;
     fitness          = Double.MaxValue;
 }