Esempio n. 1
0
 public Chromosome Mutate(Chromosome chromosome, Bounds bounds)
 {
     Vector vector = new Vector(bounds.Lower.NRows);
     for (int i = 0; i < vector.NRows; i++)
     {
         vector[i] = GeneticAlgorithm.Random.NextDouble()*(bounds.Upper[i] - bounds.Lower[i]) + bounds.Lower[i];
     }
     return new Chromosome(vector);
 }
Esempio n. 2
0
 public Chromosome Cross(Chromosome chromosome1, Chromosome chromosome2, Bounds bounds)
 {
     int nRows = chromosome1.Vector.NRows;
     Vector vector = new Vector(nRows);
     for (int i = 0; i < nRows; i++)
     {
         double num = Math.Min(chromosome1.Vector[i], chromosome2.Vector[i]);
         double expr_55 = Math.Max(chromosome1.Vector[i], chromosome2.Vector[i]);
         double num2 = (expr_55 - num)*this.Alpha;
         double num3 = Math.Max(num - num2, bounds.Lower[i]);
         double num4 = Math.Min(expr_55 + num2, bounds.Upper[i]);
         double num5 = GeneticAlgorithm.Random.NextDouble();
         vector[i] = num5*(num4 - num3) + num3;
         if (this.IsPorfolioOptimization)
         {
             if (num5 < 0.1)
             {
                 vector[i] = bounds.Lower[i];
             }
             else if (num5 < 0.2)
             {
                 vector[i] = bounds.Upper[i];
             }
         }
     }
     return new Chromosome(vector);
 }