public GeneticAlgorithmOptions(string cromozoms, string generations, string elites, string crossOver, string mutationOccurance, string mutationPercentage, List <string> benchmarks, AlgorithmSelectionMode selectionMode) { // parse ints without check; it's by design NumberOfCromozoms = int.Parse(cromozoms); NumberOfGenerations = int.Parse(generations); ElitesPercentage = int.Parse(elites); CrossOverPercentage = 1 - (double.Parse(crossOver) / 100.0); MutationPercentage = 1 - (double.Parse(mutationPercentage) / 100.00); MutationOccurance = 1 - (double.Parse(mutationOccurance) / 100.00); Benchmarks = benchmarks; SelectionMode = selectionMode; if (SelectionMode == AlgorithmSelectionMode.RouletteWheel) { throw new NotImplementedException("Roulette Wheel Selection not implemented yet, please change to another selection."); } if (SelectionMode == AlgorithmSelectionMode.Tournament) { if (NumberOfCromozoms < 5) { throw new ArgumentException("In case of 'Tournament Selection' the number of cromozoms must be at least 5!", cromozoms); } } }
protected void OnRadiobutton1Toggled(object sender, EventArgs e) { var label = (sender as RadioButton).Label; switch (label) { case "Elitist": selectionMode = AlgorithmSelectionMode.Elitist; break; case "Tournament": selectionMode = AlgorithmSelectionMode.Tournament; break; case "Roulette Wheel": selectionMode = AlgorithmSelectionMode.RouletteWheel; break; default: throw new Exception("Invalid selection: " + selectionMode); } }