//Thread Start private void button6_Click(object sender, EventArgs e) { if (this.IsStarted) { if (this.IsPaused) { ControlProgram.RunPopulation.Resume(); this.IsPaused = false; btnRun.Text = "Suspend"; } else { ControlProgram.RunPopulation.Suspend(); this.IsPaused = true; btnRun.Text = "Resume"; } } else { this.IsStarted = true; btnRun.Text = "Suspend"; MyReport.StartTimer(ControlProgram.Population, ControlProgram.tsp); ControlProgram.RunPopulation = new Thread(Process); ControlProgram.RunPopulation.Start(); } }
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); } } }
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 }