public void CreateChromosomeFromReproduction(SGAChromosome parent) { for (int i = 0; i < chromosomeBit.Length; i++) { this.chromosomeBit[i] = parent.ChromosomeBit[i]; } }
public SGASolutionFinder(double minRange, double maxRange, int bitSize, int precision, int crosProb, int mutProb, int populationSize, int generations, double stopCritValue, int stopCritRange) { this.minRange = minRange; this.maxRange = maxRange; this.bitSize = bitSize; this.crosProb = crosProb; this.mutProb = mutProb; this.populationSize = populationSize; this.generations = generations; this.stopCritValue = stopCritValue; this.stopCritRange = stopCritRange; this.precisionDenominator = Math.Pow(10, precision); this.overallFitness = new double[generations]; this.bestFit = new double[generations]; this.solutions = new SGAChromosome[generations][]; for (int i = 0; i < generations; i++) { solutions[i] = new SGAChromosome[populationSize]; for (int j = 0; j < populationSize; j++) { solutions[i][j] = new SGAChromosome(bitSize); } } this.fitness = new double[generations][]; for (int i = 0; i < generations; i++) { fitness[i] = new double[populationSize]; } }
public void CreateChromosomeFromMutation(SGAChromosome parent) { for (int i = 0; i < chromosomeBit.Length; i++) { this.chromosomeBit[i] = parent.ChromosomeBit[i]; } int position = rand.Next(chromosomeBit.Length); chromosomeBit[position] = !chromosomeBit[position]; }
public void CreateChromosomeFromCrossing(SGAChromosome parentLeft, SGAChromosome parentRight) { int position = rand.Next(0, chromosomeBit.Length); for (int i = 0; i < position; i++) { this.chromosomeBit[i] = parentLeft.ChromosomeBit[i]; } for (int i = position; i < chromosomeBit.Length; i++) { this.chromosomeBit[i] = parentRight.ChromosomeBit[i]; } }