/// <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="metaNeatGenome">NEAT genome 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> public AddNodeStrategy( MetaNeatGenome <T> metaNeatGenome, INeatGenomeBuilder <T> genomeBuilder, Int32Sequence genomeIdSeq, Int32Sequence innovationIdSeq, Int32Sequence generationSeq, AddedNodeBuffer addedNodeBuffer) { _metaNeatGenome = metaNeatGenome; _genomeBuilder = genomeBuilder; _genomeIdSeq = genomeIdSeq; _innovationIdSeq = innovationIdSeq; _generationSeq = generationSeq; _addedNodeBuffer = addedNodeBuffer; }
/// <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">Sexual reproduction settings.</param> public NeatReproductionSexual( MetaNeatGenome <T> metaNeatGenome, INeatGenomeBuilder <T> genomeBuilder, Int32Sequence genomeIdSeq, Int32Sequence innovationIdSeq, Int32Sequence generationSeq, AddedNodeBuffer addedNodeBuffer, NeatReproductionSexualSettings settings) { _settings = settings; _strategy = new UniformCrossoverReproductionStrategy <T>( metaNeatGenome.IsAcyclic, settings.SecondaryParentGeneProbability, genomeBuilder, genomeIdSeq, generationSeq); }
public void TestLookup() { AddedNodeBuffer buff = new AddedNodeBuffer(10); // Register some added nodes. buff.Register(new DirectedConnection(100, 101), 102); buff.Register(new DirectedConnection(103, 104), 105); // Test lookups. TestLookupSuccess(buff, new DirectedConnection(100, 101), 102); TestLookupSuccess(buff, new DirectedConnection(103, 104), 105); // Test lookup failure. TestLookupFail(buff, new DirectedConnection(100, 102)); TestLookupFail(buff, new DirectedConnection(101, 100)); TestLookupFail(buff, new DirectedConnection(103, 102)); TestLookupFail(buff, new DirectedConnection(104, 103)); }
public NeatReproductionSexual( MetaNeatGenome <T> metaNeatGenome, INeatGenomeBuilder <T> genomeBuilder, Int32Sequence genomeIdSeq, Int32Sequence innovationIdSeq, Int32Sequence generationSeq, AddedNodeBuffer addedNodeBuffer, NeatReproductionSexualSettings settings, IRandomSourceBuilder rngBuilder) { _settings = settings; _rng = rngBuilder.Create(); _strategy = new UniformCrossoverReproductionStrategy <T>( metaNeatGenome, genomeBuilder, genomeIdSeq, generationSeq, rngBuilder.Create()); }
/// <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); }
private static void TestLookupSuccess(AddedNodeBuffer buff, in DirectedConnection connection, int expectedAddedNodeId)
private static void TestLookupFail(AddedNodeBuffer buff, DirectedConnection connection) { Assert.IsFalse(buff.TryLookup(connection, out int addedNodeId)); }
private static void TestLookupSuccess(AddedNodeBuffer buff, DirectedConnection connection, int expectedAddedNodeId) { Assert.IsTrue(buff.TryLookup(connection, out int addedNodeId)); Assert.AreEqual(expectedAddedNodeId, addedNodeId); }