Пример #1
0
        public void Process(NewFactEvent nfh, NewFactEvent dfh, NewFactEvent mfh)
        {
            ie.NewFactHandler    += nfh;
            ie.DeleteFactHandler += dfh;
            ie.ModifyFactHandler += mfh;

            if (ie.BinderType != null)
            {
                ie.Process(new Hashtable());
            }
            else
            {
                ie.Process();
            }

            ie.DeleteFactHandler -= dfh;
            ie.NewFactHandler    -= nfh;
        }
Пример #2
0
        private void RunTestBinderEvents(IInferenceEngine ie)
        {
            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "events-test.ruleml",
                                                          FileAccess.Read));

            Hashtable bo = new Hashtable();

            bo.Add("ASSERTED", new ArrayList());
            bo.Add("RETRACTED", new ArrayList());
            bo.Add("MODIFIED", new ArrayList());

            ie.Process(bo);

            Assert.AreEqual(2, ((ArrayList)bo["ASSERTED"]).Count, "Count Asserted");
            Assert.IsTrue(Misc.IListToString((ArrayList)bo["ASSERTED"]).Contains("toAssert{whatever}"), "Asserted Right");

            Assert.AreEqual(1, ((ArrayList)bo["RETRACTED"]).Count, "Count Retracted");
            Assert.AreEqual("toRetract{whatever}", ((ArrayList)bo["RETRACTED"])[0].ToString(), "Retracted Right");

            Assert.AreEqual(2, ((ArrayList)bo["MODIFIED"]).Count, "Count Modified");
            Assert.AreEqual("toModify{whatever}", ((ArrayList)bo["MODIFIED"])[0].ToString(), "Modified From Right");
            Assert.AreEqual("toModify{done}", ((ArrayList)bo["MODIFIED"])[1].ToString(), "Modified To Right");
        }
Пример #3
0
        public void Run()
        {
            // prepare some dummy data
            Hashtable businessObjects = new Hashtable();
            ArrayList callData        = DummyData.GetInstance().GetBusinessObjects(nbDodecaCalls);

            businessObjects.Add("CALLSDATA", callData);

            // process this data
            Console.WriteLine("Using RuleBase: {0}", ie.Label);
            long iniTime = DateTime.Now.Ticks;

            ie.Process(businessObjects);
            Console.WriteLine("{0} Calls processed in: {1} milliseconds",
                              12 * nbDodecaCalls,
                              (int)(DateTime.Now.Ticks - iniTime) / 10000);

            // ensure the engine is rating correctly
            foreach (CallData cd in callData)
            {
                cd.CheckValidity();
            }
        }
Пример #4
0
        private void RunTestBinderEvents(IInferenceEngine ie)
        {
            ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFilesFolder + "events-test.ruleml",
                                                   	 FileAccess.Read));

            //ie.LogHandlers += new DispatchLog(ShowAllLogs);
              Hashtable bo = new Hashtable();
              bo.Add("ASSERTED", new ArrayList());
              bo.Add("RETRACTED", new ArrayList());
              bo.Add("MODIFIED", new ArrayList());

              ie.Process(bo);

            Assert.AreEqual(1, ((ArrayList)bo["ASSERTED"]).Count, "Count Asserted");
            Assert.AreEqual("toAssert{whatever}", ((ArrayList)bo["ASSERTED"])[0].ToString(), "Asserted Right");

            Assert.AreEqual(1, ((ArrayList)bo["RETRACTED"]).Count, "Count Retracted");
            Assert.AreEqual("toRetract{whatever}", ((ArrayList)bo["RETRACTED"])[0].ToString(), "Retracted Right");

            Assert.AreEqual(2, ((ArrayList)bo["MODIFIED"]).Count, "Count Modified");
            Assert.AreEqual("toModify{whatever}", ((ArrayList)bo["MODIFIED"])[0].ToString(), "Modified From Right");
            Assert.AreEqual("toModify{done}", ((ArrayList)bo["MODIFIED"])[1].ToString(), "Modified To Right");
        }
Пример #5
0
 protected void Process()
 {
     PreProcess();
     ie.Process();
 }
Пример #6
0
            public void Run()
            {
                mc.threadMap.Add(Thread.CurrentThread, stresserID);

                //Console.WriteLine("Stresser {0} Starting...", stresserID);

                try {
                    while (mc.running)
                    {
                        mc.hits++;
                        bumps++;
                        a = mc.rnd.Next(1, 1 + LIMIT);
                        b = mc.rnd.Next(1, 1 + LIMIT);

                        ie.NewWorkingMemory(WorkingMemoryTypes.Isolated);

                        if ((ie.Label != "subtract") && (binder))
                        {
                            Hashtable bo = new Hashtable();
                            bo.Add(ie.Label + "-a", a);
                            bo.Add(ie.Label + "-b", b);
                            ie.Process(bo);
                        }
                        else
                        {
                            ie.Assert(new Fact("values", new Individual(a), new Individual(b)));
                            ie.Process();
                        }

                        if (ie.FactsCount != 2)
                        {
                            throw new Exception("Got wrong fact count: " + ie.FactsCount);
                        }
                        result = (int)ie.GetFact("result").GetPredicateValue(0);

                        if (((ie.Label == "multiply") && (result != (7 + a * b))) ||
                            ((ie.Label == "add") && (result != (3 + a + b))) ||
                            ((ie.Label == "subtract") && (result != (11 + a - b))))
                        {
                            mc.errors++;
                            //Console.Write("[{0}?{1}={2}:{3}]  ", a, b, result, ie.Label);
                        }
                        else
                        if ((ie.Label != "multiply") && (ie.Label != "add") && (ie.Label != "subtract"))
                        {
                            throw new Exception("Unknown label: " + ie.Label);
                        }

                        if (HOT_SWAP)
                        {
                            ie.DisposeIsolatedMemory();
                        }
                    }

                    if ((switched) && (ie.Label == RULES[0]))
                    {
                        throw new Exception("Thread should have switched, but is still: " + ie.Label);
                    }

                    //Console.WriteLine("Stresser {0} Stopped (bumps: {3} - label:{2})", stresserID, switched, ie.Label, bumps);
                } catch (Exception e) {
                    mc.errors++;
                    Console.WriteLine("Stresser {0} Dead (bumps: {2} - ActiveRule:{3} - label:{4})", stresserID, switched, bumps, ActiveRule, ie.Label);
                    Console.WriteLine(e);
                }
            }