Beispiel #1
0
        /// <summary>
        /// Solves a given identification problem
        /// </summary>
        public void Solve()
        {
            factsBase.Facts.Clear();
            if (initialFactsBase != null)
            {
                factsBase.Facts = new List <IFact>(initialFactsBase.Facts);
            }

            // Copie de la base de règles pour pouvoir faire des manipulations dedans (suppression de règles)
            RulesBase usableRules = new RulesBase();

            usableRules.Rules = new List <Rule>(rulesBase.Rules);
            bool moreRules = true;

            while (moreRules)
            {
                Rule ruleToApply = FindUsableRule(usableRules);
                if (ruleToApply != null)
                {
                    // Une règle à appliquer a été trouvée
                    IFact newFact = ruleToApply.Conclusion;
                    newFact.Level = currentLevel + 1;
                    factsBase.Facts.Add(newFact);
                    usableRules.Rules.Remove(ruleToApply);
                    currentLevel = -1;
                }
                else
                {
                    // Il n'y a plus de règle à appliquer
                    moreRules = false;
                }
            }
            ihm.PrintFacts(factsBase.Facts);
        }
Beispiel #2
0
 /// <summary>
 /// Creates an instance of the Engine class
 /// </summary>
 /// <param name="a_ihm">Reference to the application object instance that must implement the IUserInterface</param>
 public Engine(IUserInterface a_ihm)
 {
     rulesBase        = new RulesBase();
     initialFactsBase = null;
     factsBase        = new FactsBase();
     ihm = a_ihm;
 }
Beispiel #3
0
 /// <summary>
 /// Loops the rules base to find all applicable rules
 /// </summary>
 /// <param name="a_rulesBase">RulesBase object of the given identification problem</param>
 /// <returns></returns>
 protected Rule FindUsableRule(RulesBase a_rulesBase)
 {
     foreach (Rule rule in a_rulesBase.Rules)
     {
         currentLevel = CanApply(rule);
         if (currentLevel != -1)
         {
             return(rule);
         }
     }
     return(null);
 }
Beispiel #4
0
 /// <summary>
 /// Creates an instance of the Engine class
 /// </summary>
 /// <param name="a_ihm">Reference to the application object instance that must implement the IUserInterface</param>
 /// <param name="a_rulesBase">RulesBase instance for the given identification problem</param>
 public Engine(IUserInterface a_ihm, RulesBase a_rulesBase)
 {
     if (a_rulesBase != null)
     {
         rulesBase = a_rulesBase;
     }
     else
     {
         rulesBase = new RulesBase();
     }
     initialFactsBase = null;
     factsBase        = new FactsBase();
     ihm = a_ihm;
 }
Beispiel #5
0
        /// <summary>
        /// Creates an instance of the Engine class
        /// </summary>
        /// <param name="a_ihm">Reference to the application object instance that must implement the IUserInterface</param>
        /// <param name="a_rulesBase">RulesBase instance for the given identification problem</param>
        /// <param name="a_factsBase">FactsBase instance including already known facts for the given identification problem</param>
        public Engine(IUserInterface a_ihm, RulesBase a_rulesBase, FactsBase a_factsBase)
        {
            if (a_rulesBase != null)
            {
                rulesBase = a_rulesBase;
            }
            else
            {
                rulesBase = new RulesBase();
            }
            if (a_factsBase != null && a_factsBase.Facts.Count != 0)
            {
                initialFactsBase = a_factsBase;
                factsBase        = new FactsBase();
                factsBase.Facts  = new List <IFact>(initialFactsBase.Facts);
            }
            else
            {
                initialFactsBase = null;
                factsBase        = new FactsBase();
            }

            ihm = a_ihm;
        }