Ejemplo n.º 1
0
        private ChromosomeVector ProportionalCrossover(ChromosomeVector parentA, ChromosomeVector parentB)
        {
            double fitnessA     = Math.Abs(1 / _equation(parentA));
            double fitnessB     = Math.Abs(1 / _equation(parentB));
            double probabilityA = fitnessA / (fitnessA + fitnessB);
            double probabilityB = 1 - probabilityA;

            ChromosomeVector child = new ChromosomeVector();

            for (int i = 0; i < ChromosomeVector.Length; i++)
            {
                double probability = Random.NextDouble();
                if (probability < probabilityA)
                {
                    if (probability < probabilityB)
                    {
                        child[i] = probabilityA >= probabilityB ? parentA[i] : parentB[i];
                    }
                    else
                    {
                        child[i] = parentA[i];
                    }
                }
                else
                {
                    child[i] = parentB[i];
                }
            }
            return(child);
        }
Ejemplo n.º 2
0
        private List <ChromosomeVector> Crossover(List <ChromosomeVector> parents)
        {
            var children = new List <ChromosomeVector>();

            while (children.Count < _childrenAmount)
            {
                // removing self-crossover ?
                var(parentAIndex, parentBIndex) = (0, 0);
                while (parentAIndex == parentBIndex)
                {
                    (parentAIndex, parentBIndex) = (Random.Next(parents.Count), Random.Next(parents.Count));
                }

                ChromosomeVector child = ProportionalCrossover(parents[parentAIndex], parents[parentBIndex]);
                children.Add(child);
            }

            return(children);
        }
Ejemplo n.º 3
0
 public static int EquationA(ChromosomeVector chromosome)
 {
     var(u, w, x, y, z) = (chromosome.U, chromosome.W, chromosome.X, chromosome.Y, chromosome.Z);
     return(Math.Abs(((w * w) * x * (y * y) * z) + ((w * w) * (x * x) * (y * y) * z) + ((u * u) * w * x) + ((w * w) * (x * x) * (y * y) * (z * z)) + (y * z) + 5));
 }
Ejemplo n.º 4
0
 public static int EquationExtra(ChromosomeVector chromosome)
 {
     var(u, w, x, y, z) = (chromosome.U, chromosome.W, chromosome.X, chromosome.Y, chromosome.Z);
     return(Math.Abs(-22 + ((y * y) + (w * w * z) + (w * y * z) + (u * (z * z) + (u * w * (x * x) * (y * y) * (z * z))))));
 }
Ejemplo n.º 5
0
 public static int EquationB(ChromosomeVector chromosome)
 {
     var(u, w, x, y, z) = (chromosome.U, chromosome.W, chromosome.X, chromosome.Y, chromosome.Z);
     return(Math.Abs(z + (u * x * y) + ((w * w) * x * (z * z)) + (w * (x * x) * (z * z)) + ((u * u) * (x * x) * y * (z * z)) + 50));
 }