Exemplo n.º 1
0
        public void SelectDistribution(int tournamentSize, Named <double[]> expected, Optimize opt)
        {
            if (!Enum.IsDefined(typeof(Optimize), opt))
            {
                throw new InvalidEnumArgumentException(nameof(opt), (int)opt, typeof(Optimize));
            }
            if (!Enum.IsDefined(typeof(Optimize), opt))
            {
                throw new InvalidEnumArgumentException(nameof(opt), (int)opt, typeof(Optimize));
            }
            Retry <Exception>(3, () =>
            {
                const int loops       = 1;
                const int npopulation = PopulationCount;

                //ThreadLocal<LCG64ShiftRandom> random = new LCG64ShiftRandom.ThreadLocal();
                var random = RandomRegistry.GetRandom();
                RandomRegistry.Using(random, r =>
                {
                    var distribution = Distribution(
                        new TournamentSelector <DoubleGene, double>(tournamentSize),
                        opt,
                        npopulation,
                        loops
                        );

                    StatisticsAssert.AssertDistribution(distribution, expected.Value, 0.001, 20);
                });
            });
        }
        public void SelectDistribution(Named <double[]> expected, Optimize opt)
        {
            Retry <Exception>(3, () =>
            {
                const int loops = 50;
                var npopulation = PopulationCount;

                //ThreadLocal<LCG64ShiftRandom> random = new LCG64ShiftRandom.ThreadLocal();
                var random = RandomRegistry.GetRandom();
                RandomRegistry.Using(random, r =>
                {
                    var distribution = Distribution(
                        new RouletteWheelSelector <DoubleGene, double>(),
                        opt,
                        npopulation,
                        loops
                        );

                    StatisticsAssert.AssertDistribution(distribution, expected.Value, 0.001, 5);
                });
            });
        }