Artificial Intelligence
Artificial Intelligence
Information

InferenceEngine class


      Represents the inference engine that makes the system capable of reasoning from facts and rules.


Namespace : ielib
Assembly : ielib.dll
   C#
   public class InferenceEngine

Constructors

InferenceEngine():Initializes a new instance of the InferenceEngine class.

InferenceEngine(KnowledgeBase kb): Initializes a new instance of the InferenceEngine class by setting a knowledge base.

InferenceEngine(string aFromXmlFile): Initializes a new instance of the InferenceEngine class by setting a knowledge base from an Xml file.


Properties

CurrentBase : Gets or sets an active knowledge base in the inference engine.


Methods

Restart() : Resumes execution of inference engine in resetting the memory of the knowledge base.

Run() : Runs the inference engine. This method works with the mode of joint chaining combining the chaining forward that has deducted all what with the rules follows, and the chaining backward that determines what question should be posed to progress towards a goal.


Example of using the InferenceEngine class in C#:

using ielib;
public void RunIE(string XmlBaseName)
{
     // Instantiates the inference engine from an Xml file
     InferenceEngine ie = new InferenceEngine(XmlBaseName);
     ChainingResult result = ie.Run();

     switch(result.Result)
     {
     case ChainingResult.ExecuteResult.Contradictory:
             //The contradiction is detected
            MessageBox.Show("The Fact " + result.ContradictoryConclusion.FactObject.Name + "is contradictory");
             break;
     case ChainingResult.ExecuteResult.Question:
             //The inference engine my pose the question regarding this Fact
            AskFor(result.Question);
             break;
     case ChainingResult.ExecuteResult.Conclusion:
             //The expert system can binding the result
            for (int i = 0; i < result.Count; i++)
                   DisplayResult(result[i]);
             break;
     default:
             MessageBox.Show("I can not binding");
             break;
     }
}

      In some applications, sometimes you have to get the conclusion by running expert system back plant without asking questions to users. You can set the data in the Facts before and then you run the inference engine hoping to obtain immediately the conclusion.

      Example : The "MyBase.xml" file in this example is a record of the knowledge base developed by our VESD software, so we can integrate it into our application.

// I instantiate the objects of the class KnowledgeBase and class InferenceEngine
KnowledgeBase kb = new KnowledgeBase();
InferenceEngine ie = new InferenceEngine();

kb.LoadFrom("MyKBase.xml");
Ie.CurrentBase = kb;
// I affects the answers in the Facts
Kb.GetFactByName("many museums").SetValue(true);
Kb.GetFactByName("Vegetation abundant") .SetValue(true);
Kb.GetFactByName("many monuments") .SetValue(true);

ChainingResult result = ie.Run();

for (int i = 0; i < result.Count; i++)
      DisplayResult(result[i]);


      Remark : Suppose that we had a large complex expert system to develop, if we can cut into subsystems to facilitate the task of development, the results of reasoning of a sub-system used data for another expert system, like the procedural programming, the results of the execution of a procedure are data that allows to perform another procedure.

      Example : We had 3 bases of knowledge A, B, and C, the results of reasoning of B and C are used for reasoning of A.

      We use a single inference engine.


ChainingResult result;
Fact f;
InferenceEngine ie = new InferenceEngine();
KnowledgeBase kbA = new KnowledgeBase("kbA.xml");
KnowledgeBase kbB = new KnowledgeBase("kbB.xml");
KnowledgeBase kbC = new KnowledgeBase("kbC.xml");

ie.CurrentBase = kbB;
result = ie.Run(); // Here, I assume that the expert system led to a conclusion
for (int i = 0 ; i < result.Count ; i++)
{
     f = result[i];
     kbA.Affect(f.Name,.f.Value);
}
ie.CurrentBase = kbC;
result = ie.Run(); // Run with kbC
for (int i = 0 ; i < result.Count ; i++)
{
     f = result[i];
     kbA.Affect(f.Name,.f.Value);
}
// Finally, I can run with kbA to reach the final result
ie.CurrentBase = kbA;
result = ie.Run(); // Run with kbA


      Example : with 3 inference engines

      Remark : You can instantiate these 3 engines of inference in threads differences

ChainingResult result;
Fact f;
InferenceEngine ieA = new InferenceEngine("kbA.xml");
InferenceEngine ieB = new InferenceEngine("kbB.xml");
InferenceEngine ieC = new InferenceEngine("kbC.xml");
result = ieB.Run();
for (int i = 0 ; i < result.Count ; i++)
{
     f = result[i];
     ieA.CurrentBase.Affect(f.Name,.f.Value);
}
result = ieC.Run();
for (int i = 0 ; i < result.Count ; i++)
{
     f = result[i];
     ieA.CurrentBase.Affect(f.Name,.f.Value);
}
// Finally result
result = ieA.Run();