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); }
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); } }
/** * 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); }
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); }
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; }
// 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); }