public void TestCompare() { BasicGenome genome1 = new IntegerArrayGenome(1); genome1.AdjustedScore = 10; genome1.Score = 4; BasicGenome genome2 = new IntegerArrayGenome(1); genome2.AdjustedScore = 4; genome2.Score = 10; MinimizeAdjustedScoreComp comp = new MinimizeAdjustedScoreComp(); Assert.IsTrue(comp.Compare(genome1, genome2) > 0); }
public void TestShouldMinimize() { MinimizeAdjustedScoreComp comp = new MinimizeAdjustedScoreComp(); Assert.IsTrue(comp.ShouldMinimize); }
public void TestIsBetterThan() { MinimizeAdjustedScoreComp comp = new MinimizeAdjustedScoreComp(); Assert.IsTrue(comp.IsBetterThan(10, 20)); }
public void TestApplyPenalty() { MinimizeAdjustedScoreComp comp = new MinimizeAdjustedScoreComp(); Assert.AreEqual(11, comp.ApplyPenalty(10, 0.1), EncogFramework.DefaultDoubleEqual); }
/// <summary> /// Construct an EA. /// </summary> /// <param name="thePopulation">The population.</param> /// <param name="theScoreFunction">The score function.</param> public BasicEA(IPopulation thePopulation, ICalculateScore theScoreFunction) { RandomNumberFactory = EncogFramework.Instance.RandomFactory.FactorFactory(); EliteRate = 0.3; MaxTries = 5; MaxOperationErrors = 500; CODEC = new GenomeAsPhenomeCODEC(); Population = thePopulation; ScoreFunction = theScoreFunction; Selection = new TournamentSelection(this, 4); Rules = new BasicRuleHolder(); // set the score compare method if (theScoreFunction.ShouldMinimize) { SelectionComparer = new MinimizeAdjustedScoreComp(); BestComparer = new MinimizeScoreComp(); } else { SelectionComparer = new MaximizeAdjustedScoreComp(); BestComparer = new MaximizeScoreComp(); } // set the iteration foreach (ISpecies species in thePopulation.Species) { foreach (IGenome genome in species.Members) { IterationNumber = Math.Max(IterationNumber, genome.BirthGeneration); } } // Set a best genome, just so it is not null. // We won't know the true best genome until the first iteration. if (Population.Species.Count > 0 && Population.Species[0].Members.Count > 0) { BestGenome = Population.Species[0].Members[0]; } }