Exemple #1
0
        private void FormTest_Load(object sender, EventArgs e)
        {
            List <RuleDTO>  listRule = RulesBLL.FindAll();
            List <RuleDEMO> rules1   = new List <RuleDEMO>();

            int count = 1;

            listRule.ForEach(rule => {
                RuleDEMO ruleTMP = new RuleDEMO();
                ruleTMP.STT      = count++;
                ruleTMP.Id       = rule.Id;
                ruleTMP.Rule     = string.Join("^", rule.Left) + " -> " + rule.Right;
                rules1.Add(ruleTMP);
            });



            dgvRule.DataSource = rules1;
            dgvRule.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            List <RuleDEMO> rules = new List <RuleDEMO>();

            count = 1;
            ForwardChainingUtil.OptimizeRule(listRule).ForEach(rule => {
                RuleDEMO ruleTMP = new RuleDEMO();
                ruleTMP.STT      = count++;
                ruleTMP.Id       = rule.Id;
                ruleTMP.Rule     = string.Join("^", rule.Left) + " -> " + rule.Right;
                rules.Add(ruleTMP);
            });

            dgvTest.DataSource = rules;
            dgvTest.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }
        /// <summary>
        /// Phuong thuc tra ve ket qua cua <b>suy dien tien</b> voi dau vao
        /// la danh sach gia thiet (assumptions)<br/>
        /// <i>Ngay cap nhat : 18/04/2021</i>
        /// </summary>
        /// <param name="assumptions"></param>
        /// <returns></returns>
        public static List <MobileDTO> Result(List <string> assumptions)
        {
            // Ket qua
            var result = new List <MobileDTO>();
            // Lay tat ca cac luat trong database va tou uu hoa tap luat
            List <RuleDTO> rules = OptimizeRule(RulesBLL.FindAll());

            List <RuleDTO> rulesCopy = new List <RuleDTO>(rules);
            // Lay tat ca cac doi tuong mobile trong database
            var mobiles = MobileBLL.FindAll();
            //var mobileId = mobile.Id;
            //-----------------------------------------------------------------------------------------
            //Buoc 1: Gan trung gian bang gia thiet
            List <string> mediate = assumptions;

            //Buoc 2: THuc hien suy dien
            Queue <int> SAT = new Queue <int>();

            mediate = ForwardChaining(SAT, rulesCopy, rules, mediate);

            //Buoc 3: Kiem tra neu bien trung gian co chua mobile thi them vao ket qua
            mobiles.ForEach(mobile =>
            {
                if (mediate.Contains(mobile.Id))
                {
                    result.Add(mobile);
                }
            });
            return(result);
        }
Exemple #3
0
        private void dgvRules_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int row = e.RowIndex;
            int id  = int.Parse(dgvRules.Rows[row].Cells[0].Value.ToString());

            ruleDTOTemp       = RulesBLL.FindByID(id);
            txtRuleLeft.Text  = string.Join("^", ruleDTOTemp.Left);
            txtRuleRight.Text = ruleDTOTemp.Right.ToString();
        }
Exemple #4
0
        private void btnInsertRule_Click(object sender, EventArgs e)
        {
            string left  = txtRuleLeft.Text.Trim();
            string right = txtRuleRight.Text.Trim();

            if (RulesBLL.Insert(left, right))
            {
                MessageBox.Show("Thêm luật thành công!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                LoadRule();
            }
        }
Exemple #5
0
        private void LoadRule()
        {
            List <RuleTMP> listRule = new List <RuleTMP>();

            //List<string> rules = new List<string>();
            RulesBLL.FindAll().ForEach(rule => {
                //rules.Add(string.Join("^",rule.Left)+" -> "+ rule.Right);
                RuleTMP ruleTMP = new RuleTMP();
                ruleTMP.Id      = rule.Id;
                ruleTMP.Rule    = string.Join("^", rule.Left) + " -> " + rule.Right;
                listRule.Add(ruleTMP);
            });
            //dgvRules.DataSource = rules.Select(x => new { Rule = x }).ToList();
            dgvRules.DataSource = listRule;
            //this.dgvRules.Columns["Id"].Visible = false;
            dgvRules.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }
Exemple #6
0
 private void btnDeleteRule_Click(object sender, EventArgs e)
 {
     if (ruleDTOTemp != null)
     {
         if (RulesBLL.Delete(ruleDTOTemp.Id))
         {
             MessageBox.Show("Xóa luật thành công!", "Thông báo",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadRule();
             ruleDTOTemp = null;
             ClearTextBoxes();
         }
     }
     else
     {
         MessageBox.Show("Xóa luật thất bại!", "Thông báo",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }