Exemplo n.º 1
0
        void GetEdge_prime()
        {
            Edge           edge  = null;
            int            min   = 0;
            EdgeCollection edges = graphUI1.Data.GetAllEdgeFromNodes(nodes);
            string         text  = "Các cạnh xét :\r\n";

            foreach (Edge item in edges)
            {
                text            = text + item.ToString() + "\r\n";
                item.IsSelected = true;
                if (min > item.weight || min == 0)
                {
                    min  = item.weight;
                    edge = item;
                }
            }
            if (edge != null)
            {
                text         += "Cạnh được chọn:\r\n";
                text         += edge.ToString() + "\r\n";
                textBox.Text += text;
                graphUI1._list.Add(edge);
                edge.start.IsVisit = true;
                edge.end.IsVisit   = true;
                nodes.Add(edge.start);
                nodes.Add(edge.end);
            }
        }
Exemplo n.º 2
0
        bool KruskalNext()
        {
            graph.edgeCollection.Reset();
            int    lab1 = 0;
            int    lab2 = 0;
            string text = null;

            if (sodem_kruskal >= graph.edgeCollection.Count || graphUI1._list.Count == graph.n - 1)
            {
                graphUI1.Invalidate();
                MessageBox.Show("Thuật toán xong");
                text = "Kết quả là \r\n";
                foreach (var item in graphUI1._list)
                {
                    text += item.ToString() + "\r\n";
                }
                MessageBox.Show(text);
                textBox.Text  += text;
                algorithmTools = AlgorithmTools.None;
                return(true);
            }
            Edge edge = rd_euler.Items[sodem_kruskal] as Edge;

            text            = "Kiếm tra cạnh " + edge.ToString() + "\r\n";
            edge.IsSelected = true;
            if (label[edge.start.Index] != label[edge.end.Index])
            {
                text += "Lấy vì không tạo thành chu trình với các cạnh còn lại\r\n";
                graphUI1._list.Add(edge);
                if (label[edge.start.Index] > label[edge.end.Index])
                {
                    lab1 = label[edge.end.Index];
                    lab2 = label[edge.start.Index];
                }
                else
                {
                    lab2 = label[edge.end.Index];
                    lab1 = label[edge.start.Index];
                }
                for (int i = 0; i < graph.nodeCollection.Count; i++)
                {
                    if (label[i] == lab2)
                    {
                        label[i] = lab1;
                    }
                }
            }
            else
            {
                text += "Không lấy vì tạo thành chu trình với các cạnh còn lại\r\n";
            }
            textBox.Text += text;
            sodem_kruskal++;
            return(false);
        }