Beispiel #1
0
        public async void MOGA_FitnessEvaluation(int[] token)
        {
            List <Task> lTasks      = new List <Task>();
            int         remainTasks = tempPool.Count;

            // Test inputs Generation
            // Fitness Evaluation
            for (int k = 0; k < tempPool.Count; k++)
            {
                //Console.WriteLine("{0}'th genotype fitness assement", k);
                GAEncoding ga = tempPool.ElementAt(k).Key;

                //// Single Thread
                //var tmpTuple = ga.CalEstFitness(enVar);
                //tempPool[ga][0] = tmpTuple.Item1;
                //ga.SetCEFitness(tmpTuple.Item2.ToArray());

                lTasks.Add(Task.Run(() =>
                {
                    ga.CalEstFitness(enVar);
                    // Console.WriteLine("{0}'th finished assement", k);
                }));
                if (lTasks.Count == 8 || (tempPool.Count - k - 1 < 8))
                {
                    for (int i = 0; i < lTasks.Count; i++)
                    {
                        await lTasks[i];
                    }
                    lTasks.Clear();
                }
            }
            token[0] = 1;
            //Console.WriteLine("Fitness Evaluation Done");
        }
Beispiel #2
0
 private void MOGA_Initialization()
 {
     //CEPool cePool = null;
     //CEPool tempPool = null;
     // public CEPool ceFitness = null;
     cePool   = new CEPool();
     tempPool = new CEPool();
     for (int i = 0; i < popSize; i++)
     {
         var newSolution = new GAEncoding(pNumOfParams, dimension, enVar);
         newSolution.FixInputs(enVar);
         tempPool.Add(newSolution, new double[] { -1, -1 });
     }
 }
Beispiel #3
0
        // Recombination: create a new solution, call this function;
        // Add the new solution to the population
        internal GAEncoding PanmicticRecomb(CEPool currentPool, int[] selectedList)
        {
            // Select solution to combine
            // Find Average
            Matrix <double> avgWeight = Matrix.Build.Dense(_numOfParams + 1, _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, _enVar);

            newSolution.FixInputs(_enVar);
            newSolution.weights = avgWeight;

            return(newSolution);
        }
Beispiel #4
0
        public List <string> Print_Solution(GAEncoding solution)
        {
            string theta  = null;
            string weight = null;

            for (int i = 0; i < solution.thetaDelta.RowCount; i++)
            {
                string          tmp   = "(";
                Vector <double> vTemp = solution.thetaDelta.Row(i);
                for (int j = 0; j < dimension; j++)
                {
                    tmp = tmp + Math.Round(vTemp[j], 2) + " ";
                }
                tmp.Remove(tmp.Length - 1, 1);
                tmp   = tmp + ")";
                theta = theta + tmp + " ";
            }
            theta.Remove(theta.Length - 1, 1);

            for (int i = 0; i < solution.weights.RowCount; i++)
            {
                string          tmp   = "[";
                Vector <double> vTemp = solution.weights.Row(i);
                for (int j = 0; j < dimension; j++)
                {
                    tmp = tmp + Math.Round(vTemp[j], 2) + " ";
                }
                tmp.Remove(tmp.Length - 1, 1);
                tmp    = tmp + "]";
                weight = weight + tmp + " ";
            }
            weight.Remove(weight.Length - 1, 1);

            return(new List <string>()
            {
                theta, weight
            });
        }