public IGeneticSettings UpdateAlgorithm(int index, IGeneticSettings settings) { AlgorithmVisitorParam visitor = new AlgorithmVisitorParam(null, (algorithm) => UpdateGeneticAlgorithm(algorithm, settings)); visitor.Visit(Context.Algorithms[index].Element); return(settings); }
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); }
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); }
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); }
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; } }
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); } }