public long Evaluate(PolygonalImage image) { Bitmap bitmap = new Bitmap(this.original.Width, this.original.Height); image.DrawBitmap(bitmap); image.Distance = BitmapDistance(this.original, bitmap, this.points); return(image.Distance); }
public static Population CreatePopulation(int nimages, int width, int height, int npolygons, int nsides) { PolygonalImage[] images = new PolygonalImage[nimages]; for (int k = 0; k < images.Length; k++) { images[k] = CreatePolygonalImage(width, height, npolygons, nsides); } return(new Population(images)); }
public static PolygonalImage CreatePolygonalImage(int width, int height, int npolygons, int nsides) { Polygon[] polygons = new Polygon[npolygons]; for (int k = 0; k < polygons.Length; k++) { polygons[k] = CreatePolygon(width, height, nsides, width / 5, height / 5); } PolygonalImage image = new PolygonalImage(polygons); return(image); }
public PolygonalImage GetBestImage() { long best = 0; PolygonalImage selected = null; foreach (PolygonalImage image in this.images) { if (selected == null || best > image.Distance) { best = image.Distance; selected = image; } } return(selected); }
public PolygonalImage Mutate(PolygonalImage image) { Polygon[] newpolygons = new Polygon[image.Polygons.Length]; //System.Array.Copy(image.Polygons, newpolygons, newpolygons.Length); //int p = random.Next(newpolygons.Length); //newpolygons[p] = this.MutatePolygon(newpolygons[p]); for (int k = 0; k < newpolygons.Length; k++) { newpolygons[k] = this.MutatePolygon(image.Polygons[k]); } return(new PolygonalImage(newpolygons)); }
public Population Mutate(Mutator mutator, Evaluator evaluator) { PolygonalImage[] newimages = new PolygonalImage[this.images.Length]; for (int k = 0; k < this.images.Length; k++) { PolygonalImage newimage = mutator.Mutate(this.images[k]); if (this.images[k].Distance == 0) { evaluator.Evaluate(this.images[k]); } if (this.images[k].Distance < evaluator.Evaluate(newimage)) { newimages[k] = this.images[k]; } else { newimages[k] = newimage; } } newimages = newimages.OrderBy(i => i.Distance).ToArray(); //PolygonalImage[] newimages = this.images.OrderBy(i => i.Distance).ToArray(); for (int k = 0; k < newimages.Length / 2; k++) { // newimages[k] = mutator.Mutate(newimages[k]); // newimages[k + newimages.Length / 2] = mutator.Mutate(newimages[k]); newimages[k + newimages.Length / 2] = newimages[k]; } return(new Population(newimages)); }