private void StartEvolution() { if (currentDrawing == null) { currentDrawing = GetNewInitializedDrawing(); } lastSelected = 0; NewFitnessCalculator calc = new NewFitnessCalculator(); readyToBreed = false; while (isRunning) { DnaDrawing newDrawing; lock (currentDrawing) { newDrawing = currentDrawing.Clone(); } newDrawing.Mutate(); if (newDrawing.IsDirty) { generation++; double newErrorLevel = calc.GetDrawingFitness(newDrawing, sourceColours); if (newErrorLevel <= _errorLevel) { selected++; selectedThisGeneration++; lock (currentDrawing) { currentDrawing = newDrawing; } _errorLevel = newErrorLevel; } } if (metCompletionCritera) { readyToBreed = true; } } }
public EvolutionEngine(Bitmap sourceBitmap) { _sourceBitmap = sourceBitmap; _fitnessCalculator = new NewFitnessCalculator(sourceBitmap); }