public GeneticAlgorithm(GeneticSettings geneticSettings) { _settings = geneticSettings; _random = new Random(_settings.Seed == -1 ? DateTime.Now.Millisecond : _settings.Seed); _stateLock = new object(); State = States.Idle; }
private void MapSettingsToForm(GeneticSettings settings) { this.nudSize.Value = settings.Size; this.nudMutation.Value = settings.Mutation; this.nudMutabilityMin.Value = settings.MutabilityMin; this.nudMutabilityMax.Value = settings.MutabilityMax; this.nudElitism.Value = settings.Elitism; this.nudIterations.Value = settings.Iterations; this.nudAge.Value = settings.Age; this.nudSeed.Value = settings.Seed; this.cbxComparsion.SelectedIndex = settings.Comparsion; this.btnTarget.BackColor = Color.FromArgb(byte.MaxValue, settings.Target.Red, settings.Target.Green, settings.Target.Blue); this.tbxValue.Text = string.Concat(settings.Target.Red, " ", settings.Target.Green, " ", settings.Target.Blue); }
private GeneticSettings MapSettingsFromForm() { var result = new GeneticSettings() { Size = Convert.ToInt32(this.nudSize.Value), Mutation = Convert.ToInt32(this.nudMutation.Value), MutabilityMin = Convert.ToInt32(this.nudMutabilityMin.Value), MutabilityMax = Convert.ToInt32(this.nudMutabilityMax.Value), Elitism = Convert.ToInt32(this.nudElitism.Value), Iterations = Convert.ToInt32(this.nudIterations.Value), Age=Convert.ToInt32(this.nudAge.Value), Seed = Convert.ToInt32(this.nudSeed.Value), Comparsion = cbxComparsion.SelectedIndex, Target = new GeneticColor { Red = btnTarget.BackColor.R, Green = btnTarget.BackColor.G, Blue = btnTarget.BackColor.B } }; return result; }
public static GeneticSettings Load(string pathToXml) { GeneticSettings result = null; XElement xml = null; try { xml = XElement.Load(pathToXml); } catch{} if (xml!=null) { var size = GetIntSetting("size", xml); var mutation = GetIntSetting("mutation", xml); var mutabilityMin = GetIntSetting("mutabilityMin", xml); var mutabilityMax = GetIntSetting("mutabilityMax", xml); var elitism = GetIntSetting("elitism", xml); var iterations = GetIntSetting("iterations", xml); var age = GetIntSetting("age", xml); var seed = GetIntSetting("seed", xml); var comparsion = GetIntSetting("comparsion", xml); var xTarget = xml.Element("target"); byte? red = null, green = null, blue = null; if (xTarget!=null) { red = GetByteSetting("red", xTarget); green = GetByteSetting("green", xTarget); blue = GetByteSetting("blue", xTarget); } if (new object[] {size,mutation,mutabilityMin,mutabilityMax, elitism,iterations,age,seed,red,green,blue}.All(x => x != null)) { result = new GeneticSettings { Size = size.Value, Mutation = mutation.Value, MutabilityMin = mutabilityMin.Value, MutabilityMax = mutabilityMax.Value, Elitism = elitism.Value, Iterations = iterations.Value, Age=age.Value, Seed = seed.Value, Comparsion = comparsion.Value, Target = new GeneticColor { Red = red.Value, Green = green.Value, Blue = blue.Value } }; } } return result; }