public Log(ClickOMania.Board brd) { board = brd; logData = new List <GenerationData>(); }
private void startButton_Click(object sender, RoutedEventArgs e) { startButton.IsEnabled = false; statusLabel.Content = "Running..."; // Attempt to load board from input file if a file has been specified if (String.IsNullOrWhiteSpace(inputFilePath.Text)) { // If no file specified, generate randomly gameBoard = ClickOMania.Board.GenerateRandomBoard(rand); } else { // If a file is specified, attempt to read it try { gameBoard = ClickOMania.Board.LoadBoardFromFile(inputFilePath.Text); } catch (ApplicationException ex) { // If loading fails, display error message and don't attempt to run statusLabel.Content = ex.Message; startButton.IsEnabled = true; return; } } log = new Log(gameBoard); crossoverProbability = crossoverProbabilitySlider.Value / 100; mutationProbability = mutationProbabilitySlider.Value / 100; elitismPercentage = Convert.ToInt32(elitismPercentageSlider.Value); initialPopulationSize = Convert.ToInt32(populationSizeSlider.Value); maxGenerations = Convert.ToInt32(maxGenerationsSlider.Value); lastFiveGens = new Queue <double>(); var population = GenerateInitialPopulation(initialPopulationSize); //create the genetic operators var elite = new Elite(elitismPercentage); var crossover = new Crossover(crossoverProbability, true) { AllowDuplicates = true, CrossoverType = CrossoverType.SinglePoint, ReplacementMethod = ReplacementMethod.GenerationalReplacement }; var mutation = new SwapMutate(mutationProbability); var ga = new GeneticAlgorithm(population, CalculateFitness); ga.Operators.Add(elite); ga.Operators.Add(crossover); ga.Operators.Add(mutation); ga.OnGenerationComplete += ga_OnGenerationComplete; ga.OnRunComplete += ga_OnRunComplete; BackgroundWorker bw = new BackgroundWorker(); bw.WorkerReportsProgress = true; bw.DoWork += new DoWorkEventHandler( delegate(object o, DoWorkEventArgs args) { b = o as BackgroundWorker; ga.Run(TerminateFunction); }); bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerComplete); bw.RunWorkerAsync(); }