Exemplo n.º 1
0
 public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
 {
     int count = 0;
     if (params_Renamed != null && params_Renamed.Length == 1)
     {
         int fc = params_Renamed[0].IntValue;
         try
         {
             count = engine.fire(fc);
         }
         catch (ExecuteException e)
         {
             Trace.WriteLine(e.Message);
         }
     }
     else
     {
         count = engine.fire();
     }
     // engine.writeMessage(String.valueOf(count) + Constants.LINEBREAK,"t");
     DefaultReturnVector ret = new DefaultReturnVector();
     DefaultReturnValue rv = new DefaultReturnValue(Constants.INTEGER_OBJECT, count);
     ret.addReturnValue(rv);
     return ret;
 }
Exemplo n.º 2
0
        public void ObjectBindingTest1()
        {
            long ts = DateTime.Now.Ticks;
            int fired = 0;
            int activations = 0;
            using (TextWriter writer = Console.Out)
            {
                Rete engine = new Rete();
                engine.Watch = WatchType.WATCH_ALL;
                engine.addPrintWriter("Console", writer);
                engine.declareObject(typeof (Account), "Account");
                engine.loadRuleset(getRule1());
                engine.assertObject(GetAcct0(), "Account", false, false);
                activations = engine.CurrentFocus.ActivationCount;
                fired = engine.fire();
                engine.printWorkingMemory(true, false);

            double endTime = DateTime.Now.Ticks - ts;
            Console.WriteLine(String.Format("ObjectBindingTest1 completed in {0} seconds.", (endTime/10000000).ToString("0.000000")));
                writer.Flush();
                writer.Close();
                engine.close();
            }

            Assert.IsTrue(fired == 1);
            Assert.IsTrue(activations == 1);
            //AppDomain.Unload(AppDomain.CurrentDomain);
        }
Exemplo n.º 3
0
        public void BasicObjectBindingTest1()
        {
            long ts = DateTime.Now.Ticks;
            int fired = 0;
            int activations = 0;
            Basic basic = new Basic("one", 1);
            using (TextWriter writer = Console.Out)
            {
                Rete engine = new Rete();
                engine.Watch = WatchType.WATCH_ALL;
                engine.addPrintWriter("Console", writer);
                engine.declareObject(typeof (Basic), "Basic");
                engine.loadRuleset(getRule3());

                foreach (Defrule rule in  engine.CurrentFocus.AllRules)
                {
                    Console.WriteLine(rule.toPPString());
                }

                engine.assertObject(basic, "Basic", false, false);
                activations = engine.CurrentFocus.ActivationCount;
                fired = engine.fire();
                engine.printWorkingMemory(true, false);
            double endTime = DateTime.Now.Ticks - ts;
            Console.WriteLine(String.Format("BasicObjectBindingTest1 completed in {0} seconds.", (endTime/10000000).ToString("0.000000")));
                writer.Flush();
                writer.Close();
                engine.close();
            }

            Assert.IsTrue(fired == 1);
            Assert.IsTrue(activations == 1);
            //AppDomain.Unload(AppDomain.CurrentDomain);
        }
Exemplo n.º 4
0
 public void testAssertTwoObjects()
 {
     Console.WriteLine("start testAssertTwoObjects");
     Rete engine = new Rete();
     engine.declareObject(typeof (Account));
     engine.declareObject(typeof (TestBean3));
     Assert.IsNotNull(engine);
     // create instance of Account
     Account acc1 = new Account();
     acc1.AccountId = "1234";
     acc1.AccountType = "new";
     acc1.First = "fName";
     acc1.Last = "lName";
     acc1.Middle = "m";
     acc1.OfficeCode = "MA";
     acc1.RegionCode = "NE";
     acc1.Status = "active";
     acc1.Title = "MR";
     acc1.Username = "******";
     // create instance of TestBean3
     TestBean3 b = new TestBean3();
     b.Count = 3;
     b.Float = 10000;
     try
     {
         long start = DateTime.Now.Ticks;
         engine.assertObject(acc1, null, false, true);
         int count = engine.ObjectCount;
         engine.assertObject(b, null, false, true);
         int count2 = engine.ObjectCount;
         long end = DateTime.Now.Ticks;
         int fired = engine.fire();
         Assert.IsTrue(true);
         Assert.IsTrue(true);
         Assert.AreEqual(1, count);
         Assert.AreEqual(2, count2);
         Console.WriteLine("Number of facts: " + count);
         Console.WriteLine("Number of facts: " + count2);
         Console.WriteLine("ET: " + (end - start) + " ns");
         double el = ((double) end - (double) start)/100000;
         Console.WriteLine("ET: " + el + " ms");
     }
     catch (AssertException e)
     {
         Console.WriteLine(e.Message);
     }
 }
Exemplo n.º 5
0
        public void MainTest()
        {
            String rulefile = getRoot("account_5.clp");

            ArrayList objects = new ArrayList();
            //AssertWRules awr = new AssertWRules();

            // Runtime rt = Runtime.getRuntime();
            long total1 = GC.GetTotalMemory(true);
            //long free1 = rt.freeMemory();
            //long used1 = total1 - free1;
            int count = 5000;
            Console.WriteLine("loading file " + rulefile);
            Console.WriteLine("Used memory before creating objects " + total1 + " bytes " +
                              (total1/1024) + " Kb");
            for (int idx = 0; idx < count; idx++)
            {
                Account acc = new Account();
                acc.AccountId = "acc" + idx;
                // acc.setAccountId("acc" + ran.Next(4));
                acc.AccountType = "standard";
                acc.First = Convert.ToString(ran.Next(100000));
                acc.Last = Convert.ToString(ran.Next(100000));
                acc.Middle = Convert.ToString(ran.Next(100000));
                acc.OfficeCode = Convert.ToString(ran.Next(100000));
                acc.RegionCode = Convert.ToString(ran.Next(100000));
                acc.Status = "active";
                acc.Title = "mr";
                acc.Username = Convert.ToString(ran.Next(100000));
                acc.AreaCode = Convert.ToString(ran.Next(999));
                acc.Exchange = Convert.ToString(ran.Next(999));
                acc.Number = Convert.ToString(ran.Next(999));
                acc.Ext = Convert.ToString(ran.Next(9999));
                objects.Add(acc);
            }
            long total2 = GC.GetTotalMemory(true);
            //long free2 = rt.freeMemory();
            //long used2 = total2 - free2;
            Console.WriteLine("Used memory after creating objects " + total2 + " bytes " +
                              (total2/1024) + " Kb " + (total2/1024/1024) + " Mb");
            int loop = 5;
            long ETTotal = 0;
            for (int idx = 0; idx < loop; idx++)
            {
                Rete engine = new Rete();
                engine.declareObject(typeof (Account), "Account");

                try
                {
                    StreamReader freader = new StreamReader(rulefile);
                    CLIPSParser parser = new CLIPSParser(engine, freader);
                    //Object item = null;
                    ArrayList list = new ArrayList();
                    long start = DateTime.Now.Ticks;
                    parse(engine, parser, list);
                    long end = DateTime.Now.Ticks;
                    long el = end - start;
                    // parser.close();
                    //rt.gc();
                    Console.WriteLine("time to parse rules " + el + " ms");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                IEnumerator itr = objects.GetEnumerator();
                long start2 = DateTime.Now.Ticks;
                try
                {
                    while (itr.MoveNext())
                    {
                        engine.assertObject(itr.Current, "Account", false, false);
                    }
                }
                catch (AssertException e)
                {
                    Console.WriteLine(e.Message);
                }
                long end2 = DateTime.Now.Ticks;
                long start3 = DateTime.Now.Ticks;
                int fired = 0;
                try
                {
                    fired = engine.fire();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                long end3 = DateTime.Now.Ticks;
                long total3 = GC.GetTotalMemory(true);
                //long free3 = rt.freeMemory();
                //long used3 = total3 - free3;
                Console.WriteLine("Number of rules: " +
                                  engine.CurrentFocus.RuleCount);
                Console.WriteLine("rules fired " + fired);
                Console.WriteLine("Used memory after asserting objects " + total3 + " bytes " +
                                  (total3/1024) + " Kb " + (total3/1024/1024) + " Mb");
                Console.WriteLine("number of facts " + engine.ObjectCount);
                Console.WriteLine("memory used by facts " + (total3 - total3)/1024/1024 + " Mb");
                Console.WriteLine("elapsed time to assert " + (end2 - start2) + " ms");
                Console.WriteLine("elapsed time to fire " + (end3 - start3) + " ms");
                ETTotal += (end2 - start2);
                engine.printWorkingMemory(true, false);
                //engine.close();
                engine.clearAll();
                engine.close();
                //rt.gc();
            }
            Console.WriteLine("Average ET to assert " + (ETTotal/loop) + " ms");
        }
Exemplo n.º 6
0
        public static void main(String[] args)
        {
            String rulefile = "./benchmark_files/4K_rules_50Kdata_sequential.clp";
            //String datafile = "./benchmark_files/test.clp";
            //bool keepopen = false;
            if (args != null && args.Length > 0)
            {
                rulefile = args[0];
            }
            //if (args.Length >= 2)
            //{
            //    if (args[1].Equals("true", StringComparison.InvariantCultureIgnoreCase))
            //    {
            //        keepopen = true;
            //    }
            //}
            Console.WriteLine("Using file " + rulefile);

            MemoryBenchmark2 mb = new MemoryBenchmark2();
            long begin = DateTime.Now.Ticks;
            long totalET = 0;
            long parseET = 0;
            ArrayList facts = new ArrayList(50000);
            // Runtime rt = Runtime.getRuntime();
            long total1 = GC.GetTotalMemory(true);
            //long free1 = rt.freeMemory();
            //long used1 = total1 - free1;
            int loopcount = 5;
            Console.WriteLine("Used memory before creating engine " + total1 + " bytes " +
                              (total1/1024) + " Kb");
            for (int loop = 0; loop < loopcount; loop++)
            {
                Console.WriteLine(" ---------------------------------- ");
                Rete engine = new Rete();
                facts.Clear();

                long total2 = GC.GetTotalMemory(true);
                //long free2 = rt.freeMemory();
                //long used2 = total2 - free2;
                Console.WriteLine("Used memory after creating engine " + total2 + " bytes " +
                                  (total2/1024) + " Kb");

                try
                {
                    StreamReader freader = new StreamReader(rulefile);
                    CLIPSParser parser = new CLIPSParser(engine, freader);
                    long start = DateTime.Now.Ticks;
                    mb.parse(engine, parser, facts);
                    long end = DateTime.Now.Ticks;
                    long el = end - start;
                    parser.close();
                    //rt.gc();
                    parseET += el;

                    long total3 = GC.GetTotalMemory(true);
                    //long free3 = rt.freeMemory();
                    //long used3 = total3 - free3;
                    Console.WriteLine("Used memory after loading rules, and parsing data " +
                                      (total3/1024) + " Kb " + (total3/1024/1024) + " Mb");
                    Console.WriteLine("elapsed time to parse the rules and data " +
                                      el + " ms");

                    Console.WriteLine("Number of rules: " +
                                      engine.CurrentFocus.RuleCount);
                    // now assert the facts
                    IEnumerator itr = facts.GetEnumerator();
                    long start2 = DateTime.Now.Ticks;
                    while (itr.MoveNext())
                    {
                        Deffact fct = (Deffact) itr.Current;
                        engine.assertFact(fct);
                    }
                    int actCount = engine.ActivationList.size();
                    long end2 = DateTime.Now.Ticks;
                    long et2 = end2 - start2;
                    totalET += et2;
                    // now fire the rules
                    long start3 = 0;
                    long end3 = 0;
                    int fired = 0;
                    try
                    {
                        start3 = DateTime.Now.Ticks;
                        fired = engine.fire();
                        end3 = DateTime.Now.Ticks;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    facts.Clear();

                    long total4 = GC.GetTotalMemory(true);
                    //long free4 = rt.freeMemory();
                    //long used4 = total4 - free4;

                    Console.WriteLine("");
                    Console.WriteLine("Number of facts - " + engine.DeffactCount);
                    Console.WriteLine("Time to assert facts " + et2 + " ms");
                    Console.WriteLine("Used memory after assert " +
                                      (total4/1024) + " Kb " + (total4/1024/1024) + " Mb");
                    engine.printWorkingMemory(true, false);
                    Console.WriteLine("number of activations " + actCount);
                    Console.WriteLine("rules fired " + fired);
                    Console.WriteLine("time to fire rules " + (end3 - start3) + " ms");
                }
                catch (FileNotFoundException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (AssertException e)
                {
                    Console.WriteLine(e.Message);
                }
                engine.close();
                engine = null;
                //rt.gc();engine.close();
            }
            long finished = DateTime.Now.Ticks;
            Console.WriteLine("average parse ET - " + parseET/loopcount + " ms");
            Console.WriteLine("average assert ET - " + totalET/loopcount + " ms");
            Console.WriteLine("total run time " + (finished - begin) + " ms");
        }
Exemplo n.º 7
0
        public void mainTest()
        {
            String rulefile = getRoot("share_5nodes.clp");
            //bool keepopen = false;
            int fcount = 50000;

            Console.WriteLine("Using file " + rulefile);

            RulesetBenchmark2 mb = new RulesetBenchmark2();
            long begin = DateTime.Now.Ticks;
            long totalET = 0;
            long parseET = 0;
            ArrayList facts = new ArrayList(50000);
            // Runtime rt = Runtime.getRuntime();
            long total1 = GC.GetTotalMemory(true);
            //long free1 = rt.freeMemory();
            //long used1 = total1 - free1;
            int loopcount = 5;
            Console.WriteLine("Used memory before creating engine " + total1 + " bytes " +
                              (total1/1024) + " Kb");
            for (int loop = 0; loop < loopcount; loop++)
            {
                Console.WriteLine(" ---------------------------------- ");
                Rete engine = new Rete();
                facts.Clear();
                // declare the objects
                engine.declareObject(typeof (Account), "account");
                engine.declareObject(typeof (Transaction), "transaction");

                long total2 = GC.GetTotalMemory(true);
                //long free2 = rt.freeMemory();
                //long used2 = total2 - free2;
                Console.WriteLine("Used memory after creating engine " + total2 + " bytes " +
                                  (total2/1024) + " Kb");

                try
                {
                    StreamReader freader = new StreamReader(rulefile);
                    CLIPSParser parser = new CLIPSParser(engine, freader);
                    long start = DateTime.Now.Ticks;
                    mb.parse(engine, parser, facts);
                    long end = DateTime.Now.Ticks;
                    long el = end - start;
                    parser.close();
                    //rt.gc();
                    parseET += el;

                    long total3 = GC.GetTotalMemory(true);
                    //long free3 = rt.freeMemory();
                    //long used3 = total3 - free3;
                    Console.WriteLine("Used memory after loading rules, and parsing data " +
                                      (total3/1024) + " Kb " + (total3/1024/1024) + " Mb");
                    Console.WriteLine("elapsed time to parse the rules and data " +
                                      el + " ms");

                    Console.WriteLine("Number of rules: " +
                                      engine.CurrentFocus.RuleCount);
                    // now create the facts
                    Account acc = new Account();
                    acc.AccountType = "standard";
                    facts.Add(acc);
                    for (int i = 0; i < fcount; i++)
                    {
                        Transaction tx = new Transaction();
                        tx.AccountId = "acc" + i;
                        tx.Exchange = "NYSE";
                        tx.Issuer = "AAA";
                        tx.Shares = 100.00;
                        tx.SecurityType = "stocks";
                        tx.SubIndustryID = 25201010;
                        facts.Add(tx);
                    }
                    IEnumerator itr = facts.GetEnumerator();
                    long start2 = DateTime.Now.Ticks;
                    while (itr.MoveNext())
                    {
                        Object d = itr.Current;
                        if (d is Account)
                        {
                            engine.assertObject(d, "account", false, true);
                        }
                        else
                        {
                            engine.assertObject(d, "transaction", false, false);
                        }
                    }
                    int actCount = engine.ActivationList.size();
                    long end2 = DateTime.Now.Ticks;
                    long et2 = end2 - start2;
                    totalET += et2;
                    // now fire the rules
                    long start3 = 0;
                    long end3 = 0;
                    int fired = 0;
                    try
                    {
                        start3 = DateTime.Now.Ticks;
                        fired = engine.fire();
                        end3 = DateTime.Now.Ticks;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    facts.Clear();

                    long total4 = GC.GetTotalMemory(true);
                    //long free4 = rt.freeMemory();
                    //long used4 = total4 - free4;

                    Console.WriteLine("");
                    Console.WriteLine("Number of facts - " + engine.ObjectCount);
                    Console.WriteLine("Time to assert facts " + et2 + " ms");
                    Console.WriteLine("Used memory after assert " +
                                      (total4/1024) + " Kb " + (total4/1024/1024) + " Mb");
                    engine.printWorkingMemory(true, false);
                    Console.WriteLine("number of activations " + actCount);
                    Console.WriteLine("rules fired " + fired);
                    Console.WriteLine("time to fire rules " + (end3 - start3) + " ms");
                }
                catch (FileNotFoundException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (AssertException e)
                {
                    Console.WriteLine(e.Message);
                }
                engine.close();
                engine = null;
                //rt.gc();
            }
            long finished = DateTime.Now.Ticks;
            Console.WriteLine("average parse ET - " + parseET/loopcount + " ms");
            Console.WriteLine("average assert ET - " + totalET/loopcount + " ms");
            Console.WriteLine("total run time " + (finished - begin) + " ms");
        }