public BitGeneString(int numGenes, bool randomize)
        {
            genes = new BitGene[numGenes];

            for (int n = 0; n < numGenes; n++)
            {
                genes[n] = new BitGene(SharedRandom.Next(2) == 0);
            }
        }
Example #2
0
        private static double parseDouble(int length, double maxSize, BitGene[] genes, Cursor cursor)
        {
            double num = (double)parseNumber(length, genes, cursor);

            num = num / (Math.Pow(2.0d, length) - 1);

            num = num * maxSize;

            return num;
        }
Example #3
0
        private static void addOne(BitGene[] genes, int position)
        {
            if (position == genes.Length) return;

            genes[position] = (BitGene)genes[position].mutate();
            if (genes[position].getValue() == true)
            {
                addOne(genes, position + 1);
            }
        }
Example #4
0
        private static int parseNumber(int length, BitGene[] genes, Cursor cursor)
        {
            int num = 0;
            int pow = 1;

            for (int n = 0; n < length && cursor.cursor < genes.Length; n++)
            {
                if (((BitGene)genes[cursor.cursor++]).getValue()) num += pow;
                pow *= 2;
            }

            return num;
        }
Example #5
0
        public static void run()
        {
            BitGene[] genes = new BitGene[gL];

            for (int n = 0; n < gL; n++)
            {
                genes[n] = new BitGene(false);
            }

            for (int n = 0; n < Math.Pow(2, gL); n++)
            {
                addOne(genes, 0);

                System.Diagnostics.Debug.Print(parseNumber(gL, genes, new Cursor()) + " -> " + parseDouble(gL, 100, genes, new Cursor()));
            }
        }