internal void Init(DnaDrawing drawing, JobInfo info) { Points = new List<DnaPoint>(); //int count = info.GetRandomNumber(3, 3); var origin = new DnaPoint(); origin.Init(drawing, info); if (drawing.Polygons.Count < 1) { origin.X = info.SourceImage.Width / 2; origin.Y = info.SourceImage.Height / 2; } for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++) { var point = new DnaPoint { X = Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)), info.SourceImage.Width), Y = Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)), info.SourceImage.Height) }; Points.Add(point); } Brush = new DnaBrush(); Brush.Init(info); }
public void Mutate(JobInfo info) { IsDirty = false; while (!IsDirty) { if (!info.Settings.MuteAddPolygonNew) if (info.WillMutate(info.Settings.AddPolygonMutationRate)) AddPolygon(info); if (!info.Settings.MuteAddPolygonClone) if (info.WillMutate(info.Settings.AddPolygonCloneMutationRate)) AddPolygonClone(info); if (!info.Settings.MuteRemovePolygon) if (info.WillMutate(info.Settings.RemovePolygonMutationRate)) RemovePolygon(info); if (!info.Settings.MuteMovePolygon) if (info.WillMutate(info.Settings.MovePolygonMutationRate)) MovePolygon(info); foreach (DnaPolygon polygon in Polygons) polygon.Mutate(this, info); } }
internal void Init(JobInfo info) { Red = info.GetRandomNumber(0, 255); Green = info.GetRandomNumber(0, 255); Blue = info.GetRandomNumber(0, 255); Alpha = info.GetRandomNumber(10, 60); }
internal void Mutate(JobInfo info) { IsDirty = false; while (!IsDirty) { if (!info.Settings.MuteAddPolygonNew) if (info.WillMutate(info.Settings.AddPolygonMutationRate)) AddPolygon(info); if (!info.Settings.MuteAddPolygonClone) if (info.WillMutate(info.Settings.AddPolygonCloneMutationRate)) AddPolygonClone(info); if (!info.Settings.MuteRemovePolygon) if (info.WillMutate(info.Settings.RemovePolygonMutationRate)) RemovePolygon(info); if (!info.Settings.MuteMovePolygon) if (info.WillMutate(info.Settings.MovePolygonMutationRate)) MovePolygon(info); unchecked { for (int i = 0; i < Polygons.Count; i++) { DnaPolygon polygon = Polygons[i]; polygon.Mutate(this, info); } } } }
internal void Mutate(DnaDrawing drawing, JobInfo info) { if (info.WillMutate(info.Settings.ColorMutationRate)) { Red = info.GetRandomNumber(0, 255); drawing.SetDirty(); } if (info.WillMutate(info.Settings.ColorMutationRate)) { Green = info.GetRandomNumber(0, 255); drawing.SetDirty(); } if (info.WillMutate(info.Settings.ColorMutationRate)) { Blue = info.GetRandomNumber(0, 255); drawing.SetDirty(); } if (info.WillMutate(info.Settings.ColorMutationRate)) { Alpha = info.GetRandomNumber(info.Settings.AlphaRangeMin, info.Settings.AlphaRangeMax); drawing.SetDirty(); } }
public void Init(JobInfo info) { Polygons = new List<DnaPolygon>(); for (int i = 0; i < info.Settings.PolygonsMin; i++) AddPolygon(info); SetDirty(); }
internal WorkerInstance(int randomSeed, JobInfo info) { this.randomSeed = randomSeed; this.info = info; info.InitRandom(randomSeed); parentDrawing = new DnaDrawing { Polygons = new List<DnaPolygon>(), }; }
private void StartEvolution() { var sourceImage = new SourceImage { Pixels = SetupSourceColorMatrix(picPattern.Image as Bitmap), Width = picPattern.Width, Height = picPattern.Height }; var info = new JobInfo { Settings = Project.Settings, SourceImage = sourceImage, }; //IEvolutionJob job = new LayeredEvolutionJob(sourceImage, 4); //DefaultEvolutionJob job = new DefaultEvolutionJob(sourceImage, currentDrawing); //IEvolutionJob job = new DefaultEvolutionJob(info); IEvolutionJob job = new ClusteredEvolutionJob(info); while (Project.IsRunning) { double newErrorLevel = job.GetNextErrorLevel(); var defJob = job as DefaultEvolutionJob; if (defJob != null) Project.Generations += defJob.Generations; Project.Mutations++; if (newErrorLevel <= Project.ErrorLevel) { Project.Selected++; if (newErrorLevel < Project.ErrorLevel) Project.Positive++; else Project.Neutral++; DnaDrawing newDrawing = job.GetDrawing(); if (currentDrawing == null) // to make always lockable... currentDrawing = new DnaDrawing(); lock (currentDrawing) { currentDrawing = newDrawing; Project.Drawing = currentDrawing.Clone(); } Project.ErrorLevel = newErrorLevel; SaveAnimationImage(newDrawing); } } }
internal void MovePolygon(JobInfo info) { if (Polygons.Count < 1) return; int index = info.GetRandomNumber(0, Polygons.Count); DnaPolygon poly = Polygons[index]; Polygons.RemoveAt(index); index = info.GetRandomNumber(0, Polygons.Count); Polygons.Insert(index, poly); SetDirty(); }
public DefaultEvolutionJob(DnaDrawing drawing, JobInfo info) { this.info = info; if (drawing == null) drawing = GetNewInitializedDrawing(info); lock (drawing) { currentDrawing = drawing.Clone(); } currentErrorLevel = FitnessCalculator.GetDrawingFitness(currentDrawing, info.SourceImage); }
public ClusteredWorker(int randomSeed, int partitionY, int partitionHeight, JobInfo info) { data = new WorkerData { randomSeed = randomSeed, workerTail = new Queue<DnaPartitionResult>(), workerUsedTail = new List<DnaPartitionResult>(), }; this.partitionY = partitionY; this.partitionHeight = partitionHeight; this.info = info; }
internal static void Run(Intracommunicator comm) { var info = new JobInfo { //hack, let every node init their own job data Settings = new Settings(), //should be shared and sent to all workers later SourceImage = GetSourceImage() //should also be sent to all workers later }; info.Settings.PolygonsMax = 50/comm.Size; var instance = new WorkerInstance(comm.Rank*10, info); instance.WorkLoop(comm); }
public void Init(DnaDrawing drawing, JobInfo info) { Points = new List<DnaPoint>(); //int count = info.GetRandomNumber(3, 3); var origin = new DnaPoint(); origin.Init(drawing, info); if (drawing.Polygons.Count < 1) { origin.X = info.SourceImage.Width / 2; origin.Y = info.SourceImage.Height / 2; } for (int i = 0; i < info.Settings.PointsPerPolygonMin; i++) { var point = new DnaPoint { X = Math.Min(Math.Max(0, origin.X + info.GetRandomNumber(-3, 3)), info.SourceImage.Width), Y = Math.Min(Math.Max(0, origin.Y + info.GetRandomNumber(-3, 3)), info.SourceImage.Height) }; Points.Add(point); } bool findNew = true; if (info.Settings.MuteCurvePolygon && info.Settings.MuteLinePolygon && info.Settings.MuteCurveFillPolygon && info.Settings.MuteLineFillPolygon) findNew = false; Width = info.GetRandomNumber(1, 8); while (findNew) { bool splines = (info.GetRandomNumber(0, 2) == 1) ? true : false; bool filled = (info.GetRandomNumber(0, 2) == 1) ? true : false; findNew = !SetSplinesAndFilled(info.Settings, splines, filled); } Brush = new DnaBrush(); Brush.Init(info); }
internal void Mutate(DnaDrawing drawing, JobInfo info) { if (!info.Settings.MuteMovePointMax) { if (info.WillMutate(info.Settings.MovePointMaxMutationRate)) { X = info.GetRandomNumber(0, info.SourceImage.Width); Y = info.GetRandomNumber(0, info.SourceImage.Height); drawing.SetDirty(); } } if (!info.Settings.MuteMovePointMid) { if (info.WillMutate(info.Settings.MovePointMidMutationRate)) { X = X .Randomize(info ,- info.Settings.MovePointRangeMid, info.Settings.MovePointRangeMid) .Max(0) .Min(info.SourceImage.Width); Y = Y .Randomize(info, -info.Settings.MovePointRangeMid, info.Settings.MovePointRangeMid) .Max(0) .Min(info.SourceImage.Height); drawing.SetDirty(); } } if (!info.Settings.MuteMovePointMin) { if (info.WillMutate(info.Settings.MovePointMinMutationRate)) { X = X .Randomize(info, -info.Settings.MovePointRangeMin, info.Settings.MovePointRangeMin) .Max(0) .Min(info.SourceImage.Width); Y = Y .Randomize(info, -info.Settings.MovePointRangeMin, info.Settings.MovePointRangeMin) .Max(0) .Min(info.SourceImage.Height); drawing.SetDirty(); } } }
public ClusteredEvolutionJob(JobInfo info) { workers = new List<ClusteredWorker>(); const int workerCount = 2; int partitionHeight = info.SourceImage.Height / workerCount; for (int i = 0; i < workerCount; i++) { var worker = new ClusteredWorker(1, i * partitionHeight, partitionHeight, info); workers.Add(worker); } foreach(ClusteredWorker worker in workers) { worker.StartWorking(); } }
internal void Mutate(DnaDrawing drawing, JobInfo info) { if (info.WillMutate(info.Settings.AddPointMutationRate)) AddPoint(drawing, info); if (info.WillMutate(info.Settings.RemovePointMutationRate)) RemovePoint(drawing, info); Brush.Mutate(drawing, info); unchecked { for (int i = 0; i < Points.Count;i++) { var point = Points[i]; point.Mutate(drawing, info); } } }
internal static int Randomize(this int self,JobInfo info, int min, int max) { return self + info.GetRandomNumber(min, max); }
internal void Init(DnaDrawing drawing,JobInfo info) { X = info.GetRandomNumber(0, info.SourceImage.Width); Y = info.GetRandomNumber(0, info.SourceImage.Height); }
public void RemovePolygon(JobInfo info) { if (Polygons.Count > info.Settings.PolygonsMin) { int index = info.GetRandomNumber(0, Polygons.Count); Polygons.RemoveAt(index); SetDirty(); } }
public void Mutate(DnaDrawing drawing, JobInfo info) { if (info.WillMutate(info.Settings.AddPointMutationRate)) AddPoint(drawing, info); if (info.WillMutate(info.Settings.RemovePointMutationRate)) RemovePoint(drawing, info); if (info.WillMutate(info.Settings.FlipSplinesMutationRate)) FlipSplines(drawing, info); if (info.WillMutate(info.Settings.FlipFilledMutationRate)) FlipFilled(drawing, info); if (info.WillMutate(info.Settings.FlipFilledMutationRate)) Width = info.GetRandomNumber(1, 8); Brush.Mutate(drawing, info); foreach(var point in Points) { point.Mutate(drawing, info); } //IsComplex = false;// checkComplex(); }
public DefaultEvolutionJob(JobInfo info) : this(null, info) { }
public void AddPolygonClone(JobInfo info) { if (Polygons.Count < info.Settings.PolygonsMax) { if (Polygons.Count < 1) AddPolygon(info); else { DnaPolygon parent = Polygons[info.GetRandomNumber(0, Polygons.Count)]; var newPolygon = parent.Clone(); Polygons.Insert(Polygons.IndexOf(parent), newPolygon); newPolygon.Offset(info.GetRandomNumber(-6, 6), info.GetRandomNumber(-6, 6)); newPolygon.Width = info.GetRandomNumber(1, 8); SetDirty(); } } }
public void AddPolygon(JobInfo info) { if (Polygons.Count < info.Settings.PolygonsMax) { var newPolygon = new DnaPolygon(); newPolygon.Init(this, info); int index = info.GetRandomNumber(0, Polygons.Count); Polygons.Insert(index, newPolygon); SetDirty(); } }
private void RemovePoint(DnaDrawing drawing, JobInfo info) { if (Points.Count > info.Settings.PointsPerPolygonMin) { if (drawing.PointCount > info.Settings.PointsMin) { int index = info.GetRandomNumber(0, Points.Count); Points.RemoveAt(index); drawing.SetDirty(); } } }
private void AddPoint(DnaDrawing drawing, JobInfo info) { if (Points.Count < info.Settings.PointsPerPolygonMax) { if (drawing.PointCount < info.Settings.PointsMax) { var newPoint = new DnaPoint(); int index = info.GetRandomNumber(1, Points.Count - 1); DnaPoint prev = Points[index - 1]; DnaPoint next = Points[index]; newPoint.X = (prev.X + next.X) / 2; newPoint.Y = (prev.Y + next.Y) / 2; Points.Insert(index, newPoint); drawing.SetDirty(); } } }
private void FlipSplines(DnaDrawing drawing, JobInfo info) { SetSplinesAndFilled(info.Settings, !Splines, Filled); }
private static DnaDrawing GetNewInitializedDrawing(JobInfo info) { var drawing = new DnaDrawing(); drawing.Init(info); return drawing; }
internal DnaDrawing GetMutatedChild(JobInfo info) { DnaDrawing child = Clone(); child.Mutate(info); return child; }