コード例 #1
0
        // Update fitness
        public bool UpdateFitness()
        {
            double fitness = 0.0, averageFitness = 0.0;
            int    index = -1;

            for (int i = 0; i < _populationsize; ++i)
            {
                fitness         = Fitness(_population[i]);
                averageFitness += fitness;
                if (_bestFitness < fitness)
                {
                    _bestFitness = fitness;
                    index        = i;
                }
                else
                {
                }
            }
            if (_bestAverageFitness < averageFitness && index >= 0)
            {
                _bestAverageFitness = averageFitness;
                _bestSolution       = DataCentre.DeepCopy(_population[index]);
                return(true);
            }
            else
            {
            }
            return(false);
        }
コード例 #2
0
        //////////////////////////////////////////////////////////////////////////
        // Visualization Tab
        // Problem to Static Chart for number of online and offline virtual machines
        public void Problem2StaticChart(DataCentre iDataCentre, ref Chart chart)
        {
            List <Variation> iObjects = iDataCentre._variations;

            chart.Series[0].Points.Clear();
            chart.Series[1].Points.Clear();
            for (int i = 0; i < iObjects.Count; ++i)
            {
                chart.Series[0].Points.Add(new DataPoint(iObjects[i]._time,
                                                         iObjects[i]._vmsoff.Count));
                chart.Series[1].Points.Add(new DataPoint(iObjects[i]._time, -
                                                         iObjects[i]._vmson.Count));
            }
            chart.ChartAreas[0].AxisX.Maximum = iDataCentre._duration;
        }
コード例 #3
0
 // Evolve the GA population
 public void Evolve()
 {
     while (_noupdate < _termination)
     {
         int[][] newpopulation = DataCentre.DeepCopy(_population);
         for (int i = 0; i < _populationsize; ++i)
         {
             DataCentre._random = new Random((int)DateTime.Now.Ticks);
             if (DataCentre._random.NextDouble() <= _pcrossover)
             {
                 int   j     = Selection(i);
                 int[] child = CrossOver(_population[i], _population[j]);
                 if (Fitness(child) > Fitness(newpopulation[i]))
                 {
                     newpopulation[i] = child;
                 }
                 else
                 {
                 }
             }
             else
             {
             }
             DataCentre._random = new Random((int)DateTime.Now.Ticks);
             if (DataCentre._random.NextDouble() <= _pmutation)
             {
                 newpopulation[i] = Mutation(newpopulation[i]);
             }
             else
             {
             }
         }
         _population = DataCentre.DeepCopy(newpopulation);
         if (UpdateFitness())
         {
             _noupdate = 0;
         }
         else
         {
             ++_noupdate;
         }
     }
 }