private PolygonIndividual ReproduceImages(LabeledPolygonImage image1, LabeledPolygonImage image2) { var newIndividual = adapter.CrossOver(new PolygonIndividual(image1.SavedPolygon), new PolygonIndividual(image2.SavedPolygon)); adapter.Mutate(newIndividual, Genetic_Algorithm.Utils.SettingsAccessor.MutationProbability); return(newIndividual); }
private void ReplaceIndividual(LabeledPolygonImage toReplace, PolygonIndividual replaceWith) { population.Replace( population.Find(toReplace.SavedPolygon.Name), replaceWith); picturesLayoutPanel.Controls.Remove(toReplace); picturesLayoutPanel.Controls.Add(BuildLabeledImage(replaceWith)); }
private void picturesLayoutPanel_MouseDown(object sender, MouseEventArgs e) { var imageAtLocation = picturesLayoutPanel.GetChildAtPoint(e.Location) as LabeledPolygonImage; if (imageAtLocation == null) { return; } beingDragged = imageAtLocation; }
private LabeledPolygonImage BuildLabeledImage(PolygonIndividual buildFrom) { var result = new LabeledPolygonImage(Polygon.Copy(buildFrom.Polygon)) { Description = $"{buildFrom.Polygon.Name}{Environment.NewLine}Fitness: {FitnessCalculator?.IndividualFitness(buildFrom)}", BackColor = picturesBackgroundColorDialog.Color, Width = currentImagesWidth, Height = currentImagesHeight, AllowSelectionCheckbox = false }; return(result); }
private LabeledPolygonImage BuildLabeledImage(PolygonIndividual buildFrom) { var result = new LabeledPolygonImage(Polygon.Copy(buildFrom.Polygon)); result.Description = $"{buildFrom.Polygon.Name}{System.Environment.NewLine}Fitness: {fitnessCalculator?.IndividualFitness(buildFrom)}"; result.BackColor = picturesBackgroundColorDialog.Color; result.ContextMenuStrip = labeledImageContextMenu; result.Width = currentImagesWidth; result.Height = currentImagesHeight; result.ImageMouseDown += picturesLayoutPanel_MouseDown; result.ImageMouseUp += picturesLayoutPanel_MouseUp; return(result); }
private void picturesLayoutPanel_MouseUp(object sender, MouseEventArgs e) { var imageAtLocation = picturesLayoutPanel.GetChildAtPoint(e.Location) as LabeledPolygonImage; if (imageAtLocation == null || beingDragged == null || imageAtLocation == beingDragged) { //either dragged didn't land on another image or landed on itself => no UI reaction beingDragged = null; return; } var child = ReproduceImages(imageAtLocation, beingDragged); population.Add(child); if (sortPopulationCheckbox.Checked) { OverwritePopulationPictures(); } else { picturesLayoutPanel.Controls.Add(BuildLabeledImage(child)); } beingDragged = null; }
private void RemoveIndividual(LabeledPolygonImage image) { population.Remove(population.FirstOrDefault(indiv => indiv.Polygon == image.SavedPolygon)); picturesLayoutPanel.Controls.Remove(image); }
private void DeleteIndividual(LabeledPolygonImage selectedToDelete) { population.Remove(population.Find(selectedToDelete.SavedPolygon.Name)); picturesLayoutPanel.Controls.Remove(selectedToDelete); }