public void FlipGene_Index_ValueFlip()
        {
            RandomizationProvider.Current = Substitute.For <IRandomization>();
            RandomizationProvider.Current.GetInt(0, 3).Returns(-2);

            var target = new IntegerChromosome(0, 3);

            Assert.AreEqual("11111111111111111111111111111110", target.ToString());

            target.FlipGene(0);
            Assert.AreEqual("01111111111111111111111111111110", target.ToString());

            target.FlipGene(1);
            Assert.AreEqual("00111111111111111111111111111110", target.ToString());

            target.FlipGene(10);
            Assert.AreEqual("00111111110111111111111111111110", target.ToString());

            target.FlipGene(31);
            Assert.AreEqual("00111111110111111111111111111111", target.ToString());

            target.FlipGene(30);
            Assert.AreEqual("00111111110111111111111111111101", target.ToString());
        }
Beispiel #2
0
        void Example()
        {
            var i = new IntegerChromosome(3, 3);

            // 31 is the least significant bit
            // 0 is sign bit
            i.FlipGene(31);
            Console.WriteLine("I3: " + i.ToInteger());


            var array = new int[1];
            // most significant bit is the right most bit.
            // Last bit is sign bit
            var genes    = new bool[] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };
            var bitArray = new BitArray(genes);

            bitArray.CopyTo(array, 0);

            Console.WriteLine(array[0]);
        }
        public void Integer()
        {
            var target = new IntegerChromosome(0, 10);

            target.Clone();
            target.CompareTo(new IntegerChromosome(0, 10));
            target.CreateNew();
            var x = target.Fitness;

            target.FlipGene(0);
            target.GenerateGene(0);
            target.GetGene(0);
            target.GetGenes();
            target.GetHashCode();
            var y = target.Length;

            target.ReplaceGene(0, new Gene(false));
            target.ReplaceGenes(0, new Gene[] { new Gene(false), new Gene(true) });
            target.Resize(20);
            target.ToInteger();
            target.ToString();
        }