public void  TestStateWithAgendaGroup()
        {
            System.IO.Stream stream  = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.StateExampleUsingAgendGroup.drl");
            PackageBuilder   builder = new PackageBuilder();

            builder.AddPackageFromDrl(stream);
            Package  pkg      = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            workingMemory.addEventListener(new AnonymousClassDefaultAgendaEventListener());

            State a = new State("A");
            State b = new State("B");
            State c = new State("C");
            State d = new State("D");

            // By setting dynamic to TRUE, Drools will use JavaBean
            // PropertyChangeListeners so you don't have to call modifyObject().
            //UPGRADE_NOTE: Final was removed from the declaration of 'dynamic '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
            bool dynamic = true;

            workingMemory.assertObject(a, dynamic);
            workingMemory.assertObject(b, dynamic);
            workingMemory.assertObject(c, dynamic);
            workingMemory.assertObject(d, dynamic);

            workingMemory.fireAllRules();
        }
        public void  TestExecute()
        {
            SpreadsheetCompiler converter = new SpreadsheetCompiler();

            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.resources.data.IntegrationExampleTest.xls");
            System.String    drl    = converter.Compile(stream, InputType.XLS);
            Assert.IsNotNull(drl);
            //COMPILE
            PackageBuilder builder = new PackageBuilder();

            builder.AddPackageFromDrl(drl);

            Package pkg = builder.GetPackage();

            Assert.IsNotNull(pkg);
            System.Console.Out.WriteLine(pkg.GetErrorSummary());
            Assert.AreEqual(0, builder.GetErrors().Length);

            RuleBase rb = RuleBaseFactory.NewRuleBase();

            rb.AddPackage(pkg);

            WorkingMemory wm = rb.NewWorkingMemory();

            //ASSERT AND FIRE
            wm.assertObject(new Cheese("stilton", 42));
            wm.assertObject(new Person("michael", "stilton", 42));
            System.Collections.IList list = new System.Collections.ArrayList();
            wm.setGlobal("list", list);
            wm.fireAllRules();
            Assert.AreEqual(1, list.Count);
        }
Exemplo n.º 3
0
        public void Simulate(Simulation formSimulation, SimulationDebug formDebug)
        {
            _formDebug      = formDebug;
            _formSimulation = formSimulation;
            formDebug.Show();

            //Imprimo this para saber sobre que objeto operaran las reglas
            FallasI.Simulator.ImprimirEnDebug(this);

            //Inicio la carga de drools
            formDebug.debugTxtBox.Text += "\nLoading Rule Base: ";
            formDebug.debugTxtBox.Refresh();
            PackageBuilder builder = new PackageBuilder();
            Stream         stream  = new FileStream(FallasI.Src.App.Default.PATH_ARCHIVO_REGLAS, FileMode.Open);

            formDebug.debugTxtBox.Text += "\nStream Set ";
            formDebug.debugTxtBox.Refresh();
            formDebug.debugTxtBox.Text += "\nReading DRL (Please wait... this may take a few moments...) ";
            formDebug.debugTxtBox.Refresh();

            builder.AddPackageFromDrl("FallasI.Rules.drl", stream);
            formDebug.debugTxtBox.Text += "... Finished ";
            formDebug.debugTxtBox.Refresh();
            Package pkg = builder.GetPackage();

            formDebug.debugTxtBox.Text += "\nPackage Added ";
            formDebug.debugTxtBox.Refresh();

            ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);
            formDebug.debugTxtBox.Text += "\nRule Base Set ";
            formDebug.debugTxtBox.Refresh();

            workingMemory = ruleBase.NewWorkingMemory();
            workingObj    = this;
            formDebug.debugTxtBox.Text += "\nWorking Object Set ";
            formDebug.debugTxtBox.Refresh();

            //Inicio la ejecucion de drool
            formDebug.debugTxtBox.Text += "\nRule Runing... ";
            formDebug.debugTxtBox.Refresh();

            if (_currentCust == null)
            {
                _currentCust = workingMemory.assertObject(workingObj);
            }
            else
            {
                workingMemory.modifyObject(_currentCust, workingObj);
            }

            workingMemory.fireAllRules();

            formDebug.debugTxtBox.Text += "\nFin ";
            formDebug.debugTxtBox.Refresh();

            // llamo a simular
            _formSimulation.DibujarSimulacion();
            //formDebug.Close();
        }
Exemplo n.º 4
0
        public void  TestMannerBenchmark()
        {
            System.IO.Stream stream  = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.benchmark.manners.manners.drl");
            PackageBuilder   builder = new PackageBuilder();

            builder.AddPackageFromDrl(stream);
            Package  pkg      = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();



            System.IO.Stream         inStr = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.resources.benchmark.manners.manners64.dat");
            System.Collections.IList list  = getInputObjects(inStr);
            for (System.Collections.IEnumerator it = list.GetEnumerator(); it.MoveNext();)
            {
                System.Object obj = it.Current;
                workingMemory.assertObject(obj);
            }

            workingMemory.assertObject(new Count(1));

            long start = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;

            workingMemory.fireAllRules();
            System.Console.Out.WriteLine((System.DateTime.Now.Ticks - 621355968000000000) / 10000 - start);
        }
Exemplo n.º 5
0
        public void  TestHonestPolitician()
        {
            System.IO.Stream stream  = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.HonestPolitician.drl");
            PackageBuilder   builder = new PackageBuilder();

            builder.AddPackageFromDrl(stream);
            Package  pkg      = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();



            Politician blair    = new Politician("blair", true);
            Politician bush     = new Politician("bush", true);
            Politician chirac   = new Politician("chirac", true);
            Politician schroder = new Politician("schroder", true);

            workingMemory.assertObject(blair);
            workingMemory.assertObject(bush);
            workingMemory.assertObject(chirac);
            workingMemory.assertObject(schroder);

            workingMemory.fireAllRules();
        }
Exemplo n.º 6
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            _thisForm         = this;
            debugOutput.Text += "\nLoading Rule Base: ";
            _thisForm.Refresh();
            PackageBuilder builder = new PackageBuilder();
            Stream         stream  = new FileStream(@"C:\Documents and Settings\TricolorerVirtual\Escritorio\MinimalDroolsForm.rar\MinimalDroolsForm\SimpleRulesExt.drl", FileMode.Open);

            debugOutput.Text += "\nStream Set ";
            _thisForm.Refresh();
            debugOutput.Text += "\nReading DRL (Please wait... this may take a few moments...) ";
            _thisForm.Refresh();

            builder.AddPackageFromDrl("MinimalDroolsForm.SimpleRules.drl", stream);
            debugOutput.Text += "... Finished ";
            _thisForm.Refresh();
            Package pkg = builder.GetPackage();

            debugOutput.Text += "\nPackage Added ";
            _thisForm.Refresh();
            ruleBase = RuleBaseFactory.NewRuleBase();
            ruleBase.AddPackage(pkg);
            debugOutput.Text += "\nRule Base Set ";
            _thisForm.Refresh();
            workingMemory    = ruleBase.NewWorkingMemory();
            workingObj       = new CustomerRecord();
            secondWorkingObj = null;
        }
Exemplo n.º 7
0
        public void  TestGolfingExample()
        {
            System.IO.Stream stream  = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.golf.drl");
            PackageBuilder   builder = new PackageBuilder();

            builder.AddPackageFromDrl(stream);
            Package  pkg      = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();


            string[] names     = new string[] { "Fred", "Joe", "Bob", "Tom" };
            string[] colors    = new string[] { "red", "blue", "plaid", "orange" };
            int[]    positions = new int[] { 1, 2, 3, 4 };

            for (int n = 0; n < names.Length; n++)
            {
                for (int c = 0; c < colors.Length; c++)
                {
                    for (int p = 0; p < positions.Length; p++)
                    {
                        workingMemory.assertObject(new Golfer(names[n], colors[c], positions[p]));
                    }
                }
            }

            workingMemory.fireAllRules();
        }
Exemplo n.º 8
0
        public decimal GetTravelInsurancePrice(TravelRiskItem riskItem)
        {
            string assemblyPath = AppDomain.CurrentDomain.RelativeSearchPath;

            System.IO.Stream stream = new FileStream(Path.Combine(assemblyPath, @"Rules\", "TravelInsurancePrice.drl"), FileMode.Open);
            try
            {
                var region = _riskItemRepository.GetById(riskItem.RegionID);
                var sport  = riskItem.SportId.HasValue ? _riskItemRepository.GetById(riskItem.SportId.Value) : null;

                PackageBuilder builder = new PackageBuilder();
                builder.AddPackageFromDrl("TravelInsurancePrice.drl", stream);
                Package  pkg      = builder.GetPackage();
                RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
                ruleBase.AddPackage(pkg);
                WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

                workingMemory.assertObject(region);
                workingMemory.assertObject(sport);
                workingMemory.assertObject(riskItem);

                return(riskItem.RuleAmmount);
            }
            finally
            {
                stream.Close();
            }
        }
        public void TestLoadState()
        {
            FileStream fstream  = new FileStream("StateDynamic.rlb", FileMode.Open);
            RuleBase   ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.Load(fstream);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            State a = new State("A");
            State b = new State("B");
            State c = new State("C");
            State d = new State("D");
            State e = new State("E");

            // By setting dynamic to TRUE, Drools will use JavaBean
            // PropertyChangeListeners so you don't have to call modifyObject().
            //UPGRADE_NOTE: Final was removed from the declaration of 'dynamic '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
            bool dynamic = true;

            workingMemory.assertObject(a, dynamic);
            workingMemory.assertObject(b, dynamic);
            workingMemory.assertObject(c, dynamic);
            workingMemory.assertObject(d, dynamic);
            workingMemory.assertObject(e, dynamic);

            workingMemory.fireAllRules();
        }
Exemplo n.º 10
0
        public void  TestTroubleTicketwithDSL()
        {
            System.IO.Stream source  = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.TroubleTicketWithDSL.drl");
            System.IO.Stream dsl     = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.ticketing.dsl");
            PackageBuilder   builder = new PackageBuilder();

            builder.AddPackageFromDrl(source, dsl);

            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.AddPackage(builder.GetPackage());

            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            Customer a = new Customer("A", "Gold");
            Customer b = new Customer("B", "Platinum");
            Customer c = new Customer("C", "Silver");
            Customer d = new Customer("D", "Silver");

            Ticket t1 = new Ticket(a);
            Ticket t2 = new Ticket(b);
            Ticket t3 = new Ticket(c);
            Ticket t4 = new Ticket(d);

            FactHandle fa = workingMemory.assertObject(a);
            FactHandle fb = workingMemory.assertObject(b);
            FactHandle fc = workingMemory.assertObject(c);
            FactHandle fd = workingMemory.assertObject(d);

            FactHandle ft1 = workingMemory.assertObject(t1);
            FactHandle ft2 = workingMemory.assertObject(t2);
            FactHandle ft3 = workingMemory.assertObject(t3);
            FactHandle ft4 = workingMemory.assertObject(t4);

            workingMemory.fireAllRules();

            t3.Status = "Done";

            workingMemory.modifyObject(ft3, t3);

            try
            {
                System.Console.Error.WriteLine("[[ Sleeping 5 seconds ]]");
                System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 5000));
            }
            catch (System.Threading.ThreadInterruptedException e)
            {
                //SupportClass.WriteStackTrace(e, Console.Error);
            }

            workingMemory.fireAllRules();

            //logger.writeToDisk();
        }
Exemplo n.º 11
0
        public void doParsing()
        {
            //go !
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            //Message message = new Message();

            //message.status = Message.GOODBYE;
            workingMemory.assertObject(message);
            workingMemory.fireAllRules();
        }
Exemplo n.º 12
0
        public void TestBLoadRuleBase()
        {
            RuleBase   ruleBase = RuleBaseFactory.NewRuleBase();
            FileStream fstream  = new FileStream("HelloworldRuleBase.rlb", FileMode.Open);

            ruleBase.Load(fstream);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            //go !
            Message message = new Message();

            message.message = "Hello World";
            message.status  = Message.HELLO;
            workingMemory.assertObject(message);
            workingMemory.fireAllRules();
        }
Exemplo n.º 13
0
        public virtual void  testFourThousandLoad()
        {
            try
            {
                System.String file      = "4000_rules_type1.drl";
                long          loadStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                RuleBase      ruleBase  = readRule(file);
                long          loadEnd   = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                System.Console.Out.WriteLine("time to load " + file + " " + (loadEnd - loadStart) + "ms");
                WorkingMemory workingMemory = ruleBase.NewWorkingMemory();
            }
            catch (System.Exception e)
            {
//				SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
Exemplo n.º 14
0
        public void TestBLoadPkg()
        {
            //AppDomain.CurrentDomain.Load("tempAssembly.dll");
            FileStream stream   = new FileStream("TroubleticketRuleBase.rlb", FileMode.Open);
            RuleBase   ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.Load(stream);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            Customer a = new Customer("A", "Gold");
            Customer b = new Customer("B", "Platinum");
            Customer c = new Customer("C", "Silver");
            Customer d = new Customer("D", "Silver");

            Ticket t1 = new Ticket(a);
            Ticket t2 = new Ticket(b);
            Ticket t3 = new Ticket(c);
            Ticket t4 = new Ticket(d);

            FactHandle fa = workingMemory.assertObject(a);
            FactHandle fb = workingMemory.assertObject(b);
            FactHandle fc = workingMemory.assertObject(c);
            FactHandle fd = workingMemory.assertObject(d);

            FactHandle ft1 = workingMemory.assertObject(t1);
            FactHandle ft2 = workingMemory.assertObject(t2);
            FactHandle ft3 = workingMemory.assertObject(t3);
            FactHandle ft4 = workingMemory.assertObject(t4);

            workingMemory.fireAllRules();

            t3.Status = "Done";

            workingMemory.modifyObject(ft3, t3);

            try
            {
                System.Console.Error.WriteLine("[[ Sleeping 5 seconds ]]");
                System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 5000));
            }
            catch (System.Threading.ThreadInterruptedException e)
            {
                //SupportClass.WriteStackTrace(e, Console.Error);
            }

            System.Console.Error.WriteLine("[[ awake ]]");
        }
Exemplo n.º 15
0
        static void TestRules(RuleBase ruleBase, CustomerRecord workingObj)
        {
            if (workingMemory == null)
            {
                workingMemory = ruleBase.NewWorkingMemory();
            }


            if (_currentCust == null)
            {
                _currentCust = workingMemory.assertObject(workingObj);
            }
            else
            {
                workingMemory.modifyObject(_currentCust, workingObj);
            }
            workingMemory.fireAllRules();
        }
Exemplo n.º 16
0
        public void  TestWaltzBenchmark()
        {
            System.IO.Stream stream  = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.benchmark.waltz.waltz.drl");
            PackageBuilder   builder = new PackageBuilder();

            builder.AddPackageFromDrl(stream);
            Package  pkg      = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            //this.loadLines( workingMemory, "waltz12.dat" );

            Stage stage = new Stage(Stage.START);

            workingMemory.assertObject(stage);
            workingMemory.fireAllRules();
        }
        public void TestBLoadAndChangeSavedState()
        {
            FileStream fstream  = new FileStream("StateDynamic.rlb", FileMode.Open);
            RuleBase   ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.Load(fstream);
            fstream.Close();
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();
            State         a             = new State("A");
            State         b             = new State("B");
            State         c             = new State("C");
            State         d             = new State("D");
            State         e             = new State("E");

            // By setting dynamic to TRUE, Drools will use JavaBean
            // PropertyChangeListeners so you don't have to call modifyObject().
            //UPGRADE_NOTE: Final was removed from the declaration of 'dynamic '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
            bool dynamic = true;

            workingMemory.assertObject(a, dynamic);
            workingMemory.assertObject(b, dynamic);
            workingMemory.assertObject(c, dynamic);
            workingMemory.assertObject(d, dynamic);
            workingMemory.assertObject(e, dynamic);

            workingMemory.fireAllRules();


            Stream         stream  = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.StateExampleDynamicRule.drl");
            PackageBuilder builder = new PackageBuilder();

            builder.AddPackageFromDrl(stream);
            Package pkg = builder.GetPackage();

            ruleBase.AddPackage(pkg);

            fstream = new FileStream("StateDynamic.rlb", FileMode.Create);
            ruleBase.Save(fstream);

            stream.Close();
            fstream.Close();
        }
Exemplo n.º 18
0
        public void TestHelloWorldExample()
        {
            PackageBuilder builder = new PackageBuilder();

            System.IO.Stream stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.HelloWorld.drl");
            builder.AddPackageFromDrl("HelloWorld.drl", stream);
            Package  pkg      = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.AddPackage(pkg);
            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();

            //go !
            Message message = new Message();

            message.message = "Hello World";
            message.status  = Message.HELLO;
            workingMemory.assertObject(message);
            workingMemory.fireAllRules();
        }
Exemplo n.º 19
0
        public void  TestFibonacciExample()
        {
            System.IO.Stream stream  = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("org.drools.dotnet.examples.rules.Fibonacci.drl");
            PackageBuilder   builder = new PackageBuilder();

            builder.AddPackageFromDrl(stream);
            Package  pkg      = builder.GetPackage();
            RuleBase ruleBase = RuleBaseFactory.NewRuleBase();

            ruleBase.AddPackage(pkg);

            WorkingMemory workingMemory = ruleBase.NewWorkingMemory();



            // By setting dynamic to TRUE, Drools will use JavaBean
            // PropertyChangeListeners so you don't have to call modifyObject().
            //UPGRADE_NOTE: Final was removed from the declaration of 'dynamic '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
            bool dynamic = false;

            workingMemory.assertObject(new Fibonacci(50), dynamic);
            workingMemory.fireAllRules();
        }
Exemplo n.º 20
0
 public void  testNoneSharedNodes()
 {
     try
     {
         int    factCount              = 5000;
         string file                   = "20rules_0shared.drl";
         int    loop                   = 5;
         long   totalload              = 0;
         long   totalassert            = 0;
         long   totalfire              = 0;
         System.Diagnostics.Process rt = System.Diagnostics.Process.GetCurrentProcess();
         for (int c = 0; c < loop; c++)
         {
             System.GC.Collect();
             long     loadStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             RuleBase ruleBase  = readRule(file);
             long     loadEnd   = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             long     loadet    = loadEnd - loadStart;
             totalload += loadet;
             System.GC.Collect();
             System.Console.Out.WriteLine("time to load " + file + " " + loadet + "ms");
             WorkingMemory workingMemory          = ruleBase.NewWorkingMemory();
             System.Collections.ArrayList objects = new System.Collections.ArrayList();
             // create the objects
             for (int idx = 0; idx < factCount; idx++)
             {
                 Address addr = new Address();
                 addr.AccountId = "acc" + idx;
                 addr.City      = "boston";
                 addr.State     = "ma";
                 addr.HouseType = "single family";
                 addr.Status    = "not listed";
                 addr.Country   = "usa";
                 objects.Add(addr);
             }
             System.Collections.IEnumerator itr = objects.GetEnumerator();
             long assertStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             while (itr.MoveNext())
             {
                 workingMemory.assertObject(itr.Current);
             }
             long assertEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             long assertet  = assertEnd - assertStart;
             totalassert += assertet;
             System.GC.Collect();
             System.Console.Out.WriteLine("time to assert " + assertet + " ms");
             long fireStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             workingMemory.fireAllRules();
             long fireEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             long fireet  = fireEnd - fireStart;
             totalfire += fireet;
             System.Console.Out.WriteLine("time to fireAllRules " + fireet + " ms");
             workingMemory.dispose();
             System.GC.Collect();
         }
         System.Console.Out.WriteLine(file);
         System.Console.Out.WriteLine("number of objects asserted " + factCount);
         System.Console.Out.WriteLine("average load " + (totalload / loop) + " ms");
         System.Console.Out.WriteLine("average assert " + (totalassert / loop) + " ms");
         System.Console.Out.WriteLine("average fire " + (totalfire / loop) + " ms");
     }
     catch (System.Exception e)
     {
         //SupportClass.WriteStackTrace(e, Console.Error);
     }
 }
Exemplo n.º 21
0
        public virtual void  testNoneSharedNodes()
        {
            try
            {
                int    factCount              = 5000;
                string file                   = "20rules_2CE_0shared.drl";
                int    loop                   = 5;
                long   totalload              = 0;
                long   totalassert            = 0;
                long   totalfire              = 0;
                System.Diagnostics.Process rt = System.Diagnostics.Process.GetCurrentProcess();
                for (int c = 0; c < loop; c++)
                {
                    long     loadStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    RuleBase ruleBase  = readRule(file);
                    long     loadEnd   = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    long     loadet    = loadEnd - loadStart;
                    totalload += loadet;
                    System.GC.Collect();
                    System.Console.Out.WriteLine("time to load " + file + " " + loadet + "ms");
                    WorkingMemory workingMemory          = ruleBase.NewWorkingMemory();
                    System.Collections.ArrayList objects = new System.Collections.ArrayList();
                    Account acc = new Account();
                    acc.Status = "standard";
                    objects.Add(acc);
                    // create the objects
                    for (int idx = 0; idx < factCount; idx++)
                    {
                        Address addr = new Address();
                        addr.AccountId = "acc" + idx;
                        addr.City      = "boston";
                        addr.State     = "ma";
                        addr.HouseType = "single family";
                        addr.Status    = "not listed";
                        addr.Country   = "usa";
                        objects.Add(addr);
                    }
                    System.Collections.IEnumerator itr = objects.GetEnumerator();
                    long assertStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                    while (itr.MoveNext())
                    {
                        //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                        workingMemory.assertObject(itr.Current);
                    }
                    long assertEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    long assertet  = assertEnd - assertStart;
                    totalassert += assertet;
                    System.GC.Collect();
                    System.Console.Out.WriteLine("time to assert " + assertet + " ms");
                    long fireStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    workingMemory.fireAllRules();
                    long fireEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    long fireet  = fireEnd - fireStart;
                    totalfire += fireet;
                    System.Console.Out.WriteLine("time to fireAllRules " + fireet + " ms");
                    workingMemory.dispose();
                    System.GC.Collect();
                }
                System.Console.Out.WriteLine(file);
                System.Console.Out.WriteLine("number of objects asserted " + factCount);
                System.Console.Out.WriteLine("average load " + (totalload / loop) + " ms");
                System.Console.Out.WriteLine("average assert " + (totalassert / loop) + " ms");
                System.Console.Out.WriteLine("average fire " + (totalfire / loop) + " ms");
            }
            catch (System.Exception e)
            {
//				SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
Exemplo n.º 22
0
        /// <summary> test the performance with 50 facts and 5 rules. The test measures
        /// the load, assert and fire time.
        /// </summary>
        public virtual void  testFiveSharedNodes()
        {
            try
            {
                int    factCount              = 5000;
                string file                   = "20rules_2CE_5shared.drl";
                int    loop                   = 5;
                long   totalload              = 0;
                long   totalassert            = 0;
                long   totalfire              = 0;
                long   aveloadmem             = 0;
                long   aveassertmem           = 0;
                System.Diagnostics.Process rt = System.Diagnostics.Process.GetCurrentProcess();
                for (int c = 0; c < loop; c++)
                {
                    System.GC.Collect();
                    //long memt1 = rt.totalMemory();
                    //long memf1 = rt.freeMemory();
                    //long used1 = memt1 - memf1;
                    long     loadStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    RuleBase ruleBase  = readRule(file);
                    long     loadEnd   = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    //long memt2 = rt.totalMemory();
                    //long memf2 = rt.freeMemory();
                    //long used2 = memt2 - memf2;
                    long loadet = loadEnd - loadStart;
                    System.GC.Collect();
                    totalload += loadet;
                    //aveloadmem += (used2 - used1);
                    System.Console.Out.WriteLine("time to load " + file + " " + loadet + "ms");
                    //System.Console.Out.WriteLine("load memory used " + ((used2 - used1) / 1024) + " kb");
                    WorkingMemory workingMemory          = ruleBase.NewWorkingMemory();
                    System.Collections.ArrayList objects = new System.Collections.ArrayList();
                    Account acc = new Account();
                    acc.Status = "standard";
                    objects.Add(acc);
                    // create the objects
                    for (int idx = 0; idx < factCount; idx++)
                    {
                        Address addr = new Address();
                        addr.City      = "boston";
                        addr.State     = "ma";
                        addr.HouseType = "single family";
                        addr.Status    = "not listed";
                        addr.Country   = "usa";
                        addr.AccountId = "acc" + idx;
                        objects.Add(addr);
                    }
                    System.Collections.IEnumerator itr = objects.GetEnumerator();
                    //long memt3 = rt.totalMemory();
                    //long memf3 = rt.freeMemory();
                    //long used3 = memt3 - memf3;
                    long assertStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    while (itr.MoveNext())
                    {
                        workingMemory.assertObject(itr.Current);
                    }
                    long assertEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    //long memt4 = rt.totalMemory();
                    //long memf4 = rt.freeMemory();
                    //long used4 = memt4 - memf4;
                    long assertet = assertEnd - assertStart;
                    totalassert += assertet;
                    //aveassertmem += (used4 - used3);
                    System.Console.Out.WriteLine("time to assert " + assertet + " ms");
                    //System.Console.Out.WriteLine("assert memory used " + ((used4 - used3) / 1024) + " kb");
                    long fireStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    workingMemory.fireAllRules();
                    long fireEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
                    long fireet  = fireEnd - fireStart;
                    totalfire += fireet;
                    System.Console.Out.WriteLine("time to fireAllRules " + fireet + " ms");
                    workingMemory.dispose();
                    System.GC.Collect();
                    System.Console.Out.WriteLine("");
                }
                System.Console.Out.WriteLine(file);
                System.Console.Out.WriteLine("number of objects asserted " + factCount);
                System.Console.Out.WriteLine("average load " + (totalload / loop) + " ms");
                //System.Console.Out.WriteLine("average load mem " + (aveloadmem / 1024 / loop) + " kb");
                System.Console.Out.WriteLine("average assert " + (totalassert / loop) + " ms");
                //System.Console.Out.WriteLine("average assert mem " + (aveassertmem / 1024 / loop) + " kb");
                System.Console.Out.WriteLine("average fire " + (totalfire / loop) + " ms");
            }
            catch (System.Exception e)
            {
//				SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
Exemplo n.º 23
0
 /// <summary> test the performance with 50 facts and 5 rules. The test measures
 /// the load, assert and fire time.
 /// </summary>
 public virtual void  testFiveRuleFire()
 {
     try
     {
         int           factCount   = 50000;
         System.String file        = "5_rules.drl";
         int           loop        = 5;
         long          totalload   = 0;
         long          totalassert = 0;
         long          totalfire   = 0;
         for (int c = 0; c < loop; c++)
         {
             long     loadStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             RuleBase ruleBase  = null;
             if (c == 0)
             {
                 ruleBase = readRule(file, "C:\\PerformanceTest_5Rules.rlb");
             }
             else
             {
                 ruleBase = readPrecompiled("C:\\PerformanceTest_5Rules.rlb");
             }
             long loadEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             long loadet  = loadEnd - loadStart;
             totalload += loadet;
             System.Console.Out.WriteLine("time to load " + file + " " + loadet + "ms");
             WorkingMemory workingMemory          = ruleBase.NewWorkingMemory();
             System.Collections.ArrayList objects = new System.Collections.ArrayList();
             // create the objects
             for (int idx = 0; idx < factCount; idx++)
             {
                 Account acc = new Account();
                 acc.AccountId = "acc" + idx;
                 acc.Title     = "mr";
                 acc.Status    = "standard";
                 objects.Add(acc);
             }
             System.Collections.IEnumerator itr = objects.GetEnumerator();
             long assertStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
             while (itr.MoveNext())
             {
                 //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                 workingMemory.assertObject(itr.Current);
             }
             long assertEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             long assertet  = assertEnd - assertStart;
             totalassert += assertet;
             System.Console.Out.WriteLine("time to assert " + assertet + " ms");
             long fireStart = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             workingMemory.fireAllRules();
             long fireEnd = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
             long fireet  = fireEnd - fireStart;
             totalfire += fireet;
             System.Console.Out.WriteLine("time to fireAllRules " + fireet + " ms");
             workingMemory.dispose();
         }
         System.Console.Out.WriteLine(file);
         System.Console.Out.WriteLine("number of objects asserted " + factCount);
         System.Console.Out.WriteLine("average load " + (totalload / loop) + " ms");
         System.Console.Out.WriteLine("average assert " + (totalassert / loop) + " ms");
         System.Console.Out.WriteLine("average fire " + (totalfire / loop) + " ms");
     }
     catch (System.Exception e)
     {
         //SupportClass.WriteStackTrace(e, Console.Error);
     }
 }