private void buttonStartExhaustive_Click(object sender, EventArgs e) { int Size = AdjacencyMatrix.GetLength(0); int temp = 0; for (int i = 0; i < Size; ++i) { for (int j = i + 1; j < Size; ++j) { if (dataGridViewMain[i, j].Value == null || !int.TryParse((string)(dataGridViewMain[i, j].Value), out temp)) { MessageBox.Show("Wrong values of adjacency matrix"); return; } else { AdjacencyMatrix[i, j] = AdjacencyMatrix[j, i] = temp; } } } byte StartTown = (byte)(numericUpDownStartTown.Value); if (!SalesmanTaskSolver.InitializeAdjancencyMatrix(ref AdjacencyMatrix, StartTown)) { MessageBox.Show("Wrong values of adjacency matrix"); } else { var Genom = SalesmanTaskSolver.SolveViaExhaustiveAlgorithm(); StringBuilder Builder = new StringBuilder(StartTown.ToString(), 11); for (int i = 0; i < Genom.GenesCount; ++i) { Builder.Append('-'); Builder.Append(Genom[i].ToString()); } Builder.Append("-" + StartTown.ToString()); int Length = 0; for (int i = 0; i < Genom.GenesCount - 1; ++i) { Length += AdjacencyMatrix[i, i + 1]; } labelExhaustiveResult.Text = Builder.ToString(); labelExhaustivePathLength.Text = Length.ToString(); labelExhaustiveTotalTime.Text = SalesmanTaskSolver.ExhaustiveExecutionTime.ToString(); } }
private void buttonStartGenetic_Click(object sender, EventArgs e) { byte StartTown = (byte)(numericUpDownStartTown.Value); SalesmanTaskSolver.StartTown = (int)numericUpDownStartTown.Value; SalesmanGenom Genom = SalesmanTaskSolver.SolveViaGeneticAlgorithm(); StringBuilder Builder = new StringBuilder(StartTown.ToString(), 11); for (int i = 0; i < Genom.GenesCount; ++i) { Builder.Append('-'); Builder.Append(Genom[i].ToString()); } Builder.Append("-" + StartTown.ToString()); labelGeneticResult.Text = Builder.ToString(); int Length = 0; for (int i = 0; i < Genom.GenesCount - 1; ++i) { Length += AdjacencyMatrix[i, i + 1]; } labelGeneticPathLength.Text = Length.ToString(); labelGeneticTotalTime.Text = SalesmanTaskSolver.GeneticExecutionTime.ToString(); }