Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private void ReplaceIndividual(LabeledPolygonImage toReplace, PolygonIndividual replaceWith)
        {
            population.Replace(
                population.Find(toReplace.SavedPolygon.Name),
                replaceWith);

            picturesLayoutPanel.Controls.Remove(toReplace);
            picturesLayoutPanel.Controls.Add(BuildLabeledImage(replaceWith));
        }
Exemplo n.º 3
0
        private void picturesLayoutPanel_MouseDown(object sender, MouseEventArgs e)
        {
            var imageAtLocation = picturesLayoutPanel.GetChildAtPoint(e.Location) as LabeledPolygonImage;

            if (imageAtLocation == null)
            {
                return;
            }
            beingDragged = imageAtLocation;
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
 private void RemoveIndividual(LabeledPolygonImage image)
 {
     population.Remove(population.FirstOrDefault(indiv => indiv.Polygon == image.SavedPolygon));
     picturesLayoutPanel.Controls.Remove(image);
 }
Exemplo n.º 8
0
 private void DeleteIndividual(LabeledPolygonImage selectedToDelete)
 {
     population.Remove(population.Find(selectedToDelete.SavedPolygon.Name));
     picturesLayoutPanel.Controls.Remove(selectedToDelete);
 }