Beispiel #1
0
        public FormPrimOnGraph(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.
            foreach (Vertex vertex in exampleGraph.vertices)
            {
                vertex.MouseDown += new MouseEventHandler(Vertex_MouseDown_ChooseStartingVertex);
            }
            foreach (Label label in exampleGraph.labelWeights)
            {
                label.Click += new EventHandler(LabelWeights_Click);
            }
            vertices  = exampleGraph.GetVertices();
            mapMatrix = exampleGraph.GetMatrix();
        }
Beispiel #2
0
        public FormKruskal(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();
            InitialiseUnionFind();
        }
Beispiel #3
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 = "-";
                    }
                }
            }
        }