コード例 #1
0
ファイル: Evolver.cs プロジェクト: MattLloyd101/EvoLisa
        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;
                }
            }
        }
コード例 #2
0
 public EvolutionEngine(Bitmap sourceBitmap)
 {
     _sourceBitmap = sourceBitmap;
     _fitnessCalculator = new NewFitnessCalculator(sourceBitmap);
 }