예제 #1
0
        private void btnShowStabilityDiagram_Click(object sender, EventArgs e)
        {
            // Check User Input
            if (txtInputFilePath.Text.Trim() == "" || (!System.IO.File.Exists(txtInputFilePath.Text)))
            {
                MessageBox.Show("Please choose an input file that contains problem parameters.", "Invalid input");
                return;
            }

            // Load Problem Parameters
            bool err;

            err = ProblemParameters.Load(txtInputFilePath.Text);
            if (err)
            {
                MessageBox.Show("Invalid input file, please verify content of input file.", "Invalid input file");
                return;
            }

            // Show FormStabilityDiagram
            FormStabilityDiagram frmSD = new FormStabilityDiagram();

            frmSD.MainForm = this;
            frmSD.ShowDialog();
        }
예제 #2
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            // Check User Input

            if (txtInputFilePath.Text.Trim() == "" || (!System.IO.File.Exists(txtInputFilePath.Text)))
            {
                MessageBox.Show("Please choose an input file that contains problem parameters.", "Invalid input");
                return;
            }

            // Load Problem Parameters
            bool err;

            err = ProblemParameters.Load(txtInputFilePath.Text);
            if (err)
            {
                MessageBox.Show("Invalid input file, please verify content of input file.", "Invalid input file");
                return;
            }

            // Create GeneticAlgorithm Object and set it
            GeneticAlgorithm ga = new GeneticAlgorithm();

            ga.PopulationSize                               = (int)numPopSize.Value;
            ga.ProbabilityOfCrossover                       = (float)numCrossover.Value;
            ga.ProbabilityOfMutation                        = (float)numMutation.Value;
            ga.Termination.MaxNumberOfGenerations           = (int)numMaxGenerations.Value;
            ga.Termination.MaxUselessIterations             = (int)numMaxUselessIterations.Value;
            ga.Termination.UselessIterationFactor           = (float)numUselessIterationFactor.Value;
            GeneticAlgorithm.SpaceQuantizationDecimalPlaces = cmbSpaceQuantizationFactor.SelectedIndex + 1;

            // Run
            _gaResults = ga.Run();

            // Show Results
            Chromosome    best;
            StringBuilder bestChromosomeGenomes = new StringBuilder(ProblemParameters.Dimension * 12);

            lblGenerations.Text = _gaResults.NumberOfGenerations.ToString();
            best = _gaResults.BestChromosomes[_gaResults.NumberOfGenerations - 1];
            lblBestChromosomeFitness.Text = best.FitnessValue.ToString();
            foreach (double genom in best.Genomes)
            {
                bestChromosomeGenomes.Append(genom.ToString("F" + (GeneticAlgorithm.SpaceQuantizationDecimalPlaces).ToString()) + " ; ");
            }
            txtBestChromosomeGenomes.Text = bestChromosomeGenomes.ToString();

            // Change GUI
            btnShowConvergenceDiagram.Enabled = true;
        }