private static bool ConstraintCheck(ShapeNode shapeNode, GoalNode goalNode,
                                     string constraint1, ShapeType constraint2, out object output)
 {
     output = null;
     //TODO
     return(false);
 }
        private static bool ConstraintCheck(ShapeNode shapeNode, GoalNode goalNode,
                                            object constraint, out object output)
        {
            output = null;
            var shape1 = shapeNode.ShapeSymbol;
            var goal   = goalNode.Goal as EqGoal;

            Debug.Assert(shape1 != null);
            Debug.Assert(goal != null);

            var label = constraint as string;

            if (label != null)
            {
                var pt1 = shape1 as PointSymbol;
                if (pt1 != null)
                {
                    if (LineAcronym.EqualGeneralFormLabels(label))
                    {
                        var ls = LineBinaryRelation.Unify(pt1, goal);
                        if (ls != null)
                        {
                            ls.OutputType = LineType.GeneralForm;
                            output        = ls;
                            return(true);
                        }
                    }
                }
            }
            //TODO
            return(false);
        }
Exemplo n.º 3
0
        private void BuildRelation(GraphNode goalNode, object obj)
        {
            var unaryNode  = obj as GraphNode;
            var binaryNode = obj as Tuple <GraphNode, GraphNode>;

            var eqGoal = obj as EqGoal;  //new node synthesize

            if (unaryNode != null)
            {
                CreateEdge(goalNode, unaryNode);
            }
            if (binaryNode != null)
            {
                var node1 = binaryNode.Item1;
                var node2 = binaryNode.Item2;
                CreateEdge(goalNode, node1);
                CreateEdge(goalNode, node2);
            }
            if (eqGoal != null)
            {
                GoalNode synNode = AddGoalNode(eqGoal);
                synNode.Synthesized = true;
                CreateEdge(goalNode, synNode);
            }
        }
Exemplo n.º 4
0
        private void BuildRelation(object obj, GraphNode goalNode)
        {
            var unaryNode  = obj as GraphNode;
            var binaryNode = obj as Tuple <object, object>;
            var eqGoal     = obj as EqGoal; //new node synthesize

            if (unaryNode != null)
            {
                CreateEdge(unaryNode, goalNode);
            }

            if (binaryNode != null)
            {
                var node1 = binaryNode.Item1 as GraphNode;
                var node2 = binaryNode.Item2 as GraphNode;
                CreateEdge(node1, goalNode);
                CreateEdge(node2, goalNode);
            }

            if (eqGoal != null)
            {
                GoalNode synNode = AddGoalNode(eqGoal);
                synNode.Synthesized = true;
                CreateEdge(synNode, goalNode);
            }
        }
        private void UnReify(GoalNode goalNode)
        {
            var eqGoal = goalNode.Goal as EqGoal;

            Debug.Assert(eqGoal != null);
            if (!eqGoal.Concrete)
            {
                return;
            }

            for (int i = 0; i < goalNode.OutEdges.Count; i++)
            {
                GraphEdge outEdge = goalNode.OutEdges[i];
                if (outEdge.Target.Equals(goalNode))
                {
                    return;                                  // cyclic halt
                }
                var shapeNode = outEdge.Target as ShapeNode;
                if (shapeNode != null)
                {
                    if (DispatchUnreify(shapeNode.ShapeSymbol, eqGoal))
                    {
                        UnReify(shapeNode); //dfs
                    }
                }
                var eqNode = outEdge.Target as EquationNode;
                if (eqNode != null)
                {
                    if (DispatchUnreify(eqNode.Equation, eqGoal))
                    {
                        UnReify(eqNode);//dfs
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static bool Satisfy(this GoalNode goalNode, string variable)
        {
            var eqGoal = goalNode.Goal as EqGoal;

            if (eqGoal != null && eqGoal.Rhs != null)
            {
                return(eqGoal.Lhs.ToString().Equals(variable));
            }
            return(false);
        }
Exemplo n.º 7
0
        private QueryNode CreateQueryNode(EqGoal goal)
        {
            var query     = new Query(goal.Lhs);
            var queryNode = new QueryNode(query);

            var iGoalNode = new GoalNode(goal);

            queryNode.InternalNodes.Add(iGoalNode);
            return(queryNode);
        }
        private void Reify(GoalNode goalNode, GraphNode rootNode)
        {
            var eqGoal = goalNode.Goal as EqGoal;

            Debug.Assert(eqGoal != null);
            if (!eqGoal.Concrete)
            {
                return;
            }

            foreach (GraphEdge ge in goalNode.OutEdges)
            {
                var upperNode = ge.Target;
                if (upperNode.Equals(rootNode))
                {
                    return;
                }
                if (upperNode.Synthesized)
                {
                    return;
                }

                #region Target Node Analysis

                var shapeNode = upperNode as ShapeNode;
                if (shapeNode != null)
                {
                    if (shapeNode.ShapeSymbol.Shape.Concrete)
                    {
                        continue;
                    }

/*                    if (DispatchReify(shapeNode.ShapeSymbol, eqGoal))
 *                  {
 *                      Reify(shapeNode); //depth first search
 *                  }                    */
                    DispatchReify(shapeNode.ShapeSymbol, eqGoal);
                }
                var eqNode = upperNode as EquationNode;
                if (eqNode != null)
                {
                    DispatchReify(eqNode.Equation, eqGoal);

/*                    if (DispatchReify(eqNode.Equation, eqGoal))
 *                  {
 *                      Reify(eqNode);
 *                  }*/
                }

                #endregion

                Reify(upperNode, rootNode); //depth first search
            }
        }
Exemplo n.º 9
0
        private QueryNode CreateQueryNode(List <EqGoal> goals)
        {
            var query     = new Query(goals[0].Lhs);
            var queryNode = new QueryNode(query);

            foreach (EqGoal igoal in goals)
            {
                var iGoalNode = new GoalNode(igoal);
                queryNode.InternalNodes.Add(iGoalNode);
            }
            return(queryNode);
        }
        private static bool ConstraintCheck(GoalNode goalNode1, GoalNode goalNode2,
                                            object constraint, out object output)
        {
            Debug.Assert(constraint != null);
            var st    = constraint as ShapeType?;
            var goal1 = goalNode1.Goal as EqGoal;
            var goal2 = goalNode2.Goal as EqGoal;

            Debug.Assert(goal1 != null);
            Debug.Assert(goal2 != null);
            output = null;
            if (st != null)
            {
                switch (st.Value)
                {
                case ShapeType.Line:
                    output = LineBinaryRelation.Unify(goal1, goal2);
                    break;
                }
                return(output != null);
            }
            var label = constraint as string;

            if (label != null)
            {
                //TODO
                if (LineAcronym.EqualGeneralFormLabels(label))
                {
                    output = LineBinaryRelation.Unify(goal1, goal2);
                    var ls = output as LineSymbol;
                    if (ls != null)
                    {
                        ls.OutputType = LineType.GeneralForm;
                        TraceInstructionalDesign.FromLineSlopeIntercetpToLineGeneralForm(ls);
                        return(true);
                    }
                    return(false);
                }
                if (LineAcronym.EqualSlopeInterceptFormLabels(label))
                {
                    output = LineBinaryRelation.Unify(goal1, goal2);
                    var ls = output as LineSymbol;
                    if (ls != null)
                    {
                        ls.OutputType = LineType.SlopeIntercept;
                        return(true);
                    }
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 11
0
        public static bool Satisfy(this GoalNode goalNode, Equation eq)
        {
            var goal = goalNode.Goal as EqGoal;

            Debug.Assert(goal != null);
            if (!goal.Concrete)
            {
                return(false);
            }
            var goalVar = goal.Lhs as Var;

            Debug.Assert(goalVar != null);
            return(eq.ContainsVar(goalVar));
        }
 private static bool ConstraintCheck(GoalNode goalNode1, GoalNode goalNode2,
             object constraint, out object output)
 {
     Debug.Assert(constraint != null);
     var st = constraint as ShapeType?;
     var goal1 = goalNode1.Goal as EqGoal;
     var goal2 = goalNode2.Goal as EqGoal;
     Debug.Assert(goal1 != null);
     Debug.Assert(goal2 != null);
     output = null;
     if (st != null)
     {
         switch (st.Value)
         {
             case ShapeType.Line:
                 output = LineBinaryRelation.Unify(goal1, goal2);
                 break;
         }
         return output != null;
     }
     var label = constraint as string;
     if (label != null)
     {
         //TODO
         if (LineAcronym.EqualGeneralFormLabels(label))
         {
             output = LineBinaryRelation.Unify(goal1, goal2);
             var ls = output as LineSymbol;
             if (ls != null)
             {
                 ls.OutputType = LineType.GeneralForm;
                 TraceInstructionalDesign.FromLineSlopeIntercetpToLineGeneralForm(ls);
                 return true;
             }
             return false;
         }
         if (LineAcronym.EqualSlopeInterceptFormLabels(label))
         {
             output = LineBinaryRelation.Unify(goal1, goal2);
             var ls = output as LineSymbol;
             if (ls != null)
             {
                 ls.OutputType = LineType.SlopeIntercept;
                 return true;
             }
             return false;
         }
     }
     return false;
 }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        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"));
        }
Exemplo n.º 17
0
        private GoalNode AddGoalNode(Goal goal)
        {
            //1. build relation using geometry constraint-solving (synthesize new node) (Top-Down)
            //2. Reify itself (Bottom-up)
            var eqGoal = goal as EqGoal;

            Debug.Assert(eqGoal != null);
            Debug.Assert(eqGoal.Lhs != null);
            Debug.Assert(eqGoal.Rhs != null);
            var lhs = eqGoal.Lhs.ToString();

            Debug.Assert(lhs != null);

            object relations;

            ConstraintSatisfy(eqGoal, out relations);
            GoalNode gGoalNode = CreateGoalNode(eqGoal, relations);

            Reify(gGoalNode);
            return(gGoalNode);
        }
Exemplo n.º 18
0
        private GoalNode CreateGoalNode(EqGoal goal, object obj)
        {
            var gn = new GoalNode(goal);

            var lst = obj as List <Tuple <object, object> >;

            if (lst == null)
            {
                return(gn);
            }
            foreach (var tuple in lst)
            {
                if (tuple.Item1.Equals(goal))
                {
                    BuildRelation(gn, tuple.Item2);
                }
                else if (tuple.Item2.Equals(goal))
                {
                    BuildRelation(tuple.Item1, gn);
                }
                else
                {
                    /* var gn1 = tuple.Item1 as GraphNode;
                     * if (gn1 != null)
                     * {
                     *   BuildRelation(gn1, tuple.Item2);
                     * }
                     * var gn2 = tuple.Item2 as GraphNode;
                     * if (gn2 != null)
                     * {
                     *   BuildRelation(tuple.Item1, gn2);
                     * }*/
                }
            }

            _nodes.Add(gn);
            return(gn);
        }
        private static bool ConstraintCheck(ShapeNode shapeNode, GoalNode goalNode,
                    object constraint, out object output)
        {
            output = null;
            var shape1 = shapeNode.ShapeSymbol;
            var goal = goalNode.Goal as EqGoal;
            Debug.Assert(shape1 != null);
            Debug.Assert(goal!= null);

            var label = constraint as string;
            if (label != null)
            {
                var pt1 = shape1 as PointSymbol;
                if (pt1 != null)
                {
                    if (LineAcronym.EqualGeneralFormLabels(label))
                    {
                        var ls = LineBinaryRelation.Unify(pt1, goal);
                        if (ls != null)
                        {
                            ls.OutputType = LineType.GeneralForm;
                            output = ls;
                            return true;
                        }
                    }
                }                
            }
            //TODO
            return false;
        }
Exemplo n.º 20
0
        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"));
        }
Exemplo n.º 21
0
        private GoalNode CreateGoalNode(EqGoal goal, object obj)
        {
            var gn = new GoalNode(goal);

            var lst = obj as List<Tuple<object, object>>;
            if (lst == null) return gn;
            foreach (var tuple in lst)
            {
                if (tuple.Item1.Equals(goal))
                {
                    BuildRelation(gn, tuple.Item2);
                }
                else if (tuple.Item2.Equals(goal))
                {
                    BuildRelation(tuple.Item1, gn);
                }
                else
                {
                   /* var gn1 = tuple.Item1 as GraphNode;
                    if (gn1 != null)
                    {
                        BuildRelation(gn1, tuple.Item2);                        
                    }
                    var gn2 = tuple.Item2 as GraphNode;
                    if (gn2 != null)
                    {
                        BuildRelation(tuple.Item1, gn2);
                    }*/
                }
            }

            _nodes.Add(gn);
            return gn;
        }
Exemplo n.º 22
0
        private QueryNode CreateQueryNode(Query query, object obj)
        {
            var queryNode = new QueryNode(query);

            var dict = obj as Dictionary<object, object>;
            if (dict == null) return queryNode;

            #region Unary and Binary Relation

            foreach (KeyValuePair<object, object> pair in dict)
            {
                var unaryNode = pair.Key as GraphNode;
                var binaryNode = pair.Key as Tuple<GraphNode, GraphNode>;
                var uunaryNode = pair.Key as List<GraphNode>;

                if (unaryNode != null)
                {
                    #region Unary Node
                    var eqGoal = pair.Value as EqGoal;
                    var shapeSymbol = pair.Value as ShapeSymbol;
                    if (eqGoal != null)
                    {
                        var gGoalNode = new GoalNode(eqGoal);
                        queryNode.InternalNodes.Add(gGoalNode);
                        CreateEdge(unaryNode, gGoalNode);
                        continue;
                    }
                    if (shapeSymbol != null)
                    {
                        var gShapeNode = new ShapeNode(shapeSymbol);
                        queryNode.InternalNodes.Add(gShapeNode);
                        var sourceNode = pair.Key;
                        Debug.Assert(sourceNode != null);
                        CreateEdge(unaryNode, gShapeNode);
                        continue;
                    }
                    #endregion
                }

                if (binaryNode != null)
                {
                    #region Binary Node
                    var gShape = pair.Value as ShapeSymbol;
                    if (gShape != null)
                    {
                        var shapeNode = new ShapeNode(gShape);
                        queryNode.InternalNodes.Add(shapeNode);
                        var sourceNode1 = binaryNode.Item1;
                        var sourceNode2 = binaryNode.Item2;
                        Debug.Assert(sourceNode1 != null);
                        Debug.Assert(sourceNode2 != null);
                        CreateEdge(sourceNode1, shapeNode);
                        CreateEdge(sourceNode2, shapeNode);
                    }

                    var gGoal = pair.Value as EqGoal;
                    if (gGoal != null)
                    {
                        var goalNode = new GoalNode(gGoal);
                        queryNode.InternalNodes.Add(goalNode);
                        var sourceNode1 = binaryNode.Item1;
                        var sourceNode2 = binaryNode.Item2;
                        Debug.Assert(sourceNode1 != null);
                        Debug.Assert(sourceNode2 != null);
                        CreateEdge(sourceNode1, goalNode);
                        CreateEdge(sourceNode2, goalNode);
                    }

                    #endregion
                }

                var findNode = SearchNode(pair.Key);
                if (findNode != null)
                {
                    #region Find Node
                    var eqGoal = pair.Value as EqGoal;
                    var shapeSymbol = pair.Value as ShapeSymbol;
                    if (eqGoal != null)
                    {
                        var gGoalNode = new GoalNode(eqGoal);
                        queryNode.InternalNodes.Add(gGoalNode);
                        CreateEdge(findNode, gGoalNode);
                        continue;
                    }
                    if (shapeSymbol != null)
                    {
                        var gShapeNode = new ShapeNode(shapeSymbol);
                        queryNode.InternalNodes.Add(gShapeNode);
                        var sourceNode = pair.Key;
                        Debug.Assert(sourceNode != null);
                        CreateEdge(findNode, gShapeNode);
                        continue;
                    }
                    #endregion
                }

                var findNodeInCurrentqQuery = queryNode.SearchInternalNode(pair.Key);
                if (findNodeInCurrentqQuery != null)
                {
                    #region Find Node
                    var eqGoal = pair.Value as EqGoal;
                    var shapeSymbol = pair.Value as ShapeSymbol;
                    if (eqGoal != null)
                    {
                        var gGoalNode = new GoalNode(eqGoal);
                        queryNode.InternalNodes.Add(gGoalNode);
                        CreateEdge(findNodeInCurrentqQuery, gGoalNode);
                        continue;
                    }
                    if (shapeSymbol != null)
                    {
                        var gShapeNode = new ShapeNode(shapeSymbol);
                        queryNode.InternalNodes.Add(gShapeNode);
                        var sourceNode = pair.Key;
                        Debug.Assert(sourceNode != null);
                        CreateEdge(findNodeInCurrentqQuery, gShapeNode);
                        continue;
                    }
                    #endregion
                }

                if (uunaryNode != null)
                {
                    var equation = pair.Value as Equation;
                    var eqNode = new EquationNode(equation);
                    queryNode.InternalNodes.Add(eqNode);
                    foreach (GraphNode gn in uunaryNode)
                    {
                        CreateEdge(gn, eqNode);
                    }
                }
            }

            #endregion

            return queryNode;
        }
Exemplo n.º 23
0
        private QueryNode CreateQueryNode(EqGoal goal)
        {
            var query = new Query(goal.Lhs);
            var queryNode = new QueryNode(query);

            var iGoalNode = new GoalNode(goal);
            queryNode.InternalNodes.Add(iGoalNode);
            return queryNode;
        }
Exemplo n.º 24
0
 private QueryNode CreateQueryNode(List<EqGoal> goals)
 {
     var query = new Query(goals[0].Lhs);
     var queryNode = new QueryNode(query);
     foreach (EqGoal igoal in goals)
     {
         var iGoalNode = new GoalNode(igoal);
         queryNode.InternalNodes.Add(iGoalNode);
     }
     return queryNode;
 }
 private static bool ConstraintCheck(GoalNode goalNode1, GoalNode goalNode2,
                                     string constraint1, ShapeType constraint2, out object output)
 {
     output = null;
     return(false);
 }
Exemplo n.º 26
0
        private QueryNode CreateQueryNode(Query query, object obj)
        {
            var queryNode = new QueryNode(query);

            var dict = obj as Dictionary <object, object>;

            if (dict == null)
            {
                return(queryNode);
            }

            #region Unary and Binary Relation

            foreach (KeyValuePair <object, object> pair in dict)
            {
                var unaryNode  = pair.Key as GraphNode;
                var binaryNode = pair.Key as Tuple <GraphNode, GraphNode>;
                var uunaryNode = pair.Key as List <GraphNode>;

                if (unaryNode != null)
                {
                    #region Unary Node
                    var eqGoal      = pair.Value as EqGoal;
                    var shapeSymbol = pair.Value as ShapeSymbol;
                    if (eqGoal != null)
                    {
                        var gGoalNode = new GoalNode(eqGoal);
                        queryNode.InternalNodes.Add(gGoalNode);
                        CreateEdge(unaryNode, gGoalNode);
                        continue;
                    }
                    if (shapeSymbol != null)
                    {
                        var gShapeNode = new ShapeNode(shapeSymbol);
                        queryNode.InternalNodes.Add(gShapeNode);
                        var sourceNode = pair.Key;
                        Debug.Assert(sourceNode != null);
                        CreateEdge(unaryNode, gShapeNode);
                        continue;
                    }
                    #endregion
                }

                if (binaryNode != null)
                {
                    #region Binary Node
                    var gShape = pair.Value as ShapeSymbol;
                    if (gShape != null)
                    {
                        var shapeNode = new ShapeNode(gShape);
                        queryNode.InternalNodes.Add(shapeNode);
                        var sourceNode1 = binaryNode.Item1;
                        var sourceNode2 = binaryNode.Item2;
                        Debug.Assert(sourceNode1 != null);
                        Debug.Assert(sourceNode2 != null);
                        CreateEdge(sourceNode1, shapeNode);
                        CreateEdge(sourceNode2, shapeNode);
                    }

                    var gGoal = pair.Value as EqGoal;
                    if (gGoal != null)
                    {
                        var goalNode = new GoalNode(gGoal);
                        queryNode.InternalNodes.Add(goalNode);
                        var sourceNode1 = binaryNode.Item1;
                        var sourceNode2 = binaryNode.Item2;
                        Debug.Assert(sourceNode1 != null);
                        Debug.Assert(sourceNode2 != null);
                        CreateEdge(sourceNode1, goalNode);
                        CreateEdge(sourceNode2, goalNode);
                    }

                    #endregion
                }

                var findNode = SearchNode(pair.Key);
                if (findNode != null)
                {
                    #region Find Node
                    var eqGoal      = pair.Value as EqGoal;
                    var shapeSymbol = pair.Value as ShapeSymbol;
                    if (eqGoal != null)
                    {
                        var gGoalNode = new GoalNode(eqGoal);
                        queryNode.InternalNodes.Add(gGoalNode);
                        CreateEdge(findNode, gGoalNode);
                        continue;
                    }
                    if (shapeSymbol != null)
                    {
                        var gShapeNode = new ShapeNode(shapeSymbol);
                        queryNode.InternalNodes.Add(gShapeNode);
                        var sourceNode = pair.Key;
                        Debug.Assert(sourceNode != null);
                        CreateEdge(findNode, gShapeNode);
                        continue;
                    }
                    #endregion
                }

                var findNodeInCurrentqQuery = queryNode.SearchInternalNode(pair.Key);
                if (findNodeInCurrentqQuery != null)
                {
                    #region Find Node
                    var eqGoal      = pair.Value as EqGoal;
                    var shapeSymbol = pair.Value as ShapeSymbol;
                    if (eqGoal != null)
                    {
                        var gGoalNode = new GoalNode(eqGoal);
                        queryNode.InternalNodes.Add(gGoalNode);
                        CreateEdge(findNodeInCurrentqQuery, gGoalNode);
                        continue;
                    }
                    if (shapeSymbol != null)
                    {
                        var gShapeNode = new ShapeNode(shapeSymbol);
                        queryNode.InternalNodes.Add(gShapeNode);
                        var sourceNode = pair.Key;
                        Debug.Assert(sourceNode != null);
                        CreateEdge(findNodeInCurrentqQuery, gShapeNode);
                        continue;
                    }
                    #endregion
                }

                if (uunaryNode != null)
                {
                    var equation = pair.Value as Equation;
                    var eqNode   = new EquationNode(equation);
                    queryNode.InternalNodes.Add(eqNode);
                    foreach (GraphNode gn in uunaryNode)
                    {
                        CreateEdge(gn, eqNode);
                    }
                }
            }

            #endregion

            return(queryNode);
        }
        private static bool ConstraintCheck(GoalNode gn, object constraint, out object output)
        {
            output = null;
            var label = constraint as string;

            var eqGoal = gn.Goal as EqGoal;

            Debug.Assert(eqGoal != null);
            if (label != null && gn.Satisfy(label))
            {
                output = gn.Goal;
                //output = new EqGoal(new Var(label), eqGoal.Rhs);
                return(true);
            }

            var goal = constraint as EqGoal;

            if (goal != null)
            {
                return(false);
            }

            var eq = constraint as Equation;

            if (eq != null && gn.Satisfy(eq))
            {
                var lst = new List <Tuple <object, object> >();
                eq.Reify(eqGoal);
                for (int i = 0; i < eq.CachedEntities.Count; i++)
                {
                    var cachedEq = eq.CachedEntities.ToList()[i] as Equation;
                    if (cachedEq == null)
                    {
                        continue;
                    }

                    object obj1;
                    bool   tempResult = cachedEq.IsEqGoal(out obj1);
                    if (tempResult)
                    {
                        var gGoal = obj1 as EqGoal;
                        Debug.Assert(gGoal != null);
                        var newTraces = new List <Tuple <object, object> >();
                        newTraces.AddRange(eqGoal.Traces);
                        for (int j = 0; j < cachedEq.Traces.Count - 1; j++)
                        {
                            newTraces.Add(cachedEq.Traces[j]);
                        }
                        var    trace    = cachedEq.Traces[cachedEq.Traces.Count - 1];
                        string strategy = "Derive new property by manipulating the given algebraic equation.";
                        var    newTrace = new Tuple <object, object>(strategy, trace.Item2);
                        newTraces.Add(newTrace);
                        gGoal.Traces = newTraces;
                        lst.Add(new Tuple <object, object>(eq, gGoal));
                    }
                }
                lst.Add(new Tuple <object, object>(gn, eq));
                output = lst;
                return(true);
            }

            var variable = constraint as Var;

            if (variable != null && gn.Satisfy(variable))
            {
                //output = new EqGoal(variable, eqGoal.Rhs);
                output = gn.Goal;
                return(true);
            }
            return(false);
        }
 private static bool ConstraintCheck(GoalNode gn, object constraint1, object constraint2, out object output)
 {
     output = null;
     return(false);
 }
Exemplo n.º 29
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);
        }
 private static bool ConstraintCheck(ShapeNode shapeNode, GoalNode goalNode,
     string constraint1, ShapeType constraint2, out object output)
 {
     output = null;
     //TODO
     return false;
 }
        private static bool ConstraintCheck(GoalNode gn, object constraint, out object output)
        {
            output = null;
            var label = constraint as string;

            var eqGoal = gn.Goal as EqGoal;
            Debug.Assert(eqGoal != null);
            if (label != null && gn.Satisfy(label))
            {
                output = gn.Goal;
                //output = new EqGoal(new Var(label), eqGoal.Rhs);
                return true;
            }

            var goal = constraint as EqGoal;
            if (goal != null)
            {
                return false;
            }

            var eq = constraint as Equation;
            if (eq != null && gn.Satisfy(eq))
            {
                var lst = new List<Tuple<object, object>>();
                eq.Reify(eqGoal);
                for (int i = 0; i < eq.CachedEntities.Count; i++)
                {
                    var cachedEq = eq.CachedEntities.ToList()[i] as Equation;
                    if (cachedEq == null) continue;

                    object obj1;
                    bool tempResult = cachedEq.IsEqGoal(out obj1);
                    if (tempResult)
                    {
                        var gGoal = obj1 as EqGoal;
                        Debug.Assert(gGoal != null);
                        var newTraces = new List<Tuple<object, object>>();
                        newTraces.AddRange(eqGoal.Traces);
                        for (int j = 0; j < cachedEq.Traces.Count - 1; j++)
                        {
                            newTraces.Add(cachedEq.Traces[j]);
                        }
                        var trace = cachedEq.Traces[cachedEq.Traces.Count - 1];
                        string strategy = "Derive new property by manipulating the given algebraic equation.";
                        var newTrace = new Tuple<object, object>(strategy, trace.Item2);
                        newTraces.Add(newTrace);
                        gGoal.Traces = newTraces;
                        lst.Add(new Tuple<object, object>(eq, gGoal));
                    }
                }
                lst.Add(new Tuple<object, object>(gn, eq));
                output = lst;
                return true;
            }

            var variable = constraint as Var;
            if (variable != null && gn.Satisfy(variable))
            {
                //output = new EqGoal(variable, eqGoal.Rhs);
                output = gn.Goal;
                return true;
            }
            return false;
        }
 private static bool ConstraintCheck(GoalNode goalNode1, GoalNode goalNode2,
     string constraint1, ShapeType constraint2, out object output)
 {
     output = null;
     return false;
 }
Exemplo n.º 33
0
        private void Reify(GoalNode goalNode, GraphNode rootNode)
        {
            var eqGoal = goalNode.Goal as EqGoal;
            Debug.Assert(eqGoal != null);
            if (!eqGoal.Concrete) return;

            foreach (GraphEdge ge in goalNode.OutEdges)
            {
                var upperNode = ge.Target;
                if (upperNode.Equals(rootNode)) return;
                if (upperNode.Synthesized) return;

                #region Target Node Analysis

                var shapeNode = upperNode as ShapeNode;
                if (shapeNode != null)
                {
                    if (shapeNode.ShapeSymbol.Shape.Concrete) continue;
/*                    if (DispatchReify(shapeNode.ShapeSymbol, eqGoal))
                    {
                        Reify(shapeNode); //depth first search
                    }                    */
                    DispatchReify(shapeNode.ShapeSymbol, eqGoal);

                }
                var eqNode = upperNode as EquationNode;
                if (eqNode != null)
                {
                    DispatchReify(eqNode.Equation, eqGoal);
/*                    if (DispatchReify(eqNode.Equation, eqGoal))
                    {
                        Reify(eqNode);
                    }*/
                }

                #endregion

                Reify(upperNode, rootNode); //depth first search
            }
        }
Exemplo n.º 34
0
        private void UnReify(GoalNode goalNode)
        {
            var eqGoal = goalNode.Goal as EqGoal;
            Debug.Assert(eqGoal != null);
            if (!eqGoal.Concrete) return;

            for (int i = 0; i < goalNode.OutEdges.Count; i++)
            {
                GraphEdge outEdge = goalNode.OutEdges[i];
                if (outEdge.Target.Equals(goalNode)) return; // cyclic halt
                var shapeNode = outEdge.Target as ShapeNode;
                if (shapeNode != null)
                {
                    if (DispatchUnreify(shapeNode.ShapeSymbol, eqGoal))
                    {
                        UnReify(shapeNode); //dfs
                    }
                }
                var eqNode = outEdge.Target as EquationNode;
                if (eqNode != null)
                {
                    if (DispatchUnreify(eqNode.Equation, eqGoal))
                    {
                        UnReify(eqNode);//dfs
                    }
                }
            }
        }
 private static bool ConstraintCheck(GoalNode gn, object constraint1, object constraint2, out object output)
 {
     output = null;
     return false;
 }