/// <summary>
 /// Show the tag window of the vertex, and all its adjacenct edge information.
 /// </summary>
 private void FormVertexTag_Load(object sender, EventArgs e)
 {
     for (int finishingVertex = 0; finishingVertex < mapMatrix.GetSize(); finishingVertex++)
     {
         int startingVertex = mapMatrix.GetVertexIndex((sender as FormVertexTag).Text.Trim("Vertex ".ToCharArray()));
         if (mapMatrix.IsVertexExisting(finishingVertex) && finishingVertex != startingVertex)
         {
             (sender as FormVertexTag).AddVertexTagControl(finishingVertex);
             if (mapMatrix.ContainsEdge(startingVertex, finishingVertex))
             {
                 (sender as FormVertexTag).edgeControls[(sender as FormVertexTag).edgeControls.Count - 1].GetCheckBoxContainsEdge().Checked = true;
                 (sender as FormVertexTag).edgeControls[(sender as FormVertexTag).edgeControls.Count - 1].GetTextBoxWeight().Text           = mapMatrix.GetEdge(startingVertex, finishingVertex).ToString();
             }
         }
     }
 }
예제 #2
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 = "-";
                    }
                }
            }
        }