Ejemplo n.º 1
0
 public void RunGA(int runsNumber, TxtParser textParser, int populationQuantity, double MutationRate, double CrossoverRate, int GenerationsNumber)
 {
     txtParser  = textParser;
     population = new Population[runsNumber];
     oper       = new Operator();
     for (series = 0; series < runsNumber; series++)
     {
         population[series] = oper.InitialiseFromInitialData(populationQuantity, txtParser.Numbers, txtParser.NumberOfLines,
                                                             txtParser.NumberOfColumns, percentOfChangeGeneInInitializationStep);
         tempPopulation   = new Population(populationQuantity);
         mutationRate     = (int)(MutationRate * population[series].PopulationQuantity);
         crossoveRate     = (int)(CrossoverRate * population[series].PopulationQuantity);
         generationNumber = GenerationsNumber;
         population[0]    = oper.FitnessEvaluationByMinAndQuantity(population[0], txtParser.Numbers, txtParser.NumberOfLines, txtParser.NumberOfColumns);
         for (generation = 0; generation < generationNumber; generation++)
         {
             population[series].SortListByFitness();
             for (int i = 0; i < crossoveRate; i++)
             {
                 parentIndiv     = oper.SelectionTournament(population[series], 4);
                 offspringsIndiv = oper.TwoPointCrossover(parentIndiv);
                 tempPopulation.AddIndividual(offspringsIndiv);
             }
             for (int i = 0; i < mutationRate; i++)
             {
                 population[series] = oper.MutationFromInitialData(population[series], txtParser.Numbers, txtParser.NumberOfLines);
                 population[series] = oper.MutationFromInitialDataInSecondChromosome(population[series], txtParser.Numbers, txtParser.NumberOfLines);
             }
             population[series] = oper.FitnessEvaluationByMinAndQuantity(population[series], txtParser.Numbers, txtParser.NumberOfLines, txtParser.NumberOfColumns);
             population[series] = oper.ReductionSelecionScheme(population[series], tempPopulation);
         }
     }
 }
Ejemplo n.º 2
0
        public void RunGA(int numberOfParallelPopulations, TxtParser textParser, int populationQuantity, double MutationRate, double CrossoverRate, int GenerationsNumber)
        {
            txtParser  = textParser;
            population = new Population[numberOfParallelPopulations];
            oper       = new Operator();
            Random rnd  = new Random();
            int    indx = 0;

            for (series = 0; series < numberOfParallelPopulations; series++)
            {
                population[series] = oper.InitialiseFromInitialData(populationQuantity, txtParser.Numbers,
                                                                    txtParser.NumberOfLines, txtParser.NumberOfColumns, percentOfChangeGeneInInitializationStep);
                mutationRate       = (int)(MutationRate * population[series].PopulationQuantity);
                crossoveRate       = (int)(CrossoverRate * population[series].PopulationQuantity);
                generationNumber   = GenerationsNumber;
                population[series] = oper.FitnessEvaluationByMinAndQuantity(population[series], txtParser.Numbers, txtParser.NumberOfLines, txtParser.NumberOfColumns);
            }
            for (generation = 0; generation < generationNumber; generation++)
            {
                if (rnd.NextDouble() < transmissionRateBetweenParallelPopulations)
                {
                    for (series = 1; series < numberOfParallelPopulations; series++)
                    {
                        indx = (int)(rnd.NextDouble() * (double)population[series].PopulationQuantity);
                        Individual indiv = population[series].GetIndividualByIndex(indx);
                        population[series].SetIndividualByIndex(indx, population[series - 1].GetIndividualByIndex(indx));
                        population[series - 1].SetIndividualByIndex(indx, indiv);
                        oper.FitnessEvaluationByMinAndQuantityByIndex(population[series - 1], txtParser.Numbers, txtParser.NumberOfLines, txtParser.NumberOfColumns, indx);
                        oper.FitnessEvaluationByMinAndQuantityByIndex(population[series], txtParser.Numbers, txtParser.NumberOfLines, txtParser.NumberOfColumns, indx);
                    }
                }
                for (series = 0; series < numberOfParallelPopulations; series++)
                {
                    tempPopulation = new Population(populationQuantity);
                    population[series].SortListByFitness();
                    for (int i = 0; i < crossoveRate; i++)
                    {
                        parentIndiv     = oper.SelectionTournament(population[series], tournamentGroupQuantity);
                        offspringsIndiv = oper.TwoPointCrossover(parentIndiv);
                        //offspringsIndiv = oper.IntermediateRecombinationCrossover(parentIndiv);
                        tempPopulation.AddIndividual(offspringsIndiv);
                    }
                    for (int i = 0; i < mutationRate; i++)
                    {
                        tempPopulation = oper.MutationFromInitialData(tempPopulation, txtParser.Numbers, txtParser.NumberOfLines);
                        tempPopulation = oper.MutationFromInitialDataInSecondChromosome(tempPopulation, txtParser.Numbers, txtParser.NumberOfLines);
                    }
                    population[series] = oper.FitnessEvaluationByMinAndQuantity(population[series], txtParser.Numbers, txtParser.NumberOfLines, txtParser.NumberOfColumns);
                    population[series] = oper.ReductionSelecionScheme(population[series], tempPopulation);
                    population[series].SortListByFitness();
                }
            }
        }
Ejemplo n.º 3
0
 public Individual[] RunSerialGATest(int SeriesNumber, TxtParser TextParser, int PopulationQuantity, double MutationRate,
                                     double CrossoverRate, int GenerationsNumber, int NumberOfTestRuns)
 {
     for (currentTestNumber = 0; currentTestNumber < NumberOfTestRuns; currentTestNumber++)
     {
         SGA.RunGA(SeriesNumber, TextParser, PopulationQuantity, MutationRate, CrossoverRate, GenerationsNumber);
         for (int j = 0; j < SeriesNumber; j++)
         {
             AddOneBestIndividualToList(SGA.PopulationList[j]);
         }
     }
     return(individualList);
 }
Ejemplo n.º 4
0
 private void buttonLoadData_Click(object sender, EventArgs e)
 {
     if (openFileDialogLoadData.ShowDialog() == DialogResult.OK)
     {
         txtParser = new TxtParser(openFileDialogLoadData.FileName, int.Parse(textBoxObservationsNumber.Text));
         if (openFileDialogTestData.ShowDialog() == DialogResult.OK)
         {
             txtParserForTest = new TxtParser(openFileDialogTestData.FileName, int.Parse(textBoxObservationsNumber.Text));
             if (this.checkBoxTest.Checked)
             {
                 this.buttonTestGA.Enabled = true;
             }
             else
             {
                 this.buttonSearch.Enabled = true;
             }
         }
     }
 }