Example #1
0
 /// <summary>
 /// Notify the strategy of a change in complexity regulation mode in the evolution algorithm.
 /// </summary>
 /// <param name="mode">The current mode.</param>
 public void NotifyComplexityRegulationMode(ComplexityRegulationMode mode)
 {
     _mutationTypeDistributionsCurrent = mode switch
     {
         ComplexityRegulationMode.Complexifying => _mutationTypeDistributionsComplexifying,
         ComplexityRegulationMode.Simplifying => _mutationTypeDistributionsSimplifying,
         _ => throw new ArgumentException("Unexpected complexity regulation mode."),
     };
 }
        /// <summary>
        /// Notify the strategy of a change in complexity regulation mode in the evolution algorithm.
        /// </summary>
        /// <param name="mode">The current mode.</param>
        public void NotifyComplexityRegulationMode(ComplexityRegulationMode mode)
        {
            switch (mode)
            {
            case ComplexityRegulationMode.Complexifying:
                _settingsCurrent = _settingsComplexifying;
                _mutationTypeDistributionsCurrent = _mutationTypeDistributionsComplexifying;
                break;

            case ComplexityRegulationMode.Simplifying:
                _settingsCurrent = _settingsSimplifying;
                _mutationTypeDistributionsCurrent = _mutationTypeDistributionsSimplifying;
                break;

            default:
                throw new ArgumentException("Unexpected complexity regulation mode.");
            }
        }
        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="metaNeatGenome">NeatGenome metadata.</param>
        /// <param name="genomeBuilder">NeatGenome builder.</param>
        /// <param name="genomeIdSeq">Genome ID sequence; for obtaining new genome IDs.</param>
        /// <param name="innovationIdSeq">Innovation ID sequence; for obtaining new innovation IDs.</param>
        /// <param name="generationSeq">Generation sequence; for obtaining the current generation number.</param>
        /// <param name="addedNodeBuffer">A history buffer of added nodes.</param>
        /// <param name="settings">Asexual reproduction settings.</param>
        /// <param name="weightMutationScheme">Connection weight mutation scheme.</param>
        public NeatReproductionAsexual(
            MetaNeatGenome <T> metaNeatGenome,
            INeatGenomeBuilder <T> genomeBuilder,
            Int32Sequence genomeIdSeq,
            Int32Sequence innovationIdSeq,
            Int32Sequence generationSeq,
            AddedNodeBuffer addedNodeBuffer,
            NeatReproductionAsexualSettings settings,
            WeightMutationScheme <T> weightMutationScheme)
        {
            _settingsComplexifying = settings;
            _settingsSimplifying   = settings.CreateSimplifyingSettings();
            _settingsCurrent       = _settingsComplexifying;

            _mutationTypeDistributionsComplexifying = new MutationTypeDistributions(_settingsComplexifying);
            _mutationTypeDistributionsSimplifying   = new MutationTypeDistributions(_settingsSimplifying);
            _mutationTypeDistributionsCurrent       = _mutationTypeDistributionsComplexifying;

            // Instantiate reproduction strategies.
            _mutateWeightsStrategy    = new MutateWeightsStrategy <T>(metaNeatGenome, genomeBuilder, genomeIdSeq, generationSeq, weightMutationScheme);
            _deleteConnectionStrategy = new DeleteConnectionStrategy <T>(metaNeatGenome, genomeBuilder, genomeIdSeq, generationSeq);

            // Add connection mutation; select acyclic/cyclic strategy as appropriate.
            if (metaNeatGenome.IsAcyclic)
            {
                _addConnectionStrategy = new AddAcyclicConnectionStrategy <T>(
                    metaNeatGenome, genomeBuilder,
                    genomeIdSeq, innovationIdSeq, generationSeq);
            }
            else
            {
                _addConnectionStrategy = new AddCyclicConnectionStrategy <T>(
                    metaNeatGenome, genomeBuilder,
                    genomeIdSeq, generationSeq);
            }

            _addNodeStrategy = new AddNodeStrategy <T>(metaNeatGenome, genomeBuilder, genomeIdSeq, innovationIdSeq, generationSeq, addedNodeBuffer);
        }