示例#1
0
        public IGeneticSettings UpdateAlgorithm(int index, IGeneticSettings settings)
        {
            AlgorithmVisitorParam visitor = new AlgorithmVisitorParam(null,
                                                                      (algorithm) => UpdateGeneticAlgorithm(algorithm, settings));

            visitor.Visit(Context.Algorithms[index].Element);
            return(settings);
        }
示例#2
0
        public void Load()
        {
            List <AlgorithmSaveBase> algorithms = new List <AlgorithmSaveBase>
            {
                new GaleShapleyAlgorithmSave
                {
                    AlgorithmName = "galeshapley"
                },
                new GeneticAlgorithmSave
                {
                    AlgorithmName              = "genetic",
                    AbsoluteSelection          = _settings.AbsoluteSelection,
                    SelectionRate              = _settings.SelectionRate,
                    MutationChance             = _settings.MutationChance,
                    StablePairWeight           = _settings.StablePairWeight,
                    GroupHappinessWeight       = _settings.GroupHappinessWeight,
                    EgalitarianHappinessWeight = _settings.EgalitarianHappinessWeight,
                    Generations = _settings.Generations,
                    Size        = _settings.Size
                }
            };
            MockPersistence mockPersistence = new MockPersistence
            {
                MockData = new SaveData
                {
                    Algorithms = algorithms
                }
            };

            NewModel();

            _context.Persistence = mockPersistence;
            _context.Persistence.Load("");

            _model.Load();
            Assert.AreEqual(2, _context.Algorithms.Count());

            Assert.AreEqual("galeshapley", _context.Algorithms[0].Name);
            _visitor = new AlgorithmVisitor(null,
                                            () => Assert.Fail());
            _visitor.Visit(_context.Algorithms[0].Element);

            Assert.AreEqual("genetic", _context.Algorithms[1].Name);
            _visitorParam = new AlgorithmVisitorParam((x) => Assert.Fail(),
                                                      (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);
        }
示例#3
0
        public void VisitAlgorithm(int index, Action <GaleShapleyAlgorithm> galeShapleyMethod,
                                   Action <GeneticAlgorithm> geneticMethod)
        {
            AlgorithmData         data    = Context.Algorithms[index];
            AlgorithmVisitorParam visitor = new AlgorithmVisitorParam((x) => galeShapleyMethod?.Invoke(x),
                                                                      (x) => geneticMethod?.Invoke(x));

            visitor.Visit(data.Element);
        }
示例#4
0
        public void CreateGenetic()
        {
            NewModel();

            GeneticSettings settings = _model.CreateGeneticAlgorithm();

            Assert.AreEqual(1, _context.Algorithms.Count());

            _visitorParam = new AlgorithmVisitorParam((x) => Assert.Fail(),
                                                      (x) => Assert.AreEqual(settings, x.Settings));
            _visitorParam.Visit(_context.Algorithms[0].Element);
            Assert.IsTrue(_context.AlgorithmsChanged);
        }
示例#5
0
 public void Load()
 {
     Context.PreferencesChanged = true;
     Initialize();
     foreach (AlgorithmSaveBase algorithm in Context.Persistence.Data.Algorithms)
     {
         AlgorithmSaveVisitorParam saveVisitor = new AlgorithmSaveVisitorParam((x) =>
         {
             CreateGaleShapleyAlgorithm();
         },
                                                                               (x) =>
         {
             CreateGeneticAlgorithm();
             AlgorithmVisitorParam visitor = new AlgorithmVisitorParam(null,
                                                                       (y) => UpdateGeneticAlgorithm(y, x));
             visitor.Visit(Context.Algorithms.Last().Element);
         });
         saveVisitor.Visit(algorithm);
         Context.Algorithms.Last().Name = algorithm.AlgorithmName;
     }
 }
示例#6
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);
            }
        }