示例#1
0
 private void btnBackwardChaining_Click(object sender, EventArgs e)
 {
     try
     {
         if (rbProduction.Checked)
         {
             var engine = new ProductionInferenceEngine(ProductionRulesConverter.ConvertToRules(txtbxRules.Text));
             var result = engine.ExecuteBackwardChaining(txtbxFact.Text, txtbxGoal.Text);
             if (result.HasSolution)
             {
                 txtbxSolution.Text = ProductionRulesConverter.ConvertBackwardRulesToText(result.Explanation);
             }
             else
             {
                 txtbxSolution.Text = "Нет решений";
             }
         }
         else if (rbLogic.Checked)
         {
             var engine = new LogicInferenceEngine(LogicRulesLoader.LoadFromFile(txtbxRules.Text));
             var rule   = LogicRulesLoader.ParseRule(txtbxGoal.Text);
             var result = engine.ExecuteBackwardChaining(rule);
             if (result.HasSolution)
             {
                 txtbxSolution.Text = LogicRulesConverter.ConvertToString(result.Explanation);
             }
             else
             {
                 txtbxSolution.Text = "Доказываемое утверждение неверно";
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }