Exemple #1
0
        private void frmLuat_Load(object sender, EventArgs e)
        {
            StreamReader f = new StreamReader("dulieuluat.dat");

            while (f.Peek() != -1)
            {
                vt = vt + 1;

                Luat         dt = new Luat();
                string       s  = f.ReadLine();
                string[]     ss = s.Split('|');
                ListViewItem lv = new ListViewItem(ss);
                listLuat.Items.Add(lv);
            }
            f.Close();
            f = new StreamReader("dulieu.dat"); //mo file
            while (f.Peek() != -1)              //trong khi chua den cuoi file
            {
                vt = vt + 1;
                //SuKien dt = new SuKien();
                string   s  = f.ReadLine(); //doc 1 dong tu file roi gan cho s
                string[] ss = s.Split('|'); //cat s thanh 2 phan:ten va NN
                //khai bao va khoi tao doi tuong listviewitem
                ListViewItem lv = new ListViewItem(ss);
                listSukien.Items.Add(lv);
            }
            f.Close();
            if (vt != -1)
            {
                txtVT.Text = listLuat.Items[0].SubItems[0].Text;
                txtVP.Text = listLuat.Items[0].SubItems[1].Text;
                vt         = 0;
            }
        }
Exemple #2
0
        private void suydientien()
        {
            ArrayList sat = new ArrayList();//khai báo tập sat để chứa các luật

            loadskTP();
            //gán biến tg bằng giả thiết factsbase
            foreach (string a in tapkl)
            {
                string tg = factsbase;
                vet            = "";                         //gán vết bằng rỗng
                txtKetqua.Text = "";
                huyluat        = "";                         //khởi tạo hủy luật bằng rỗng
                TimLuat(rulesbase, tg, ref sat);             //tìm luật có vt thuộc tg đưa vào sat
                while (sat.Count > 0)                        //trong khi tập sat khác rỗng
                {
                    int  cs = (int)sat[0];                   //lấy trong tập sat 1 chỉ số luật và gán cho cs
                    Luat r  = (Luat)rulesbase[cs];           //lấy luật ứng với cs và gán cho r
                    sat.RemoveAt(0);                         //xóa luật ở vị trí đầu tiên trong sat
                    tg      = tg + " " + r.Right;            //thêm vế phải của luật r vào tg
                    huyluat = huyluat + " " + cs.ToString(); //hủy luật r
                    vet     = vet + cs.ToString() + " ";     //thêm cs luật r vào vết
                    if (tg.Contains(a))                      //nếu kết luận thuộc tg thì inkq
                    {
                        txtKetqua.Text = "Thanh cong\r\n";
                        vet            = vet.Trim();
                        string[] ss = vet.Split(' ');//tách vet thành các cs luật
                        for (int i = 0; i < ss.Length; i++)
                        {
                            int    vt = int.Parse(ss[i]);                               //chuyển chuỗi ss[i] thành số
                            Luat   l  = (Luat)rulesbase[vt];                            //lấy luật tại vt về gán cho l
                            string s  = string.Format("{0}->{1}\r\n", l.Left, l.Right); //định dạng để in luật
                            txtKetqua.Text = txtKetqua.Text + s;                        //thêm s vào textbox3
                        }
                        foreach (string tempkl in tapskt)
                        {
                            if (factsbase.Contains(tempkl))
                            {
                                int    ii = Array.IndexOf(tapskt, tempkl);
                                string kl = tapsk[ii];
                                txtKetqua.Text = txtKetqua.Text + tempkl + "->" + kl + "\r\n";
                            }
                        }
                        txtKetqua.Text = txtKetqua.Text + "--------------------\r\n";
                        int    iii = Array.IndexOf(tapskt, a);
                        string kl1 = tapsk[iii];
                        txtKetqua.Text = txtKetqua.Text + "Chẩn đoán: " + kl1 + "\r\n";
                        string images = "images/" + kl1 + ".jpg";
                        pictureBox1.Image = Image.FromFile(images);
                        return;                      //kết thúc suy diễn
                    }
                    TimLuat(rulesbase, tg, ref sat); //tìm luật lại
                }//while
                txtKetqua.Text = " Không trùng trong tập luật !";
            }
        }
Exemple #3
0
        private void frmSuydien_Load(object sender, EventArgs e)
        {
            imageList1           = new ImageList();
            imageList1.ImageSize = new Size(255, 255);
            soluat = FileCount();
            sosk   = FileCountsk();
            loadtapkl();

            //mở file để đọc tập luật vào biến rulesbase
            StreamReader f = new StreamReader("dulieu.dat");//mở file
            Sukien       sk;

            while (f.Peek() != -1)          //trong khi chưa kết thúc file
            {
                string   s  = f.ReadLine(); //đọc 1 dòng từ file
                string[] ss = s.Split('|'); //tách vế trái (ss[0]) và vế phải (ss[1])
                sk = new Sukien(ss[0], ss[1]);
                facts.Add(sk);
                //khởi tạo đối tượng Luật dt
                // ss[0] = ss[0] + " ->"; //nối -> vào cuối vế trái
                ListViewItem lv = new ListViewItem(ss); //khởi tạo dt listviewitem
                listSukien.Items.Add(lv);               // thêm 1 dòng vào listview1
                //rulesbase.Add(dt);//thêm 1 luật vào rulesbase
            }
            f.Close();//đóng file

            //mở file để đọc tập sự kiện vào biến facts
            f = new StreamReader("dulieuluat.dat"); //mở file
            Luat dt;                                //khai báo dt là đối tượng  của lớp Luat

            while (f.Peek() != -1)
            {
                string   s  = f.ReadLine();
                string[] ss = s.Split('|');
                dt = new Luat(ss[0], ss[1]);
                rulesbase.Add(dt);
                // sk = new SuKien(ss[0], ss[1]);
                // facts.Add(sk);
            }
            f.Close();
        }
Exemple #4
0
 public void TimLuat(ArrayList tapluat, string tg, ref ArrayList sat)
 {
     for (int i = 0; i < tapluat.Count; i++)
     {
         //khai báo dt là đối tượng Luật và lấy luật thứ i về gán cho dt
         Luat     dt = (Luat)tapluat[i];
         string[] ss = dt.Left.Split(' ');         //tách vế trái thành các sự kiện
         int      j  = 0;
         while (!huyluat.Contains(i.ToString()) && //luật chưa bị xóa
                !sat.Contains(i) &&                //tập sat chưa chứa luật i
                j < ss.Length &&                   // chưa duyệt hết sự kiện ở vế trái
                tg.IndexOf(ss[j]) != -1)           //trung gian có chứa sự kiện ss[j]
         {
             j++;
         }
         if (j == ss.Length)
         {
             sat.Add(i);                //vế trái thuộc tg nên thêm luật i vào sat
         }
     }
 }
Exemple #5
0
        private void frmLuat_Load(object sender, EventArgs e)
        {
            StreamReader f = new StreamReader("dulieuluat.dat");
            while (f.Peek() != -1)
            {
                vt = vt + 1;

                Luat dt = new Luat();
                string s = f.ReadLine();
                string[] ss = s.Split('|');
                ListViewItem lv = new ListViewItem(ss);
                listLuat.Items.Add(lv);

            }
            f.Close();
            f = new StreamReader("dulieu.dat");//mo file
            while (f.Peek() != -1)//trong khi chua den cuoi file
            {
                vt = vt + 1;
                //SuKien dt = new SuKien();
                string s = f.ReadLine();//doc 1 dong tu file roi gan cho s
                string[] ss = s.Split('|');//cat s thanh 2 phan:ten va NN
                //khai bao va khoi tao doi tuong listviewitem
                ListViewItem lv = new ListViewItem(ss);
                listSukien.Items.Add(lv);
            }
            f.Close();
            if (vt != -1)
            {
                txtVT.Text = listLuat.Items[0].SubItems[0].Text;
                txtVP.Text = listLuat.Items[0].SubItems[1].Text;
                vt = 0;
            }
        }
Exemple #6
0
        private void frmSuydien_Load(object sender, EventArgs e)
        {
            imageList1 = new ImageList();
            imageList1.ImageSize = new Size(255, 255);
            soluat = FileCount();
            sosk = FileCountsk();
            loadtapkl();

            //mở file để đọc tập luật vào biến rulesbase
            StreamReader f = new StreamReader("dulieu.dat");//mở file
            Sukien sk;
            while (f.Peek() != -1)//trong khi chưa kết thúc file
            {
                string s = f.ReadLine();//đọc 1 dòng từ file
                string[] ss = s.Split('|');//tách vế trái (ss[0]) và vế phải (ss[1])
                sk = new Sukien(ss[0], ss[1]);
                facts.Add(sk);
                //khởi tạo đối tượng Luật dt
                // ss[0] = ss[0] + " ->"; //nối -> vào cuối vế trái
                ListViewItem lv = new ListViewItem(ss);//khởi tạo dt listviewitem
                listSukien.Items.Add(lv);// thêm 1 dòng vào listview1
                //rulesbase.Add(dt);//thêm 1 luật vào rulesbase
            }
            f.Close();//đóng file

            //mở file để đọc tập sự kiện vào biến facts
            f = new StreamReader("dulieuluat.dat");//mở file
            Luat dt;//khai báo dt là đối tượng  của lớp Luat

            while (f.Peek() != -1)
            {
                string s = f.ReadLine();
                string[] ss = s.Split('|');
                dt = new Luat(ss[0], ss[1]);
                rulesbase.Add(dt);
                // sk = new SuKien(ss[0], ss[1]);
                // facts.Add(sk);
            }
            f.Close();
        }