コード例 #1
0
        /// <summary>
        /// Get the length of the line.
        /// </summary>
        /// <param name="propName">The property name indicates the line.</param>
        /// <param name="entity">An entity in the service.</param>
        /// <returns>Return the length of the line.</returns>
        private double GetLength(string propName, JObject entity)
        {
            var propVal = entity[propName]["coordinates"] as JArray;
            var pts     = new List <Point>();

            for (int i = 0; i < propVal.Count - 1; i += 2)
            {
                var pt = new Point(Convert.ToDouble(propVal[i]), Convert.ToDouble(propVal[i + 1]));
                pts.Add(pt);
            }

            var segs = new List <SegmentEquation>();

            for (int i = 0; i < pts.Count - 1; i++)
            {
                var seg = new SegmentEquation(pts[i], pts[i + 1]);
                segs.Add(seg);
            }

            double len = 0.0;

            foreach (var seg in segs)
            {
                len += seg.Length;
            }

            return(len);
        }
コード例 #2
0
        private static bool HandleSimpleSegmentEquation(KnownMeasurementsAggregator known, SegmentEquation theEq)
        {
            if (theEq.GetAtomicity() != Equation.BOTH_ATOMIC)
            {
                return(false);
            }

            Segment unknownSegment = null;
            double  segmentValue   = -1;

            if (theEq.lhs is NumericValue)
            {
                unknownSegment = theEq.rhs as Segment;
                segmentValue   = (theEq.lhs as NumericValue).DoubleValue;
            }
            else if (theEq.rhs is NumericValue)
            {
                unknownSegment = theEq.lhs as Segment;
                segmentValue   = (theEq.rhs as NumericValue).DoubleValue;
            }
            else
            {
                return(false);
            }

            //
            // (7) Add to the list of knowns
            //
            return(known.AddSegmentLength(unknownSegment, segmentValue));
        }
コード例 #3
0
        //
        // (1) Make a copy
        // (2) Collect the equation terms.
        // (3) Are all but one known?
        // (4) Substitute
        // (5) Simplify
        // (6) Acquire the unknown and its value.
        // (7) Add to the list of knowns.
        //
        private static bool HandleSegmentEquation(KnownMeasurementsAggregator known, List <GroundedClause> clauses, SegmentEquation theEq)
        {
            if (theEq.GetAtomicity() == Equation.BOTH_ATOMIC)
            {
                return(HandleSimpleSegmentEquation(known, theEq));
            }

            // CTA: Verify this calls the correct Equation deep copy mechanism.
            // (1) Make a copy
            SegmentEquation copy = (SegmentEquation)theEq.DeepCopy();

            // (2) Collect the equation terms.
            List <GroundedClause> left = copy.lhs.CollectTerms();

            double[] leftVal            = new double[left.Count];
            List <GroundedClause> right = copy.rhs.CollectTerms();

            double[] rightVal = new double[right.Count];

            // (3) Are all but one term known?
            int unknownCount = 0;

            for (int ell = 0; ell < left.Count; ell++)
            {
                if (left[ell] is NumericValue)
                {
                    leftVal[ell] = (left[ell] as NumericValue).DoubleValue;
                }
                else
                {
                    leftVal[ell] = known.GetSegmentLength(left[ell] as Segment);
                    if (leftVal[ell] <= 0)
                    {
                        unknownCount++;
                    }
                }
            }
            for (int r = 0; r < right.Count; r++)
            {
                if (right[r] is NumericValue)
                {
                    rightVal[r] = (right[r] as NumericValue).DoubleValue;
                }
                else
                {
                    rightVal[r] = known.GetSegmentLength(right[r] as Segment);
                    if (rightVal[r] <= 0)
                    {
                        unknownCount++;
                    }
                }
            }

            // We can't solve for more or less than one unknown.
            if (unknownCount != 1)
            {
                return(false);
            }

            //
            // (4) Substitute
            //
            for (int ell = 0; ell < left.Count; ell++)
            {
                if (leftVal[ell] > 0)
                {
                    copy.Substitute(left[ell], new NumericValue(leftVal[ell]));
                }
            }
            for (int r = 0; r < right.Count; r++)
            {
                if (rightVal[r] > 0)
                {
                    copy.Substitute(right[r], new NumericValue(rightVal[r]));
                }
            }

            //
            // (5) Simplify
            //
            SegmentEquation simplified = (SegmentEquation)GenericInstantiator.Simplification.Simplify(copy);

            return(HandleSimpleSegmentEquation(known, simplified));
        }