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;

            MaximizeAdjustedScoreComp comp = new MaximizeAdjustedScoreComp();

            Assert.IsTrue(comp.Compare(genome1, genome2) < 0);
        }
Exemplo n.º 2
0
        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;

            MaximizeAdjustedScoreComp comp = new MaximizeAdjustedScoreComp();

            Assert.IsTrue(comp.Compare(genome1, genome2) < 0);
        }
 public void TestShouldMinimize()
 {
     MaximizeAdjustedScoreComp comp = new MaximizeAdjustedScoreComp();
     Assert.IsFalse(comp.ShouldMinimize);
 }
 public void TestIsBetterThan()
 {
     MaximizeAdjustedScoreComp comp = new MaximizeAdjustedScoreComp();
     Assert.IsFalse(comp.IsBetterThan(10, 20));
 }
 public void TestApplyPenalty()
 {
     MaximizeAdjustedScoreComp comp = new MaximizeAdjustedScoreComp();
     Assert.AreEqual(9, comp.ApplyPenalty(10, 0.1), EncogFramework.DefaultDoubleEqual);
 }
Exemplo n.º 6
0
        /// <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];
            }
        }
Exemplo n.º 7
0
        public void TestApplyPenalty()
        {
            MaximizeAdjustedScoreComp comp = new MaximizeAdjustedScoreComp();

            Assert.AreEqual(9, comp.ApplyPenalty(10, 0.1), EncogFramework.DefaultDoubleEqual);
        }
Exemplo n.º 8
0
        public void TestShouldMinimize()
        {
            MaximizeAdjustedScoreComp comp = new MaximizeAdjustedScoreComp();

            Assert.IsFalse(comp.ShouldMinimize);
        }
Exemplo n.º 9
0
        public void TestIsBetterThan()
        {
            MaximizeAdjustedScoreComp comp = new MaximizeAdjustedScoreComp();

            Assert.IsFalse(comp.IsBetterThan(10, 20));
        }