예제 #1
0
 private void MOGA_Initialization()
 {
     cePool   = new CEPool();
     tempPool = new CEPool();
     ceDB     = new CEPool();
     Console.BackgroundColor = ConsoleColor.DarkRed;
     numOfNNLocalSearch      = 1000; //(pNumOfParams + 1) * (pNumOfParams + 2) / 2 * dimension;
     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 });
     }
 }
        internal GAEncoding PanmicticDiscreteRecomb(CEPool currentPool, int[] selectedList)
        {
            GAEncoding newSolution = new GAEncoding(_numOfParams, _dimension, _lowbounds, _highbounds);

            for (int i = 0; i < _dimension; i++)
            {
                for (int j = 0; j < _numOfParams; j++)
                {
                    int selectedIndex = selectedList[GlobalVar.rnd.Next(0, selectedList.Length - 1 + 1)];
                    newSolution.weights[j, i] = currentPool.ElementAt(selectedIndex).Key.weights[j, i];
                }
            }
            newSolution.FixInputs(_lowbounds, _highbounds);
            newSolution.UpdateID();
            return(newSolution);
        }
        // Recombination: create a new solution, call this function;
        // Add the new solution to the population
        internal GAEncoding PanmicticAvgRecomb(CEPool currentPool, int[] selectedList)
        {
            // Select solution to combine
            // Find Average
            Matrix <double> avgWeight = Matrix.Build.Dense(_numOfParams, _dimension);

            for (int i = 0; i < selectedList.Length; i++)
            {
                avgWeight += currentPool.ElementAt(selectedList[i]).Key.weights;
            }
            avgWeight = avgWeight / selectedList.Length;
            // ... Check the sum of each row should be equal to a constant max
            GAEncoding newSolution = new GAEncoding(_numOfParams, _dimension, _lowbounds, _highbounds);

            newSolution.weights = avgWeight;
            newSolution.FixInputs(_lowbounds, _highbounds);
            return(newSolution);
        }