Exemplo n.º 1
0
        private void UpdateGeneticSettings(int index)
        {
            IGeneticSettings settings = null;

            _visitor = new AlgorithmOptionVisitorParam(null,
                                                       (x) => settings = x);
            _visitor.Visit(AlgorithmElements[index]);

            if (settings != null)
            {
                IGeneticSettings newSettings = ConvertToViewModelSettings(
                    _model.UpdateAlgorithm(index, ConvertToModelSettings(settings)));

                if (settings != newSettings)
                {
                    settings.SelectionRate              = newSettings.SelectionRate;
                    settings.AbsoluteSelection          = newSettings.AbsoluteSelection;
                    settings.MutationChance             = newSettings.MutationChance;
                    settings.StablePairWeight           = newSettings.StablePairWeight;
                    settings.GroupHappinessWeight       = newSettings.GroupHappinessWeight;
                    settings.EgalitarianHappinessWeight = newSettings.EgalitarianHappinessWeight;
                    settings.Size        = newSettings.Size;
                    settings.Generations = newSettings.Generations;
                }
                OnPropertyChanged("AlgorithmOptions");
            }
        }
Exemplo n.º 2
0
        public void UpdateAlgorithm()
        {
            NewModel();

            _model.CreateGaleShapleyAlgorithm();
            try
            {
                _model.UpdateAlgorithm(0, _settings);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }

            _model.CreateGeneticAlgorithm();
            try
            {
                _model.UpdateAlgorithm(1, _settings);
                _visitorParam = new AlgorithmVisitorParam(null,
                                                          (x) =>
                {
                    Assert.AreEqual(x.Settings.AbsoluteSelection, _settings.AbsoluteSelection);
                    Assert.AreEqual(x.Settings.SelectionRate, _settings.SelectionRate);
                    Assert.AreEqual(x.Settings.MutationChance, _settings.MutationChance);
                    Assert.AreEqual(x.Settings.StablePairWeight, _settings.StablePairWeight);
                    Assert.AreEqual(x.Settings.GroupHappinessWeight, _settings.GroupHappinessWeight);
                    Assert.AreEqual(x.Settings.EgalitarianHappinessWeight, _settings.EgalitarianHappinessWeight);
                    Assert.AreEqual(x.Settings.Generations, _settings.Generations);
                    Assert.AreEqual(x.Settings.Size, _settings.Size);
                });
                _visitorParam.Visit(_context.Algorithms[1].Element);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }