private void Reify(EquationNode eqNode, GraphNode rootNode) { foreach (GraphEdge ge in eqNode.OutEdges) { var upperNode = ge.Target; if (upperNode.Equals(rootNode)) return; if (upperNode.Synthesized) return; Reify(upperNode, rootNode); //depth first search } }
private static bool ConstraintCheck(GraphNode gn, object constraint, out object output) { var shapeNode = gn as ShapeNode; var goalNode = gn as GoalNode; var queryNode = gn as QueryNode; var eqNode = gn as EquationNode; if (shapeNode != null) return ConstraintCheck(shapeNode, constraint, out output); if (goalNode != null) return ConstraintCheck(goalNode, constraint, out output); if (queryNode != null) return ConstraintCheck(queryNode, constraint, out output); if (eqNode != null) return ConstraintCheck(eqNode, constraint, out output); throw new Exception("Graph.Unify.UnaryConstraint.cs: Cannot reach here"); }
public void Reify(GraphNode gn, GraphNode rootNode = null) { var shapeNode = gn as ShapeNode; var goalNode = gn as GoalNode; var equationNode = gn as EquationNode; if (shapeNode != null) { if (rootNode != null) { Reify(shapeNode, rootNode); } else { Reify(shapeNode, shapeNode); } } else if(goalNode != null) { if (rootNode != null) { Reify(goalNode, rootNode); } else { Reify(goalNode, goalNode); } } else if (equationNode != null) { if (rootNode != null) { Reify(equationNode, rootNode); } else { Reify(equationNode, equationNode); } } }
public static bool ConstraintCheck(GraphNode obj1, object constraint1, object constraint2, out object output) { if (constraint1 == null) return ConstraintCheck(obj1, constraint2, out output); if (constraint2 == null) return ConstraintCheck(obj1, constraint1, out output); var shapeType = constraint2 as ShapeType?; Debug.Assert(constraint1 != null); Debug.Assert(shapeType != null); output = null; var shape1 = obj1 as ShapeNode; var goal1 = obj1 as GoalNode; var query1 = obj1 as QueryNode; //Combinatoric Pattern Match if (shape1 != null) return ConstraintCheck(shape1, constraint1, constraint2, out output); if (goal1 != null) return ConstraintCheck(goal1, constraint1, constraint2, out output); if (query1 != null) return ConstraintCheck(query1, constraint1, constraint2, out output); //TODO other relations return false; }
/// <summary> /// The output of relation creation can be Shape /// or List<type>. /// </summary> /// <param name="obj1">Shape or Goal</param> /// <param name="obj2">Shape or Goal</param> /// <param name="st"></param> /// <param name="constraint"></param> /// <param name="output">Shape or Goal</param> /// <returns></returns> private static bool ConstraintCheck(GraphNode obj1, GraphNode obj2, object constraint, out object output) { Debug.Assert(constraint != null); output = null; var shape1 = obj1 as ShapeNode; var shape2 = obj2 as ShapeNode; var goal1 = obj1 as GoalNode; var goal2 = obj2 as GoalNode; var query1 = obj1 as QueryNode; var query2 = obj2 as QueryNode; //Combinatoric Pattern Match if (shape1 != null && shape2 != null) return ConstraintCheck(shape1, shape2, constraint, out output); if (goal1 != null && goal2 != null) return ConstraintCheck(goal1, goal2, constraint, out output); if (shape1 != null && goal2 != null) return ConstraintCheck(shape1, goal2, constraint, out output); if (goal1 != null && shape2 != null) return ConstraintCheck(shape2, goal1, constraint, out output); //TODO other relations return false; }
public static bool ConstraintCheck(GraphNode obj1, GraphNode obj2, object constraint1, object constraint2, out object output) { if (constraint1 == null) return ConstraintCheck(obj1, obj2, constraint2, out output); if (constraint2 == null) return ConstraintCheck(obj1, obj2, constraint1, out output); var label = constraint1 as string; if (DefaultLabels.EqualDefaultLabel(label)) return ConstraintCheck(obj1, obj2, constraint2, out output); var shapeType = constraint2 as ShapeType?; Debug.Assert(label != null); Debug.Assert(shapeType != null); output = null; var shape1 = obj1 as ShapeNode; var shape2 = obj2 as ShapeNode; var goal1 = obj1 as GoalNode; var goal2 = obj2 as GoalNode; var query1 = obj1 as QueryNode; var query2 = obj2 as QueryNode; //Combinatoric Pattern Match if (shape1 != null && shape2 != null) return ConstraintCheck(shape1, shape2, label, shapeType.Value, out output); if (goal1 != null && goal2 != null) return ConstraintCheck(goal1, goal2, label, shapeType.Value, out output); if (shape1 != null && goal2 != null) return ConstraintCheck(shape1, goal2, label, shapeType.Value, out output); if (goal1 != null && shape2 != null) return ConstraintCheck(shape2, goal1, label, shapeType.Value, out output); //TODO other relations return false; }
private void UnBuildRelation(GraphNode graphNode) { for (int i = 0; i < graphNode.OutEdges.Count; i++) { GraphEdge outEdge = graphNode.OutEdges[i]; GraphNode targetNode = outEdge.Target; foreach (var edge in targetNode.InEdges) { if (edge.Source.Equals(graphNode)) continue; var binaryAltNode = edge.Source; binaryAltNode.OutEdges.Remove(edge); } targetNode.InEdges.Clear(); } for (int j = 0; j < graphNode.InEdges.Count; j++) { var inEdge = graphNode.InEdges[j]; var sourceNode = inEdge.Source; sourceNode.OutEdges.Remove(inEdge); } }
private void CreateEdge(GraphNode source, GraphNode target) { if (source == null || target == null) return; var graphEdge = new GraphEdge(source, target); source.OutEdges.Add(graphEdge); target.InEdges.Add(graphEdge); }
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); } }
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 bool SatisfyRelation(Tuple<GraphNode, GraphNode> tuple1, GraphNode gn2, out object deleteNode) { deleteNode = null; var tuple1Node1 = tuple1.Item1; var tuple1Node2 = tuple1.Item2; object obj; bool cond1 = SatisfyRelation(tuple1Node1, gn2, out obj); bool cond2 = SatisfyRelation(tuple1Node2, gn2, out obj); if (cond1 || cond2) { deleteNode = tuple1; return true; } return false; }
private bool SatisfyRelation(GraphNode gn1, GraphNode gn2, out object deleteNode) { deleteNode = null; Debug.Assert(gn1 != null); Debug.Assert(gn2 != null); foreach (var edge in gn1.OutEdges) { if (edge.Target == null) continue; if (edge.Target.Equals(gn2)) { if (gn1.Synthesized) { deleteNode = gn2; } else { deleteNode = gn1; } return true; } } foreach (var edge in gn2.OutEdges) { if (edge.Target == null) continue; if (edge.Target.Equals(gn1)) { if (gn2.Synthesized) { deleteNode = gn1; } else { deleteNode = gn2; } return true; } } //TODO fix it later if (gn1.Synthesized && gn2.Synthesized) return false; bool cond1 = FindPath(gn1, gn2); bool cond2 = FindPath(gn2, gn1); if (cond1) { deleteNode = gn1; return true; } if (cond2) { deleteNode = gn2; return true; } return false; }
private void AddNode(GraphNode node) { var sn = node as ShapeNode; var gn = node as GoalNode; var qn = node as QueryNode; var en = node as EquationNode; if (sn != null) { AddNode(sn.ShapeSymbol); return; } if (gn != null) { AddNode(gn.Goal); return; } if (qn != null) { AddNode(qn.Query); return; } if (en != null) AddNode(en.Equation); }
private void Reify(ShapeNode shapeNode, GraphNode rootNode) { foreach (GraphEdge ge in shapeNode.OutEdges) { var upperNode = ge.Target; if (upperNode.Equals(rootNode)) return; if (upperNode.Synthesized) return; #region Target Node Analysis var upperShapeNode = upperNode as ShapeNode; if (upperShapeNode != null) { var lstSource = InEdgeNodes(upperShapeNode); if (lstSource.Count == 2) { Reify(upperShapeNode, lstSource[0], lstSource[1]); } } #endregion Reify(upperNode, rootNode); //depth first search } }
private void DeleteNode(GraphNode node) { var shapeNode = node as ShapeNode; var goalNode = node as GoalNode; if (shapeNode != null) DeleteShapeNode(shapeNode.ShapeSymbol); if (goalNode != null) DeleteGoalNode(goalNode.Goal); }
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 } }
private bool Reify(ShapeNode currentShapeNode, GraphNode sourceNode1, GraphNode sourceNode2) { var sn1 = sourceNode1 as ShapeNode; var sn2 = sourceNode2 as ShapeNode; if (sn1 != null && sn2 != null) { var shapeSymbol1 = sn1.ShapeSymbol; var shapeSymbol2 = sn2.ShapeSymbol; var currentShape = currentShapeNode.ShapeSymbol; return RelationLogic.Reify(currentShape, shapeSymbol1, shapeSymbol2); } return false; }
private void DeleteSynNode(GraphNode gn) { //find all related syn node var synLst = SearchSynNodes(gn); foreach (GraphNode tempGn in synLst) { DeleteNode(tempGn); } }
private void UpdateUpperQueryNode(GraphNode gn) { for (int i = 0; i < gn.OutEdges.Count; i++) { var targetNode = gn.OutEdges[i].Target; QueryNode tempQueryNode; if (BelongQueryNode(targetNode, out tempQueryNode)) { DeleteNode(tempQueryNode.Query); AddNode(tempQueryNode.Query); } } }