Esempio n. 1
0
 /// <summary>
 /// Called when [WME] is visited.
 /// </summary>
 /// <param name="wme">The wme.</param>
 public virtual void OnWME(WME wme)
 {
 }
Esempio n. 2
0
        public void MultiBuiltinTest()
        {
            Production prod = new Production();

            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            //Variable z = new Variable("z");
            Variable c = new Variable("c");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            //prod.AddConditionToLHS(new condition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", x, "color", c));

            FunctionCondition funCond = new FunctionCondition("F4", c, new FuncTerm("funcNotEquals", new funcNotEquals()), new StringTerm("blue"));

            funCond.ConditionType = ConditionType.Function;
            prod.AddConditionToLHS(funCond);

            prod.AddConditionToRHS(new AssertCondition("C4", x, "is", c));

            Rete rete = new Rete();

            rete.AddProduction(prod);

            NetworkPrinter printer = new NetworkPrinter();

            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\MultiBuiltinTest.log", false))
            {
                writer.Write(printer.Output);
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine("-----------------------------------------------");
                writer.Flush();
            }

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            printer = new NetworkPrinter();
            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\MultiBuiltinTest.log", true))
            {
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine();
                writer.Write(printer.Output);
                writer.Flush();
            }

            //Assert.IsTrue(rete.RulesThatFired.Count == 1, "Rule did not fire.");
            Assert.IsTrue(prod.InferredFacts.Count == 2, "Wrong number of InferredFacts");
            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
        }
Esempio n. 3
0
 /// <summary>
 /// Called when [WME] is visited.
 /// </summary>
 /// <param name="wme">The wme.</param>
 public virtual void OnWME(WME wme)
 {
 }
Esempio n. 4
0
        public void BasicOverrideTest()
        {
            Agenda agenda = new Agenda();

            agenda.ConflictResolutionStrategy = new SalienceResolver();

            Production prod = new Production();

            prod.Label = "Gold Customer";
            Variable customer  = new Variable("customer");
            Variable purchases = new Variable("purchases");

            prod.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            FunctionCondition gt = new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 10);

            gt.ConditionType = ConditionType.Function;
            prod.AddConditionToLHS(gt);
            AssertCondition rhs = new AssertCondition("R1", customer, "is", "gold");

            rhs.ConditionType = ConditionType.Assert;
            prod.AddConditionToRHS(rhs);
            agenda.AddProduction(prod);

            Production prod1 = new Production();

            prod1.Label = "Platinum Customer";

            prod1.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            FunctionCondition gt1 = new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 20);

            gt1.ConditionType = ConditionType.Function;
            prod1.AddConditionToLHS(gt1);
            AssertCondition rhs1 = new AssertCondition("R1", customer, "is", "Platinum");

            rhs.ConditionType = ConditionType.Assert;
            prod1.AddConditionToRHS(rhs1);
            agenda.AddProduction(prod1);

            Override me = new Override();

            me.Winner = "Platinum Customer";
            me.Loser  = "Gold Customer";

            agenda.AddOverride(me);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "joe";
            wme1.Fields[1] = "purchases";
            wme1.Fields[2] = "1";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "ted";
            wme2.Fields[1] = "purchases";
            wme2.Fields[2] = "10";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "ed";
            wme3.Fields[1] = "purchases";
            wme3.Fields[2] = "11";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "phil";
            wme4.Fields[1] = "purchases";
            wme4.Fields[2] = "18";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "mary";
            wme5.Fields[1] = "purchases";
            wme5.Fields[2] = "22";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "jane";
            wme6.Fields[1] = "purchases";
            wme6.Fields[2] = "25";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "fred";
            wme7.Fields[1] = "purchases";
            wme7.Fields[2] = "50";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "harry";
            wme8.Fields[1] = "purchases";
            wme8.Fields[2] = "55";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "jon";
            wme9.Fields[1] = "purchases";
            wme9.Fields[2] = "99";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\BasicOverrideTest.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Rule did not fire.");
            Assert.IsTrue(agenda.InferredFacts.Count == 5, "Bad");
        }
Esempio n. 5
0
        public void Test4pointsTo1()
        {
            Production prod = new Production();

            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            prod.AddConditionToLHS(new PositiveCondition("C4", x, "has", "car"));
            prod.AddConditionToLHS(new PositiveCondition("C5", x, "wants", z));
            prod.AddConditionToRHS(new AssertCondition("C5", x, "gets", z));
            Rete rete = new Rete();

            rete.AddProduction(prod);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            WME wme10 = new WME("W10");

            wme10.Fields[0] = "B2";
            wme10.Fields[1] = "has";
            wme10.Fields[2] = "bike";
            rete.AddWME(wme10);

            WME wme11 = new WME("W11");

            wme11.Fields[0] = "B1";
            wme11.Fields[1] = "has";
            wme11.Fields[2] = "car";
            rete.AddWME(wme11);

            WME wme12 = new WME("W12");

            wme12.Fields[0] = "B1";
            wme12.Fields[1] = "wants";
            wme12.Fields[2] = "B3";
            rete.AddWME(wme12);

            //Assert.IsTrue(rete.RulesThatFired.Count == 1, "Rule did not fire.");
            Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");
            Assert.IsTrue(rete.WorkingMemory.Count == 12, "Bad");
        }
Esempio n. 6
0
        public void RetractRule()
        {
            Agenda agenda = new Agenda();
            agenda.ConflictResolutionStrategy = new SalienceResolver();

            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            Production prod = new Production("find-stack-of-two-blocks-to-the-left-of-a-red-block");
            prod.Salience = 1;

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            prod.AddConditionToRHS(new AssertCondition("R1", x, "is", "on top"));
            prod.AddConditionToRHS(new AssertCondition("R2", "mary", "looks", "fine"));
            agenda.AddProduction(prod);

            Production dependentProd = new Production("Dependent Production");
            dependentProd.Salience = 55;
            dependentProd.AddConditionToLHS(new AND("mary", "looks", "fine"));
            dependentProd.AddConditionToRHS(new ASSERT("should", "not", "see"));
            agenda.AddProduction(dependentProd);

            Production retractProd = new Production("Retract Production");
            retractProd.Salience = 50;
            retractProd.AddConditionToLHS(new AND(x, "is", "on top"));
            retractProd.AddConditionToRHS(new RETRACT("mary", "looks", "fine"));
            agenda.AddProduction(retractProd);

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\RetractRule.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 2, "Rule did not fire.");
            Assert.IsTrue(agenda.NotActivatedRuleCount == 1, "Rule should not have fired.");
            Assert.IsTrue(agenda.InferredFacts.Count == 1, "Bad");
        }
        public void EvaluatorTest()
        {
            Production prod = new Production();
            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");
            //Variable c = new Variable("c");
            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            //prod.AddConditionToLHS(new condition("C3", z, "color", "red"));

            PositiveCondition noteq = new PositiveCondition("NOT BLUE", x, "color", "blue");
            noteq.Evaluator = EvaluatorManager.Instance.Evaluators["NotEquals"];
            prod.AddConditionToLHS(noteq);

            prod.AddConditionToRHS(new AssertCondition("C5", x, "calls", z));

            Rete rete = new Rete();
            rete.AddProduction(prod);

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            NetworkPrinter printer = new NetworkPrinter();
            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\EvaluatorTest.log", false))
            {
                writer.Write(printer.Output);
                writer.Flush();
            }

            Assert.IsTrue(prod.InferredFacts.Count == 2, "Wrong number of conclusions");
            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
        }
Esempio n. 8
0
        public void EvaluatorTest()
        {
            Production prod = new Production();

            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            //Variable c = new Variable("c");
            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            //prod.AddConditionToLHS(new condition("C3", z, "color", "red"));

            PositiveCondition noteq = new PositiveCondition("NOT BLUE", x, "color", "blue");

            noteq.Evaluator = EvaluatorManager.Instance.Evaluators["NotEquals"];
            prod.AddConditionToLHS(noteq);

            prod.AddConditionToRHS(new AssertCondition("C5", x, "calls", z));

            Rete rete = new Rete();

            rete.AddProduction(prod);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            NetworkPrinter printer = new NetworkPrinter();

            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\EvaluatorTest.log", false))
            {
                writer.Write(printer.Output);
                writer.Flush();
            }

            Assert.IsTrue(prod.InferredFacts.Count == 2, "Wrong number of conclusions");
            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
        }
Esempio n. 9
0
        /// <summary>
        /// use the objectmaptable to create the facts
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="objectMapTable">The object map table.</param>
        /// <param name="parentObj">The parent obj.</param>
        /// <returns></returns>
        public List <WME> createFactSetFromObjectInstance(Object obj, ObjectMapTable objectMapTable, Object parentObj)
        {
            objectmaptable = objectMapTable;
            ArrayList  mappedPredicateNames = null;
            WME        cliteral             = null;
            List <WME> cliteralList         = new List <WME>();

            // TODO:  Fix it
            if (obj == null)
            {
                return(cliteralList);
            }

            if (objectmaptable != null)
            {
                mappedPredicateNames = objectmaptable.getObjectMappingsByClassName(obj.GetType().FullName);

                if (mappedPredicateNames.Count > 0)
                {
                    //loop through the object mappings for each class and create the List<WME>
                    //

                    #region build cliterals from an object mapping

                    foreach (ObjectMapping eachMapping in mappedPredicateNames)
                    {
                        bool bParentMapped = false;

                        // Add the object reference
                        List <Term> termlist = new List <Term>();
                        termlist.Add(new ObjectTerm(obj));

                        // Add the parent object reference if contained in a list
                        if ((eachMapping.IsContained) && (!bParentMapped))
                        {
                            if (parentObj != null)
                            {
                                termlist.Add(new ObjectTerm(parentObj));
                            }
                            else
                            {
                                termlist.Add(new StringTerm(""));
                            }
                            bParentMapped = true;
                        }

                        //ALiteral aliteral = new ALiteral(eachMapping.getPredicateName());
                        //cliteral = new CLiteral(1, aliteral);
                        //cliteral.ArgList = (termlist);

                        foreach (string eachPred in eachMapping.getAttNames())
                        {
                            PropertyInfo theProp = obj.GetType().GetProperty(eachPred);
                            if (theProp == null)
                            {
                                termlist.Add(new StringTerm(""));
                            }
                            else
                            {
                                object objProp = theProp.GetValue(obj, BindingFlags.GetProperty, null, null, null);
                                if (objProp == null)
                                {
                                    objProp = String.Empty;
                                }

                                switch (theProp.PropertyType.Name)
                                {
                                case "String[]":
                                    List <Term> termList1 = new List <Term>();
                                    foreach (string eachString in (String[])objProp)
                                    {
                                        termList1.Add(new StringTerm(eachString));
                                    }
                                    //FuncTerm functerm = new FuncTerm("list", termList1);
                                    //termlist.Add(functerm);
                                    break;

                                case "String":
                                    termlist.Add(new StringTerm(objProp.ToString()));
                                    break;

                                case ("Int32"):
                                    termlist.Add(new IntegerTerm((int)objProp));
                                    break;

                                case ("DateTime"):
                                    termlist.Add(new DateTimeTerm((DateTime)objProp));
                                    break;

                                case ("Double"):
                                    termlist.Add(new DoubleTerm((double)objProp));
                                    break;

                                case ("ArrayList"):
                                    List <Term> termList2_ = new List <Term>();
                                    foreach (string eachString in (IEnumerable)objProp)
                                    {
                                        termList2_.Add(new StringTerm(eachString));
                                    }
                                    //FuncTerm functerm2_ = new FuncTerm("list", termList2_);
                                    //termlist.Add(functerm2_);

                                    foreach (object eachObject in (IEnumerable)objProp)
                                    {
                                        if (!eachObject.GetType().IsPrimitive)
                                        {
                                            List <WME> clist =
                                                createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                            cliteralList.AddRange(clist);
                                        }
                                    }

                                    break;

                                case ("Boolean"):
                                    termlist.Add(new BooleanTerm((bool)objProp));
                                    break;

                                default:
                                    bool bAddObjectTerm = true;
                                    if (objProp is IEnumerable)
                                    {
                                        if (objProp is Hashtable)
                                        {
                                            foreach (object eachObject in ((IDictionary)objProp).Values)
                                            {
                                                if (eachObject.GetType().FullName == "System.String")
                                                {
                                                    //ALiteral aliteral_ = new ALiteral(objProp.GetType().Name + "Values");
                                                    //CLiteral cliteral_ = new CLiteral(1, aliteral_);

                                                    //List<Term> termlist_ = new List<Term>();
                                                    //termlist_.Add(new StringTerm(eachObject.ToString()));
                                                    //termlist_.Add(new ObjectTerm(objProp));

                                                    //cliteral_.ArgList = (termlist_);
                                                    //cliteralList.Add(cliteral_);
                                                }
                                                else
                                                {
                                                    List <WME> clist =
                                                        createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                    cliteralList.AddRange(clist);
                                                }
                                            }
                                        }
                                        else if (objProp.GetType().BaseType.ToString() == "System.Collections.ArrayList")
                                        {
                                            bAddObjectTerm = false;
                                            // Map as an embedded list t
                                            List <Term> termList1_ = new List <Term>();
                                            foreach (object eachObject in (IEnumerable)objProp)
                                            {
                                                if (eachObject is string)
                                                {
                                                    termList1_.Add(new StringTerm(eachObject as string));
                                                }
                                                else
                                                {
                                                    List <WME> clist = createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                    cliteralList.AddRange(clist);
                                                }
                                            }
                                            if (termList1_.Count > 0)
                                            {
                                                //FuncTerm functerm_ = new FuncTerm("list", termList1_);
                                                //termlist.Add(functerm_);
                                            }

                                            //												foreach (object eachObject in (IEnumerable) objProp)
                                            //												{
                                            //													List<WME> clist = this.createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                            //													cliteralList.addCLiteralList(clist);
                                            //												}
                                        }
                                        else
                                        {
                                            foreach (object eachObject in (IEnumerable)objProp)
                                            {
                                                List <WME> clist =
                                                    createFactSetFromObjectInstance(eachObject, objectmaptable, objProp);
                                                cliteralList.AddRange(clist);
                                            }
                                        }
                                    }

                                    if (bAddObjectTerm)
                                    {
                                        termlist.Add(new ObjectTerm(objProp));
                                    }
                                    List <WME> newList = createFactSetFromObjectInstance(objProp, objectmaptable);
                                    cliteralList.AddRange(newList);
                                    break;
                                } //end switch
                            }     // end if prop null
                        }         //end foreach eachpred
                    }             //end foreach mapping

                    #endregion

                    cliteralList.Add(cliteral);
                } //if (mappedPredicateNames.Count > 0)
            }     //if (objectmaptable != null)
            else
            {
                #region build cliterals without an object mapping

                return(createFactSetObjectInstanceWithObjectGrapher(obj));

                #endregion
            } //else
            if (CaptureDataValues)
            {
                WriteDataValues(_LogFile + "." + obj.GetType().FullName, cliteralList.ToString());
            }
            return(cliteralList);
        }
Esempio n. 10
0
        public void TestAddWME()
        {
            WME wme = new WME();
            wme.Fields[0] = "x";
            wme.Fields[1] = "y";
            wme.Fields[2] = "z";

            Rete am = new Rete();
            am.AddWME(wme);
        }
Esempio n. 11
0
        public void ListTest2()
        {
            Production prod = new Production();

            prod.Label = "ListTest";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");
            Variable l = new Variable("l");
            Variable v = new Variable("v");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            prod.AddConditionToLHS(new PositiveCondition("C4", x, "has virtue", l));
            prod.AddConditionToLHS(new PositiveCondition("C5", "virtues", "virtueList", v));
            prod.AddConditionToLHS(new FunctionCondition("C6", l, new FuncTerm("isInList", new isInList()), v));

            AssertCondition rhs = new AssertCondition("R1", x, "is", "good");

            rhs.ConditionType = ConditionType.Assert;

            prod.AddConditionToRHS(rhs);

            Agenda agenda = new Agenda();

            agenda.ConflictResolutionStrategy = new SalienceResolver();
            agenda.AddProduction(prod);


            WME v1 = new WME("V1", "B1", "has virtue", "Calm");

            agenda.AddFact(v1);

            WME v2 = new WME("V2", "virtues", "virtueList", new string[] { "Calm", "Cool", "Collected" });

            agenda.AddFact(v2);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\ListTest2.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Rule did not fire.");
            Assert.IsTrue(agenda.InferredFacts.Count == 1, "Bad");
        }
Esempio n. 12
0
        public void GiveBestDiscount()
        {
            Agenda agenda = new Agenda();
            agenda.ConflictResolutionStrategy = new SalienceResolver();

            Variable customer = new Variable("customer");
            Variable purchases = new Variable("purchases");
            Variable discount = new Variable("discount");

            Production SilverCustomer = new Production("Silver Customer");
            SilverCustomer.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            SilverCustomer.AddConditionToLHS(new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 10));
            SilverCustomer.AddConditionToRHS(new AssertCondition("R1", customer, "is", "silver"));
            agenda.AddProduction(SilverCustomer);

            Production GoldCustomer = new Production("Gold Customer");
            GoldCustomer.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            GoldCustomer.AddConditionToLHS(new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 25));
            GoldCustomer.AddConditionToRHS(new AssertCondition("R1", customer, "is", "gold"));
            agenda.AddProduction(GoldCustomer);

            Production PlatinumCustomer = new Production("Platinum Customer");
            PlatinumCustomer.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            PlatinumCustomer.AddConditionToLHS(new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 50));
            PlatinumCustomer.AddConditionToRHS(new AssertCondition("R1", customer, "is", "platinum"));
            agenda.AddProduction(PlatinumCustomer);

            Production SilverDiscount = new Production("Silver Discount");
            SilverDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "is", "silver"));
            SilverDiscount.AddConditionToRHS(new AssertCondition("R1", customer, "give discount", 5));
            agenda.AddProduction(SilverDiscount);

            Production GoldDiscount = new Production("Gold Discount");
            GoldDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "is", "gold"));
            GoldDiscount.AddConditionToRHS(new AssertCondition("R1", customer, "give discount", 10));
            agenda.AddProduction(GoldDiscount);

            Production PlatinumDiscount = new Production("Platinum Discount");
            PlatinumDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "is", "platinum"));
            PlatinumDiscount.AddConditionToRHS(new AssertCondition("R1", customer, "give discount", 15));
            agenda.AddProduction(PlatinumDiscount);

            Mutex BestDiscount = new Mutex("Best Discount");
            //BestDiscount.AddAggregator(new Max(), customer, new StringTerm("give discount"), discount);
            BestDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "give discount", discount));
            //BestDiscount.AddConditionToLHS(new condition("C2", ConditionType.Function, customer, "funcMax", discount));
            BestDiscount.AddConditionToRHS(new InvokeCondition("R1", customer, "Customer.GiveDiscount", discount));
            //BestDiscount.AddEvaluator(new Max(), customer, new StringTerm("give discount"), discount);
            BestDiscount.Evaluator = new Max(customer, new StringTerm("give discount"), discount);
            agenda.AddMutex(BestDiscount);

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "joe";
            wme1.Fields[1] = "purchases";
            wme1.Fields[2] = "1";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "ted";
            wme2.Fields[1] = "purchases";
            wme2.Fields[2] = "10";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "ed";
            wme3.Fields[1] = "purchases";
            wme3.Fields[2] = "11";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "phil";
            wme4.Fields[1] = "purchases";
            wme4.Fields[2] = "18";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "mary";
            wme5.Fields[1] = "purchases";
            wme5.Fields[2] = "22";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "jane";
            wme6.Fields[1] = "purchases";
            wme6.Fields[2] = "25";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "fred";
            wme7.Fields[1] = "purchases";
            wme7.Fields[2] = "50";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "harry";
            wme8.Fields[1] = "purchases";
            wme8.Fields[2] = "55";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "jon";
            wme9.Fields[1] = "purchases";
            wme9.Fields[2] = "99";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\GiveBestDiscount.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 5, "Rule did not fire.");
            Assert.IsTrue(agenda.InferredFacts.Count == 21, "Bad");
            Assert.IsTrue(BestDiscount.InferredFacts.Count == 7, "Bad");
        }
Esempio n. 13
0
        public void BasicMetaTest()
        {
            Agenda agenda = new Agenda();
            agenda.ConflictResolutionStrategy = new SalienceResolver();

            Production prod = new Production();
            prod.Label = "Gold Customer";
            Variable customer = new Variable("customer");
            Variable purchases = new Variable("purchases");
            //Variable y = new Variable("y");
            //Variable x = new Variable("x");

            prod.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            FunctionCondition gt = new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 10);
            gt.ConditionType = ConditionType.Function;
            prod.AddConditionToLHS(gt);
            AssertCondition rhs = new AssertCondition("R1", customer, "is", "gold");
            rhs.ConditionType = ConditionType.Assert;
            prod.AddConditionToRHS(rhs);
            agenda.AddProduction(prod);

            Production prod1 = new Production();
            prod1.Label = "Platinum Customer";

            prod1.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            FunctionCondition gt1 = new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 20);
            gt1.ConditionType = ConditionType.Function;
            prod1.AddConditionToLHS(gt1);
            AssertCondition rhs1 = new AssertCondition("R1", customer, "is", "Platinum");
            rhs1.ConditionType = ConditionType.Assert;
            prod1.AddConditionToRHS(rhs1);
            agenda.AddProduction(prod1);

            //production mut = new production();
            //mut.label = "mutex";
            //mut.AddConditionToLHS(new condition("C1", customer, "is", "Platinum"));
            //mut.AddConditionToLHS(new condition("C2", customer, "is", "gold"));

            //condition gtx = new condition("C3", y, "funcNotEquals", x);
            //gt1.ConditionType = ConditionType.Function;
            ////prod1.AddConditionToLHS(gtx);
            //condition rhsx = new condition("R1", customer, "is", "Platinum");
            //rhs1.ConditionType = ConditionType.Assert;
            //prod1.AddConditionToRHS(rhsx);
            //agenda.AddProduction(mut);

            //agenda.AddMutexNode(prod, new condition("R1", customer, "is", "gold"), prod1, new condition("R1", customer, "is", "Platinum"), new NotEquals());

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "joe";
            wme1.Fields[1] = "purchases";
            wme1.Fields[2] = "1";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "ted";
            wme2.Fields[1] = "purchases";
            wme2.Fields[2] = "10";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "ed";
            wme3.Fields[1] = "purchases";
            wme3.Fields[2] = "11";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "phil";
            wme4.Fields[1] = "purchases";
            wme4.Fields[2] = "18";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "mary";
            wme5.Fields[1] = "purchases";
            wme5.Fields[2] = "22";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "jane";
            wme6.Fields[1] = "purchases";
            wme6.Fields[2] = "25";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "fred";
            wme7.Fields[1] = "purchases";
            wme7.Fields[2] = "50";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "harry";
            wme8.Fields[1] = "purchases";
            wme8.Fields[2] = "55";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "jon";
            wme9.Fields[1] = "purchases";
            wme9.Fields[2] = "99";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\BasicOverrideTest.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 2, "Rule did not fire.");
            Assert.IsTrue(agenda.InferredFacts.Count == 12, "Bad");
        }
Esempio n. 14
0
        public void TestAddProduction()
        {
            Production prod = new Production();

            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            prod.AddConditionToRHS(new AssertCondition("C4", x, "is", "on top"));

            Rete rete = new Rete();

            rete.AddProduction(prod);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            NetworkPrinter printer = new NetworkPrinter();

            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\TestAddProduction - 1.log", false))
            {
                writer.Write(printer.Output);
                writer.Flush();
            }

            //Assert.IsTrue(rete.RulesThatFired.Count == 1, "Rule did not fire.");
            Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");
            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
        }
Esempio n. 15
0
        public void MultiBuiltinTest()
        {
            Production prod = new Production();
            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            //Variable z = new Variable("z");
            Variable c = new Variable("c");
            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            //prod.AddConditionToLHS(new condition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", x, "color", c));

            FunctionCondition funCond = new FunctionCondition("F4", c, new FuncTerm("funcNotEquals", new funcNotEquals()), new StringTerm("blue"));
            funCond.ConditionType = ConditionType.Function;
            prod.AddConditionToLHS(funCond);

            prod.AddConditionToRHS(new AssertCondition("C4", x, "is", c));

            Rete rete = new Rete();
            rete.AddProduction(prod);

            NetworkPrinter printer = new NetworkPrinter();
            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\MultiBuiltinTest.log", false))
            {
                writer.Write(printer.Output);
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine("-----------------------------------------------");
                writer.Flush();
            }

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            printer = new NetworkPrinter();
            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\MultiBuiltinTest.log", true))
            {
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine();
                writer.WriteLine();
                writer.Write(printer.Output);
                writer.Flush();
            }

            //Assert.IsTrue(rete.RulesThatFired.Count == 1, "Rule did not fire.");
            Assert.IsTrue(prod.InferredFacts.Count == 2, "Wrong number of InferredFacts");
            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
        }
Esempio n. 16
0
        public void ReteWithHash()
        {
            Production prod = new Production();

            prod.Label = "ReteWithHash";
            Variable a = new Variable("a");
            Variable b = new Variable("b");
            Variable c = new Variable("c");
            Variable d = new Variable("d");
            Variable s = new Variable("s");

            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            prod.AddConditionToLHS(new PositiveCondition("C4", a, "color", "maize"));
            prod.AddConditionToLHS(new PositiveCondition("C5", b, "color", "blue"));
            prod.AddConditionToLHS(new PositiveCondition("C6", c, "color", "green"));
            prod.AddConditionToLHS(new PositiveCondition("C7", d, "color", "white"));
            prod.AddConditionToLHS(new PositiveCondition("C8", s, "on", "table"));
            prod.AddConditionToLHS(new PositiveCondition("C9", z, a, b));
            prod.AddConditionToLHS(new PositiveCondition("C10", a, "left of", d));

            prod.AddConditionToRHS(new AssertCondition("C4", x, "is", "on top"));

            Rete rete = new Rete();

            rete.AddProduction(prod);

            NetworkPrinter printer = new NetworkPrinter();

            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\ReteWithHash-Pre.log", false))
            {
                writer.Write(printer.Output);
                writer.Flush();
            }

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            printer = new NetworkPrinter();
            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\ReteWithHash.log", false))
            {
                writer.Write(printer.Output);
                writer.Flush();
            }

            Assert.IsTrue(prod.InferredFacts.Count == 0, "Wrong number of conclusions");
        }
Esempio n. 17
0
        public void NegativeConditionTest()
        {
            Production prod = new Production();
            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");
            //Variable c = new Variable("c");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            //prod.AddConditionToLHS(new condition("C3", z, "color", c));

            NegativeCondition neg = new NegativeCondition("C3", z, "color", "blue");
            neg.ConditionType = ConditionType.Negative;
            //neg.IsPositive = false;
            //neg.IsNegative = true;
            prod.AddConditionToLHS(neg);

            AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");
            rhs.ConditionType = ConditionType.Assert;

            prod.AddConditionToRHS(rhs);

            Rete rete = new Rete();
            rete.AddProduction(prod);

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            //WME wme10 = new WME("W10");
            //wme10.fields[0] = "B4";
            //wme10.fields[1] = "color";
            //wme10.fields[2] = "green";
            //rete.add_wme(wme10);

            //rete_node dummy = rete.DummyTopNode;

            NetworkPrinter printer = new NetworkPrinter();
            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\NegativeConditionTest.log", false))
            {
                writer.Write(printer.Output);
                writer.Flush();
            }

            //Assert.IsTrue(rete.RulesThatFired.Count == 1, "Rule did not fire.");
            Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");
            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
        }
Esempio n. 18
0
        public void RemoveProduction()
        {
            Production prod = new Production();

            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");

            rhs.ConditionType = ConditionType.Assert;

            prod.AddConditionToRHS(rhs);
            Rete rete = new Rete();

            rete.AddProduction(prod);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");

            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");

            rete.RemoveProduction(prod);

            Assert.IsTrue(prod.InferredFacts.Count == 0, "Wrong number of conclusions");

            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");
        }
Esempio n. 19
0
        public void RemoveWME()
        {
            Production prod = new Production();
            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");
            rhs.ConditionType = ConditionType.Assert;

            prod.AddConditionToRHS(rhs);
            Rete rete = new Rete();

            rete.AddProduction(prod);

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");

            Assert.IsTrue(rete.WorkingMemory.Count == 9, "Bad");

            rete.RemoveWME(wme9);

            Assert.IsTrue(prod.InferredFacts.Count == 0, "Wrong number of conclusions");

            Assert.IsTrue(rete.WorkingMemory.Count == 8, "Bad");
        }
Esempio n. 20
0
 /// <summary>
 /// Called when [WME] is visited.
 /// </summary>
 /// <param name="wme">The wme.</param>
 public override void OnWME(WME wme)
 {
     _sb.AppendLine(wme.ToString());
 }
Esempio n. 21
0
        public void ReteWithHash()
        {
            Production prod = new Production();
            prod.Label = "ReteWithHash";
            Variable a = new Variable("a");
            Variable b = new Variable("b");
            Variable c = new Variable("c");
            Variable d = new Variable("d");
            Variable s = new Variable("s");

            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            prod.AddConditionToLHS(new PositiveCondition("C4", a, "color", "maize"));
            prod.AddConditionToLHS(new PositiveCondition("C5", b, "color", "blue"));
            prod.AddConditionToLHS(new PositiveCondition("C6", c, "color", "green"));
            prod.AddConditionToLHS(new PositiveCondition("C7", d, "color", "white"));
            prod.AddConditionToLHS(new PositiveCondition("C8", s, "on", "table"));
            prod.AddConditionToLHS(new PositiveCondition("C9", z, a, b));
            prod.AddConditionToLHS(new PositiveCondition("C10", a, "left of", d));

            prod.AddConditionToRHS(new AssertCondition("C4", x, "is", "on top"));

            Rete rete = new Rete();
            rete.AddProduction(prod);

            NetworkPrinter printer = new NetworkPrinter();
            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\ReteWithHash-Pre.log", false))
            {
                writer.Write(printer.Output);
                writer.Flush();
            }

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            printer = new NetworkPrinter();
            rete.DummyTopNode.Accept(printer);

            using (StreamWriter writer = new StreamWriter(@"C:\Temp\ReteWithHash.log", false))
            {
                writer.Write(printer.Output);
                writer.Flush();
            }

            Assert.IsTrue(prod.InferredFacts.Count == 0, "Wrong number of conclusions");
        }
 /// <summary>
 /// Called when [WME] is visited.
 /// </summary>
 /// <param name="wme">The wme.</param>
 public override void OnWME(WME wme)
 {
     _sb.AppendLine(wme.ToString());
 }
Esempio n. 23
0
        public void Test4pointsTo1()
        {
            Production prod = new Production();
            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));
            prod.AddConditionToLHS(new PositiveCondition("C4", x, "has", "car"));
            prod.AddConditionToLHS(new PositiveCondition("C5", x, "wants", z));
            prod.AddConditionToRHS(new AssertCondition("C5", x, "gets", z));
            Rete rete = new Rete();

            rete.AddProduction(prod);

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            rete.AddWME(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            rete.AddWME(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            rete.AddWME(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            rete.AddWME(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            rete.AddWME(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            rete.AddWME(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            rete.AddWME(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            rete.AddWME(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            rete.AddWME(wme9);

            WME wme10 = new WME("W10");
            wme10.Fields[0] = "B2";
            wme10.Fields[1] = "has";
            wme10.Fields[2] = "bike";
            rete.AddWME(wme10);

            WME wme11 = new WME("W11");
            wme11.Fields[0] = "B1";
            wme11.Fields[1] = "has";
            wme11.Fields[2] = "car";
            rete.AddWME(wme11);

            WME wme12 = new WME("W12");
            wme12.Fields[0] = "B1";
            wme12.Fields[1] = "wants";
            wme12.Fields[2] = "B3";
            rete.AddWME(wme12);

            //Assert.IsTrue(rete.RulesThatFired.Count == 1, "Rule did not fire.");
            Assert.IsTrue(prod.InferredFacts.Count == 1, "Wrong number of conclusions");
            Assert.IsTrue(rete.WorkingMemory.Count == 12, "Bad");
        }
Esempio n. 24
0
        public void TestAddProduction()
        {
            Production prod = new Production();
            prod.Label = "find-stack-of-two-blocks-to-the-left-of-a-red-block";
            Variable x = new Variable("x");
            Variable y = new Variable("y");
            Variable z = new Variable("z");

            prod.AddConditionToLHS(new PositiveCondition("C1", x, "on", y));
            prod.AddConditionToLHS(new PositiveCondition("C2", y, "left of", z));
            prod.AddConditionToLHS(new PositiveCondition("C3", z, "color", "red"));

            AssertCondition rhs = new AssertCondition("C4", x, "is", "on top");
            rhs.ConditionType = ConditionType.Assert;

            prod.AddConditionToRHS(rhs);

            Agenda agenda = new Agenda();
            agenda.ConflictResolutionStrategy = new SalienceResolver();
            agenda.AddProduction(prod);

            WME wme1 = new WME("W1");
            wme1.Fields[0] = "B1";
            wme1.Fields[1] = "on";
            wme1.Fields[2] = "B2";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");
            wme2.Fields[0] = "B1";
            wme2.Fields[1] = "on";
            wme2.Fields[2] = "B3";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");
            wme3.Fields[0] = "B1";
            wme3.Fields[1] = "color";
            wme3.Fields[2] = "red";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");
            wme4.Fields[0] = "B2";
            wme4.Fields[1] = "on";
            wme4.Fields[2] = "table";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");
            wme5.Fields[0] = "B2";
            wme5.Fields[1] = "left of";
            wme5.Fields[2] = "B3";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");
            wme6.Fields[0] = "B2";
            wme6.Fields[1] = "color";
            wme6.Fields[2] = "blue";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");
            wme7.Fields[0] = "B3";
            wme7.Fields[1] = "left of";
            wme7.Fields[2] = "B4";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");
            wme8.Fields[0] = "B3";
            wme8.Fields[1] = "on";
            wme8.Fields[2] = "table";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");
            wme9.Fields[0] = "B3";
            wme9.Fields[1] = "color";
            wme9.Fields[2] = "red";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\TestAgenda.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 1, "Rule did not fire.");
            Assert.IsTrue(agenda.InferredFacts.Count == 1, "Bad");
        }
Esempio n. 25
0
        public void GiveBestDiscount()
        {
            Agenda agenda = new Agenda();

            agenda.ConflictResolutionStrategy = new SalienceResolver();


            Variable customer  = new Variable("customer");
            Variable purchases = new Variable("purchases");
            Variable discount  = new Variable("discount");

            Production SilverCustomer = new Production("Silver Customer");

            SilverCustomer.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            SilverCustomer.AddConditionToLHS(new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 10));
            SilverCustomer.AddConditionToRHS(new AssertCondition("R1", customer, "is", "silver"));
            agenda.AddProduction(SilverCustomer);

            Production GoldCustomer = new Production("Gold Customer");

            GoldCustomer.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            GoldCustomer.AddConditionToLHS(new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 25));
            GoldCustomer.AddConditionToRHS(new AssertCondition("R1", customer, "is", "gold"));
            agenda.AddProduction(GoldCustomer);

            Production PlatinumCustomer = new Production("Platinum Customer");

            PlatinumCustomer.AddConditionToLHS(new PositiveCondition("C1", customer, "purchases", purchases));
            PlatinumCustomer.AddConditionToLHS(new FunctionCondition("C2", purchases, new FuncTerm("funcGreaterThan", new funcGreaterThan()), 50));
            PlatinumCustomer.AddConditionToRHS(new AssertCondition("R1", customer, "is", "platinum"));
            agenda.AddProduction(PlatinumCustomer);

            Production SilverDiscount = new Production("Silver Discount");

            SilverDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "is", "silver"));
            SilverDiscount.AddConditionToRHS(new AssertCondition("R1", customer, "give discount", 5));
            agenda.AddProduction(SilverDiscount);

            Production GoldDiscount = new Production("Gold Discount");

            GoldDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "is", "gold"));
            GoldDiscount.AddConditionToRHS(new AssertCondition("R1", customer, "give discount", 10));
            agenda.AddProduction(GoldDiscount);

            Production PlatinumDiscount = new Production("Platinum Discount");

            PlatinumDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "is", "platinum"));
            PlatinumDiscount.AddConditionToRHS(new AssertCondition("R1", customer, "give discount", 15));
            agenda.AddProduction(PlatinumDiscount);

            Mutex BestDiscount = new Mutex("Best Discount");

            //BestDiscount.AddAggregator(new Max(), customer, new StringTerm("give discount"), discount);
            BestDiscount.AddConditionToLHS(new PositiveCondition("C1", customer, "give discount", discount));
            //BestDiscount.AddConditionToLHS(new condition("C2", ConditionType.Function, customer, "funcMax", discount));
            BestDiscount.AddConditionToRHS(new InvokeCondition("R1", customer, "Customer.GiveDiscount", discount));
            //BestDiscount.AddEvaluator(new Max(), customer, new StringTerm("give discount"), discount);
            BestDiscount.Evaluator = new Max(customer, new StringTerm("give discount"), discount);
            agenda.AddMutex(BestDiscount);

            WME wme1 = new WME("W1");

            wme1.Fields[0] = "joe";
            wme1.Fields[1] = "purchases";
            wme1.Fields[2] = "1";
            agenda.AddFact(wme1);

            WME wme2 = new WME("W2");

            wme2.Fields[0] = "ted";
            wme2.Fields[1] = "purchases";
            wme2.Fields[2] = "10";
            agenda.AddFact(wme2);

            WME wme3 = new WME("W3");

            wme3.Fields[0] = "ed";
            wme3.Fields[1] = "purchases";
            wme3.Fields[2] = "11";
            agenda.AddFact(wme3);

            WME wme4 = new WME("W4");

            wme4.Fields[0] = "phil";
            wme4.Fields[1] = "purchases";
            wme4.Fields[2] = "18";
            agenda.AddFact(wme4);

            WME wme5 = new WME("W5");

            wme5.Fields[0] = "mary";
            wme5.Fields[1] = "purchases";
            wme5.Fields[2] = "22";
            agenda.AddFact(wme5);

            WME wme6 = new WME("W6");

            wme6.Fields[0] = "jane";
            wme6.Fields[1] = "purchases";
            wme6.Fields[2] = "25";
            agenda.AddFact(wme6);

            WME wme7 = new WME("W7");

            wme7.Fields[0] = "fred";
            wme7.Fields[1] = "purchases";
            wme7.Fields[2] = "50";
            agenda.AddFact(wme7);

            WME wme8 = new WME("W8");

            wme8.Fields[0] = "harry";
            wme8.Fields[1] = "purchases";
            wme8.Fields[2] = "55";
            agenda.AddFact(wme8);

            WME wme9 = new WME("W9");

            wme9.Fields[0] = "jon";
            wme9.Fields[1] = "purchases";
            wme9.Fields[2] = "99";
            agenda.AddFact(wme9);

            agenda.Run();

            agenda.VisualizeNetworkToFile(@"C:\Temp\GiveBestDiscount.log", false);

            Assert.IsTrue(agenda.ActivatedRuleCount == 5, "Rule did not fire.");
            Assert.IsTrue(agenda.InferredFacts.Count == 21, "Bad");
            Assert.IsTrue(BestDiscount.InferredFacts.Count == 7, "Bad");
        }