コード例 #1
0
        public void Process()
        {
            TspManager.Start((x => !IsProgramAlive));
            //while (true)
            while (false)
            {
                ControlProgram.Population.NextGeneration();
                SetControlPropertyThreadSafe(lblCurGen, "Text", "Gen: " + ControlProgram.Population.CurrentGeneration);
                MyReport.CheckAndAddBest(ControlProgram.Population);
                //lblCurGen.Text = "Gen: " + ControlProgram.Population.CurrentGeneration;

                var p = ControlProgram.Population;
                //GetBestFromProblem
                var bestFromProblem = "null";
                if (ControlProgram.tsp != null)
                {
                    bestFromProblem = "Dis= " + ControlProgram.tsp.OptimalTourDistance;
                }

                if (ControlProgram.Environment.IsuseOneFit)
                {
                    if (MyReport.BestList.Count > 1 && MyReport.BestList.Last().Chromosome.ToString(ControlProgram.Environment) == ControlProgram.LastTour)
                    {
                        continue;
                    }
                    SetControlPropertyThreadSafe(textBox1, "Text",
                                                 string.Format(
                                                     @"Distance: {0}  
Fit {1} 
Fit1 {4}
Fit2 {5}
Tour with Fit1: {2}
BestList from problem: {3}",
                                                     p.BestOneFitChromosome.Distance, //1
                                                     p.BestOneFit,                    //2
                                                     p.BestOneFitChromosome,          //3
                                                     bestFromProblem,                 //4
                                                     p.BestOneFitChromosome.Fit1,     //5
                                                     p.BestOneFitChromosome.Fit2));   //6

                    DrawATour(p.BestOneFitChromosome.ToString(ControlProgram.Environment), Color.Green);
                }
                else
                {
                    textBox1.Text = string.Format(
                        @"Distance: {0}  
Fit1: {1} 
Fit2: {2} 
Tour with Fit1: {3} 
Tour with Fit2 {4}
BestList from problem: {5}",
                        p.BestFit1Chromosome.Distance, p.BestFit1, p.BestFit2, p.BestFit1Chromosome, p.BestFit2Chromosome,
                        "null"); //ControlProgram.tsp.OptimalTourDistance??"null");
                    DrawATour(p.BestFit2Chromosome.ToString(ControlProgram.Environment), Color.Green);
                }
            }
        }
コード例 #2
0
        public void NextGeneration(Population population)
        {
            SetControlPropertyThreadSafe(lblCurGen, "Text", "Gen: " + population.CurrentGeneration);
            MyReport.CheckAndAddBest(ControlProgram.Population);
            //lblCurGen.Text = "Gen: " + ControlProgram.Population.CurrentGeneration;

            var p = population;
            //GetBestFromProblem
            var bestFromProblem = "null";

            if (ControlProgram.tsp != null)
            {
                bestFromProblem = "Dis= " + ControlProgram.tsp.OptimalTourDistance;
            }

            if (population.Environment.IsuseOneFit)
            {
                if (MyReport.BestList.Count > 1 && MyReport.BestList.Last().Chromosome.ToString(population.Environment) == ControlProgram.LastTour)
                {
                    return;
                }
                SetControlPropertyThreadSafe(textBox1, "Text",
                                             string.Format(
                                                 @"Distance: {0}  
Fit {1} 
Fit1 {4}
Fit2 {5}
Tour with Fit1: {2}
BestList from problem: {3}",
                                                 p.BestOneFitChromosome.Distance, //1
                                                 p.BestOneFit,                    //2
                                                 p.BestOneFitChromosome,          //3
                                                 bestFromProblem,                 //4
                                                 p.BestOneFitChromosome.Fit1,     //5
                                                 p.BestOneFitChromosome.Fit2));   //6

                DrawATour(p.BestOneFitChromosome.ToString(population.Environment), Color.Green);
            }
            #region two fit don't use
            //two fit don't use
            else
            {
                textBox1.Text = string.Format(
                    @"Distance: {0}  
Fit1: {1} 
Fit2: {2} 
Tour with Fit1: {3} 
Tour with Fit2 {4}
BestList from problem: {5}",
                    p.BestFit1Chromosome.Distance, p.BestFit1, p.BestFit2, p.BestFit1Chromosome, p.BestFit2Chromosome,
                    "null"); //ControlProgram.tsp.OptimalTourDistance??"null");
                DrawATour(p.BestFit2Chromosome.ToString(ControlProgram.Environment), Color.Green);
            }
            #endregion
        }