Пример #1
0
        static public void DemoBackwardChainWithNullMemory()
        {
            RuleInferenceEngine rie = getInferenceEngine();

            Console.WriteLine("Infer with All Facts Cleared:");
            rie.ClearFacts();

            List <Clause> unproved_conditions = new List <Clause>();

            Clause conclusion = null;

            while (conclusion == null)
            {
                conclusion = rie.Infer("vehicle", unproved_conditions);
                if (conclusion == null)
                {
                    if (unproved_conditions.Count == 0)
                    {
                        break;
                    }
                    Clause c = unproved_conditions[0];
                    Console.WriteLine("ask: " + c + "?");
                    unproved_conditions.Clear();
                    Console.WriteLine("What is " + c.Variable + "?");
                    String value = Console.ReadLine();
                    rie.AddFact(new ClauseIs(c.Variable, value));
                }
            }

            Console.WriteLine("Conclusion: " + conclusion);
            Console.WriteLine("Memory: ");
            Console.WriteLine("{0}", rie.Facts);
        }
Пример #2
0
        private void ExpertCycle()
        {
            RuleInferenceEngine rie = AutoRules.getInferenceEngine();

            rie.ClearFacts();

            List <Clause> unproved_conditions = new List <Clause>();

            conclusion = null;
            while (conclusion == null)
            {
                conclusion = rie.Infer("vehicle", unproved_conditions);
                if (conclusion == null)
                {
                    if (unproved_conditions.Count == 0)
                    {
                        break;
                    }
                    Clause c = unproved_conditions[0];

                    number_value = false;

                    for (int i = 0; i < rie.m_rules.Count(); i++)
                    {
                        if (number_value == true)
                        {
                            break;
                        }
                        for (int j = 0; j < rie.m_rules[i].m_antecedents.Count(); j++)
                        {
                            if (rie.m_rules[i].m_antecedents[j].Variable == c.Variable)
                            {
                                if (rie.m_rules[i].m_antecedents[j].Condition != "=")
                                {
                                    number_value = true;
                                    break;
                                }
                                else
                                {
                                    if (!answers_list.Contains(rie.m_rules[i].m_antecedents[j].Value))
                                    {
                                        answers_list.Add(rie.m_rules[i].m_antecedents[j].Value);
                                    }
                                }
                            }
                        }
                    }
                    if (number_value)
                    {
                        question = "У данного ТС сколько " + c.Variable + "?";
                    }
                    else
                    {
                        question = "У данного ТС " + c.Variable + "?";
                    }
                    //Console.WriteLine("ask: " + c + "?");
                    //question = "What is " + c.Variable + "?";
                    readyEvent.Set();
                    nextEvent.Reset();
                    unproved_conditions.Clear();
                    nextEvent.WaitOne();
                    answers_list.Clear();
                    //Console.WriteLine("What is " + c.Variable + "?");
                    String value = answer;//Console.ReadLine();
                    rie.AddFact(new IsClause(c.Variable, value));
                }
            }
            readyEvent.Set();
            finished = true;
            //Console.WriteLine("Conclusion: " + conclusion);
            //Console.WriteLine("Memory: ");
            //Console.WriteLine("{0}", rie.Facts);
            //Console.ReadLine();
        }