예제 #1
0
    private IExperimentUI GetExperimentUI()
    {
        // Create a new experiment instance if one has not already been created.
        if (_experimentUI is null)
        {
            _experimentUI = CreateAndConfigureExperimentUI((ExperimentInfo)cmbExperiments.SelectedItem);
        }

        return(_experimentUI);
    }
예제 #2
0
    private void cmbExperiments_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Clear any existing references, as these are specific to each experiment.
        _neatExperiment = null;
        _experimentUI   = null;

        // Close the genome form if it is open, as the content of this form is specific to each experiment.
        GenomeForm bestGenomeForm = _bestGenomeForm;

        if (bestGenomeForm is not null)
        {
            // Note. This will trigger the FormClosed event which will do further clean-up; Close() will also Dispose() the form.
            bestGenomeForm.Close();
        }
    }
    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);
    }
예제 #4
0
        public static IExperimentUI CreateAndConfigureExperimentUI(ExperimentInfo expInfo)
        {
            if (expInfo.ExperimentUIFactory is null)
            {
                return(null);
            }

            // Create an experimentUI factory.
            IExperimentUIFactory factory = (IExperimentUIFactory)Activator.CreateInstance(
                expInfo.ExperimentUIFactory.AssemblyName,
                expInfo.ExperimentUIFactory.TypeName)
                                           .Unwrap();

            // Load experiment json config from file.
            JsonDocument configDoc = JsonUtils.LoadUtf8(expInfo.ConfigFile);

            // Create an instance of INeatExperiment, configured using the supplied json config.
            IExperimentUI experimentUI = factory.CreateExperimentUI(configDoc.RootElement);

            return(experimentUI);
        }