Exemplo n.º 1
0
        public void test_reify_object_dynamic()
        {
            //dynamic approach
            /*            obj = reify_object(Foo(1, var(3)), {var(3): 4})
                        assert obj.a == 1
                        assert obj.b == 4

                        f = Foo(1, 2)
                        assert reify_object(f, {}) is f
             */

            dynamic foo = new DyLogicObject();
            foo.a = 1;
            var variable = new Var(3);
            foo.b = variable;

            var dict = new Dictionary<object, object>();
            dict.Add(variable, 4);

            dynamic obj = LogicSharp.Reify_Object(foo, dict);
            Assert.NotNull(obj);
            Assert.True(1.Equals(obj.a));
            Assert.True(4.Equals(obj.b));

            dynamic f = new DyLogicObject();
            f.a = 1;
            f.b = 2;

            dict = new Dictionary<object, object>();
            obj = LogicSharp.Reify_Object(f, dict);
            Assert.True(obj == f);
        }
Exemplo n.º 2
0
 public void ImportTrace(DyLogicObject obj)
 {
     if (obj.Traces.Count == 0) return;
     foreach (var tuple in obj.Traces)
     {
         Traces.Add(tuple);
     }
 }
Exemplo n.º 3
0
        public void test_reify_object2()
        {
            var foo = new DyLogicObject();
            foo.Properties.Add("y", 1);
            var goal = new EqGoal(new Var("x"), 2);
            foo.Reify(goal);

            Assert.True(foo.Properties.Count == 2);
        }
Exemplo n.º 4
0
 public void ImportTrace(DyLogicObject obj)
 {
     foreach (var tuple in obj.Traces)
     {
         Traces.Add(tuple);
     }
     foreach (var tempObj in obj._innerLoop)
     {
         _innerLoop.Add(tempObj);                
     }
 }
Exemplo n.º 5
0
 public static object Run(Var variable, DyLogicObject obj)
 {
     if (obj.Properties.ContainsKey(variable))
     {
         return(obj.Properties[variable]);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 6
0
 public void ImportTrace(DyLogicObject obj)
 {
     foreach (var tuple in obj.Traces)
     {
         Traces.Add(tuple);
     }
     foreach (var tempObj in obj._innerLoop)
     {
         _innerLoop.Add(tempObj);
     }
 }
 public void ImportTrace(DyLogicObject obj)
 {
     if (obj.Traces.Count == 0)
     {
         return;
     }
     foreach (var tuple in obj.Traces)
     {
         Traces.Add(tuple);
     }
 }
Exemplo n.º 8
0
 public static object Run(Var variable, Goal goal, DyLogicObject obj)
 {
     if (goal.Unify(obj.Properties))
     {
         return(obj.Properties[variable]);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 9
0
        public static void Reify(this DyLogicObject logicObj, IEnumerable <Goal> goals)
        {
            IEnumerable <KeyValuePair <object, object> > pairs =
                LogicSharp.logic_All(goals, logicObj.Properties);

            if (pairs == null)
            {
                return;
            }

            foreach (KeyValuePair <object, object> pair in pairs)
            {
                if (!logicObj.Properties.ContainsKey(pair.Key))
                {
                    logicObj.Properties.Add(pair.Key, pair.Value);
                }
            }
        }
Exemplo n.º 10
0
 public static object Reify_Object(DyLogicObject logicObj, Dictionary<object, object> s)
 {
     var obj = Reify(logicObj.Properties, s) as Dictionary<object, object>;
     if (LogicSharp.equal_test(obj, logicObj.Properties))
     {
         return logicObj;
     }
     else
     {
         //Initialize a new dynamic object
         var newObj = new DyLogicObject();
         if (obj != null)
         {
             foreach (var pair in obj)
             {
                 newObj.Properties.Add(pair.Key, pair.Value);
             }
         }
         return newObj;
     }
 }
Exemplo n.º 11
0
        public static object Reify_Object(DyLogicObject logicObj, Dictionary <object, object> s)
        {
            var obj = Reify(logicObj.Properties, s) as Dictionary <object, object>;

            if (LogicSharp.equal_test(obj, logicObj.Properties))
            {
                return(logicObj);
            }
            else
            {
                //Initialize a new dynamic object
                var newObj = new DyLogicObject();
                if (obj != null)
                {
                    foreach (var pair in obj)
                    {
                        newObj.Properties.Add(pair.Key, pair.Value);
                    }
                }
                return(newObj);
            }
        }
Exemplo n.º 12
0
        public void test_unify_dyna_object()
        {
            /*                
                        assert unify_object(Foo(1, 2), Foo(1, 2), {}) == {}
                        assert unify_object(Foo(1, 2), Foo(1, 3), {}) == False
                        assert unify_object(Foo(1, 2), Foo(1, var(3)), {}) == {var(3): 2}
             */
            dynamic foo = new DyLogicObject();
            foo.a = 1;
            foo.b = 2;

            dynamic foo2 = new DyLogicObject();
            foo2.a = 1;
            foo2.b = 2;

            var dict = new Dictionary<object, object>();
            bool result = LogicSharp.Unify_Object(foo, foo2, dict);
            Assert.True(result);
            Assert.True(dict.Count == 0);

            dynamic foo3 = new DyLogicObject();
            foo3.a = 1;
            foo3.b = 3;
            result = LogicSharp.Unify_Object(foo, foo3, dict);
            Assert.False(result);

            dynamic foo4 = new DyLogicObject();
            foo4.a = 1;
            var variable = new Var(3);
            foo4.b = variable;
            result = LogicSharp.Unify_Object(foo, foo4, dict);
            Assert.True(result);
            Assert.True(dict.Count == 1);
            Assert.True(dict.ContainsKey(variable));
            Assert.True(dict[variable].Equals(2));
        }
Exemplo n.º 13
0
 public static object Run(Var variable, List<Goal> goals, DyLogicObject obj)
 {
     return null;
 }
Exemplo n.º 14
0
 public static object Run(Var variable, Goal goal, DyLogicObject obj)
 {
     if (goal.Unify(obj.Properties))
     {
         return obj.Properties[variable];
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 15
0
 public static object Run(Var variable, DyLogicObject obj)
 {
     if (obj.Properties.ContainsKey(variable))
     {
         return obj.Properties[variable];
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 16
0
 public static void Reify(this DyLogicObject logicObj, Goal goal)
 {
     goal.Unify(logicObj.Properties);
 }
Exemplo n.º 17
0
 public static object Unify_Object(DyLogicObject dy1, DyLogicObject dy2, Dictionary<object, object> s)
 {
     return Unify(dy1.Properties, dy2.Properties, s);
 }
Exemplo n.º 18
0
 public static object Run(Var variable, List <Goal> goals, DyLogicObject obj)
 {
     return(null);
 }
Exemplo n.º 19
0
 public static object Unify_Object(DyLogicObject dy1, DyLogicObject dy2, Dictionary <object, object> s)
 {
     return(Unify(dy1.Properties, dy2.Properties, s));
 }