public static void ShortestWays(ref int[,] Ways, ref int[,] Data, ref int[][] Points, ref int[] NamesOfPoints, ref int[,] TempGraph, int Size) { bool[] CheckedPoints = new bool[Size - 1]; int PointNumber = 0; for (int k = 0; k < Size - 1; k++) { Ways[0, k] = TempGraph[0, k + 1]; } //Defining Initial Point// CheckedPoints[0] = true; for (int l = 0; l < Size - 1; l++) { if (Ways[0, l] < Ways[0, 0]) { PointNumber = l; CheckedPoints[l] = true; CheckedPoints[0] = false; } } for (int x = 1; x < Size - 1; x++) { for (int y = 0; y < Size - 1; y++) { if (Data[PointNumber, y] + Ways[x - 1, PointNumber] < Ways[x - 1, y] && Data[PointNumber, y] != 0) { Ways[x, y] = Data[PointNumber, y] + Ways[x-1, PointNumber]; Methods1.CheckingPoints(ref Points, Size, y, PointNumber, ref NamesOfPoints); } else { Ways[x, y] = Ways[x - 1, y]; } } PointNumber = x; CheckedPoints[x] = true; for (int z = 0; z < Size - 1; z++) { if (Ways[x, z] < Ways[x, PointNumber] && CheckedPoints[z] == false) { PointNumber = z; CheckedPoints[z] = true; CheckedPoints[x] = false; } } } }
private void button3_Click(object sender, EventArgs e) { int[,] TempGraph1 = new int[Graph_Size, Graph_Size]; int[,] Data = null; int[,] Ways = new int[Graph_Size-1,Graph_Size-1]; int [] NamesofPoints=new int[Graph_Size-1]; int[][] Points = new int[Graph_Size - 1][]; string PrintTextBox1 = ""; string PrintTextBox2 = ""; Methods1.ChoiceOfElement(ref Graph1,ref Graph_Size,out TempGraph1,StartPoint); Methods1.AlteringGraphArray(ref TempGraph1, ref Graph_Size, out Data); Methods1.NamingPoints(ref Points, ref NamesofPoints, Graph_Size, StartPoint); Methods1.ShortestWays(ref Ways,ref Data,ref Points,ref NamesofPoints,ref TempGraph1,Graph_Size); Methods1.PrintResults(ref Ways, ref Points, ref NamesofPoints, Graph_Size, StartPoint, Point,ref PrintTextBox1,ref PrintTextBox2); richTextBox1.Text =PrintTextBox1+"\n"+PrintTextBox2; }
private void toolStripButton4_Click(object sender, EventArgs e) { Graph1 = new int[Graph_Size, Graph_Size]; for (int i = 0; i < Graph_Size; i++) { for (int j = 0; j < Graph_Size; j++) { Graph1[i, j] = Convert.ToInt32(dataGridView1.Rows[i].Cells[j].Value); } } Methods1.CheckingGraph(ref Graph1, ref Graph_Size, ref GraphIsSet); if (GraphIsSet == true) { for (int i = 0; i < Graph_Size; i++) { for (int j = 0; j < Graph_Size; j++) { dataGridView1.Rows[i].Cells[j].ReadOnly = true; } } button1.Enabled = true; button2.Enabled = true; textBox1.Enabled = true; textBox2.Enabled = true; button1.Focus(); button3.Enabled = true; button4.Enabled = true; toolStripButton4.Enabled = false; toolStripButton5.Enabled = true; toolStripButton1.Enabled = false; toolStripButton3.Enabled = true;//saving file } }