/// <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) { _settings = settings; // 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, innovationIdSeq, generationSeq); } _addNodeStrategy = new AddNodeStrategy <T>(metaNeatGenome, genomeBuilder, genomeIdSeq, innovationIdSeq, generationSeq, addedNodeBuffer); }
/// <summary> /// Construct a new instance. /// </summary> /// <param name="eaSettings">NEAT evolution algorithm settings.</param> /// <param name="evaluator">An evaluator of lists of genomes.</param> /// <param name="speciationStrategy">Speciation strategy.</param> /// <param name="population">An initial population of genomes.</param> /// <param name="complexityRegulationStrategy">Complexity regulation strategy.</param> /// <param name="reproductionAsexualSettings">Asexual reproduction settings.</param> /// <param name="reproductionSexualSettings">Sexual reproduction settings.</param> /// <param name="weightMutationScheme">Connection weight mutation scheme.</param> /// <param name="rng">Random source.</param> public NeatEvolutionAlgorithm( NeatEvolutionAlgorithmSettings eaSettings, IGenomeListEvaluator <NeatGenome <T> > evaluator, ISpeciationStrategy <NeatGenome <T>, T> speciationStrategy, NeatPopulation <T> population, IComplexityRegulationStrategy complexityRegulationStrategy, NeatReproductionAsexualSettings reproductionAsexualSettings, NeatReproductionSexualSettings reproductionSexualSettings, WeightMutationScheme <T> weightMutationScheme, IRandomSource rng) { _eaSettingsCurrent = eaSettings ?? throw new ArgumentNullException(nameof(eaSettings)); _eaSettingsComplexifying = eaSettings; _eaSettingsSimplifying = eaSettings.CreateSimplifyingSettings(); _evaluator = evaluator ?? throw new ArgumentNullException(nameof(evaluator)); _speciationStrategy = speciationStrategy ?? throw new ArgumentNullException(nameof(speciationStrategy)); _pop = population ?? throw new ArgumentNullException(nameof(population)); _complexityRegulationStrategy = complexityRegulationStrategy ?? throw new ArgumentNullException(nameof(complexityRegulationStrategy)); if (reproductionAsexualSettings == null) { throw new ArgumentNullException(nameof(reproductionAsexualSettings)); } if (reproductionSexualSettings == null) { throw new ArgumentNullException(nameof(reproductionSexualSettings)); } _rng = rng; _genomeComparerDescending = new GenomeComparerDescending(evaluator.FitnessComparer); if (eaSettings.SpeciesCount > population.PopulationSize) { throw new ArgumentException("Species count is higher then the population size."); } _generationSeq = new Int32Sequence(); _reproductionAsexual = new NeatReproductionAsexual <T>( _pop.MetaNeatGenome, _pop.GenomeBuilder, _pop.GenomeIdSeq, population.InnovationIdSeq, _generationSeq, _pop.AddedNodeBuffer, reproductionAsexualSettings, weightMutationScheme); _reproductionSexual = new NeatReproductionSexual <T>( _pop.MetaNeatGenome, _pop.GenomeBuilder, _pop.GenomeIdSeq, _generationSeq, reproductionSexualSettings); _offspringBuilder = new OffspringBuilder <T>( _reproductionAsexual, _reproductionSexual, eaSettings.InterspeciesMatingProportion, evaluator.FitnessComparer); }
/// <summary> /// Construct a new instance. /// </summary> /// <param name="genomeBuilder">NeatGenome builder.</param> /// <param name="genomeIdSeq">Genome ID sequence; for obtaining new genome IDs.</param> /// <param name="generationSeq">Generation sequence; for obtaining the current generation number.</param> /// <param name="weightMutationScheme">Connection weight mutation scheme.</param> public MutateWeightsStrategy( INeatGenomeBuilder <T> genomeBuilder, Int32Sequence genomeIdSeq, Int32Sequence generationSeq, WeightMutationScheme <T> weightMutationScheme) { _genomeBuilder = genomeBuilder; _genomeIdSeq = genomeIdSeq; _generationSeq = generationSeq; _weightMutationScheme = weightMutationScheme; }
/// <summary> /// Construct a new instance. /// </summary> /// <param name="eaSettings">NEAT evolution algorithm settings.</param> /// <param name="evaluator">An evaluator of lists of genomes.</param> /// <param name="speciationStrategy">Speciation strategy.</param> /// <param name="population">An initial population of genomes.</param> /// <param name="reproductionAsexualSettings">Asexual reproduction settings.</param> /// <param name="reproductionSexualSettings">Sexual reproduction settings.</param> /// <param name="weightMutationScheme">Connection weight mutation scheme.</param> public NeatEvolutionAlgorithm( NeatEvolutionAlgorithmSettings eaSettings, IGenomeListEvaluator <NeatGenome <T> > evaluator, ISpeciationStrategy <NeatGenome <T>, T> speciationStrategy, NeatPopulation <T> population, NeatReproductionAsexualSettings reproductionAsexualSettings, NeatReproductionSexualSettings reproductionSexualSettings, WeightMutationScheme <T> weightMutationScheme) : this(eaSettings, evaluator, speciationStrategy, population, reproductionAsexualSettings, reproductionSexualSettings, weightMutationScheme, RandomDefaults.CreateRandomSource()) { }
/// <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) { var settingsComplexifying = settings; var settingsSimplifying = settings.CreateSimplifyingSettings(); _mutationTypeDistributionsComplexifying = new MutationTypeDistributions(settingsComplexifying); _mutationTypeDistributionsSimplifying = new MutationTypeDistributions(settingsSimplifying); _mutationTypeDistributionsCurrent = _mutationTypeDistributionsComplexifying; // Instantiate reproduction strategies. _mutateWeightsStrategy = new MutateWeightsStrategy <T>(genomeBuilder, genomeIdSeq, generationSeq, weightMutationScheme); _deleteConnectionStrategy = new DeleteConnectionStrategy <T>(genomeBuilder, genomeIdSeq, generationSeq); // Add connection mutation; select acyclic/cyclic strategy as appropriate. if (metaNeatGenome.IsAcyclic) { _addConnectionStrategy = new AddAcyclicConnectionStrategy <T>( metaNeatGenome, genomeBuilder, genomeIdSeq, generationSeq); } else { _addConnectionStrategy = new AddCyclicConnectionStrategy <T>( metaNeatGenome, genomeBuilder, genomeIdSeq, generationSeq); } _addNodeStrategy = new AddNodeStrategy <T>(metaNeatGenome, genomeBuilder, genomeIdSeq, innovationIdSeq, generationSeq, addedNodeBuffer); }