示例#1
0
        public static Point GenPoint(ConsistentRandom rnd)
        {
            var x = GenCoord(rnd);
            var y = GenCoord(rnd);

            return(new Point(x, y));
        }
示例#2
0
        static void Main()
        {
            var rnd    = new ConsistentRandom();
            var points = Enumerable.Range(0, 100000)
                         .Select(x => Point.GenPoint(rnd))
                         //.Select(p =>
                         //{
                         //    p.X = 1;
                         //    return p;
                         //})
                         .ToArray();

            {
                var st = new Stopwatch();
                st.Start();
                var tuple = FindClosestPairNaive(points);
                st.Stop();
                var distance = points[tuple.Item1].DistanceTo(points[tuple.Item2]);
                Console.WriteLine($"{tuple.Item1} {tuple.Item2} {distance}");
                Console.WriteLine($"Naive: {st.Elapsed}");
            }
            {
                var st = new Stopwatch();
                st.Start();
                var tuple = FindClosestPairDivideConquer(points);
                st.Stop();
                var distance = points[tuple.Item1].DistanceTo(points[tuple.Item2]);
                Console.WriteLine($"{tuple.Item1} {tuple.Item2} {distance}");
                Console.WriteLine($"DivConq: {st.Elapsed}");
            }
        }
示例#3
0
 private static double GenCoord(ConsistentRandom rnd)
 {
     //return rnd.Next();
     return((double)rnd.Next() + (rnd.Next() % 1000 - 500) / (rnd.Next() + 1));
 }