Exemplo n.º 1
0
    /// <summary>
    /// Construct with the provided form title, genome view/renderer and evolution algorithm. We listen to update events
    /// from the evolution algorithm and cleanly detach from it when this form closes.
    /// </summary>
    public GenomeForm(string title, GenomeControl genomeCtrl)
    {
        ArgumentNullException.ThrowIfNull(genomeCtrl);

        this.genomeCtrl = genomeCtrl;

        InitializeComponent();
        this.Text = title;
    }
Exemplo n.º 2
0
        /// <summary>
        /// Construct with the provided form title, genome view/renderer and evolution algorithm. We listen to update events
        /// from the evolution algorithm and cleanly detach from it when this form closes.
        /// </summary>
        public GenomeForm(string title, GenomeControl genomeCtrl)
        {
            if (genomeCtrl is null)
            {
                throw new ArgumentNullException(nameof(genomeCtrl));
            }

            this.genomeCtrl = genomeCtrl;

            InitializeComponent();
            this.Text = title;
        }
    private void bestGenomeToolStripMenuItem_Click(object sender, EventArgs e)
    {
        IExperimentUI experimentUI = GetExperimentUI();

        if (experimentUI is null)
        {
            return;
        }

        GenomeControl genomeCtrl = experimentUI.CreateGenomeControl();

        if (experimentUI is null)
        {
            return;
        }

        // Create form.
        _bestGenomeForm = new GenomeForm("Best Genome", genomeCtrl);

        // Attach an event handler to update this main form when the genome form is closed.
        _bestGenomeForm.FormClosed += new FormClosedEventHandler(delegate(object senderObj, FormClosedEventArgs eArgs)
        {
            _bestGenomeForm = null;
            bestGenomeToolStripMenuItem.Enabled = true;
        });

        // Prevent creation of more then one instance of the genome form.
        bestGenomeToolStripMenuItem.Enabled = false;

        // Get the current best genome.
        NeatGenome <double> bestGenome = _neatPop?.BestGenome;

        if (bestGenome is not null)
        {
            // Set the form's current genome. If the EA is running it will be set shortly anyway, but this ensures we
            // see a genome right away, regardless of whether the EA is running or not.
            _bestGenomeForm.Genome = bestGenome;
        }

        // Show the form.
        _bestGenomeForm.Show(this);
    }