public void TestLineSegment_Unify_Reify_0() { /* * Input sequence: * 1: (AB) [LineSegment] => LineSegment * 2: A(2,3) => Point * 3: B(2,3) => Point * Update: AB [Label] => LineSegment */ var graph = new RelationGraph(); var ptA = new Point("A", 2, 3); var ptASym = new PointSymbol(ptA); graph.AddNode(ptASym); //api call Assert.True(graph.Nodes.Count == 1); var query = new Query(ShapeType.LineSegment); var queryNode = graph.AddNode(query) as QueryNode; Assert.Null(queryNode); var ptB = new Point("B", 3, 4); var PtBSym = new PointSymbol(ptB); graph.AddNode(PtBSym); //api call Assert.True(graph.Nodes.Count == 3); queryNode = graph.RetrieveQueryNode(query); Assert.NotNull(queryNode); }
public void Test_CreateLine_2() { var pt1 = new Point(1.0, 2.0); var pt2 = new Point(1.0, 2.0); var ptSym1 = new PointSymbol(pt1); var ptSym2 = new PointSymbol(pt2); var lineSym = LineBinaryRelation.Unify(ptSym1, ptSym2); Assert.Null(lineSym); }
public static LineSegmentSymbol GenerateLineSegment(Point pt1, Point pt2) { if (pt1.Equals(pt2)) return null; Debug.Assert(pt1.Concrete); Debug.Assert(pt2.Concrete); var ls = new LineSegment(pt1, pt2); var lss = new LineSegmentSymbol(ls); if(pt1.Traces.Count != 0) lss.Traces.AddRange(pt1.Traces); if(pt2.Traces.Count != 0) lss.Traces.AddRange(pt2.Traces); TraceInstructionalDesign.FromPointsToLineSegment(lss); return lss; }
public void Problem16() { var pt1 = new Point(-1, 2); var ps1 = new PointSymbol(pt1); var pt2 = new Point(5, 8); var ps2 = new PointSymbol(pt2); var pt3 = new Point(2, 4); var midPoint = new PointSymbol(pt3); TraceInstructionalDesign.FromPointsToMidPoint(ps1, ps2, midPoint); }
public void Test_CreateLine_4() { var pt1 = new Point(2.0, 1.0); var pt2 = new Point(2.0, 2.0); var ptSym1 = new PointSymbol(pt1); var ptSym2 = new PointSymbol(pt2); var lineSym = LineBinaryRelation.Unify(ptSym1, ptSym2) as LineSymbol; Assert.NotNull(lineSym); var line = lineSym.Shape as Line; Assert.NotNull(line); Assert.True(line.A.Equals(1.0)); Assert.True(line.B.Equals(0.0)); Assert.True(line.C.Equals(-2.0)); }
public void GenerateYCacheSymbol(object obj, EqGoal goal) { var point = Shape as Point; Debug.Assert(point != null); CachedGoals.Add(new KeyValuePair<object, EqGoal>(PointAcronym.Y, goal)); if (CachedSymbols.Count == 0) { var gPoint = new Point(point.Label, point.XCoordinate, obj); var gPointSymbol = new PointSymbol(gPoint); gPointSymbol.CachedGoals.Add(new KeyValuePair<object, EqGoal>(PointAcronym.Y, goal)); CachedSymbols.Add(gPointSymbol); gPointSymbol.Traces.AddRange(goal.Traces); //transform goal trace for (int i = goal.Traces.Count - 1; i >= 0; i--) { gPoint.Traces.Insert(0, goal.Traces[i]); } //Substitution trace var rule = SubstitutionRule.ApplySubstitute(); var appliedRule = SubstitutionRule.ApplySubstitute(this, goal); var ts = new TraceStep(this, gPointSymbol, SubstitutionRule.SubstituteKC(), rule, appliedRule); gPointSymbol._innerLoop.Add(ts); string strategy = "Reify a Point's y-coordinate by substituing a given fact."; gPointSymbol.GenerateATrace(strategy); //gPoint.Traces.Insert(0, ts); } else { foreach (ShapeSymbol ss in CachedSymbols.ToList()) { var pt = ss.Shape as Point; if (pt != null) { var yResult = LogicSharp.Reify(pt.YCoordinate, goal.ToDict()); if (!pt.YCoordinate.Equals(yResult)) { var gPt = new Point(pt.Label, pt.XCoordinate, pt.YCoordinate); var gPointSymbol = new PointSymbol(gPt); //substitute pt.YCoordinate = yResult; ss.CachedGoals.Add(new KeyValuePair<object, EqGoal>(PointAcronym.Y, goal)); gPointSymbol.Traces.AddRange(goal.Traces); //transform goal trace for (int i = goal.Traces.Count - 1; i >= 0; i--) { pt.Traces.Insert(0, goal.Traces[i]); } string rule = SubstitutionRule.ApplySubstitute(); string appliedRule = SubstitutionRule.ApplySubstitute(this, goal); var ts = new TraceStep(this, gPointSymbol, SubstitutionRule.SubstituteKC(), rule, appliedRule); gPointSymbol._innerLoop.Add(ts); string strategy = "Reify a Point's y-coordinate by substituing a given fact."; gPointSymbol.GenerateATrace(strategy); //pt.Traces.Insert(0, ts); } else { //generate var gPoint = new Point(pt.Label, pt.XCoordinate, obj); var gPointSymbol = new PointSymbol(gPoint); gPointSymbol.Traces.AddRange(goal.Traces); gPointSymbol.CachedGoals.Add(new KeyValuePair<object, EqGoal>(PointAcronym.Y, goal)); foreach (KeyValuePair<object, EqGoal> pair in ss.CachedGoals) { if (pair.Key.Equals(PointAcronym.X)) { gPointSymbol.CachedGoals.Add(new KeyValuePair<object, EqGoal>(PointAcronym.X, pair.Value)); } } CachedSymbols.Add(gPointSymbol); //substitute //Add traces from pt to gPoint for (int i = pt.Traces.Count - 1; i >= 0; i--) { gPoint.Traces.Insert(0, pt.Traces[i]); } //transform goal trace for (int i = goal.Traces.Count - 1; i >= 0; i--) { gPoint.Traces.Insert(0, goal.Traces[i]); } var rule = SubstitutionRule.ApplySubstitute(); var appliedRule = SubstitutionRule.ApplySubstitute(this, goal); var ts = new TraceStep(this, gPointSymbol, SubstitutionRule.SubstituteKC(), rule, appliedRule); gPointSymbol._innerLoop.Add(ts); string strategy = "Reify a Point's y-coordinate by substituing a given fact."; gPointSymbol.GenerateATrace(strategy); //gPoint.Traces.Insert(0, ts); } } } } }
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_Relation_Point_Line_2() { var pt = new Point(0, -3); var ps = new PointSymbol(pt); var line = new Line(null, 4, 1, 4); var ls = new LineSymbol(line); bool result = ls.UnifyShape(ps); Assert.False(result); }
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")); }
public void TestPoint_Unify_Reify_0() { var graph = new RelationGraph(); //true positive var x = new Var('x'); var y = new Var('y'); var point = new Point(x, y); var ps = new PointSymbol(point); graph.AddNode(ps); Assert.True(graph.Nodes.Count == 1); /* * * Current Status: * * (x,y) * * next input: * * x=1 */ var eqGoal = new EqGoal(x, 1); // x=1 graph.AddNode(eqGoal); Assert.True(graph.Nodes.Count == 2); List<ShapeSymbol> shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); var pt = shapes[0] as PointSymbol; Assert.NotNull(pt); Assert.True(pt.Equals(ps)); Assert.True(pt.CachedGoals.Count == 1); Assert.True(pt.CachedSymbols.Count == 1); var gPointSymbol = pt.CachedSymbols.ToList()[0] as PointSymbol; Assert.NotNull(gPointSymbol); var gPoint = gPointSymbol.Shape as Point; Assert.NotNull(gPoint); Assert.False(gPoint.Concrete); Assert.True(1.0.Equals(gPoint.XCoordinate)); Assert.True(y.Equals(gPoint.YCoordinate)); /****** * current status: * (1,y) * * next input: * x = 2 ****/ #region Block 2 var eqGoal1 = new EqGoal(x, 2); // x=2 graph.AddNode(eqGoal1); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); pt = shapes[0] as PointSymbol; Assert.NotNull(pt); Assert.True(pt.Equals(ps)); Assert.True(pt.CachedGoals.Count == 2); Assert.True(pt.CachedSymbols.Count == 2); Assert.False(point.Concrete); #endregion /****** * current status: * (1,y) * (2,y) * * next input: * y = 1 ****/ #region Block 3 var eqGoal2 = new EqGoal(y, 1); // y = 1 graph.AddNode(eqGoal2); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); pt = shapes[0] as PointSymbol; Assert.False(point.Concrete); Assert.True(ps.CachedGoals.Count == 3); Assert.True(ps.CachedSymbols.Count == 2); foreach (var ss in ps.CachedSymbols) { Assert.True(ss.Shape.Concrete); } var goals = graph.RetrieveGoals(); Assert.True(goals.Count == 3); #endregion /****** * current status: * (1,1) * (2,1) * * next input: * y = 2 ****/ #region Block 4 var eqGoal3 = new EqGoal(y, 2); // y = 2 graph.AddNode(eqGoal3); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); ps = shapes[0] as PointSymbol; Assert.NotNull(ps); Assert.False(ps.Shape.Concrete); Assert.True(ps.CachedGoals.Count == 4); Assert.True(ps.CachedSymbols.Count == 4); foreach (var css in ps.CachedSymbols) { Assert.True(css.Shape.Concrete); } #endregion /* * current status: * (1,1), (2,1), (1,2), (2,2) * * next input: * delete y = 2 * */ #region Block 5 graph.DeleteNode(eqGoal3); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); pt = shapes[0] as PointSymbol; Assert.NotNull(pt); Assert.False(pt.Shape.Concrete); Assert.True(pt.CachedGoals.Count == 3); Assert.True(pt.CachedSymbols.Count == 2); foreach (var ss in pt.CachedSymbols) { Assert.True(ss.Shape.Concrete); } goals = graph.RetrieveGoals(); Assert.True(goals.Count == 3); #endregion /* * current status: * (1,1), (2,1) * * next input: * delete y = 1 * */ #region Block 6 graph.DeleteNode(eqGoal2); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 1); pt = shapes[0] as PointSymbol; Assert.NotNull(pt); Assert.False(pt.Shape.Concrete); Assert.True(pt.CachedGoals.Count == 3); Assert.True(pt.CachedSymbols.Count == 2); #endregion /* foreach (var shape in pt.CachedSymbols) { Assert.False(shape.Shape.Concrete); } goals = graph.RetrieveGoals(); Assert.True(goals.Count == 2); ///////////////////////////////////////////// graph.DeleteNode(ps); shapes = graph.RetrieveShapeSymbols(); Assert.True(shapes.Count == 0);*/ }