Пример #1
0
        public void Test_TwoPoints_Calculation()
        {
            var pt1 = new Point(2, 0);
            var pt2 = new Point(5, 4);

            var ls = LineGenerationRule.GenerateLine(pt1, pt2);

            Assert.NotNull(ls);
        }
Пример #2
0
        /// <summary>
        /// construct a line through a point and a goal,
        /// e.g A(1,2) ^ S = 2=> Conjunctive Norm Form
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="goal"></param>
        /// <returns></returns>
        public static LineSymbol Unify(PointSymbol pt, EqGoal goal)
        {
            var variable1 = goal.Lhs as Var;

            Debug.Assert(variable1 != null);

            if (LineAcronym.EqualSlopeLabels(variable1.ToString()))
            {
                double dValue;
                bool   result = LogicSharp.IsDouble(goal.Rhs, out dValue);
                if (result)
                {
                    if (!pt.Shape.Concrete)
                    {
                        return(null);
                    }
                    var line = LineGenerationRule.GenerateLine((Point)pt.Shape, dValue, null);
                    if (pt.Traces.Count != 0)
                    {
                        line.Traces.AddRange(pt.Traces);
                    }
                    if (goal.Traces.Count != 0)
                    {
                        line.Traces.AddRange(goal.Traces);
                    }

                    TraceInstructionalDesign.FromPointSlopeToLine(pt, goal, line);

                    line.OutputType = LineType.SlopeIntercept;
                    return(line);
                }
                else
                {
                    var line = new Line(null); //ghost line
                    var ls   = new LineSymbol(line);
                    ls.OutputType = LineType.SlopeIntercept;
                    return(ls);
                }
            }
            return(null);
        }
        private static bool Reify(this LineSymbol line, PointSymbol pt1, PointSymbol pt2)
        {
            //if (!line.RelationStatus) return false;
            line.CachedSymbols.Clear(); //re-compute purpose

            var shape1Lst = new List <PointSymbol>();
            var shape2Lst = new List <PointSymbol>();

            #region Caching Point 1
            if (pt1.Shape.Concrete)
            {
                shape1Lst.Add(pt1);
            }
            else
            {
                foreach (var shapeSymbol in pt1.CachedSymbols.ToList())
                {
                    var ptTemp = shapeSymbol as PointSymbol;
                    Debug.Assert(ptTemp != null);
                    if (ptTemp.Shape.Concrete)
                    {
                        shape1Lst.Add(ptTemp);
                    }
                }
            }
            #endregion

            #region Caching Point 2
            if (pt2.Shape.Concrete)
            {
                shape2Lst.Add(pt2);
            }
            else
            {
                foreach (var shapeSymbol in pt2.CachedSymbols.ToList())
                {
                    var ptTemp = shapeSymbol as PointSymbol;
                    Debug.Assert(ptTemp != null);
                    if (ptTemp.Shape.Concrete)
                    {
                        shape2Lst.Add(ptTemp);
                    }
                }
            }
            #endregion

            #region Generate caching line

            if (shape1Lst.Count == 0 || shape2Lst.Count == 0)
            {
                return(false);
            }
            foreach (var gPt1 in shape1Lst)
            {
                foreach (var gPt2 in shape2Lst)
                {
                    Debug.Assert(gPt1 != null);
                    Debug.Assert(gPt2 != null);
                    var gPoint1 = gPt1.Shape as Point;
                    var gPoint2 = gPt2.Shape as Point;
                    Debug.Assert(gPoint1 != null);
                    Debug.Assert(gPoint2 != null);
                    Debug.Assert(gPoint1.Concrete);
                    Debug.Assert(gPoint2.Concrete);
                    var lineTemp = LineGenerationRule.GenerateLine(gPoint1, gPoint2);
                    if (lineTemp != null)
                    {
                        line.CachedSymbols.Add(lineTemp);
                    }
                }
            }
            #endregion

            return(true);
        }
Пример #4
0
        /// <summary>
        /// construct a line through two points
        /// </summary>
        /// <param name="pt1"></param>
        /// <param name="pt2"></param>
        /// <returns></returns>
        public static object Unify(PointSymbol pt1, PointSymbol pt2, EqGoal goal = null)
        {
            //point identify check
            if (pt1.Equals(pt2))
            {
                return(null);
            }

            //Line build process
            if (pt1.Shape.Concrete && pt2.Shape.Concrete)
            {
                var point1 = pt1.Shape as Point;
                var point2 = pt2.Shape as Point;

                Debug.Assert(point1 != null);
                Debug.Assert(point2 != null);

                var winPt1 = new System.Windows.Point((double)point1.XCoordinate, (double)point1.YCoordinate);
                var winPt2 = new System.Windows.Point((double)point2.XCoordinate, (double)point2.YCoordinate);

                var lineSymbol = LineGenerationRule.GenerateLine(point1, point2);

                if (lineSymbol == null)
                {
                    return(null);
                }

                var line = lineSymbol.Shape as Line;
                Debug.Assert(line != null);

                line.Rel1 = winPt1;
                line.Rel2 = winPt2;

                TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, lineSymbol);
                return(lineSymbol);
            }
            else
            {
                //lazy evaluation
                //Constraint solving on Graph
                var line = new Line(null); //ghost line
                line.Rel1 = pt1.Shape;
                line.Rel2 = pt2.Shape;
                var ls = new LineSymbol(line);

                #region Reification Purpose

                if (pt1.Shape.Concrete && !pt2.Shape.Concrete)
                {
                    var point1 = pt1.Shape as Point;
                    if (pt2.CachedSymbols.Count != 0)
                    {
                        foreach (ShapeSymbol ss in pt2.CachedSymbols)
                        {
                            var ps = ss as PointSymbol;
                            Debug.Assert(ps != null);
                            Debug.Assert(ps.Shape.Concrete);
                            var cachePoint = ps.Shape as Point;
                            Debug.Assert(cachePoint != null);
                            var gline = LineGenerationRule.GenerateLine(point1, cachePoint);
                            gline.Traces.AddRange(ps.Traces);
                            TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline);
                            ls.CachedSymbols.Add(gline);
                        }
                    }
                }

                if (!pt1.Shape.Concrete && pt2.Shape.Concrete)
                {
                    var point2 = pt2.Shape as Point;
                    if (pt1.CachedSymbols.Count != 0)
                    {
                        foreach (ShapeSymbol ss in pt1.CachedSymbols)
                        {
                            var ps = ss as PointSymbol;
                            Debug.Assert(ps != null);
                            Debug.Assert(ps.Shape.Concrete);
                            var cachePoint = ps.Shape as Point;
                            Debug.Assert(cachePoint != null);
                            var gline = LineGenerationRule.GenerateLine(cachePoint, point2);
                            gline.Traces.AddRange(ps.Traces);
                            TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline);
                            ls.CachedSymbols.Add(gline);
                        }
                    }
                }

                if (!pt1.Shape.Concrete && !pt2.Shape.Concrete)
                {
                    foreach (ShapeSymbol ss1 in pt1.CachedSymbols)
                    {
                        foreach (ShapeSymbol ss2 in pt2.CachedSymbols)
                        {
                            var ps1 = ss1 as PointSymbol;
                            Debug.Assert(ps1 != null);
                            Debug.Assert(ps1.Shape.Concrete);
                            var cachePoint1 = ps1.Shape as Point;
                            Debug.Assert(cachePoint1 != null);
                            var ps2 = ss2 as PointSymbol;
                            Debug.Assert(ps2 != null);
                            Debug.Assert(ps2.Shape.Concrete);
                            var cachePoint2 = ps2.Shape as Point;
                            Debug.Assert(cachePoint2 != null);
                            var gline = LineGenerationRule.GenerateLine(cachePoint1, cachePoint2);
                            gline.Traces.AddRange(ps1.Traces);
                            gline.Traces.AddRange(ps2.Traces);
                            TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline);
                            ls.CachedSymbols.Add(gline);
                        }
                    }
                }

                #endregion

                if (goal != null)
                {
                    return(ls.Unify(goal));
                }

                return(ls);
            }
        }
Пример #5
0
        /// <summary>
        /// construct a line through two goals
        /// e.g  m=2, k=3 => conjunctive norm form
        /// </summary>
        /// <param name="goal1"></param>
        /// <param name="goal2"></param>
        /// <returns></returns>
        public static LineSymbol Unify(EqGoal goal1, EqGoal goal2)
        {
            var variable1 = goal1.Lhs as Var;
            var variable2 = goal2.Lhs as Var;

            Debug.Assert(variable1 != null);
            Debug.Assert(variable2 != null);

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

            string slopeKey     = "slope";
            string interceptKey = "intercept";

            if (LineAcronym.EqualSlopeLabels(variable1.ToString()))
            //if (variable1.ToString().Equals(LineAcronym.Slope1))
            {
                dict.Add(slopeKey, goal1.Rhs);
            }
            if (LineAcronym.EqualInterceptLabels(variable1.ToString()))
            //if (variable1.ToString().Equals(LineAcronym.Intercept1))
            {
                dict.Add(interceptKey, goal1.Rhs);
            }
            if (LineAcronym.EqualSlopeLabels(variable2.ToString()))
            //if (variable2.ToString().Equals(LineAcronym.Slope1))
            {
                if (dict.ContainsKey(slopeKey))
                {
                    return(null);
                }
                dict.Add(slopeKey, goal2.Rhs);
            }
            if (LineAcronym.EqualInterceptLabels(variable2.ToString()))
            //if (variable2.ToString().Equals(LineAcronym.Intercept1))
            {
                if (dict.ContainsKey(interceptKey))
                {
                    return(null);
                }
                dict.Add(interceptKey, goal2.Rhs);
            }

            if (dict.Count == 2 &&
                dict[slopeKey] != null &&
                dict[interceptKey] != null)
            {
                if (LogicSharp.IsNumeric(dict[slopeKey]) &&
                    LogicSharp.IsNumeric(dict[interceptKey]))
                {
                    double dSlope, dIntercept;
                    LogicSharp.IsDouble(dict[slopeKey], out dSlope);
                    LogicSharp.IsDouble(dict[interceptKey], out dIntercept);
                    var line = LineGenerationRule.GenerateLine(dSlope, dIntercept);
                    var ls   = new LineSymbol(line)
                    {
                        OutputType = LineType.SlopeIntercept
                    };

                    TraceInstructionalDesign.FromSlopeInterceptToLineSlopeIntercept(goal1, goal2, ls);
                    return(ls);
                }
                else
                {
                    //lazy evaluation
                    //Constraint solving on Graph
                    var line = new Line(null); //ghost line
                    var ls   = new LineSymbol(line);
                    ls.OutputType = LineType.SlopeIntercept;
                    return(ls);
                }
            }
            return(null);
        }