示例#1
0
        public void TestDistanceCalc()
        {
            Node n1 = new Node(6.8, 4.4);
            Node n2 = new Node(-3.7, -11.2);

            Arc a = new Arc(n1, n2);

            // the Google calculated arc length = (((6.8 - (-3.7)) ^ 2) + ((4.4 - (-11.2)) ^ 2)) ^ (1/2) = 18.8045207331

            double expectedResult = 18.8045207331;
            double diff = Math.Abs(expectedResult - a.Length);

            Assert.True(diff < 0.0000000001); // The expected (previously calculated) value has 10 digits after the decimal place.
            // Therefore, the difference between the computed value and the expected value must be less than 1 * (10 ^ (-10)).
        }
示例#2
0
        public void ComputeShortestPathBruteForce()
        {
            List<List<Node>> allPossiblePaths = ComputeAllPaths(_points);

            List<Tuple<List<Node>, double>> allPathsWithLengths = new List<Tuple<List<Node>, double>>();

            foreach (List<Node> pathway in allPossiblePaths)
            {
                Arc aOne = new Arc(_origin, pathway[0]);
                Arc aTwo = new Arc(pathway[0], pathway[1]);
                Arc aThree = new Arc(pathway[1], pathway[2]);
                Arc aFour = new Arc(pathway[2], pathway[3]);
                double length = aOne.Length + aTwo.Length + aThree.Length + aFour.Length;

                allPathsWithLengths.Add(new Tuple<List<Node>, double>(pathway, length));
            }

            NumArcLengthsComputedAndSorted = allPossiblePaths.Count*4;

            allPathsWithLengths.Sort((x, y) => x.Item2.CompareTo(y.Item2));
            _shortestPath = allPathsWithLengths[0].Item1;
        }