Example #1
0
 private void buttonGraphGeneration_Click(object sender, EventArgs e)
 {
     Control.MinLength   = Convert.ToInt32(numericFrom.Value);
     Control.MaxLength   = Convert.ToInt32(numericTo.Value);
     Control.VertexCount = Convert.ToInt32(numericVertices.Value);
     GraphGrid.Generate();
 }
Example #2
0
        private void buttonToCount_Click(object sender, EventArgs e)
        {
            Graph graph = new Graph();

            GraphGrid.FixGraph(dataGridGraph);
            GraphGrid.WriteMatrix(graph, dataGridGraph);
            Control.Progress   = progressBar1;
            textBox1.Text      = Convert.ToString(Control.GetOstovCount(graph));
            progressBar1.Value = 0;
        }
Example #3
0
        private void buttonCreateSkeleton_Click(object sender, EventArgs e)
        {
            Graph graph = new Graph();

            GraphGrid.CreateMatrix(dataGridSkeleton);
            GraphGrid.FixGraph(dataGridGraph);
            GraphGrid.WriteMatrix(graph, dataGridGraph);
            Graph ostov = KruskalAlgorithm.Go(graph, dataGridSkeleton);

            GraphGrid.WriteTable(ostov, dataGridSkeleton);
        }
Example #4
0
 private void buttonCreate_Click(object sender, EventArgs e)
 {
     Control.VertexCount = Convert.ToInt32(numericVertices.Value);
     GraphGrid.CreateMatrix(dataGridGraph);
 }
        public static Graph Go(Graph graph, DataGridView grid)
        {
            visited = new bool[Control.VertexCount];
            ostov   = new Graph();
            GraphGrid.WriteMatrix(ostov, grid);

            int edgeCount = 0;

            for (int i = 0; i < Control.VertexCount; i++)
            {
                for (int j = 0; j < Control.VertexCount; j++)
                {
                    ostov.Matrix[i, j] = 0;
                    if (graph.Matrix[i, j] > 0)
                    {
                        edgeCount++;
                    }
                }
            }

            edgeCount /= 2;
            int row    = 0;
            int column = 0;

            //Algorithm
            while (edges.Count / 2 < edgeCount)
            {
                Edge edge1 = new Edge();
                Edge edge2 = new Edge();
                int  min   = Int32.MaxValue;

                for (int i = 0; i < Control.VertexCount; i++)
                {
                    for (int j = 0; j < Control.VertexCount; j++)
                    {
                        if (graph.Matrix[i, j] > 0)
                        {
                            if (graph.Matrix[i, j] <= min && !CheckEdge(edges, i, j))
                            {
                                min = Convert.ToInt32(graph.Matrix[i, j]);
                                row = i; column = j;
                            }
                        }
                    }
                }
                edge1.i = row;
                edge1.j = column;
                edge2.j = row;
                edge2.i = column;
                edges.Add(edge1);
                edges.Add(edge2);

                ostov.Matrix[row, column] = graph.Matrix[row, column];
                ostov.Matrix[column, row] = graph.Matrix[column, row];

                if (CheckLoop())
                {
                    ostov.Matrix[row, column] = 0;
                    ostov.Matrix[column, row] = 0;
                }
            }

            edges.Clear();
            return(ostov);
        }