Beispiel #1
0
        private void btnPhuToiThieu_Click(object sender, EventArgs e)
        {
            if (listBox1.Items.Count > 0)
            {
                listBox2.Items.Clear();

                S_PhuToiThieu ptt = new S_PhuToiThieu();

                ptt = tt.timPhuToiThieu(listTrai, listPhai);

                for (int i = 0; i < ptt.VP.Count; i++)
                {
                    listBox2.Items.Add(ptt.VT[i].ToUpper() + " -> " + ptt.VP[i].ToUpper());
                }
            }
            else
            {
                MessageBox.Show("Hãy nhập phụ thuộc hàm vào!!!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #2
0
        public S_PhuToiThieu timPhuToiThieu(List <string> VT, List <string> VP)
        {
            S_PhuToiThieu ptt = new S_PhuToiThieu();

            int n = VP.Count;

            //tách phụ thuộc hàm vế phải có hơn 1 thuộc tính
            for (int i = 0; i < n; i++)
            {
                if (VP[i].Length > 1)
                {
                    string tempVP = VP[i];
                    string temVT  = VT[i];

                    VT.Remove(VT[i]);
                    VP.Remove(VP[i]);

                    for (int j = 0; j < tempVP.Length; j++)
                    {
                        VT.Add(temVT);
                        VP.Add(tempVP[j].ToString());
                    }

                    i--;
                }
            }

            //loại bỏ thuộc tính dư thừa bên vế trái có hơn 1 thuộc tính
            for (int i = 0; i < VT.Count; i++)
            {
                if (VT[i].Length > 1)
                {
                    for (int j = 0; j < VT[i].Length; j++)
                    {
                        if (VT[i].Length > 1)
                        {
                            string temp = VT[i];
                            temp = CatKiTu(temp, j);

                            if (soSanhChuoi(VP[i], timBaoDong(temp, VT, VP)))
                            {
                                VT[i] = temp;
                                j--;
                            }
                        }
                    }
                }
            }

            //loại bỏ thuộc tính dư thừa
            List <string> TempVT = new List <string>();
            List <string> TempVP = new List <string>();

            for (int i = 0; i < VT.Count; i++)
            {
                TempVT.Add(VT[i]);
                TempVP.Add(VP[i]);
            }

            for (int i = 0; i < VT.Count; i++)
            {
                TempVT.RemoveAt(i);
                TempVP.RemoveAt(i);

                if (soSanhChuoi(VP[i], timBaoDong(VT[i], TempVT, TempVP)))
                {
                    VT.Clear();
                    VP.Clear();

                    for (int t = 0; t < TempVT.Count; t++)
                    {
                        VT.Add(TempVT[t]);
                        VP.Add(TempVP[t]);
                    }

                    i--;
                }
                else
                {
                    TempVT.Clear();
                    TempVP.Clear();

                    for (int t = 0; t < VT.Count; t++)
                    {
                        TempVT.Add(VT[t]);
                        TempVP.Add(VP[t]);
                    }
                }
            }

            ptt.VT = VT;
            ptt.VP = VP;

            return(ptt);
        }