Beispiel #1
0
        public bool ConstraintSatisfy(Equation eq, out object obj)
        {
            obj = null;

            var graphNodes = _nodes;

            var lst = new List <Tuple <object, object> >();

            #region Unary Relation Checking
            for (var i = 0; i < graphNodes.Count; i++)
            {
                var  tempNode = graphNodes[i];
                bool result   = RelationLogic.ConstraintCheck(tempNode, eq, null, out obj);
                if (result)
                {
                    var tempTuple = obj as Tuple <object, object>;
                    if (tempTuple != null)
                    {
                        lst.Add(tempTuple);
                    }
                    var tempTuples = obj as List <Tuple <object, object> >;
                    if (tempTuples != null)
                    {
                        lst.AddRange(tempTuples);
                    }
                }
            }
            #endregion
            obj = lst;
            return(lst.Count != 0);
        }
Beispiel #2
0
        public void Test_Unify_4()
        {
            // c=2, b=a
            var c        = new Var("c");
            var b        = new Var("b");
            var eqGoal   = new EqGoal(c, 2);
            var goalNode = new GoalNode(eqGoal);

            var a        = new Var("a");
            var equation = new Equation(b, a);

            object obj;
            bool   result = RelationLogic.ConstraintCheck(goalNode, equation, null, out obj);

            Assert.False(result);
        }
Beispiel #3
0
        public void Test_Unify_3()
        {
            // a=2, b=a
            var a        = new Var("a");
            var b        = new Var("b");
            var eqGoal   = new EqGoal(a, 2);
            var goalNode = new GoalNode(eqGoal);

            var equation = new Equation(b, a);

            object obj;
            bool   result = RelationLogic.ConstraintCheck(goalNode, equation, null, out obj);

            Assert.True(result);
            Assert.NotNull(obj);
        }
        public void Test_CreateLine_5()
        {
            var x       = new Var('x');
            var point   = new Point(2, x);
            var ps      = new PointSymbol(point);
            var psNode  = new ShapeNode(ps);
            var point1  = new Point(3, 4);
            var ps1     = new PointSymbol(point1);
            var psNode1 = new ShapeNode(ps1);

            object obj;
            bool   value = RelationLogic.ConstraintCheck(psNode, psNode1, null, ShapeType.Line, out obj);

            Assert.True(value);
            var ls = obj as LineSymbol;

            Assert.NotNull(ls);
            Assert.False(ls.Shape.Concrete);
        }
        public void Test_CreateLine_7()
        {
            var m        = new Var("m");
            var eqGoal   = new EqGoal(m, 1);
            var goalNode = new GoalNode(eqGoal);
            var point1   = new Point(5, 8);
            var ps1      = new PointSymbol(point1);
            var psNode1  = new ShapeNode(ps1);

            object obj;
            bool   value = RelationLogic.ConstraintCheck(psNode1, goalNode, "lineG", null, out obj);

            Assert.True(value);
            var ls = obj as LineSymbol;

            Assert.NotNull(ls);
            Assert.True(ls.Shape.Concrete);
            Assert.True(ls.ToString().Equals("x-y+3=0"));
        }
        public void Test_CreateLine_6()
        {
            var point   = new Point(-1, 2);
            var ps      = new PointSymbol(point);
            var psNode  = new ShapeNode(ps);
            var point1  = new Point(5, 8);
            var ps1     = new PointSymbol(point1);
            var psNode1 = new ShapeNode(ps1);

            object obj;
            bool   value = RelationLogic.ConstraintCheck(psNode, psNode1, null, ShapeType.Line, out obj);

            Assert.True(value);
            var ls = obj as LineSymbol;

            Assert.NotNull(ls);
            Assert.True(ls.Shape.Concrete);
            Assert.True(ls.ToString().Equals("x-y+3=0"));
        }
Beispiel #7
0
        public void Test_Unify_2()
        {
            //true positive
            var x         = new Var('x');
            var point     = new Point(x, 4);
            var ps        = new PointSymbol(point);
            var shapeNode = new ShapeNode(ps);

            var point1     = new Point(4, 5);
            var ps1        = new PointSymbol(point1);
            var shapeNode1 = new ShapeNode(ps1);

            var eqGoal = new EqGoal(x, 9);

            object obj;
            bool   result = RelationLogic.ConstraintCheck(shapeNode, shapeNode1, eqGoal, null, out obj);

            Assert.False(result);
        }
Beispiel #8
0
        public void Test_Unify_1()
        {
            //a = 1, a*b = -1;
            //true positive

            var a      = new Var("a");
            var b      = new Var("b");
            var eqGoal = new EqGoal(a, 1);

            var lhsTerm = new Term(Expression.Multiply, new List <object>()
            {
                a, b
            });
            var equation = new Equation(lhsTerm, -1);
            var eqNode   = new EquationNode(equation);

            object obj;
            bool   result = RelationLogic.ConstraintCheck(eqNode, eqGoal, null, out obj);

            Assert.True(result);
            Assert.NotNull(obj);
        }
Beispiel #9
0
        public void Test_Unify_1()
        {
            //true positive
            var x         = new Var('x');
            var y         = new Var('y');
            var point     = new Point(x, y);
            var ps        = new PointSymbol(point);
            var shapeNode = new ShapeNode(ps);

            var eqGoal = new EqGoal(x, 1);  // x=1

            object obj;
            bool   result = RelationLogic.ConstraintCheck(shapeNode, eqGoal, null, out obj);

            Assert.True(result);
            Assert.NotNull(obj);

/*            var lst = obj as Tuple<object, object>;
 *          Assert.NotNull(lst);
 *          Assert.True(lst.Count == 1);
 *          var tuple = lst[0];
 *          Assert.True(tuple.Item1.Equals(shapeNode));
 *          Assert.True(tuple.Item2.Equals(eqGoal));*/
        }
Beispiel #10
0
        public bool ConstraintSatisfy(EqGoal goal, out object obj)
        {
            var graphNodes = _nodes;

            var lst = new List <Tuple <object, object> >();

            #region Unary Relation Checking

            for (var i = 0; i < graphNodes.Count; i++)
            {
                var  tempNode = graphNodes[i];
                bool result   = RelationLogic.ConstraintCheck(tempNode, goal, null, out obj);
                if (result)
                {
                    var tempTuple = obj as Tuple <object, object>;
                    if (tempTuple != null)
                    {
                        lst.Add(tempTuple);
                    }
                    var tempTuples = obj as List <Tuple <object, object> >;
                    if (tempTuples != null)
                    {
                        lst.AddRange(tempTuples);
                    }
                }
            }

            #endregion

            #region Binary Relation Checking
            //Two layer for loop to iterate all Nodes
            //binary relation build up

            // overfitting:
            // underfitting:
            for (var i = 0; i < graphNodes.Count - 1; i++)
            {
                var outerNode = graphNodes[i];
                for (var j = i + 1; j < graphNodes.Count; j++)
                {
                    var  innerNode = graphNodes[j];
                    bool result    = RelationLogic.ConstraintCheck(outerNode, innerNode, goal, null, out obj);
                    if (result)
                    {
                        var tempTuple = obj as Tuple <object, object>;
                        if (tempTuple != null)
                        {
                            lst.Add(tempTuple);
                        }
                        var tempTuples = obj as List <Tuple <object, object> >;
                        if (tempTuples != null)
                        {
                            lst.AddRange(tempTuples);
                        }
                    }
                }
            }

            obj = lst;
            #endregion

            return(lst.Count != 0);
        }
Beispiel #11
0
        /// <summary>
        /// This func takes charge of pattern match string with
        /// existing nodes
        /// Two constraint
        /// Priority: label constraint > shapeType constraint
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="label"></param>
        /// <param name="st"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool ConstraintSatisfy(string label, ShapeType?st, out object obj)
        {
            obj = null;
            var graphNodes = _nodes;

            var dict = new Dictionary <object, object>();

            #region Unary Relation Checking

            for (var i = 0; i < graphNodes.Count; i++)
            {
                var  tempNode = graphNodes[i];
                bool result   = RelationLogic.ConstraintCheck(tempNode, label, st, out obj);
                if (result)
                {
                    var queryNode = tempNode as QueryNode;
                    if (queryNode == null)
                    {
                        dict.Add(tempNode, obj);
                    }
                    else
                    {
                        foreach (var tempGn in queryNode.InternalNodes)
                        {
                            if (!tempGn.Related)
                            {
                                continue;
                            }
                            dict.Add(tempGn, obj);
                        }
                    }
                }
            }

            if (dict.Count != 0)
            {
                //Conflict resolution
                ConflictResolve(dict);
            }

            #endregion

            #region Binary Relation Checking
            //Two layer for loop to iterate all Nodes
            //binary relation build up

            // overfitting:
            // underfitting:
            for (var i = 0; i < graphNodes.Count - 1; i++)
            {
                var outerNode = graphNodes[i];
                for (var j = i + 1; j < graphNodes.Count; j++)
                {
                    var  innerNode = graphNodes[j];
                    var  tuple     = new Tuple <GraphNode, GraphNode>(outerNode, innerNode);
                    bool result    = RelationLogic.ConstraintCheck(outerNode, innerNode, label, st, out obj);

                    if (result)
                    {
                        var lst = obj as List <object>;
                        if (lst != null)
                        {
                            object source, target;
                            source = tuple;
                            foreach (var tempObj in lst)
                            {
                                target = tempObj;
                                dict.Add(source, target);
                                source = target;
                            }
                        }
                        else
                        {
                            dict.Add(tuple, obj);
                        }
                    }
                    else
                    {
                        if (obj != null)
                        {
                            return(false);
                        }
                    }
                }
            }
            #endregion

            //TODO analysis
            if (dict.Count != 0)
            {
                //Conflict resolution
                //ConflictResolve(dict);
                ConflictResolve2(dict);
                obj = dict;
                return(true);
            }
            return(false);
        }