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); }
public void Test_CreateLineSegment_3() { 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.LineSegment, out obj); Assert.True(value); var lss = obj as LineSegmentSymbol; Assert.NotNull(lss); Assert.False(lss.Shape.Concrete); }
private static bool ConstraintCheck(ShapeNode shapeNode1, ShapeNode shapeNode2, string constraint1, ShapeType constraint2, out object output) { output = null; var shape1 = shapeNode1.ShapeSymbol; var shape2 = shapeNode2.ShapeSymbol; Debug.Assert(shape1 != null); Debug.Assert(shape2 != null); var pt1 = shape1 as PointSymbol; var pt2 = shape2 as PointSymbol; if (pt1 != null && pt2 != null) { return(ConstraintCheck(pt1, pt2, constraint1, constraint2, out output)); } return(false); }
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); }
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")); }
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_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); }
private void UnReify(ShapeNode shapeNode) { foreach (GraphEdge ge in shapeNode.OutEdges) { var upperNode = ge.Target as ShapeNode; if (upperNode == null) { continue; } var lstSource = InEdgeNodes(upperNode); if (lstSource.Count != 2) { continue; } if (Reify(upperNode, lstSource[0], lstSource[1])) { UnReify(upperNode); //depth first search } } }
private ShapeNode AddShapeNode(ShapeSymbol shape) { //1. build relation using geometry constraint-solving (synthesize new node) (Top-Down) object relations; ConstraintSatisfy(shape, out relations); List <object> goalRels; ShapeNode shapeNode = CreateShapeNode(shape, relations, out goalRels); //Search bottom up goalNodes, start reify foreach (object obj in goalRels) { var goalNode = obj as GoalNode; if (goalNode == null) { continue; } Reify(goalNode); } return(shapeNode); }
/// <summary> /// e.g given y = 2x + 1, ask: m = ? /// </summary> /// <param name="sn"></param> /// <param name="constraint"></param> /// <param name="output"></param> /// <returns></returns> private static bool ConstraintCheck(ShapeNode sn, object constraint, out object output) { output = null; var label = constraint as string; if (label != null) //Query { return sn.ShapeSymbol.UnifyProperty(label, out output); } var goal = constraint as EqGoal; if (goal != null) //Match { bool matched = sn.ShapeSymbol.UnifyExplicitProperty(goal); if (matched) { output = new Tuple<object, object>(goal,sn); return true; } } return false; }
/// <summary> /// e.g given y = 2x + 1, ask: m = ? /// </summary> /// <param name="sn"></param> /// <param name="constraint"></param> /// <param name="output"></param> /// <returns></returns> private static bool ConstraintCheck(ShapeNode sn, object constraint, out object output) { output = null; var label = constraint as string; if (label != null) //Query { return(sn.ShapeSymbol.UnifyProperty(label, out output)); } var goal = constraint as EqGoal; if (goal != null) //Match { bool matched = sn.ShapeSymbol.UnifyExplicitProperty(goal); if (matched) { output = new Tuple <object, object>(goal, sn); return(true); } } return(false); }
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));*/ }
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));*/ }
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(ShapeNode sn, object constraint1, object constraint2, out object output) { output = null; return(false); }
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 shapeNode1, ShapeNode shapeNode2, string constraint1, ShapeType constraint2, out object output) { output = null; var shape1 = shapeNode1.ShapeSymbol; var shape2 = shapeNode2.ShapeSymbol; Debug.Assert(shape1 != null); Debug.Assert(shape2 != null); var pt1 = shape1 as PointSymbol; var pt2 = shape2 as PointSymbol; if (pt1 != null && pt2 != null) return ConstraintCheck(pt1, pt2, constraint1, constraint2, out output); return false; }
private static bool ConstraintCheck(ShapeNode shapeNode1, ShapeNode shapeNode2, object constraint, out object output) { output = null; var shape1 = shapeNode1.ShapeSymbol; var shape2 = shapeNode2.ShapeSymbol; Debug.Assert(shape1 != null); Debug.Assert(shape2 != null); var pt1 = shape1 as PointSymbol; var pt2 = shape2 as PointSymbol; if (pt1 != null && pt2 != null) { bool result = ConstraintCheck(pt1, pt2, constraint, out output); if (!result) return false; var label = constraint as string; var goal = constraint as EqGoal; if (goal != null) { var lstTuple = new List<Tuple<object, object>>(); #region Goal Oriented var source2 = new Tuple<object, object>(shapeNode1, shapeNode2); var tuple1 = new Tuple<object, object>(source2, constraint); lstTuple.Add(tuple1); var lst = output as List<object>; if (lst != null) { foreach (EqGoal synGoal in lst) { var tempTuple = new Tuple<object, object>(constraint, synGoal); lstTuple.Add(tempTuple); } } output = lstTuple; return lstTuple.Count != 0; #endregion } if (label != null) { var lst = output as List<object>; if (lst != null && lst.Count == 1) { output = lst[0]; } } return true; } 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; }
private void UnReify(ShapeNode shapeNode) { foreach (GraphEdge ge in shapeNode.OutEdges) { var upperNode = ge.Target as ShapeNode; if (upperNode == null) continue; var lstSource = InEdgeNodes(upperNode); if (lstSource.Count != 2) continue; if (Reify(upperNode, lstSource[0], lstSource[1])) { UnReify(upperNode); //depth first search } } }
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 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 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 ShapeNode CreateShapeNode(ShapeSymbol ss, object obj, out List<object> relGoals) { var gn = new ShapeNode(ss); relGoals = new List<object>(); var lst = obj as List<Tuple<object, object>>; if (lst == null) return gn; foreach (var tuple in lst) { if (tuple.Item1.Equals(ss)) { BuildRelation(gn, tuple.Item2); relGoals.Add(tuple.Item2); } if (tuple.Item2.Equals(ss)) { BuildRelation(tuple.Item1, gn); relGoals.Add(tuple.Item1); } } _nodes.Add(gn); return gn; }
private static bool ConstraintCheck(ShapeNode sn, object constraint1, object constraint2, out object output) { output = null; return false; }