public void DefineCompetitivePopulationReturnsCurrentSearchPoints() { var originalCompetitives = new List <Genome>(); for (int i = 0; i < 5; i++) { originalCompetitives.Add(this._genomeBuilder.CreateRandomGenome(age: i % 3)); } var searchPoints = new List <GenomeSearchPoint>(); for (int i = 0; i < 8; i++) { searchPoints.Add( GenomeSearchPoint.CreateFromGenome( this._genomeBuilder.CreateRandomGenome(age: 0), this._parameterTree, 0, this._genomeBuilder)); } var informationFlowStrategy = new GlobalDifferentialEvolutionInformationFlow( this._deConfiguration, this._parameterTree, this._genomeBuilder); var competitiveIndividuals = informationFlowStrategy.DefineCompetitivePopulation(originalCompetitives, null, searchPoints); Assert.Equal( searchPoints.Select(point => point.Genome.ToString()).OrderBy(x => x).ToArray(), competitiveIndividuals.Select(genome => genome.ToString()).OrderBy(x => x).ToArray()); }
public void CreateFromGenomeThrowsForMissingGenomeBuilder() { Assert.Throws <ArgumentNullException>( () => GenomeSearchPoint.CreateFromGenome( this._genomeBuilder.CreateRandomGenome(age: 1), this._parameterTree, this._minimumDomainSize, genomeBuilder: null)); }
public void CreateFromGenomeThrowsForMissingGenome() { Assert.Throws <ArgumentNullException>( () => GenomeSearchPoint.CreateFromGenome( genome: null, parameterTree: this._parameterTree, minimumDomainSize: this._minimumDomainSize, genomeBuilder: this._genomeBuilder)); }
public void ToStringPrintsGenome() { var genome = this._genomeBuilder.CreateRandomGenome(age: 0); var point = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); Assert.Equal(genome.ToString(), point.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="GenomeSearchPointTest"/> class. /// </summary> public GenomeSearchPointTest() { Randomizer.Configure(); this._parameterTree = this.CreateParameterTree(); this._genomeBuilder = new GenomeBuilder( this._parameterTree, new AlgorithmTunerConfiguration.AlgorithmTunerConfigurationBuilder().Build(1)); this._parent = GenomeSearchPoint.CreateFromGenome( this._genomeBuilder.CreateRandomGenome(age: 1), this._parameterTree, this._minimumDomainSize, this._genomeBuilder); }
public void GenomePropertyReversesCreateFromGenome() { var originalGenome = this._genomeBuilder.CreateRandomGenome(age: 2); var point = GenomeSearchPoint.CreateFromGenome( originalGenome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); var createdGenome = point.Genome.CreateMutableGenome(); Assert.True( new Genome.GeneValueComparator().Equals(originalGenome, createdGenome), $"{createdGenome} should have the same values as the genome it is based on, {originalGenome}."); }
/// <summary> /// Creates <see cref="GenomeSearchPoint"/>s according to <see cref="GenomeBuilder"/>. /// </summary> /// <returns>The created <see cref="GenomeSearchPoint"/>s.</returns> private List <GenomeSearchPoint> CreateRandomSearchPoints() { var searchPoints = new List <GenomeSearchPoint>(); for (int i = 0; i < 8; i++) { searchPoints.Add( GenomeSearchPoint.CreateFromGenome( this._genomeBuilder.CreateRandomGenome(age: 0), this._parameterTree, 0, this._genomeBuilder)); } return(searchPoints); }
public void GenomePropertyProducesIndependentGenome() { var genome = this._genomeBuilder.CreateRandomGenome(age: 0); var point = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); genome.SetGene("a", new Allele <int>(234)); var createdGenome = point.Genome.CreateMutableGenome(); Assert.NotEqual( 234, createdGenome.GetGeneValue("a").GetValue()); }
/// <summary> /// Called before every test case. /// </summary> protected override void InitializeDefault() { var parameterTree = this.GetDefaultParameterTree(); var genomeBuilder = new GenomeBuilder(parameterTree, this.GetDefaultAlgorithmTunerConfiguration()); this._originalIncumbent = genomeBuilder.CreateRandomGenome(age: 2); for (int i = 0; i < 5; i++) { var searchPoint = GenomeSearchPoint.CreateFromGenome( genomeBuilder.CreateRandomGenome(age: 0), parameterTree, minimumDomainSize: 5, genomeBuilder: genomeBuilder); this._mostRecentSorting.Add(searchPoint); this._currentEvaluationInstances.Add(new TestInstance(i.ToString())); } }
public void IsValidChecksCustomGenomeBuilder() { var genome = this._genomeBuilder.CreateRandomGenome(age: 2); var point = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); Assert.True(point.IsValid(), $"{point} should be valid."); var pointAsForbidden = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, new ConfigurableGenomeBuilder(this._parameterTree, isValidFunction: g => false, mutationRate: 0)); Assert.False( pointAsForbidden.IsValid(), $"{pointAsForbidden} should not be valid for other genome builder."); }
public void CreateFromGenomeCopiesCorrectInformation() { var genome = this._genomeBuilder.CreateRandomGenome(age: 2); genome.IsEngineered = true; var point = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); Assert.False( point.Genome.CreateMutableGenome().IsEngineered, "IsEngineered property should not be copied over."); // Age is only relevant for GGA. As points are not generated in GGA, the age should be fixed. Assert.Equal( genome.Age, point.Genome.CreateMutableGenome().Age); }
public void CreateFromGenomeExtractsCorrectValues() { var genome = this._genomeBuilder.CreateRandomGenome(age: 2); var point = GenomeSearchPoint.CreateFromGenome( genome, this._parameterTree, this._minimumDomainSize, this._genomeBuilder); var continuousIdentifiers = new[] { "a", "c", "e", "f" }; Assert.True( continuousIdentifiers.Length == point.Values.Count, $"There should be four continuous parameters: {TestUtils.PrintList(continuousIdentifiers)}."); for (int i = 0; i < continuousIdentifiers.Length; i++) { var identifier = continuousIdentifiers[i]; Assert.Equal( Convert.ToDouble(genome.GetGeneValue(identifier).GetValue()), point.Values[i]); } }