コード例 #1
0
        public void WhenSelectorIsRequested_Tournament_AlteredConfiguration_CorrectSelectionShouldBeReturned()
        {
            Population <int> population = new Population <int> ();

            Selector selector = SelectionProvider.GetSelector(SelectionType.Tournament);

            ConfigurationProvider.Selection.NumberOfFittestSelected = 3;

            population.Initialise(5, 5);

            for (int i = 0; i < population.Individuals.Count; i++)
            {
                for (int j = 0; j < population.Individuals [0].GenomeLength; j++)
                {
                    population.Individuals [i].Code [j] = i;
                }
            }

            List <Individual <int> > fittest = selector.SelectFittest(population, new double[] { .4d, .85d, .3d, .9d, .81d }).ToList();

            Assert.AreEqual(fittest.Select(f => f.Code),
                            new List <List <int> > {
                new List <int> {
                    3, 3, 3, 3, 3
                },
                new List <int> {
                    1, 1, 1, 1, 1
                },
                new List <int> {
                    4, 4, 4, 4, 4
                }
            });
        }
コード例 #2
0
        private bool SpecializedEvaluateCanExecute(object parameter)
        {
            var activeSelection = SelectionProvider.ActiveSelection();

            if (!activeSelection.HasValue)
            {
                return(false);
            }

            var member = GetTarget();

            if (member == null || _state.IsNewOrModified(member.QualifiedModuleName))
            {
                return(false);
            }

            var parameters = _state.DeclarationFinder
                             .UserDeclarations(DeclarationType.Parameter)
                             .Where(item => member.Equals(item.ParentScopeDeclaration))
                             .ToList();

            return(member.DeclarationType == DeclarationType.PropertyLet ||
                   member.DeclarationType == DeclarationType.PropertySet
                ? parameters.Count > 1
                : parameters.Any());
        }
コード例 #3
0
        public void WhenSelectorIsRequested_Truncation_AlteredConfiguration_CorrectSelectionShouldBeReturned()
        {
            Population <int> population = new Population <int> ();

            Selector selector = SelectionProvider.GetSelector(SelectionType.Truncation);

            ConfigurationProvider.Selection.RatioOfFittestInTruncationSelection = .2m;

            population.Initialise(10, 3);

            for (int i = 0; i < population.Individuals.Count; i++)
            {
                for (int j = 0; j < population.Individuals [0].GenomeLength; j++)
                {
                    population.Individuals [i].Code [j] = i - j;
                }
            }

            List <Individual <int> > fittest = selector.SelectFittest(population,
                                                                      new double[] { .1d, .15d, .2d, .5d, .25d, .3d, .35d, .4d, .45d, .55d }).ToList();

            Assert.AreEqual(
                fittest.Select(f => f.Code).ToList(),
                new List <List <int> > {
                new List <int> {
                    9, 8, 7
                },
                new List <int> {
                    3, 2, 1
                }
            });
        }
コード例 #4
0
        public void WhenSelectorIsRequested_Roulette_AlteredConfiguration_SortDirectoryDescending_CorrectSelectionFitnessShouldBeReturned()
        {
            Population <int> population = new Population <int> ();

            Selector selector = SelectionProvider.GetSelector(SelectionType.Roulette);

            population.Initialise(9, 10);

            for (int i = 0; i < population.Individuals.Count; i++)
            {
                for (int j = 0; j < population.Individuals [0].GenomeLength; j++)
                {
                    population.Individuals [i].Code [j] = i + j;
                }
            }

            ConfigurationProvider.Selection.ForcedRouletteThreshold      = 1.2d;
            ConfigurationProvider.Selection.NumberOfFittestSelected      = 4;
            ConfigurationProvider.Selection.RouletteFitnessSortDirection = SelectionConfiguration.RouletteFitnessDirection.Descending;

            List <Individual <int> > fittest = selector.SelectFittest(population,
                                                                      new double[] { .11d, .22d, .33d, .44d, .55d, .66d, .77d, .88d, .99d }).ToList();

            Assert.AreEqual(
                new List <double> {
                Math.Round(.88d, 2),
                Math.Round(.77d, 2),
                Math.Round(.66d, 2),
                Math.Round(.55d, 2)
            },
                fittest.Select(f => Math.Round(f.Fitness.Value, 2)).ToList());
        }
コード例 #5
0
        public void WhenSelectorIsRequested_Tournament_CorrectSelectionShouldBeReturned()
        {
            TournamentSelector selector = new TournamentSelector();

            Selector requested = SelectionProvider.GetSelector(SelectionType.Tournament);

            Assert.AreEqual(selector.Name, requested.Name);
        }
コード例 #6
0
        private bool SpecializedEvaluateCanExecute(object parameter)
        {
            var activeSelection = SelectionProvider.ActiveSelection();

            if (!activeSelection.HasValue)
            {
                return(false);
            }
            return(_extractInterfaceRefactoring.CanExecute(_state, activeSelection.Value.QualifiedName));
        }
コード例 #7
0
        public void WhenSelectorIsOverloadedAndRequested_Custom_CorrectSelectorShouldBeReturned()
        {
            CustomSelector selector = new CustomSelector();

            SelectionProvider.Add(selector);

            Selector requested = SelectionProvider.GetSelector(SelectionType.Custom);

            Assert.AreSame(selector, requested);
        }
コード例 #8
0
        public void WhenSelectorIsRequested_Roulette_MaxThresholdCalculatedShouldBeCorrect()
        {
            Population <int> population = new Population <int> ();

            Selector selector = SelectionProvider.GetSelector(SelectionType.Roulette);

            population.Initialise(9, 10);

            selector.SelectFittest(population,
                                   new double[] { .11d, .22d, .33d, .44d, .55d, .66d, .77d, .88d, .99d }).ToList();

            Assert.AreEqual(Math.Round(4.95d, 2), Math.Round((selector as RouletteSelector).LastMaxThreshold, 2));
        }
コード例 #9
0
        public void WhenSelectorIsRequested_Tournament_AlteredConfiguration_CorrectSelectionCountShouldBeReturned()
        {
            Population <int> population = new Population <int> ();

            Selector selector = SelectionProvider.GetSelector(SelectionType.Tournament);

            ConfigurationProvider.Selection.NumberOfFittestSelected = 3;

            population.Initialise(5, 100);

            List <Individual <int> > fittest = selector.SelectFittest(population, new double[] { .4d, .85d, .3d, .9, .81 }).ToList();

            Assert.AreEqual(3, fittest.Count);
        }
コード例 #10
0
        public void WhenSelectorIsRequested_Truncation_AlteredConfiguration_CorrectSelectionCountShouldBeReturned()
        {
            Population <int> population = new Population <int> ();

            Selector selector = SelectionProvider.GetSelector(SelectionType.Truncation);

            ConfigurationProvider.Selection.RatioOfFittestInTruncationSelection = .2m;

            population.Initialise(10, 3);

            List <Individual <int> > fittest = selector.SelectFittest(population,
                                                                      new double[] { .1d, .15d, .2d, .25d, .3d, .35d, .4d, .45d, .5d, .55d }).ToList();

            Assert.AreEqual(2, fittest.Count);
        }
コード例 #11
0
        private bool SpecializedEvaluateCanExecute(object parameter)
        {
            var activeSelection = SelectionProvider.ActiveSelection();

            if (!activeSelection.HasValue)
            {
                return(false);
            }

            var targetInterface = _state.DeclarationFinder.FindInterface(activeSelection.Value);

            var targetClass = _state.DeclarationFinder.Members(activeSelection.Value.QualifiedName)
                              .SingleOrDefault(declaration => declaration.DeclarationType == DeclarationType.ClassModule);

            return(targetInterface != null && targetClass != null &&
                   !_state.IsNewOrModified(targetInterface.QualifiedModuleName) &&
                   !_state.IsNewOrModified(targetClass.QualifiedModuleName));
        }
コード例 #12
0
        public void WhenSelectorIsRequested_Roulette_AlteredConfiguration_CorrectSelectionShouldBeReturned()
        {
            Population <int> population = new Population <int> ();

            Selector selector = SelectionProvider.GetSelector(SelectionType.Roulette);

            population.Initialise(9, 10);

            for (int i = 0; i < population.Individuals.Count; i++)
            {
                for (int j = 0; j < population.Individuals [0].GenomeLength; j++)
                {
                    population.Individuals [i].Code [j] = i;
                }
            }

            ConfigurationProvider.Selection.ForcedRouletteThreshold = 1.2d;
            ConfigurationProvider.Selection.NumberOfFittestSelected = 4;

            List <Individual <int> > fittest = selector.SelectFittest(population,
                                                                      new double[] { .11d, .22d, .33d, .44d, .55d, .66d, .77d, .88d, .99d }).ToList();

            Assert.AreEqual(
                new List <List <int> > {
                new List <int> {
                    4, 4, 4, 4, 4, 4, 4, 4, 4, 4
                },
                new List <int> {
                    5, 5, 5, 5, 5, 5, 5, 5, 5, 5
                },
                new List <int> {
                    6, 6, 6, 6, 6, 6, 6, 6, 6, 6
                },
                new List <int> {
                    7, 7, 7, 7, 7, 7, 7, 7, 7, 7
                }
            },
                fittest.Select(f => f.Code).ToList());
        }
コード例 #13
0
        public void WhenSelectorIsRequested_Custom_NotSet_SelectorNotAvailableExceptionShouldBeThrown()
        {
            Selector selector = SelectionProvider.GetSelector(SelectionType.Custom);

            Assert.AreEqual(SelectionType.Custom, selector.SelectionMethod);
        }
コード例 #14
0
        public void WhenSelectorIsRequested_Roulette_CorrectSelectorShouldBeReturned()
        {
            Selector selector = SelectionProvider.GetSelector(SelectionType.Roulette);

            Assert.AreEqual(SelectionType.Roulette, selector.SelectionMethod);
        }
コード例 #15
0
        public void WhenSelectorIsRequested_Truncation_CorrectSelectorShouldBeReturned()
        {
            Selector selector = SelectionProvider.GetSelector(SelectionType.Truncation);

            Assert.AreEqual(SelectionType.Truncation, selector.SelectionMethod);
        }
コード例 #16
0
 public void TestSetup()
 {
     SelectionProvider.Reset();
     ConfigurationProvider.Reset();
 }