コード例 #1
0
    private void btnSearchStart_Click(object sender, EventArgs e)
    {
        if (_eaRunner is not null)
        {   // Resume existing EA & update GUI state.
            _eaRunner.StartOrResume();
            UpdateUIState();
            return;
        }

        // Get the current neat experiment, with parameters set from the UI.
        INeatExperiment <double> neatExperiment = GetNeatExperiment();

        // Create evolution algorithm and runner.
        NeatEvolutionAlgorithm <double> ea = NeatUtils.CreateNeatEvolutionAlgorithm(neatExperiment, _neatPop);

        ea.Initialise();

        _eaRunner = new EvolutionAlgorithmRunner(ea, UpdateScheme.CreateTimeSpanUpdateScheme(TimeSpan.FromSeconds(1)));

        // Attach event listeners.
        _eaRunner.UpdateEvent += _eaRunner_UpdateEvent;

        // Start the algorithm & update GUI state.
        _eaRunner.StartOrResume();
        UpdateUIState();
    }
コード例 #2
0
    private void btnSearchReset_Click(object sender, EventArgs e)
    {
        // Clear down any EA related state.
        if (_eaRunner is not null)
        {
            // Note. Dispose here will wait for the termination of the background thread use to run the EA.
            _eaRunner.Dispose();
            _eaRunner = null;
        }
        _neatPop = null;

        // Reset/update UI state.
        Logger.Clear();
        UpdateUIState();
        UpdateUIState_ResetStats();

        // Clear/reset child forms (those that are open).
        if (_bestGenomeForm is not null)
        {
            _bestGenomeForm.Genome = null;
        }

        // Time series forms.
        if (_fitnessTimeSeriesForm is not null)
        {
            _fitnessTimeSeriesForm.Clear();
        }
        if (_complexityTimeSeriesForm is not null)
        {
            _complexityTimeSeriesForm.Clear();
        }
        if (_evalsPerSecTimeSeriesForm is not null)
        {
            _evalsPerSecTimeSeriesForm.Clear();
        }

        // Rankings forms.
        if (_speciesSizeRankForm is not null)
        {
            _speciesSizeRankForm.Clear();
        }
        if (_speciesFitnessRankForm is not null)
        {
            _speciesFitnessRankForm.Clear();
        }
        if (_speciesComplexityRankForm is not null)
        {
            _speciesComplexityRankForm.Clear();
        }
        if (_genomeFitnessRankForm is not null)
        {
            _genomeFitnessRankForm.Clear();
        }
        if (_genomeComplexityRankForm is not null)
        {
            _genomeComplexityRankForm.Clear();
        }

        // Take the opportunity to clean-up the heap.
        GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
    }