Exemplo n.º 1
0
 // Linked list maintenance (Group A) is implemented here
 /// <summary>
 /// Copies and initialises all the vertices into the Union-Find structural list.
 /// </summary>
 private void InitialiseUnionFind()
 {
     for (int vertex = 0; vertex < mapMatrix.GetSize(); vertex++)
     {
         if (mapMatrix.IsVertexExisting(vertex))
         {
             unionFindVertices.Add(new UnionFind());
             unionFindVertices[unionFindVertices.Count() - 1].SetVertex(vertex);
             unionFindVertices[unionFindVertices.Count() - 1].SetLeader(vertex);
             unionFindVertices[unionFindVertices.Count() - 1].SetPrev(-1);
             unionFindVertices[unionFindVertices.Count() - 1].SetHead(vertex);
             unionFindVertices[unionFindVertices.Count() - 1].SetTail(vertex);
             unionFindVertices[unionFindVertices.Count() - 1].SetCount(1);
         }
     }
 }
 public ShortestPathExample(Panel panel)
 {
     this.panel = panel;
     // Initialise edge weight labels
     for (int v1 = 0; v1 < mapMatrix.GetSize(); v1++)
     {
         for (int v2 = 0; v2 < mapMatrix.GetSize(); v2++)
         {
             this.labelWeights[v1, v2] = new Label
             {
                 AutoSize = true,
                 Enabled  = false,
                 Location = new System.Drawing.Point(0, 0),
                 Name     = "label" + Convert.ToChar(v1 + 'A').ToString() + Convert.ToChar(v2 + 'A').ToString(),
                 Text     = "",
                 Visible  = false
             };
             this.panel.Controls.Add(this.labelWeights[v1, v2]);
         }
     }
 }
        public FormSketchBoard(int accountID, string username, string accountName, string accountType)
        {
            InitializeComponent();

            // Show account name on the account menu.
            this.accountMenu.accountID             = accountID;
            this.accountMenu.username              = username;
            this.accountMenu.labelAccountName.Text = accountName;
            this.accountMenu.accountType           = accountType;

            // Initialise array tools: assign Button values.
            tools[0] = this.buttonVertex;
            tools[1] = this.buttonEdge;
            tools[2] = this.buttonTag;

            // Initialise screen capture range.
            topLeft     = new Point(this.panelSketchBoard.Width, this.panelSketchBoard.Height);
            bottomRight = new Point(0, 0);

            // Initialise edge weight labels.
            for (int v1 = 0; v1 < mapMatrix.GetSize(); v1++)
            {
                for (int v2 = 0; v2 < mapMatrix.GetSize(); v2++)
                {
                    this.labelWeights[v1, v2] = new Label
                    {
                        AutoSize = true,
                        Enabled  = false,
                        Location = new System.Drawing.Point(0, 0),
                        Name     = "label" + Convert.ToChar(v1 + 'A').ToString() + Convert.ToChar(v2 + 'A').ToString(),
                        Text     = "",
                        Visible  = false
                    };
                    this.panelSketchBoard.Controls.Add(this.labelWeights[v1, v2]);
                }
            }
        }
Exemplo n.º 4
0
        // Graph/Tree Traversal (Group A) is implemented here.
        private void ButtonNext_Click(object sender, EventArgs e)
        {
            if (buttonNext.Text == "Close")
            {
                this.Close();
            }
            else
            {
                labelInformation.Visible = true;

                // Step 1 operation
                if (currentStep == 1)
                {
                    // Highlight current step
                    label1.ForeColor     = Color.Red;
                    labelStep1.ForeColor = Color.Red;
                    label2.ForeColor     = SystemColors.ControlText;
                    labelStep2.ForeColor = SystemColors.ControlText;
                    label3.ForeColor     = SystemColors.ControlText;
                    labelStep3.ForeColor = SystemColors.ControlText;
                    label4.ForeColor     = SystemColors.ControlText;
                    labelStep4.ForeColor = SystemColors.ControlText;

                    // Show instruction and indicate graph operation
                    labelInformation.Text = "Please pick a vertex to start Dijkstra's algorithm.\nPlease click on the vertex name in each box.";
                    currentStep           = 1;
                    buttonNext.Enabled    = false;
                }

                // Step 2 operation
                else if (currentStep == 2)
                {
                    // Highlight current step
                    label1.ForeColor     = SystemColors.ControlText;
                    labelStep1.ForeColor = SystemColors.ControlText;
                    label2.ForeColor     = Color.Red;
                    labelStep2.ForeColor = Color.Red;
                    label3.ForeColor     = SystemColors.ControlText;
                    labelStep3.ForeColor = SystemColors.ControlText;
                    label4.ForeColor     = SystemColors.ControlText;
                    labelStep4.ForeColor = SystemColors.ControlText;

                    // Initialise example graph
                    for (int v1 = 0; v1 < mapMatrix.GetSize(); v1++)
                    {
                        for (int v2 = 0; v2 < mapMatrix.GetSize(); v2++)
                        {
                            if (mapMatrix.ContainsEdge(v1, v2))
                            {
                                DirectedEdgeFocusOff(v1, v2);
                                exampleGraph.LabelFocusOff(v1, v2);
                            }
                        }
                    }
                    foreach (DijkstraVertexLabel vertex in vertices)
                    {
                        vertex.FocusOff();
                    }

                    // Highlight current vertex
                    currentVertex = permanentVertices[permanentVertices.Count - 1];
                    foreach (DijkstraVertexLabel vertex in vertices)
                    {
                        if (vertex.GetNumberIndex() == currentVertex ||
                            (temporaryVertices.Contains(vertex.GetNumberIndex()) && mapMatrix.ContainsEdge(currentVertex, vertex.GetNumberIndex())))
                        {
                            vertex.FocusOn();
                        }
                    }

                    // Relax other edges from current vertex
                    relaxedVertices.Clear();
                    foreach (int vertex in temporaryVertices)
                    {
                        RelaxEdge(currentVertex, vertex);
                        if (mapMatrix.ContainsEdge(currentVertex, vertex))
                        {
                            if (mapMatrix.ContainsEdge(vertex, currentVertex) && mapMatrix.GetEdge(currentVertex, vertex) == mapMatrix.GetEdge(vertex, currentVertex))
                            {
                                UndirectedEdgeFocusOn(currentVertex, vertex);
                                exampleGraph.LabelFocusOn(currentVertex, vertex);
                                exampleGraph.LabelFocusOn(vertex, currentVertex);
                            }
                            else
                            {
                                DirectedEdgeFocusOn(currentVertex, vertex);
                                exampleGraph.LabelFocusOn(currentVertex, vertex);
                            }
                        }
                    }

                    // Show explanation
                    if (relaxedVertices.Count == 0)
                    {
                        labelInformation.Text = "No vertex has been given a new temporary label.";
                    }
                    else if (relaxedVertices.Count == 1)
                    {
                        labelInformation.Text = "Vertex " + relaxedVertices[0] + " has been given a new temporary label.";
                    }
                    else
                    {
                        labelInformation.Text = "Vertices ";
                        foreach (string vertexName in relaxedVertices)
                        {
                            labelInformation.Text += vertexName + ", ";
                        }
                        labelInformation.Text  = labelInformation.Text.TrimEnd(", ".ToCharArray());
                        labelInformation.Text += " have been given a new temporary label.";
                    }
                    currentStep = 3;
                }

                // Step 3 operation
                else if (currentStep == 3)
                {
                    // Highlight current step
                    label1.ForeColor     = SystemColors.ControlText;
                    labelStep1.ForeColor = SystemColors.ControlText;
                    label2.ForeColor     = SystemColors.ControlText;
                    labelStep2.ForeColor = SystemColors.ControlText;
                    label3.ForeColor     = Color.Red;
                    labelStep3.ForeColor = Color.Red;
                    label4.ForeColor     = SystemColors.ControlText;
                    labelStep4.ForeColor = SystemColors.ControlText;

                    // Initialise example graph
                    for (int v1 = 0; v1 < mapMatrix.GetSize(); v1++)
                    {
                        for (int v2 = 0; v2 < mapMatrix.GetSize(); v2++)
                        {
                            if (mapMatrix.ContainsEdge(v1, v2))
                            {
                                DirectedEdgeFocusOff(v1, v2);
                                exampleGraph.LabelFocusOff(v1, v2);
                            }
                        }
                    }
                    foreach (DijkstraVertexLabel vertex in vertices)
                    {
                        vertex.FocusOff();
                    }

                    // Find candidate vertices
                    min = Double.MaxValue;
                    foreach (int i in temporaryVertices)
                    {
                        if (dijkstraMap[i].distance < min)
                        {
                            min = dijkstraMap[i].distance;
                        }
                    }
                    candidateVertices.Clear();
                    foreach (int i in temporaryVertices)
                    {
                        if (dijkstraMap[i].distance == min)
                        {
                            candidateVertices.Add(i);
                        }
                    }

                    // Show explanations and indicate graph operations if necessary
                    foreach (DijkstraVertexLabel vertex in vertices)
                    {
                        if (candidateVertices.Contains(vertex.GetNumberIndex()))
                        {
                            vertex.FocusOn();
                        }
                    }
                    if (candidateVertices.Count >= 2) // There is more than one candidate vertices so graph operations is required
                    {
                        labelInformation.Text = "Vertices ";
                        foreach (int vertex in candidateVertices)
                        {
                            labelInformation.Text += Convert.ToChar(vertex + 'A').ToString() + ", ";
                        }
                        labelInformation.Text  = labelInformation.Text.TrimEnd(", ".ToCharArray());
                        labelInformation.Text += " now all have the same smallest best temporary label (" + min.ToString() + "). Please choose any one of them.\n"
                                                 + "Please click on the vertex name in each box.";
                        currentStep        = 3;
                        buttonNext.Enabled = false;
                    }
                    else // There is only one candidate vertex so no graph operation is needed
                    {
                        temporaryVertices.Remove(candidateVertices[0]);
                        permanentVertices.Add(candidateVertices[0]);
                        labelInformation.Text = "Vertex " + Convert.ToChar(candidateVertices[0] + 'A').ToString()
                                                + " now has the smallest best temporary label (" + min.ToString() + ").\n"
                                                + "Therefore it has been made permanent with order " + permanentVertices.Count.ToString() + ".";
                        foreach (DijkstraVertexLabel vertex in vertices)
                        {
                            if (vertex.GetNumberIndex() == candidateVertices[0])
                            {
                                vertex.Finalise(min, permanentVertices.Count);
                                break;
                            }
                        }
                        currentStep = 4;
                    }
                }

                // Step 4 operation
                else // if (currentStep == 4)
                {
                    // Highlight current step
                    label1.ForeColor     = SystemColors.ControlText;
                    labelStep1.ForeColor = SystemColors.ControlText;
                    label2.ForeColor     = SystemColors.ControlText;
                    labelStep2.ForeColor = SystemColors.ControlText;
                    label3.ForeColor     = SystemColors.ControlText;
                    labelStep3.ForeColor = SystemColors.ControlText;
                    label4.ForeColor     = Color.Red;
                    labelStep4.ForeColor = Color.Red;

                    // Initialise example graph
                    for (int v1 = 0; v1 < mapMatrix.GetSize(); v1++)
                    {
                        for (int v2 = 0; v2 < mapMatrix.GetSize(); v2++)
                        {
                            if (mapMatrix.ContainsEdge(v1, v2))
                            {
                                DirectedEdgeFocusOff(v1, v2);
                                exampleGraph.LabelFocusOff(v1, v2);
                            }
                        }
                    }
                    foreach (DijkstraVertexLabel vertex in vertices)
                    {
                        vertex.FocusOff();
                    }

                    // Check if the algorithm is finished and show explanations
                    if (temporaryVertices.Any())
                    {
                        foreach (DijkstraVertexLabel vertex in vertices)
                        {
                            if (vertex.GetNumberIndex() == permanentVertices[permanentVertices.Count - 1])
                            {
                                vertex.FocusOn();
                                break;
                            }
                        }
                        labelInformation.Text = "We still have at least one temporary vertex, so we should return to STEP 2.";
                        currentStep           = 2;
                    }
                    else
                    {
                        labelInformation.Text = "Now that every vertex is permanent, "
                                                + "we have found the shortest distance from the starting vertex ("
                                                + Convert.ToChar(permanentVertices[0] + 'A').ToString()
                                                + ") to all the other vertices.\n"
                                                + "Please click on a vertex to see the shortest route.\n"
                                                + "Please click on the vertex name in each box.";
                        currentStep     = 4;
                        buttonNext.Text = "Close";
                    }
                }
            }
        }
Exemplo n.º 5
0
        // Graph/Tree Traversal (Group A) is implemented here.
        private void ButtonNext_Click(object sender, EventArgs e)
        {
            if (buttonNext.Text == "Close")
            {
                this.Close();
            }
            else
            {
                labelInformation.Visible = true;

                // Step 1 operation
                if (currentStep == 1)
                {
                    // Highlight current step
                    label1.ForeColor     = Color.Red;
                    labelStep1.ForeColor = Color.Red;
                    label2.ForeColor     = SystemColors.ControlText;
                    labelStep2.ForeColor = SystemColors.ControlText;
                    label3.ForeColor     = SystemColors.ControlText;
                    labelStep3.ForeColor = SystemColors.ControlText;

                    // Initialise Prim's algorithm
                    for (int i = 0; i < mapMatrix.GetSize(); i++)
                    {
                        if (mapMatrix.IsVertexExisting(i))
                        {
                            remainingVertices.Add(i);
                        }
                    }
                    labelInformation.Text = "Please pick a vertex of your choice:\nPlease click on the vertex of the graph.";
                    buttonNext.Enabled    = false;
                }

                // Step 2 operation
                else if (currentStep == 2)
                {
                    // Highlight current step
                    label1.ForeColor     = SystemColors.ControlText;
                    labelStep1.ForeColor = SystemColors.ControlText;
                    label2.ForeColor     = Color.Red;
                    labelStep2.ForeColor = Color.Red;
                    label3.ForeColor     = SystemColors.ControlText;
                    labelStep3.ForeColor = SystemColors.ControlText;

                    // Find minimum value of edge weight and candidate edges
                    double       min            = Double.MaxValue;
                    List <int[]> candidateEdges = new List <int[]>();

                    foreach (int i in visitedVertices)
                    {
                        foreach (int j in remainingVertices)
                        {
                            if (mapMatrix.ContainsEdge(i, j) && mapMatrix.GetEdge(i, j) < min) // Find minimum value of edge weight
                            {
                                min = mapMatrix.GetEdge(i, j);
                            }
                        }
                    }

                    foreach (int i in visitedVertices)
                    {
                        foreach (int j in remainingVertices)
                        {
                            if (mapMatrix.ContainsEdge(i, j) && mapMatrix.GetEdge(i, j) == min) // Find candidate edges
                            {
                                candidateEdges.Add(new int[2] {
                                    i, j
                                });
                            }
                        }
                    }

                    // More than two candidate edges - User operation required
                    if (candidateEdges.Count >= 2)
                    {
                        // Show explanation
                        labelInformation.Text = "Edges ";
                        foreach (int[] edge in candidateEdges)
                        {
                            labelInformation.Text += Convert.ToChar(edge[0] + 'A').ToString() + Convert.ToChar(edge[1] + 'A').ToString() + ", ";
                        }
                        labelInformation.Text  = labelInformation.Text.TrimEnd(", ".ToCharArray());
                        labelInformation.Text += " have the same weight (" + min.ToString() + "). Please pick one of your choice:\n"
                                                 + "Please click on the vertex or the weight.";

                        // Highlight candidate edges
                        for (int i = 0; i < candidateEdges.Count; i++)
                        {
                            int    v1        = Math.Min(candidateEdges[i][0], candidateEdges[i][1]);
                            int    v2        = Math.Max(candidateEdges[i][0], candidateEdges[i][1]);
                            string labelName = "label" + Convert.ToChar(v1 + 'A').ToString() + Convert.ToChar(v2 + 'A').ToString();
                            foreach (Label label in exampleGraph.labelWeights)
                            {
                                if (label.Name == labelName)
                                {
                                    label.ForeColor = Color.Red;
                                    break;
                                }
                            }
                            foreach (Vertex vertex in vertices)
                            {
                                if (vertex.GetNumberIndex() == candidateEdges[i][1])
                                {
                                    vertex.labelName.ForeColor = Color.Red;
                                    break;
                                }
                            }
                        }

                        currentStep        = 2;
                        buttonNext.Enabled = false;
                    }

                    // Only one candidate edge avaliable - No user operation needed
                    else
                    {
                        // Show explanation
                        int[] newEdge = new int[2] {
                            candidateEdges[0][0], candidateEdges[0][1]
                        };
                        labelInformation.Text = "Edge " + Convert.ToChar(candidateEdges[0][0] + 'A').ToString() + Convert.ToChar(candidateEdges[0][1] + 'A').ToString()
                                                + " has the minimum weight joining a vertex already included to a vertex not already included (" + min.ToString() + "),"
                                                + " therefore it has been added to the Minimum Spanning Tree.";

                        // Update Prim's algorithm
                        foreach (Vertex vertex in vertices)
                        {
                            if (vertex.GetNumberIndex() == newEdge[1])
                            {
                                weightMST             += min;
                                labelTotalWeight.Text += min.ToString() + " + ";
                                visitedVertices.Add(newEdge[1]);
                                remainingVertices.Remove(newEdge[1]);
                                EdgeFocusOn(newEdge[0], newEdge[1]);
                                exampleGraph.LabelFocusOn(newEdge[0], newEdge[1]);
                                currentStep = 3;
                                break;
                            }
                        }
                    }
                }

                // Step 3 operation
                else // if (currentStep == 3)
                {
                    // Highlight current steps
                    label1.ForeColor     = SystemColors.ControlText;
                    labelStep1.ForeColor = SystemColors.ControlText;
                    label2.ForeColor     = SystemColors.ControlText;
                    labelStep2.ForeColor = SystemColors.ControlText;
                    label3.ForeColor     = Color.Red;
                    labelStep3.ForeColor = Color.Red;

                    // Check if Prim's algorithm has finished
                    if (remainingVertices.Any())
                    {
                        labelInformation.Text = "We have not yet formed a Minimum Spanning Tree, so go back to STEP 2.";
                        currentStep           = 2;
                    }
                    else
                    {
                        labelInformation.Text    = "Now we have picked " + (mapMatrix.Count() - 1).ToString() + " edges and has formed a Minimum Spanning Tree.\nTherefore Prim's algorithm has finished.";
                        labelTotalWeight.Text    = labelTotalWeight.Text.TrimEnd(" + ".ToCharArray());
                        labelTotalWeight.Text   += " = " + weightMST.ToString();
                        labelTotalWeight.Visible = true;
                        buttonNext.Text          = "Close";
                    }
                }
            }
        }
Exemplo n.º 6
0
        public FormPrimOnMatrix(int accountID, string username, string accountName, string accountType, int example)
        {
            InitializeComponent();

            // Show account name on the account menu.
            this.accountMenu.accountID             = accountID;
            this.accountMenu.username              = username;
            this.accountMenu.labelAccountName.Text = accountName;
            this.accountMenu.accountType           = accountType;
            this.example = example;

            // Select the correct example graph to perform the demonstration.
            if (example == 1)
            {
                exampleGraph = new MinimumSpanningTreeExample1(this.panelGraph);
            }
            else
            {
                exampleGraph = new MinimumSpanningTreeExample2(this.panelGraph);
            }

            // Initialise the example graph.
            vertices  = exampleGraph.GetVertices();
            mapMatrix = exampleGraph.GetMatrix();

            // Initialise the table for the example graph.
            for (int i = 0; i <= mapMatrix.Count(); i++)
            {
                DataGridViewColumn newColumn = new DataGridViewColumn
                {
                    CellTemplate = new DataGridViewTextBoxCell(),
                    SortMode     = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable,
                    Width        = 60
                };
                if (i == 0)
                {
                    newColumn.Width = 41;
                }
                dataGridViewGraph.Columns.Add(newColumn);
            }

            int count = 1;

            for (int i = 0; i < mapMatrix.GetSize(); i++)
            {
                if (mapMatrix.IsVertexExisting(i))
                {
                    dataGridViewGraph.Columns[count].HeaderText = Convert.ToChar('A' + i).ToString();
                    dataGridViewGraph.Columns[count].Name       = "Column" + dataGridViewGraph.Columns[count].HeaderText;
                    count++;
                }
            }

            count = 0;
            this.dataGridViewGraph.RowCount = mapMatrix.Count();
            for (int i = 0; i < mapMatrix.GetSize(); i++)
            {
                if (mapMatrix.IsVertexExisting(i))
                {
                    this.dataGridViewGraph[0, count++].Value = (Convert.ToChar('A' + i)).ToString();
                }
            }

            for (int col = 1; col <= mapMatrix.Count(); col++)
            {
                for (int row = 0; row < mapMatrix.Count(); row++)
                {
                    int vStartIndex  = mapMatrix.GetVertexIndex(dataGridViewGraph.Columns[col].HeaderText);
                    int vFinishIndex = mapMatrix.GetVertexIndex(this.dataGridViewGraph[0, row].Value.ToString());
                    if (mapMatrix.ContainsEdge(vStartIndex, vFinishIndex))
                    {
                        this.dataGridViewGraph[col, row].Value = mapMatrix.GetEdge(vStartIndex, vFinishIndex);
                    }
                    else
                    {
                        this.dataGridViewGraph[col, row].Value = "-";
                    }
                }
            }
        }
Exemplo n.º 7
0
        // Graph/Tree Traversal (Group A) is implemented here.
        private void ButtonNext_Click(object sender, EventArgs e)
        {
            if (buttonNext.Text == "Close")
            {
                this.Close();
            }
            else
            {
                labelInformation.Visible = true;
                double min;

                // Step 1 operation
                if (currentStep == 1)
                {
                    // Highlight current step
                    label1.ForeColor     = Color.Red;
                    labelStep1.ForeColor = Color.Red;
                    label2.ForeColor     = SystemColors.ControlText;
                    labelStep2.ForeColor = SystemColors.ControlText;
                    label3.ForeColor     = SystemColors.ControlText;
                    labelStep3.ForeColor = SystemColors.ControlText;
                    label4.ForeColor     = SystemColors.ControlText;
                    labelStep4.ForeColor = SystemColors.ControlText;
                    label5.ForeColor     = SystemColors.ControlText;
                    labelStep5.ForeColor = SystemColors.ControlText;

                    // Initialise Prim's algorithm
                    for (int i = 0; i < mapMatrix.GetSize(); i++)
                    {
                        if (mapMatrix.IsVertexExisting(i))
                        {
                            remainingVertices.Add(i);
                        }
                    }
                    labelInformation.Text = "Please pick a vertex of your choice:\nPlease click on the headers of the tableau.";
                    buttonNext.Enabled    = false;
                }

                // Step 2 operation
                else if (currentStep == 2)
                {
                    // Highlight current step
                    label1.ForeColor     = SystemColors.ControlText;
                    labelStep1.ForeColor = SystemColors.ControlText;
                    label2.ForeColor     = Color.Red;
                    labelStep2.ForeColor = Color.Red;
                    label3.ForeColor     = SystemColors.ControlText;
                    labelStep3.ForeColor = SystemColors.ControlText;
                    label4.ForeColor     = SystemColors.ControlText;
                    labelStep4.ForeColor = SystemColors.ControlText;
                    label5.ForeColor     = SystemColors.ControlText;
                    labelStep5.ForeColor = SystemColors.ControlText;

                    // Find minimum value of edge weight and candidate edges
                    min = double.MaxValue;
                    candidateEdges.Clear();

                    foreach (int i in visitedVertices)
                    {
                        foreach (int j in remainingVertices)
                        {
                            if (mapMatrix.ContainsEdge(i, j) && mapMatrix.GetEdge(i, j) < min) // Find minimum value of edge weight
                            {
                                min = mapMatrix.GetEdge(i, j);
                            }
                        }
                    }

                    foreach (int i in visitedVertices)
                    {
                        foreach (int j in remainingVertices)
                        {
                            if (mapMatrix.ContainsEdge(i, j) && mapMatrix.GetEdge(i, j) == min) // Find candidate edges
                            {
                                candidateEdges.Add(new int[2] {
                                    i, j
                                });
                            }
                        }
                    }

                    // Show candidate edges on the table
                    for (int i = 0; i < candidateEdges.Count; i++)
                    {
                        char v1 = Convert.ToChar(candidateEdges[i][0] + 'A');
                        char v2 = Convert.ToChar(candidateEdges[i][1] + 'A');
                        for (int col = 1; col < dataGridViewGraph.ColumnCount; col++)
                        {
                            if (dataGridViewGraph.Columns[col].HeaderText[0] == v1)
                            {
                                for (int row = 0; row < dataGridViewGraph.RowCount; row++)
                                {
                                    if (dataGridViewGraph[0, row].Value.ToString() == v2.ToString())
                                    {
                                        dataGridViewGraph[col, row].Style.ForeColor          = Color.Red;
                                        dataGridViewGraph[col, row].Style.SelectionForeColor = Color.Red;
                                    }
                                }
                            }
                        }
                    }

                    // More than two candidate edges - User operation required
                    if (candidateEdges.Count >= 2)
                    {
                        labelInformation.Text = "Edges ";
                        foreach (int[] edge in candidateEdges)
                        {
                            labelInformation.Text += Convert.ToChar(edge[0] + 'A').ToString() + Convert.ToChar(edge[1] + 'A').ToString() + ", ";
                        }
                        labelInformation.Text  = labelInformation.Text.TrimEnd(", ".ToCharArray());
                        labelInformation.Text += " have the same weight (" + min.ToString() + "). Please pick one of your choice:\n"
                                                 + "Please click on the weights in the tableau.";
                        currentStep        = 2;
                        buttonNext.Enabled = false;
                    }

                    // Only one candidate edge avaliable - No user operation needed
                    else if (candidateEdges.Count == 1)
                    {
                        newEdge = new int[2] {
                            candidateEdges[0][0], candidateEdges[0][1]
                        };
                        labelInformation.Text = "Edge " + Convert.ToChar(candidateEdges[0][0] + 'A').ToString() + Convert.ToChar(candidateEdges[0][1] + 'A').ToString()
                                                + " has the minimum weight from the uncircled entries in the marked column(s) (" + min.ToString() + "),"
                                                + " therefore it has been chosen.";
                        currentStep = 3;
                    }

                    // No candidate edge found - Algorithm about to finish
                    else
                    {
                        labelInformation.Text = "";
                        currentStep           = 3;
                    }
                }

                // Step 3 operation
                else if (currentStep == 3)
                {
                    // Highlight current step
                    label1.ForeColor     = SystemColors.ControlText;
                    labelStep1.ForeColor = SystemColors.ControlText;
                    label2.ForeColor     = SystemColors.ControlText;
                    labelStep2.ForeColor = SystemColors.ControlText;
                    label3.ForeColor     = Color.Red;
                    labelStep3.ForeColor = Color.Red;
                    label4.ForeColor     = SystemColors.ControlText;
                    labelStep4.ForeColor = SystemColors.ControlText;
                    label5.ForeColor     = SystemColors.ControlText;
                    labelStep5.ForeColor = SystemColors.ControlText;

                    // Check if Prim's algorithm has finished
                    if (candidateEdges.Count == 0)
                    {
                        labelInformation.Text = "There is no available entry to be chosen, and therefore Prim's algorithm has finished.\n"
                                                + "We have found a Minimum Spanning Tree.";
                        labelTotalWeight.Text    = labelTotalWeight.Text.TrimEnd(" + ".ToCharArray());
                        labelTotalWeight.Text   += " = " + weightMST.ToString();
                        labelTotalWeight.Visible = true;
                        buttonNext.Text          = "Close";
                    }
                    else
                    {
                        labelInformation.Text += "\nNow that we have found an entry, we should go to STEP 4.";
                        currentStep            = 4;
                    }
                }

                // Step 4 operation
                else if (currentStep == 4)
                {
                    // Highlight current step
                    label1.ForeColor     = SystemColors.ControlText;
                    labelStep1.ForeColor = SystemColors.ControlText;
                    label2.ForeColor     = SystemColors.ControlText;
                    labelStep2.ForeColor = SystemColors.ControlText;
                    label3.ForeColor     = SystemColors.ControlText;
                    labelStep3.ForeColor = SystemColors.ControlText;
                    label4.ForeColor     = Color.Red;
                    labelStep4.ForeColor = Color.Red;
                    label5.ForeColor     = SystemColors.ControlText;
                    labelStep5.ForeColor = SystemColors.ControlText;

                    // Update Prim's algorithm and show demonstration
                    labelInformation.Text = "";

                    weightMST             += mapMatrix.GetEdge(newEdge[0], newEdge[1]);
                    labelTotalWeight.Text += mapMatrix.GetEdge(newEdge[0], newEdge[1]).ToString() + " + ";
                    visitedVertices.Add(newEdge[1]);
                    remainingVertices.Remove(newEdge[1]);
                    EdgeFocusOn(newEdge[0], newEdge[1]);
                    exampleGraph.LabelFocusOn(newEdge[0], newEdge[1]);

                    char v1 = Convert.ToChar(newEdge[0] + 'A');
                    char v2 = Convert.ToChar(newEdge[1] + 'A');
                    for (int col = 1; col < dataGridViewGraph.ColumnCount; col++)
                    {
                        for (int row = 0; row < dataGridViewGraph.RowCount; row++)
                        {
                            if (dataGridViewGraph.Columns[col].HeaderText[0] == v1 && dataGridViewGraph[0, row].Value.ToString() == v2.ToString())
                            {
                                dataGridViewGraph.Columns[row + 1].HeaderCell.Style.ForeColor          = Color.Red;
                                dataGridViewGraph.Columns[row + 1].HeaderCell.Style.SelectionForeColor = Color.Red;
                                dataGridViewGraph.Columns[row + 1].HeaderCell.Value = dataGridViewGraph.Columns[row + 1].HeaderCell.Value.ToString() + " " + visitedVertices.Count.ToString();
                                dataGridViewGraph[col, row].Style.Font               = boldFont;
                                dataGridViewGraph[col, row].Style.ForeColor          = Color.Red;
                                dataGridViewGraph[col, row].Style.SelectionForeColor = Color.Red;
                            }
                            else if (dataGridViewGraph[col, row].Style.Font != boldFont)
                            {
                                dataGridViewGraph[col, row].Style.ForeColor          = SystemColors.ControlText;
                                dataGridViewGraph[col, row].Style.SelectionForeColor = SystemColors.ControlText;
                                if (visitedVertices.Contains(Convert.ToInt32(Convert.ToChar(dataGridViewGraph[0, row].Value) - 'A')))
                                {
                                    dataGridViewGraph[col, row].Style.Font = strikeoutFont;
                                }
                            }
                        }
                    }

                    currentStep = 5;
                }

                // Step 5 operation
                else // if (currentStep == 5)
                {
                    // Highlight current step
                    label1.ForeColor     = SystemColors.ControlText;
                    labelStep1.ForeColor = SystemColors.ControlText;
                    label2.ForeColor     = SystemColors.ControlText;
                    labelStep2.ForeColor = SystemColors.ControlText;
                    label3.ForeColor     = SystemColors.ControlText;
                    labelStep3.ForeColor = SystemColors.ControlText;
                    label4.ForeColor     = SystemColors.ControlText;
                    labelStep4.ForeColor = SystemColors.ControlText;
                    label5.ForeColor     = Color.Red;
                    labelStep5.ForeColor = Color.Red;

                    // Refresh and go to Step 2
                    labelInformation.Text = "";
                    currentStep           = 2;
                }
            }
        }