Exemplo n.º 1
0
        public void FillPathWidth()
        {
            path.Clear();

            //Шаг 1. Всем вершинам графа присваивается значение не посещенная. Выбирается первая вершина и заносится в очередь.
            bool[]     vertex = new bool[IncidenceList.GetLength(0)];
            List <int> stack  = new List <int>()
            {
                0
            };

            while (stack.Count != 0)
            {
                if (!vertex[stack[0]])
                {
                    //Шаг 2. Посещается первая вершина из очереди (если она не помечена как посещенная).
                    vertex[stack[0]] = true;
                    path.Add(stack[0]);

                    //Все ее соседние вершины заносятся в очередь.
                    for (int i = 0; i < IncidenceList.GetLength(1); i++)
                    {
                        if (IncidenceList[stack[0], i] == -1)
                        {
                            break;
                        }
                        stack.Add(IncidenceList[stack[0], i]);
                    }
                }

                //После этого она удаляется из очереди.
                stack.RemoveAt(0);
            }
            //Шаг 3. Повторяется шаг 2 до тех пор, пока очередь не пуста
        }
Exemplo n.º 2
0
        private void Incidence_Click(object sender, EventArgs e)
        {
            if (loadStructures() != 0)
            {
                return;
            }
            string mat = new IncidenceList(matrix).serialize();

            resultsTextBox.Text = "Incidence List format:" + Environment.NewLine + mat;
        }
Exemplo n.º 3
0
        private void Incidencex_Click(object sender, EventArgs e)
        {
            if (loadStructures() != 0)
            {
                return;
            }
            resultsTextBox.Text  = "Incidence List Matrix Multiplication:" + Environment.NewLine + Environment.NewLine;
            resultsTextBox.Text += "M =" + Environment.NewLine;
            IncidenceList mat = new IncidenceList(matrix);

            resultsTextBox.Text += mat.serialize();
            resultsTextBox.Text += Environment.NewLine + Environment.NewLine;
            resultsTextBox.Text += "V =" + Environment.NewLine;
            resultsTextBox.Text += String.Join(" ", vector.Select(x => x.ToString()).ToArray());
            resultsTextBox.Text += Environment.NewLine + Environment.NewLine;
            resultsTextBox.Text += "M*V =" + Environment.NewLine;
            double[] res = mat.vectorMultiply(vector);
            resultsTextBox.Text += String.Join(" ", res.Select(x => x.ToString()).ToArray());
        }
Exemplo n.º 4
0
        public void ShowIncidenceList()
        {
            for (int i = 0; i < IncidenceList.GetLength(0); i++)
            {
                Console.Write(i + ": ");
                for (int n = 0; n < IncidenceList.GetLength(1); n++)
                {
                    if (IncidenceList[i, n] == -1)
                    {
                        break;
                    }

                    if (n != 0)
                    {
                        Console.Write(" -> ");
                    }

                    Console.Write(IncidenceList[i, n]);
                }
                Console.Write("\n");
            }
        }