private Gene[] CreateGenes(IList <Server> childServers)
        {
            var genes = new Gene[childServers.Count];
            var i     = 0;

            foreach (var childServer in childServers)
            {
                genes[i] = new Gene(childServer);
                i++;
            }

            return(genes);
        }
Ejemplo n.º 2
0
        public EquationGenome(long length, object min, object max)
        {
            Length      = length;
            TheMin      = (int)min;
            TheMax      = (int)max;
            CurrentXPos = 0;
            CurrentYPos = 0;

            for (int i = 0; i < Length; i++)
            {
                Gene nextValue = (Gene)GenerateGeneValue(min, max, i);
                TheArray.Add(nextValue);
            }
        }
Ejemplo n.º 3
0
        /**
         * This will generate the initial genes (string) of Gen 1
         */
        public void generateInitialPopulation()
        {
            for (int x = 0; x < populationSize; x++)
            {
                Gene tempGene = new Gene();
                tempGene.code = "";
                for (int y = 0; y < this.goal.Length; y++)
                {
                    tempGene.code += this.generateRandomCharacter();
                }
                tempGene.fitness = this.calculateFitness(tempGene.code);
                allGenes.Add(tempGene);
            }

            // Sort the initial genes by fitness
            // Highest fitness will be at index 0
            allGenes = allGenes.OrderByDescending(x => x.fitness).ToList();

            // Display the initial gene population
            this.displayTopGenes(10);
        }
Ejemplo n.º 4
0
        public override object GenerateGeneValue(object min, object max, int position)
        {
            Gene g        = new Gene();
            int  nextSeed = 0;

            nextSeed    = TheSeed.Next((int)min, (int)max);
            g.operation = nextSeed;

            if (position == 0)                             // special case, want to generate a symbol for first one
            {
                g.operation = TheSeed.Next(0, NumSymbols); // generate 0 or 1, for a and b
                return(g);
            }

            if (nextSeed > 1)             // we have an operation, need postion
            {
                nextSeed       = TheSeed.Next((int)min, position);
                g.instruction1 = nextSeed;
                nextSeed       = TheSeed.Next((int)min, position);
                g.instruction2 = nextSeed;
            }

            return(g);
        }
Ejemplo n.º 5
0
        public override object GenerateGeneValue(object min, object max, int position)
        {
            Gene g = new Gene();
            int nextSeed = 0;
            nextSeed = TheSeed.Next((int)min, (int)max);
            g.operation = nextSeed;

            if (position == 0) // special case, want to generate a symbol for first one
            {
               g.operation = TheSeed.Next(0, NumSymbols);  // generate 0 or 1, for a and b
               return g;
            }

            if (nextSeed > 1) // we have an operation, need postion
            {
                nextSeed = TheSeed.Next((int)min, position);
                g.instruction1 = nextSeed;
                nextSeed = TheSeed.Next((int)min, position);
                g.instruction2 = nextSeed;
            }

            return g;
        }
Ejemplo n.º 6
0
        // Generate a gene base on my problem chromosome representation.
        public override Gene GenerateGene(int geneIndex)
        {
            Gene gene = new Gene(m_random.Next(0, 2));

            return(gene);
        }