Exemple #1
0
 static ConversionUtils()
 {
     {
         OPR_MAP = new GenericHashMap <string, string>();
         OPR_MAP.Put(Constants.ADD.ToString(), Constants.ADD_STRING);
         OPR_MAP.Put(Constants.SUBTRACT.ToString(), Constants.SUBTRACT_STRING);
         OPR_MAP.Put(Constants.MULTIPLY.ToString(), Constants.MULTIPLY_STRING);
         OPR_MAP.Put(Constants.DIVIDE.ToString(), Constants.DIVIDE_STRING);
         OPR_MAP.Put(Constants.LESS.ToString(), Constants.LESS_STRING);
         OPR_MAP.Put(Constants.LESSEQUAL.ToString(), Constants.LESSEQUAL_STRING);
         OPR_MAP.Put(Constants.GREATER.ToString(), Constants.GREATER_STRING);
         OPR_MAP.Put(Constants.GREATEREQUAL.ToString(), Constants.GREATEREQUAL_STRING);
         OPR_MAP.Put(Constants.EQUAL.ToString(), Constants.EQUAL_STRING);
         OPR_MAP.Put(Constants.NOTEQUAL.ToString(), Constants.NOTEQUAL_STRING);
     }
     {
         STROPR_MAP = new GenericHashMap <string, string>();
         OPR_MAP.Put(Constants.ADD_STRING, Constants.ADD_SYMBOL);
         OPR_MAP.Put(Constants.SUBTRACT_STRING, Constants.SUBTRACT_SYMBOL);
         OPR_MAP.Put(Constants.MULTIPLY_STRING, Constants.MULTIPLY_SYMBOL);
         OPR_MAP.Put(Constants.DIVIDE_STRING, Constants.DIVIDE_SYMBOL);
         OPR_MAP.Put(Constants.LESS_STRING, Constants.LESS_SYMBOL);
         OPR_MAP.Put(Constants.LESSEQUAL_STRING, Constants.LESSEQUAL_SYMBOL);
         OPR_MAP.Put(Constants.GREATER_STRING, Constants.GREATER_SYMBOL);
         OPR_MAP.Put(Constants.GREATEREQUAL_STRING, Constants.GREATEREQUAL_SYMBOL);
         OPR_MAP.Put(Constants.EQUAL_STRING, Constants.EQUAL_SYMBOL);
         OPR_MAP.Put(Constants.NOTEQUAL_STRING, Constants.NOTEQUAL_SYMBOL);
     }
 }
Exemple #2
0
 static ConversionUtils()
 {
     {
         OPR_MAP = new GenericHashMap<string, string>();
         OPR_MAP.Put(Constants.ADD.ToString(), Constants.ADD_STRING);
         OPR_MAP.Put(Constants.SUBTRACT.ToString(), Constants.SUBTRACT_STRING);
         OPR_MAP.Put(Constants.MULTIPLY.ToString(), Constants.MULTIPLY_STRING);
         OPR_MAP.Put(Constants.DIVIDE.ToString(), Constants.DIVIDE_STRING);
         OPR_MAP.Put(Constants.LESS.ToString(), Constants.LESS_STRING);
         OPR_MAP.Put(Constants.LESSEQUAL.ToString(), Constants.LESSEQUAL_STRING);
         OPR_MAP.Put(Constants.GREATER.ToString(), Constants.GREATER_STRING);
         OPR_MAP.Put(Constants.GREATEREQUAL.ToString(), Constants.GREATEREQUAL_STRING);
         OPR_MAP.Put(Constants.EQUAL.ToString(), Constants.EQUAL_STRING);
         OPR_MAP.Put(Constants.NOTEQUAL.ToString(), Constants.NOTEQUAL_STRING);
     }
     {
         STROPR_MAP = new GenericHashMap<string, string>();
         OPR_MAP.Put(Constants.ADD_STRING, Constants.ADD_SYMBOL);
         OPR_MAP.Put(Constants.SUBTRACT_STRING, Constants.SUBTRACT_SYMBOL);
         OPR_MAP.Put(Constants.MULTIPLY_STRING, Constants.MULTIPLY_SYMBOL);
         OPR_MAP.Put(Constants.DIVIDE_STRING, Constants.DIVIDE_SYMBOL);
         OPR_MAP.Put(Constants.LESS_STRING, Constants.LESS_SYMBOL);
         OPR_MAP.Put(Constants.LESSEQUAL_STRING, Constants.LESSEQUAL_SYMBOL);
         OPR_MAP.Put(Constants.GREATER_STRING, Constants.GREATER_SYMBOL);
         OPR_MAP.Put(Constants.GREATEREQUAL_STRING, Constants.GREATEREQUAL_SYMBOL);
         OPR_MAP.Put(Constants.EQUAL_STRING, Constants.EQUAL_SYMBOL);
         OPR_MAP.Put(Constants.NOTEQUAL_STRING, Constants.NOTEQUAL_SYMBOL);
     }
 }
Exemple #3
0
 /// <summary> the function will printout one or more templates. This implementation
 /// is slightly different than CLIPS in that it can take one or more
 /// template names. The definition in CLIPS beginners guide states the 
 /// function does the following: (ppdeftemplate &lt;deftemplate-name>)
 /// </summary>
 public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
 {
     GenericHashMap<object, object> filter = new GenericHashMap<object, object>();
     if (params_Renamed != null && params_Renamed.Length > 0)
     {
         for (int idx = 0; idx < params_Renamed.Length; idx++)
         {
             if (params_Renamed[idx] is ValueParam)
             {
                 Object df = ((ValueParam) params_Renamed[idx]).Value;
                 filter.Put(df, df);
             }
         }
     }
     List<Object> templ = (List<Object>) engine.CurrentFocus.Templates;
     IEnumerator itr = templ.GetEnumerator();
     while (itr.MoveNext())
     {
         ITemplate tp = (ITemplate) itr.Current;
         if (filter.Get(tp.Name) != null)
         {
             engine.writeMessage(tp.toPPString() + "\r\n", "t");
         }
     }
     return new DefaultReturnVector();
 }
Exemple #4
0
        public void HashPerformance()
        {
            //int[] series = new int[] {1000, 10000, 100000, 1000000, 10000000};
            int[]            series = new int[] { 1000, 10000 };
            HashMapBenchmark util   = new HashMapBenchmark();
            Random           ran    = new Random();

            for (int idx = 0; idx < series.Length; idx++)
            {
                GenericHashMap <object, object> map = util.createHashMap(series[idx]);
                long start = DateTime.Now.Ticks;
                for (int idz = 0; idz < 10000000; idz++)
                {
                    String key = ran.Next(series[idx]).ToString();
                    Object val = map.Get(key);
                }
                long   end     = DateTime.Now.Ticks;
                long   el      = end - start;
                double perOp   = (double)el / 10000000;
                String fstring = (perOp * 1000000).ToString();
                Console.WriteLine("Test for " + series[idx] + " items");
                Console.WriteLine("elapsed time " + el + " millisecond");
                Console.WriteLine("per lookup " + fstring + " nanosecond");
            }
        }
        /// <summary> the function will printout one or more templates. This implementation
        /// is slightly different than CLIPS in that it can take one or more
        /// template names. The definition in CLIPS beginners guide states the
        /// function does the following: (ppdeftemplate &lt;deftemplate-name>)
        /// </summary>
        public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
        {
            GenericHashMap <object, object> filter = new GenericHashMap <object, object>();

            if (params_Renamed != null && params_Renamed.Length > 0)
            {
                for (int idx = 0; idx < params_Renamed.Length; idx++)
                {
                    if (params_Renamed[idx] is ValueParam)
                    {
                        Object df = ((ValueParam)params_Renamed[idx]).Value;
                        filter.Put(df, df);
                    }
                }
            }
            List <Object> templ = (List <Object>)engine.CurrentFocus.Templates;
            IEnumerator   itr   = templ.GetEnumerator();

            while (itr.MoveNext())
            {
                ITemplate tp = (ITemplate)itr.Current;
                if (filter.Get(tp.Name) != null)
                {
                    engine.writeMessage(tp.toPPString() + "\r\n", "t");
                }
            }
            return(new DefaultReturnVector());
        }
Exemple #6
0
        private void InitBlock()
        {
            bindValues = new GenericHashMap <string, Object>();

            bindings = new GenericHashMap <string, Binding>();

            direction = Constants.FORWARD_CHAINING;
        }
Exemple #7
0
 public GenericHashMap<string, string> createGenericHashMap(int count)
 {
     GenericHashMap<string, string> map = new GenericHashMap<string, string>();
     for (int idx = 0; idx < count; idx++)
     {
         map.Put(count.ToString(), count + "value");
     }
     return map;
 }
        public GenericHashMap <object, object> createHashMap(int count)
        {
            GenericHashMap <object, object> map = new GenericHashMap <object, object>();

            for (int idx = 0; idx < count; idx++)
            {
                map.Put(count.ToString(), count + "value");
            }
            return(map);
        }
        public void testIndex()
        {
            Defclass    dc    = new Defclass(typeof(TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2   bean  = new TestBean2();

            bean.Attr1 = ("testString");
            bean.Attr2 = (1);
            short a3 = 3;

            bean.Attr3 = (a3);
            long a4 = 101;

            bean.Attr4 = (a4);
            float a5 = 10101;

            bean.Attr5 = (a5);
            double a6 = 101.101;

            bean.Attr6 = (a6);

            IFact fact = dtemp.createFact(bean, dc, 1);

            Assert.IsNotNull(fact);
            Console.WriteLine(fact.toFactString());
            CompositeIndex ci =
                new CompositeIndex("attr1", Constants.EQUAL, fact.getSlotValue(0));

            Assert.IsNotNull(ci);
            Console.WriteLine(ci.toPPString());
            GenericHashMap <object, object> map = new GenericHashMap <object, object>();

            map.Put(ci, bean);

            CompositeIndex ci2 =
                new CompositeIndex("attr1", Constants.EQUAL, fact.getSlotValue(0));

            Assert.IsTrue(map.ContainsKey(ci2));

            CompositeIndex ci3 =
                new CompositeIndex("attr1", Constants.NOTEQUAL, fact.getSlotValue(0));

            Assert.IsFalse(map.ContainsKey(ci3));

            CompositeIndex ci4 =
                new CompositeIndex("attr1", Constants.NILL, fact.getSlotValue(0));

            Assert.IsFalse(map.ContainsKey(ci4));

            CompositeIndex ci5 =
                new CompositeIndex("attr1", Constants.NOTNILL, fact.getSlotValue(0));

            Assert.IsFalse(map.ContainsKey(ci5));
        }
Exemple #10
0
 static Strategies()
 {
     DEPTH    = new DepthStrategy();
     BREADTH  = new BreadthStrategy();
     RECENCY  = new RecencyStrategy();
     registry = new GenericHashMap <String, IStrategy>();
     {
         registry.Put(DEPTH.Name, DEPTH);
         registry.Put(BREADTH.Name, BREADTH);
         registry.Put(RECENCY.Name, RECENCY);
     }
 }
Exemple #11
0
 static Strategies()
 {
     DEPTH = new DepthStrategy();
     BREADTH = new BreadthStrategy();
     RECENCY = new RecencyStrategy();
     registry = new GenericHashMap<String, IStrategy>();
     {
         registry.Put(DEPTH.Name, DEPTH);
         registry.Put(BREADTH.Name, BREADTH);
         registry.Put(RECENCY.Name, RECENCY);
     }
 }
Exemple #12
0
        public void GenericHashPerformance()
        {
            //int[] series = new int[] {1000, 10000, 100000, 1000000, 10000000};
            int[]            series = new int[] { 1000, 10000 };
            HashMapBenchmark util   = new HashMapBenchmark();
            Random           ran    = new Random();

            for (int idx = 0; idx < series.Length; idx++)
            {
                GenericHashMap <string, string> map = util.createGenericHashMap(series[idx]);
                long start = DateTime.Now.Ticks;
                for (int idz = 0; idz < 10000000; idz++)
                {
                    String key = ran.Next(series[idx]).ToString();
                    Object val = map.Get(key);
                }

                foreach (IHashMapEntry <string, string> entry in map)
                {
                    string val = entry.Value;
                }

                List <String> keys = new List <String>(map.Count);

                foreach (String key in map.Keys)
                {
                    keys.Add(key);
                    string val = map[key];
                }

                foreach (String val in map.Values)
                {
                    bool yes = map.ContainsValue(val);
                }


                foreach (String key in keys)
                {
                    map.Remove(key);
                }

                long   end     = DateTime.Now.Ticks;
                long   el      = end - start;
                double perOp   = (double)el / 10000000;
                String fstring = (perOp * 1000000).ToString();
                Console.WriteLine("Test for " + series[idx] + " items");
                Console.WriteLine("elapsed time " + el + " millisecond");
                Console.WriteLine("per lookup " + fstring + " nanosecond");
            }
        }
Exemple #13
0
        public void testIndex()
        {
            Defclass dc = new Defclass(typeof (TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2 bean = new TestBean2();
            bean.Attr1 = ("testString");
            bean.Attr2 = (1);
            short a3 = 3;
            bean.Attr3 = (a3);
            long a4 = 101;
            bean.Attr4 = (a4);
            float a5 = 10101;
            bean.Attr5 = (a5);
            double a6 = 101.101;
            bean.Attr6 = (a6);

            IFact fact = dtemp.createFact(bean, dc, 1);
            Assert.IsNotNull(fact);
            Console.WriteLine(fact.toFactString());
            CompositeIndex ci =
                new CompositeIndex("attr1", Constants.EQUAL, fact.getSlotValue(0));
            Assert.IsNotNull(ci);
            Console.WriteLine(ci.toPPString());
            GenericHashMap<object, object> map = new GenericHashMap<object, object>();
            map.Put(ci, bean);

            CompositeIndex ci2 =
                new CompositeIndex("attr1", Constants.EQUAL, fact.getSlotValue(0));
            Assert.IsTrue(map.ContainsKey(ci2));

            CompositeIndex ci3 =
                new CompositeIndex("attr1", Constants.NOTEQUAL, fact.getSlotValue(0));
            Assert.IsFalse(map.ContainsKey(ci3));

            CompositeIndex ci4 =
                new CompositeIndex("attr1", Constants.NILL, fact.getSlotValue(0));
            Assert.IsFalse(map.ContainsKey(ci4));

            CompositeIndex ci5 =
                new CompositeIndex("attr1", Constants.NOTNILL, fact.getSlotValue(0));
            Assert.IsFalse(map.ContainsKey(ci5));
        }
Exemple #14
0
 /// <summary> If the function is called without any parameters, it prints out
 /// all the memories. if parameters are passed, the output will be
 /// filtered.
 /// </summary>
 public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
 {
     GenericHashMap<Object, Object> filter = new GenericHashMap<Object, Object>();
     if (params_Renamed != null && params_Renamed.Length > 0)
     {
         // now we populate the filter
         for (int idx = 0; idx < params_Renamed.Length; idx++)
         {
             if (params_Renamed[idx] is ValueParam)
             {
                 filter.Put(((ValueParam) params_Renamed[idx]).StringValue, null);
             }
             else if (params_Renamed[idx] is BoundParam)
             {
                 // for now, BoundParam is not supported
             }
         }
     }
     engine.WorkingMemory.printWorkingMemory(filter);
     return new DefaultReturnVector();
 }
Exemple #15
0
        /// <summary> If the function is called without any parameters, it prints out
        /// all the memories. if parameters are passed, the output will be
        /// filtered.
        /// </summary>
        public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
        {
            GenericHashMap <Object, Object> filter = new GenericHashMap <Object, Object>();

            if (params_Renamed != null && params_Renamed.Length > 0)
            {
                // now we populate the filter
                for (int idx = 0; idx < params_Renamed.Length; idx++)
                {
                    if (params_Renamed[idx] is ValueParam)
                    {
                        filter.Put(((ValueParam)params_Renamed[idx]).StringValue, null);
                    }
                    else if (params_Renamed[idx] is BoundParam)
                    {
                        // for now, BoundParam is not supported
                    }
                }
            }
            engine.WorkingMemory.printWorkingMemory(filter);
            return(new DefaultReturnVector());
        }
Exemple #16
0
 private void InitBlock()
 {
     bindings = new GenericHashMap<string, object>();
 }
Exemple #17
0
 private void InitBlock()
 {
     bindings = new GenericHashMap <string, object>();
 }
Exemple #18
0
        private void InitBlock()
        {
            bindValues = new GenericHashMap<string, Object>();

            bindings = new GenericHashMap<string, Binding>();

            direction = Constants.FORWARD_CHAINING;
        }
Exemple #19
0
        public void testHashMapIndex()
        {
            Defclass    dc    = new Defclass(typeof(TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2   bean  = new TestBean2();

            bean.Attr1 = "testString";
            bean.Attr2 = 1;
            short a3 = 3;

            bean.Attr3 = a3;
            long a4 = 101;

            bean.Attr4 = a4;
            float a5 = 10101;

            bean.Attr5 = a5;
            double a6 = 101.101;

            bean.Attr6 = a6;

            TestBean2 bean2 = new TestBean2();

            bean2.Attr1 = "testString2";
            bean2.Attr2 = 12;
            short a32 = 32;

            bean2.Attr3 = a32;
            long a42 = 1012;

            bean2.Attr4 = a42;
            float a52 = 101012;

            bean2.Attr5 = a52;
            double a62 = 101.1012;

            bean2.Attr6 = a62;

            TestBean2 bean3 = new TestBean2();

            bean3.Attr1 = "testString3";
            bean3.Attr2 = 13;
            short a33 = 33;

            bean3.Attr3 = a33;
            long a43 = 1013;

            bean3.Attr4 = a43;
            float a53 = 101013;

            bean3.Attr5 = a53;
            double a63 = 101.1013;

            bean3.Attr6 = a63;

            TestBean2 bean4 = new TestBean2();

            bean4.Attr1 = "testString4";
            bean4.Attr2 = 14;
            short a34 = 34;

            bean4.Attr3 = a34;
            long a44 = 1014;

            bean4.Attr4 = a44;
            float a54 = 101014;

            bean4.Attr5 = a54;
            double a64 = 101.1014;

            bean4.Attr6 = a64;

            TestBean2 bean5 = new TestBean2();

            bean5.Attr1 = "testString5";
            bean5.Attr2 = 15;
            short a35 = 35;

            bean5.Attr3 = a35;
            long a45 = 1015;

            bean5.Attr4 = a45;
            float a55 = 101015;

            bean5.Attr5 = a55;
            double a65 = 101.1015;

            bean5.Attr6 = a65;

            IFact fact  = dtemp.createFact(bean, dc, 1);
            IFact fact2 = dtemp.createFact(bean2, dc, 1);
            IFact fact3 = dtemp.createFact(bean3, dc, 1);
            IFact fact4 = dtemp.createFact(bean4, dc, 1);
            IFact fact5 = dtemp.createFact(bean5, dc, 1);

            IFact[] list1 = new IFact[] { fact, fact2, fact3, fact4, fact5 };
            IFact[] list2 = new IFact[] { fact, fact2, fact3, fact4, fact5 };

            Index in1 = new Index(list1);
            Index in2 = new Index(list2);

            Assert.AreEqual(true, in1.Equals(in2));

            GenericHashMap <object, object> map = new GenericHashMap <object, object>();

            map.Put(in1, list1);
            // simple test to see if HashMap.ContainsKey(in1) works
            Assert.AreEqual(true, map.ContainsKey(in1));
            // now test with the second instance of index, this should return
            // true, since Index class overrides Equals() and GetHashCode().
            Assert.AreEqual(true, map.ContainsKey(in2));
        }
Exemple #20
0
        public void testHashMapIndex()
        {
            Defclass dc = new Defclass(typeof (TestBean2));
            Deftemplate dtemp = dc.createDeftemplate("testBean2");
            TestBean2 bean = new TestBean2();
            bean.Attr1 = "testString";
            bean.Attr2 = 1;
            short a3 = 3;
            bean.Attr3 = a3;
            long a4 = 101;
            bean.Attr4 = a4;
            float a5 = 10101;
            bean.Attr5 = a5;
            double a6 = 101.101;
            bean.Attr6 = a6;

            TestBean2 bean2 = new TestBean2();
            bean2.Attr1 = "testString2";
            bean2.Attr2 = 12;
            short a32 = 32;
            bean2.Attr3 = a32;
            long a42 = 1012;
            bean2.Attr4 = a42;
            float a52 = 101012;
            bean2.Attr5 = a52;
            double a62 = 101.1012;
            bean2.Attr6 = a62;

            TestBean2 bean3 = new TestBean2();
            bean3.Attr1 = "testString3";
            bean3.Attr2 = 13;
            short a33 = 33;
            bean3.Attr3 = a33;
            long a43 = 1013;
            bean3.Attr4 = a43;
            float a53 = 101013;
            bean3.Attr5 = a53;
            double a63 = 101.1013;
            bean3.Attr6 = a63;

            TestBean2 bean4 = new TestBean2();
            bean4.Attr1 = "testString4";
            bean4.Attr2 = 14;
            short a34 = 34;
            bean4.Attr3 = a34;
            long a44 = 1014;
            bean4.Attr4 = a44;
            float a54 = 101014;
            bean4.Attr5 = a54;
            double a64 = 101.1014;
            bean4.Attr6 = a64;

            TestBean2 bean5 = new TestBean2();
            bean5.Attr1 = "testString5";
            bean5.Attr2 = 15;
            short a35 = 35;
            bean5.Attr3 = a35;
            long a45 = 1015;
            bean5.Attr4 = a45;
            float a55 = 101015;
            bean5.Attr5 = a55;
            double a65 = 101.1015;
            bean5.Attr6 = a65;

            IFact fact = dtemp.createFact(bean, dc, 1);
            IFact fact2 = dtemp.createFact(bean2, dc, 1);
            IFact fact3 = dtemp.createFact(bean3, dc, 1);
            IFact fact4 = dtemp.createFact(bean4, dc, 1);
            IFact fact5 = dtemp.createFact(bean5, dc, 1);

            IFact[] list1 = new IFact[] {fact, fact2, fact3, fact4, fact5};
            IFact[] list2 = new IFact[] {fact, fact2, fact3, fact4, fact5};

            Index in1 = new Index(list1);
            Index in2 = new Index(list2);
            Assert.AreEqual(true, in1.Equals(in2));

            GenericHashMap<object, object> map = new GenericHashMap<object, object>();
            map.Put(in1, list1);
            // simple test to see if HashMap.ContainsKey(in1) works
            Assert.AreEqual(true, map.ContainsKey(in1));
            // now test with the second instance of index, this should return
            // true, since Index class overrides Equals() and GetHashCode().
            Assert.AreEqual(true, map.ContainsKey(in2));
        }