Exemplo n.º 1
0
        private void Processbutton5_Click(object sender, EventArgs e)
        {
            TextBoxOut.Clear();

            Graph G = setGraph();

            if (G == null)
            {
                return;
            }

            if (StartVertex.Text == "")
            {
                TextBoxOut.Text = "Введите начальную вершину!"; return;
            }
            int start = System.Convert.ToInt32(StartVertex.Text);

            if (start > G.getVertexList().Count - 1 || start < 0)
            {
                TextBoxOut.Text = "Неправильная стартовая точка! Нумерация вершин от нуля."; return;
            }

            List <int> dist = G.BFShortWay(start);

            for (int i = 0; i < dist.Count; i++)
            {
                if (i != start && dist[i] != int.MaxValue)
                {
                    TextBoxOut.Text += System.Convert.ToString(start) + "->" + System.Convert.ToString(i) + "=" + System.Convert.ToString(dist[i]) + "\n";
                }
            }
        }
Exemplo n.º 2
0
        private void Processbutton2_Click(object sender, EventArgs e)
        {
            TextBoxOut.Clear();

            Graph G = setGraph();

            if (G == null)
            {
                return;
            }

            List <Vertex> res = G.maximum_independent_set_of_vertexes();

            if (res.Count == 0)
            {
                TextBoxOut.Text = "Независимое множество вершин отсутствует";
                return;
            }

            TextBoxOut.Text = "Все вершины: ";
            foreach (Vertex item in G.getVertexList())
            {
                TextBoxOut.Text += System.Convert.ToString(item.getVertexId()) + " ";
            }
            TextBoxOut.Text += "\nНезависимое множество вершин: ";

            foreach (Vertex item in res)
            {
                TextBoxOut.Text += System.Convert.ToString(item.getVertexId()) + " ";
            }
        }
Exemplo n.º 3
0
        private void Processbutton_Click(object sender, EventArgs e)
        {
            TextBoxOut.Clear();

            if (TextBoxParamN.Text.Length == 0)
            {
                TextBoxOut.AppendText("Параметр N не задан!");
                return;
            }

            Graph G = setGraph();

            if (G == null)
            {
                return;
            }

            int N = System.Convert.ToInt32(TextBoxParamN.Text);

            // Поиск количества путей
            int res = G.countWays(N);

            // Вывод результата
            TextBoxOut.AppendText(System.Convert.ToString(res));
        }
Exemplo n.º 4
0
        private void Processbutton4_Click(object sender, EventArgs e)
        {
            TextBoxOut.Clear();

            Graph G = setGraph();

            if (G == null)
            {
                return;
            }

            if (G.isTree())
            {
                TextBoxOut.Text = "Дерево: да";
            }
            else
            {
                TextBoxOut.Text = "Дерево: нет";
            }
        }
Exemplo n.º 5
0
        private void Processbutton3_Click(object sender, EventArgs e)
        {
            TextBoxOut.Clear();

            Graph G = setGraph();

            if (G == null)
            {
                return;
            }

            if (G.topology_sort() == 1)
            {
                TextBoxOut.Text = "Граф не может быть отсортирован!"; return;
            }

            TextBoxOut.Text += "Отсортированный граф: ";
            foreach (var Vertex in G.getVertexList())
            {
                TextBoxOut.Text += System.Convert.ToString(Vertex.getVertexId()) + " ";
            }
        }
Exemplo n.º 6
0
        private Graph setGraph()
        {
            // Проверки
            if (TextBoxIn.Text.Length == 0)
            {
                TextBoxOut.AppendText("Введите матрицу!");
                return(null);
            }
            // Инициализация
            string reference = TextBoxIn.Text.Trim();

            string[] str  = reference.Split('\n');
            int      size = str.Length;

            int[,] matr = new int[size, size];

            for (int i = 0; i < size; i++)
            {
                string[] stl = str[i].Split(' ');

                if (stl.Length != size)
                {
                    TextBoxOut.AppendText("Неверный формат матрицы!");
                    return(null);
                }

                for (int j = 0; j < size; j++)
                {
                    matr[i, j] = System.Convert.ToInt32(stl[j]);
                }
            }

            Graph G = new Graph();

            G.setupGraph(matr);

            return(G);
        }
Exemplo n.º 7
0
 private void Clearbutton_Click(object sender, EventArgs e)
 {
     TextBoxIn.Clear();
     TextBoxOut.Clear();
 }