public void Test() { // create the solver. var solver = new GASolver <float, ProblemMock, ObjectiveMock, SolutionMock, float>(new ObjectiveMock(), new GeneratorMock(), new CrossOverMock(), new SelectionMock(), new LocalSearchMock(), new GASettings() { MaxGenerations = 1000, PopulationSize = 400, StagnationCount = 200, CrossOverPercentage = 10, ElitismPercentage = 5, MutationPercentage = 10 }); // execute and test result. var solutionFitness = 0.0f; var solution = solver.Solve(new ProblemMock() { Max = 100 }, new ObjectiveMock(), out solutionFitness); Assert.AreEqual(0, solution.Value, 1); }
public void TestName() { // create the solver. var solver = new GASolver <float, ProblemMock, ObjectiveMock, SolutionMock, float>(new ObjectiveMock(), new GeneratorMock(), new CrossOverMock(), new SelectionMock(), new LocalSearchMock()); Assert.AreEqual("GA_[MOCK_GENERATOR_MOCK_LOCALSEARCH_MOCK_CROSSOVER_MOCK_SELECTION]", solver.Name); }
private void rbnEvenGA_Click(object sender, EventArgs e) { MethodString = "***** 望均勻 GA 法 單段裝箱染色體 *****\n\n"; theGASolver = theProblem.CreateAGroupingGASolver(); pgdGAProperty.SelectedObject = theGASolver; pgdSolver.SelectedObject = theProblem.ParametersOfGroupingGA; rbnSmallNGA.Checked = rbnSmallExperience.Checked = rbnEvenExperience.Checked = rbnSmallGA.Checked = false; GAInitailized(); }
public void AddSolver(GASolver solver) { DataContext = solver; Populations = new ObservableCollection <PopulationContainer>(solver.Populations.Select(x => new PopulationContainer(x))); for (int i = 0; i < Populations.Count; i++) { Populations[i].PropertyChanged += PopulationsWindow_PropertyChanged; } ListViewPopulations.ItemsSource = Populations; OldSortDirection = ListSortDirection.Ascending; }
/// <summary> /// 設定ウィンドウを開きます /// </summary> private void ConfigButton_Click(object sender, RoutedEventArgs e) { var settingWindow = new SettingWindow { Owner = Window.GetWindow(this), WindowStartupLocation = WindowStartupLocation.CenterOwner, }; var ret = settingWindow.ShowDialog(); if (ret.HasValue && ret.Value) { return; } var chromosomesType = (ChromosomesType)CachingConfig.SettingCaching.ChromosomesTypeIndex; var selectionType = (SelectionType)CachingConfig.SettingCaching.SelectionTypeIndex; var crossOverType = (CrossOverType)CachingConfig.SettingCaching.CrossOverTypeIndex; var mutationType = (MutationType)CachingConfig.SettingCaching.MutationTypeIndex; var mutationRate = CachingConfig.SettingCaching.MutationRate; var populationSize = CachingConfig.SettingCaching.PopulationSize; // ソルバーの生成 _gaSolver = new GASolver(new GASolver.GASolverInfo( chromosomesType, selectionType, crossOverType, mutationType, mutationRate, populationSize, _cityList.Count, CalculatePathCost)); _gaSolver.Initialize(); _maxGeneration = CachingConfig.SettingCaching.MaxGeneration; _logDisplayNum = CachingConfig.SettingCaching.LogDisplayNum; DisplaySettingInfo(chromosomesType, selectionType, crossOverType, mutationType, mutationRate, populationSize, _maxGeneration); UpdatePhase(ExecutePhase.ExecuteReady); }
private void GInitialized() { if (File.Exists("Settings.db")) { DataStreamEx s = new DataStreamEx(File.ReadAllBytes("Settings.db")); int recipeId = s.ReadInt(); Sim.Level = s.ReadInt(); Sim.BaseCraftsmanship = s.ReadInt(); Sim.BaseControl = s.ReadInt(); Sim.BaseMaxCP = s.ReadInt(); Dispatcher.Invoke(() => { CheckBoxIsSpecialist.IsChecked = s.ReadByte() == 1; }); int id = s.ReadInt(); if (id > 0) { SelectedFood = G.Items[id]; FoodIsHQ = s.ReadByte() == 1; } id = s.ReadInt(); if (id > 0) { SelectedTea = G.Items[id]; TeaIsHQ = s.ReadByte() == 1; } Dispatcher.Invoke(() => { ApplyFoodBuffs(); }); List <CraftingAction> actions = new List <CraftingAction>(); while (s.Position < s.Length) { try { actions.Add(CraftingAction.CraftingActions[s.ReadInt()]); } catch { } } if (recipeId > 0) { LoadRecipe(G.Recipes.FirstOrDefault(x => x.Id == recipeId)); } Sim.AddActions(true, actions); s.Flush(); s.Close(); } if (Solver == null) { Solver = new GASolver(Sim); Solver.GenerationRan += Solver_GenerationRan; Solver.FoundBetterRotation += Solver_FoundBetterRotation; Solver.Stopped += Solver_Stopped; } }