Beispiel #1
0
        //Simple Mutation Assumes independence of each variable
        internal GAEncoding RealVectMutation()
        {
            GAEncoding newSolution = Copy.DeepCopy(this);

            UpdateID();
            newSolution.FixInputs(_lowbounds, _highbounds);

            //for (int i = 0; i < _numOfParams * _numOfParams; i++)
            //{
            //    if (GlobalVar.rnd.NextDouble()
            //        <= 2.0 / (_numOfParams * _numOfParams))
            //    {
            //        double k_MutPrecision = 1;
            //        double u = GlobalVar.rnd.NextDouble();
            //        int s_Direction = GlobalVar.rnd.NextDouble() <= 0.5 ? -1 : 1;
            //        double a_StepSize1 = 10*u + s_Direction;
            //        double mean = weightsVect.Sum()/(_numOfParams*_numOfParams);
            //        weightsVect[i] = weightsVect[i] * a_StepSize1 + mean * (1 - a_StepSize1);
            //        if (weightsVect[i] <= 0)
            //        {
            //            weightsVect[i] = 0.0001;
            //        }
            //    }
            //}

            if (GlobalVar.rnd.NextDouble() <= 1.0 / 100)
            {
                for (int i = 0; i < _numOfParams * _numOfParams; i++)
                {
                    double k_MutPrecision = 1;
                    double u           = GlobalVar.rnd.NextDouble();
                    int    s_Direction = GlobalVar.rnd.NextDouble() <= 0.5 ? -1 : 1;
                    double a_StepSize1 = 10 * u + s_Direction;
                    double mean        = weightsVect.Sum() / (_numOfParams * _numOfParams);
                    weightsVect[i] = weightsVect[i] * a_StepSize1 + mean * (1 - a_StepSize1);
                    if (weightsVect[i] <= 0)
                    {
                        weightsVect[i] = 0.0001;
                    }
                }
            }

            weightsVect = weightsVect.Normalize(1).Multiply(_numOfParams * _numOfParams);

            double test = weightsVect.Sum();

            if (test > _numOfParams * _numOfParams + 0.001 || test < _numOfParams * _numOfParams - 0.001)
            {
                Console.WriteLine();
            }
            return(newSolution);
        }
 private void GA_Initialization()
 {
     cePool                  = new CEPool();
     tempPool                = new CEPool();
     ceDB                    = new CEPool();
     cumulativeArray         = new double[popSize];
     Console.BackgroundColor = ConsoleColor.Yellow;
     for (int i = 0; i < popSize; i++)
     {
         var newSolution = new GAEncoding(pNumOfParams, dimension, lowbounds, highbounds);
         newSolution.FixInputs(lowbounds, highbounds);
         tempPool.Add(newSolution, new double[] { -1, -1 });
     }
     for (int i = 0; i < pNumOfParams * pNumOfParams; i++)
     {
         dt.Columns.Add(i.ToString(), Type.GetType("System.Double"));
     }
 }
Beispiel #3
0
        // Recombination: create a new solution, call this function;
        // Add the new solution to the population
        internal GAEncoding IntermidinateRecomb(CEPool currentPool, int[] selectedList)
        {
            double     d           = 0.25;
            GAEncoding newSolution = new GAEncoding(_numOfParams, _dimension, _lowbounds, _highbounds);
            double     alpha       = GlobalVar.rnd.NextDouble();

            alpha = (1 + d - -1 * d) * alpha + -1 * d;
            var deltaW = currentPool.ElementAt(selectedList[1]).Key.weightsVect
                         - currentPool.ElementAt(selectedList[0]).Key.weightsVect;

            newSolution.weightsVect =
                deltaW.Multiply(alpha) + currentPool.ElementAt(selectedList[0]).Key.weightsVect;

            double test = newSolution.weightsVect.Sum();

            if (test > _numOfParams * _numOfParams + 0.001 || test < _numOfParams * _numOfParams - 0.001)
            {
                Console.WriteLine();
            }
            newSolution.FixInputs(_lowbounds, _highbounds);
            newSolution.UpdateID();
            return(newSolution);
        }