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); }
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); }
//[TestMethod] public void mainTest() { String rulefile = getRoot("random_5_w_50Kdata.clp"); //String datafile = getRoot("test.clp"); // in case it's run within OptimizeIt and we want to keep the test running //bool keepopen = false; Console.WriteLine("Using file " + rulefile); MemoryBenchmark mb = new MemoryBenchmark(); ArrayList facts = new ArrayList(50000); // Runtime rt = Runtime.getRuntime(); long total1 = GC.GetTotalMemory(true); //long free1 = rt.freeMemory(); //long used1 = total1 - free1; //int count = 100000; Console.WriteLine("Used memory before creating engine " + total1 + " bytes " + (total1/1024) + " Kb"); Rete engine = new Rete(); 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; // parser.close(); // rt.gc(); long total3 = GC.GetTotalMemory(true); //long free3 = rt.freeMemory(); //long used3 = total3 - free3; Console.WriteLine("Used memory after loading rules, data and asserting facts " + total3 + " bytes " + (total3/1024) + " Kb " + (total3/1024/1024) + " Mb"); Console.WriteLine("elapsed time to parse and assert the data " + (end - start) + " ms"); engine.printWorkingMemory(true, false); engine.close(); } catch (FileNotFoundException e) { Console.WriteLine(e.Message); } }
public static double manners64() { long ts = DateTime.Now.Ticks; long totTime = 0; using (TextWriter writer = System.Console.Out) { Rete engine = new Rete(); //engine.CurrentFocus.Lazy = true; engine.addPrintWriter("Console", writer); engine.loadRuleset(getRoot("manners64guests.clp")); engine.printWorkingMemory(false, false); totTime = DateTime.Now.Ticks - ts; writer.Flush(); writer.Close(); engine.close(); } return totTime; }
public void manners64() { long ts = DateTime.Now.Ticks; using (TextWriter writer = Console.Out) { Rete engine = new Rete(); engine.addPrintWriter("Console", writer); engine.loadRuleset(getRoot("manners64guests.clp")); engine.printWorkingMemory(false, false); writer.Flush(); writer.Close(); //engine.MessageRouter.ShutDown(); engine.close(); } double endTime = DateTime.Now.Ticks - ts; Console.WriteLine(String.Format("Manners 64 completed in {0} seconds.", (endTime/10000000).ToString("0.000000"))); //AppDomain.Unload(AppDomain.CurrentDomain); }
private void RunRules(string dir, string clpFile) { var outFile = Path.Combine(dir, String.Concat(Path.GetFileNameWithoutExtension(clpFile), ".out")); var refFile = Path.Combine(dir, String.Concat(Path.GetFileNameWithoutExtension(clpFile), ".ref")); using (TextWriter writer = new StreamWriter(outFile)) { Rete engine = new Rete(); engine.addPrintWriter("File", writer); engine.loadRuleset(clpFile); engine.printWorkingMemory(false, false); engine.close(); writer.Flush(); writer.Close(); } var outTxt = File.ReadAllText(outFile); var refTxt = File.ReadAllText(refFile); }
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"); }
public void testAssertWithInterface() { Console.WriteLine("-----------------------------"); Console.WriteLine("start testAssertWithInterface"); Rete engine = new Rete(); engine.declareObject(typeof (IAccount), "account"); Assert.IsNotNull(engine); 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 = "******"; try { engine.assertObject(acc1, "account", false, true); Assert.IsTrue(true); Assert.AreEqual(1, engine.ObjectCount); Console.WriteLine("Number of facts: " + engine.ObjectCount); engine.printWorkingMemory(true, true); } catch (AssertException e) { Console.WriteLine(e.Message); } engine.close(); }
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"); }
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"); }