Пример #1
0
        public double Calculate(Vector vector)
        {
            double result = 0;

            for (int i = 0; i < vector.Dimension; i++)
            {
                result += Math.Pow((vector.Components[i] - Parameters[i]), 2);
            }
            return result;
        }
Пример #2
0
        public double Calculate(Vector vector)
        {
            double result = 0;

            result = (vector.Components[0] - vector.Components[1]) * (vector.Components[0] + vector.Components[1]);
            result = Math.Abs(result);
            result += Math.Pow(((vector.Components[0] * vector.Components[0]) + (vector.Components[1] * vector.Components[1])), 0.5);

            return result;
        }
Пример #3
0
        public double Calculate(Vector vector)
        {
            double result = 0;
            double sumComponentsSquare = 0;

            foreach (double component in vector.Components)
            {
                sumComponentsSquare += (Math.Pow(component, 2));
            }

            result = Math.Pow(sumComponentsSquare, 0.1);
            result *= 50;
            result = Math.Sin(result);
            result = Math.Pow(result, 2);
            result += 1;

            result *= (Math.Pow(sumComponentsSquare, 0.25));

            return result;
        }
Пример #4
0
        public static Vector CrossOver(Vector parent1, Vector parent2)
        {
            Vector child = new Vector();
            child.Dimension = VectorDimension;

            int randomNum = Algorithm.random.Next(0, VectorDimension);

            for (int i = 0; i < randomNum; i++)
            {
                int parent = Algorithm.random.Next(0, 1);
                if (parent == 0)
                    child.Components.Add(parent1.Components[i]);
                else
                    child.Components.Add(parent2.Components[i]);
            }
            for (int i = randomNum; i < VectorDimension; i++)
            {
                child.Components.Add((parent1.Components[i]) + (parent2.Components[i]) / 2);
            }
            return child;
        }
Пример #5
0
        public double Calculate(Vector vector)
        {
            double result = 0;
            double sumComponentsSquare = 0;
            double numerator, denumerator;

            foreach(double component in vector.Components)
            {
                sumComponentsSquare += (Math.Pow(component,2));
            }

            numerator = Math.Pow(sumComponentsSquare, 0.5);
            numerator = Math.Sin(numerator);
            numerator = Math.Pow(numerator,2);
            numerator -= 0.5;

            denumerator = 0.001 * sumComponentsSquare;
            denumerator += 1;
            denumerator = Math.Pow(denumerator, 2);

            result = 0.5 + (numerator / denumerator);

            return result;
        }
Пример #6
0
        private static void InitPopulation()
        {
            Population = new List<Vector>();
            PopulationEvaluation = new List<double>();

            for(int i = 0; i<Constants.POPULATIONSIZE;i++)
            {
                Vector v = new Vector();
                v.Dimension = VectorDimension;
                for(int j=0; j<VectorDimension;j++)
                {
                    double randComponent = Algorithm.GetRandomNumber(Constants.LOWERSEARCHBOUND, Constants.UPPERSEARCHBOUND);
                    v.Components.Add(randComponent);
                }
                Population.Add(v);
                PopulationEvaluation.Add(Function.Calculate(v));
            }
        }
Пример #7
0
        public static Vector Mutation(Vector child)
        {
            for (int i = 0; i < VectorDimension; i++)
            {
                double mutation = Algorithm.GetRandomNumber(0, 1);
                if (mutation <= Constants.MUTATIONPARAMETER)
                {
                    int addSub = Algorithm.random.Next(0, 1);
                    if (addSub == 0)
                        child.Components[i] += Algorithm.GetRandomNumber(Constants.LOWERSEARCHBOUND / 2, Constants.UPPERSEARCHBOUND / 2);
                    else
                        child.Components[i] -= Algorithm.GetRandomNumber(Constants.LOWERSEARCHBOUND / 2, Constants.UPPERSEARCHBOUND / 2);

                    if (child.Components[i] > Constants.UPPERSEARCHBOUND)
                        child.Components[i] = Constants.UPPERSEARCHBOUND;
                    if (child.Components[i] < Constants.LOWERSEARCHBOUND)
                        child.Components[i] = Constants.LOWERSEARCHBOUND;
                }
            }
            return child;
        }