Ejemplo n.º 1
0
        public void TestAsymmetricZipRecombinator()
        {
            Chromosome <BoolGene>  father       = new Chromosome <BoolGene>(2);
            Chromosome <BoolGene>  mother       = new Chromosome <BoolGene>(2);
            IRecombinationProvider recombinator = new AsymmetricZipRecombinator();

            father[0] = true;
            father[1] = false;
            mother[0] = false;
            mother[1] = true;

            Chromosome <BoolGene> child = father.Recombine(mother, recombinator);

            Assert.IsTrue(child.GeneCount == 2);
            Assert.IsTrue(child[0] == false && child[1] == false, "Fix recombination not correct!");

            father[0].Mutate();
            mother[1].Mutate();

            child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child[0].Equals(mother[0]) && child[1].Equals(father[1]), "Variable recombination not correct!");

            father = new Chromosome <BoolGene>(3);
            mother = new Chromosome <BoolGene>(5);

            father[0] = true;
            father[1] = false;
            father[2] = true;
            mother[0] = false;
            mother[1] = true;
            mother[2] = false;
            mother[3] = true;
            mother[4] = false;

            child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child.GeneCount == 5, "Gene Count wrong in asymmeric test");
            Assert.IsTrue(child[0] == true && child[1] == true && child[2] == true && child[3] == true && child[4] == false, "Fix recombination in asymetric Mother/Father not correct!");
        }
        public void TestAsymmetricZipRecombinator()
        {
            Chromosome<BoolGene> father = new Chromosome<BoolGene>(2);
            Chromosome<BoolGene> mother = new Chromosome<BoolGene>(2);
            IRecombinationProvider recombinator = new AsymmetricZipRecombinator();

            father[0] = true;
            father[1] = false;
            mother[0] = false;
            mother[1] = true;

            Chromosome<BoolGene> child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child.GeneCount == 2);
            Assert.IsTrue(child[0] == false && child[1] == false, "Fix recombination not correct!");

            father[0].Mutate();
            mother[1].Mutate();

            child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child[0].Equals(mother[0]) && child[1].Equals(father[1]), "Variable recombination not correct!");

            father = new Chromosome<BoolGene>(3);
            mother = new Chromosome<BoolGene>(5);

            father[0] = true;
            father[1] = false;
            father[2] = true;
            mother[0] = false;
            mother[1] = true;
            mother[2] = false;
            mother[3] = true;
            mother[4] = false;

            child = father.Recombine(mother, recombinator);
            Assert.IsTrue(child.GeneCount == 5, "Gene Count wrong in asymmeric test");
            Assert.IsTrue(child[0] == true && child[1] == true && child[2] == true && child[3] == true && child[4] == false, "Fix recombination in asymetric Mother/Father not correct!");
        }