private void button1_Click(object sender, EventArgs e) { richTextBox1.Text = richTextBox1.Text + "\r\n邻接矩阵为:" + "\r\n"; MatrixOperation mo = new MatrixOperation(); mo.Output(MyMatrix.ljMatrix, richTextBox1); }
private void button2_Click(object sender, EventArgs e) { richTextBox1.Text = richTextBox1.Text + "可达矩阵经计算为:" + "\r\n"; MatrixOperation mo = new MatrixOperation(); int[,] dwMatrix = mo.UnitMatrix(MyMatrix.ljMatrix.GetLength(0)); //声明一个与全局邻接矩阵相同维度的单位矩阵 int[,] middleMatrix = mo.MatrixAdd(MyMatrix.ljMatrix, dwMatrix); //(A+I) //richTextBox1.Text = richTextBox1.Text + "\r\n" + "(A+I)矩阵为:" + "\r\n"; //mo.Output(middleMatrix, richTextBox1); int[,] middleMatrix2 = middleMatrix; //中间变量 int judge = 1; //记录循环次数 bool b = true; while (b) { int p = 0; //用于判断与中间矩阵是否相等,不相等为1,相等为0 for (int i = 0; i < middleMatrix2.GetLength(0); i++) //对中间变量与处理后的变化进行遍历,看是否相等,若不相等,那么p=1,全部相等则p=0; { for (int j = 0; j < middleMatrix2.GetLength(1); j++) { if (middleMatrix2[i, j] != mo.ChangehMatrix(mo.MatrixMultiply(middleMatrix2, middleMatrix))[i, j]) { p = 1; } } } if (p == 0) //例:若p=0说明A+I=(A+I)的平方 { MyMatrix.kdMatrix = middleMatrix2; mo.Output(middleMatrix2, richTextBox1); b = false; } else { middleMatrix2 = mo.MatrixMultiply(middleMatrix2, middleMatrix); middleMatrix2 = mo.ChangehMatrix(middleMatrix2); judge = judge + 1; //richTextBox1.Text = richTextBox1.Text + "\r\n" + "(A+I)的:" + judge + "次方为:" + "\r\n"; //mo.Output(middleMatrix2, richTextBox1); } if (judge == 30) { MessageBox.Show("邻接矩阵不标准,请重新核对!"); return; } } }