예제 #1
0
        static void Test1_IterateRationals()
        {
            var harmonicity = new BarlowHarmonicity();
            //var harmonicity = new SimpleHarmonicity(2.0);
            //var harmonicity = new EpimoricHarmonicity(2.0);

            var r0 = new Rational(1);
            var r1 = new Rational(25, 24);

            Debug.WriteLine("Iterate {0} range {1}-{2}", harmonicity.GetType().Name, r0, r1);

            var collector = new Collector <RationalInfo>();
            var handler   = new HandlerPipe <RationalInfo>(
                new RangeRationalHandler(r0, r1),
                new RationalPrinter(),
                collector
                );
            var limits = new RationalGenerator.Limits {
                dimensionCount = 3,
                rationalCount  = 20, // accepted rational count in the range. might be slow for small range
                distance       = -1,
            };

            new RationalIterator(harmonicity, limits, null, handler).Iterate();

            Debug.WriteLine("-------------------\n Sort by distance");
            collector.Iterate(RationalInfo.CompareDistances, new RationalPrinter());

            Debug.WriteLine("-------------------\n Sort by value");
            collector.Iterate(RationalInfo.CompareValues, new RationalPrinter());
        }
예제 #2
0
        static void Test2_FindCommas()
        {
            //var harmonicity = new EulerHarmonicity();
            var harmonicity = new BarlowHarmonicity();
            //var harmonicity = new SimpleHarmonicity(2.0);
            //var harmonicity = new EpimoricHarmonicity(2.0);

            Rational r0    = new Rational(1);
            Rational r1    = new Rational(25, 24);
            int      limit = 3;
            int      count = 20;

            Debug.WriteLine("Iterate {0} range {1}-{2}", harmonicity.GetType().Name, r0, r1);

            var collector = new Collector <RationalInfo>();
            var handler   = new HandlerPipe <RationalInfo>(
                new RangeRationalHandler(r0, r1, false, true),
                //new RationalPrinter(),
                collector
                );
            var limits = new RationalGenerator.Limits {
                dimensionCount = limit, rationalCount = count, distance = -1
            };

            new RationalIterator(harmonicity, limits, null, handler).Iterate();

            Debug.WriteLine("-------------------\n Sort by distance");
            collector.Iterate(RationalInfo.CompareDistances, new RationalPrinter());

            //Debug.WriteLine("-------------------\n Sort by value");
            //collector.Iterate(RationalInfo.CompareValues, new RationalPrinter());

            // Organize commas
            Debug.WriteLine("-------------------\n Organize");
            collector.Iterate(RationalInfo.CompareDistances,
                              new HandlerPipe <RationalInfo>(
                                  new RationalOrganizer(limit),
                                  new RationalPrinter()
                                  )
                              );
        }