private void pictureBox1_Paint(object sender, PaintEventArgs e) { int i, j, k; Graphics gr = e.Graphics; Point pt = new Point(), pt2 = new Point(); if (Matrix_A == null) { return; } cx = pictureBox1.Width / 2; cy = pictureBox1.Height / 2; scrr = Math.Min(cx, cy) - 30; m = (float)(2.0f * Math.PI / TopEl.Count()); for (j = 0; j < TopEl.Count; j++) { calcPt(ref pt, j); for (i = j + 1; i < TopEl.Count; i++) { // Перебираем все дорожки и ищем соединение bool fl = false; for (k = 0; (k < LeftEl.Count) & !fl; k++) { if ((Matrix_A[k, i] == 1) & (Matrix_A[k, j] == 1)) { fl = true; } } if (!fl) { continue; } calcPt(ref pt2, i); gr.DrawLine(Pens.Black, pt, pt2); } } for (j = 0; j < TopEl.Count; j++) { calcPt(ref pt, j); if (pt.X < cx) { pt.X -= 70; } else { pt.X -= 10; } gr.FillRectangle(Brushes.White, pt.X, pt.Y - 8, 80, 18); gr.DrawRectangle(Pens.Black, pt.X, pt.Y - 8, 80, 18); gr.DrawString(TopEl[j], this.Font, Brushes.Black, pt.X + 1, pt.Y - 8 + 1); } }
void calcMatr() { int size = Math.Max(TopEl.Count(), LeftEl.Count()); Matrix_A = new MatrixOp(size, size, "Матрица_A"); Matrix_AT = new MatrixOp(size, size); MultyplyMatrix = new MatrixOp(size, size, "Умножение A * AT"); for (int i = 0; i < LeftEl.Count; i++) { for (int j = 0; j < LeftEl[i].to.Count; j++) { int value = TopEl.IndexOf(LeftEl[i].to[j]); Matrix_A[value, i] = 1; } } Matrix_AT = Matrix_A.Transperate(); //Транспонируем матрицу Matrix_AT.Name = "Матрица_AT"; //Даем имя MultyplyMatrix.Multyply(Matrix_A, Matrix_AT); //Перемножение матриц GetCountCollision(MultyplyMatrix); //Создаем матрицу коллизий т.е. где эл наши встречаются //------------------------------------------------------------------------------ string mystring; textBox2.AppendText($"\n{Matrix_A.Name}\n"); textBox2.AppendText("\t" + string.Join("\t", LeftEl.Select(v => v.name)) + "\n"); for (int i = 0; i < size; i++) { mystring = TopEl[i] + "\t"; for (int j = 0; j < size; j++) { mystring += Matrix_A[i, j] + "\t"; } textBox2.AppendText(mystring + "\n"); } //------------------------------------------------------------------------------ textBox2.AppendText($"\n{Matrix_AT.Name}\n"); textBox2.AppendText("\t" + string.Join("\t", LeftEl.Select(v => v.name)) + "\n"); for (int i = 0; i < size; i++) { mystring = TopEl[i] + "\t"; for (int j = 0; j < size; j++) { mystring += Matrix_AT[i, j] + "\t"; } textBox2.AppendText(mystring + "\n"); } //------------------------------------------------------------------------------ textBox2.AppendText($"\n{MultyplyMatrix.Name}\n"); textBox2.AppendText("\t" + string.Join("\t", LeftEl.Select(v => v.name)) + "\n"); for (int i = 0; i < size; i++) { mystring = TopEl[i] + "\t"; for (int j = 0; j < size; j++) { mystring += MultyplyMatrix[i, j] + "\t"; } textBox2.AppendText(mystring + "\n"); } this.Matrix_A = Matrix_A; }