예제 #1
0
        public void DoWork()
        {
            var physics = new PlantPhysics();
            var growth = new PlantGrowth();
            var universe = new PlantUniverse();

            universe.Reset();

            _display.Universe = universe;

            for (int i = 0; i < PlantUniverse.EvaluationCycles && !_done; i++)
            {
                physics.RunPhysics(universe);
                growth.RunGrowth(universe, SamplePlant);

                if (!Dispatcher.CheckAccess())
                {
                    Dispatcher.Invoke(() => _display.Paint());
                }
                else
                {
                    _display.Paint();
                }

                Thread.Sleep(100);
            }
            Thread.Sleep(100);
        }
예제 #2
0
        public void DoWork()
        {
            var physics  = new PlantPhysics();
            var growth   = new PlantGrowth();
            var universe = new PlantUniverse();

            universe.Reset();

            _display.Universe = universe;

            for (int i = 0; i < PlantUniverse.EvaluationCycles && !_done; i++)
            {
                physics.RunPhysics(universe);
                growth.RunGrowth(universe, SamplePlant);

                if (!Dispatcher.CheckAccess())
                {
                    Dispatcher.Invoke(() => _display.Paint());
                }
                else
                {
                    _display.Paint();
                }

                Thread.Sleep(100);
            }
            Thread.Sleep(100);
        }
예제 #3
0
        /// <inheritdoc />
        public double CalculateScore(IMLMethod algo)
        {
            var genome = (DoubleArrayGenome) algo;
            var universe = new PlantUniverse();
            universe.Reset();
            var physics = new PlantPhysics();
            var growth = new PlantGrowth();

            // Run the generations.
            for (int i = 0; i < PlantUniverse.EvaluationCycles; i++)
            {
                physics.RunPhysics(universe);
                growth.RunGrowth(universe, genome.Data);
            }

            // Count the amount of green.
            int count = 0;
            double sum = 0;
            for (int row = 0; row < PlantUniverse.UniverseHeight; row++)
            {
                for (int col = 0; col < PlantUniverse.UniverseWidth; col++)
                {
                    PlantUniverseCell cell = universe.GetCell(row, col);
                    if (cell.IsAlive)
                    {
                        if (row >= PlantUniverse.GroundLine)
                        {
                            sum += 0.5;
                        }
                        else
                        {
                            sum += cell.Leafyness;
                        }
                    }
                    count++;
                }
            }
            return sum/count;
        }
예제 #4
0
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            pop = InitPopulation();
            score = new PlantScore();
            this.genetic = new BasicEA(pop, score);

            //this.genetic.Speciation = new ArraySpeciation<DoubleArrayGenome>();

            genetic.AddOperation(0.9, new Splice(PlantUniverse.GenomeSize / 3));
            genetic.AddOperation(0.1, new MutatePerturb(0.1));

            // Display

            this.universe = new PlantUniverse();
            this.universe.Reset();


            DoubleArrayGenome bestGenome = (DoubleArrayGenome)genetic.BestGenome;
            PlantPhysics physics = new PlantPhysics();
            PlantGrowth growth = new PlantGrowth();

            for (int i = 0; i < 100; i++)
            {
                physics.RunPhysics(universe);
                growth.RunGrowth(universe, bestGenome.Data);
            }

            this.display = new DisplayPlant(CanvasOutput);
            this.display.Universe = this.universe;
            Thread t = new Thread(DoWork);
            t.Start();
        }
예제 #5
0
        private void DoWork()
        {
            int generation = 0;

            UpdateStatus("Starting up...");

            while (!_done)
            {
            generation++;
            this.genetic.Iteration();

            this.universe.Reset();

            DoubleArrayGenome bestGenome = (DoubleArrayGenome) this.genetic.BestGenome;
            PlantGrowth growth = new PlantGrowth();
            PlantPhysics physics = new PlantPhysics();

            for (int i = 0; i < PlantUniverse.EvaluationCycles; i++) {
                physics.RunPhysics(universe);
                growth.RunGrowth(universe, bestGenome.Data);
            }

                double bestScore = this.genetic.BestGenome.Score;
                UpdateStatus("Generation: " + generation + ", Best Score: " + bestScore);

            

            //System.out.println(Arrays.toString(bestGenome.getLongTermMemory()));    
            }
        }