private void ButtonGenerate_Click(object sender, EventArgs e) { TravellingSalesmanProblem.SetParameters((int)this.NumericNodeCount.Value, this.CanvasGraph.Width, this.CanvasGraph.Height, (int)this.NumericPopulationSize.Value, (int)this.NumericNodeSeed.Value); Tuple <int, List <Node> > data = TravellingSalesmanProblem.GenerateNodes(); List <Node> nodes = data.Item2; int seed = data.Item1; TextBoxActiveNodeSeed.Text = seed.ToString(); CanvasGraph.ClearNodes(); CanvasGraph.ClearPaths(); CanvasGraph.AddNodes(nodes); CanvasGraph.RePaint(); SortedPopulation = TravellingSalesmanProblem.GeneratePopulation(); Generation = 0; Render(); /* * for (int i = TravellingSalesmanProblem.PopulationSize - 1; i >= 0; i--) * { * CanvasGraph.ClearPaths(); * CanvasGraph.AddPath(sortedPopulation[i]); * CanvasGraph.RePaint(); * TextBoxDistance.Text = sortedPopulation[i].Distance.ToString("0.00"); * TextBoxDistance.Refresh(); * } */ }
private void Render() { if (SortedPopulation != null) { CanvasGraph.ClearPaths(); CanvasGraph.AddPath(SortedPopulation[0]); CanvasGraph.RePaint(); TextBoxDistance.Text = SortedPopulation[0].Distance.ToString("0.00"); TextBoxDistance.Refresh(); TextBoxGeneration.Text = Generation.ToString(); TextBoxDistance.Refresh(); } }