Ejemplo n.º 1
0
        //backward chain
        public Clause Infer(string goal_variable, List <Clause> unproved_conditions)
        {
            Clause conclusion = null;
            var    goal_stack = new List <Rule>();

            foreach (var rule in Rules)
            {
                var consequent = rule.GetConsequent();
                if (consequent.Variable == goal_variable)
                {
                    goal_stack.Add(rule);
                }
            }

            foreach (var rule in Rules)
            {
                rule.FirstAntecedent();
                var goal_reached = true;
                while (rule.HasNextAntecedents())
                {
                    var antecedent = rule.NextAntecedent();
                    if (!WorkingMemory.IsFact(antecedent))
                    {
                        if (WorkingMemory.IsNotFact(antecedent))                         //conflict with memory
                        {
                            goal_reached = false;
                            break;
                        }
                        if (IsFact(antecedent, unproved_conditions))                         //deduce to be a fact
                        {
                            WorkingMemory.AddFact(antecedent);
                        }
                        else                         //deduce to not be a fact
                        {
                            goal_reached = false;
                            break;
                        }
                    }
                }

                if (goal_reached)
                {
                    conclusion = rule.GetConsequent();
                    break;
                }
            }

            return(conclusion);
        }
Ejemplo n.º 2
0
Archivo: Rule.cs Proyecto: koanse/smart
        public void Fire(WorkingMemory wm)
        {
            if (!wm.IsFact(Consequent))
            {
                wm.AddFact(Consequent);
            }

            Fired = true;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Add another know fact into the working memory
 /// </summary>
 /// <param name="c"></param>
 public void AddFact(Clause c)
 {
     WorkingMemory.AddFact(c);
 }