예제 #1
0
        public int CreateEdge(int[,] a) //создание  матрицы смежности
        {
            int n = 0;

            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < a.GetLength(1); j++)
                {
                    int    dx = nodes[j].x - nodes[i].x;
                    int    dy = nodes[j].y - nodes[i].y;
                    double x  = dx * dx + dy * dy;
                    x = Math.Pow(x, 0.5);
                    int dist = Convert.ToInt32(x);
                    if (a[i, j] != 0)
                    {
                        NodeC.Edge edge = new NodeC.Edge();
                        edge.lehgth    = dist;
                        edge.Neighbour = nodes[j];
                        edge.relation  = a[i, j];
                        edge.ColorEdge();
                        nodes[i].edge.Add(edge);
                    }
                }
            }
            return(n);
        }
예제 #2
0
        public void AddEdge(int n1, int n2)
        {
            if (!TestEdge(n1, n2))
            {
                int    dx = nodes[n2].x - nodes[n1].x;
                int    dy = nodes[n2].y - nodes[n1].y;
                double x  = dx * dx + dy * dy;
                x = Math.Pow(x, 0.5);
                int        dist = Convert.ToInt32(x); // длина ребра -- расстояние между узлами n1 и n2
                int        len  = nodes[n1].edge.Count;
                NodeC.Edge edge = new NodeC.Edge();
                edge.lehgth    = dist;
                edge.Neighbour = nodes[n2];
                edge.color     = Color.PeachPuff;
                nodes[n1].edge.Add(edge);

                len            = nodes[n2].edge.Count;
                edge           = new NodeC.Edge();
                edge.lehgth    = dist;
                edge.Neighbour = nodes[n1];
                edge.color     = Color.PeachPuff;
                nodes[n2].edge.Add(edge);
            }
        }