public Individual(Individual i) { this.chromosome_ = new Chromosome(i.chromosome); this.strategy_ = i.strategy; this.isFeasible_ = i.isFeasible; this.fitness_ = i.fitness; }
public Individual(Chromosome chromosome, bool strategie, double fitness, bool isFeasible) { this.chromosome_ = chromosome; this.strategy_ = strategie; this.fitness_ = fitness; this.isFeasible_ = isFeasible; }
public Chromosome(Chromosome c) { genes = new bool[c.Count]; for (int i = 0; i < c.Count; i++) { genes[i] = c[i]; } }
public Population UniformCrossover(Population parents) { Population offspring = new Population(); List<int> unused = new List<int>(); for (int i = 0; i < parents.Count; i++) { unused.Add(i); } int chromosomeSize = getChromosomeSize(); for (int i = 0; i < parents.Count; i++) { if (!unused.Contains(i)) continue; unused.Remove(i); int randomIndex = unused.ElementAt(GA_GT.random.Next() % unused.Count); unused.Remove(randomIndex); if (GA_GT.random.NextDouble() >= GA_GT.crossoverRate) { offspring.Add(parents.getIndividual(i)); offspring.Add(parents.getIndividual(randomIndex)); } else { Chromosome ch1 = new Chromosome(chromosomeSize); Chromosome ch2 = new Chromosome(chromosomeSize); for (int j = 0; j < chromosomeSize; j++) { if (GA_GT.random.NextDouble() < 0.5) { ch1[j] = parents.getIndividual(i)[j]; ch2[j] = parents.getIndividual(randomIndex)[j]; } else { ch1[j] = parents.getIndividual(randomIndex)[j]; ch2[j] = parents.getIndividual(i)[j]; } } Individual ind1 = new Individual(ch1); ind1.strategy = parents.getIndividual(i).strategy; ind1.Update(GA_GT.knapsackList); Individual ind2 = new Individual(ch2); ind2.strategy = parents.getIndividual(randomIndex).strategy; ind2.Update(GA_GT.knapsackList); offspring.Add(ind1); offspring.Add(ind2); } } return offspring; }
public void RandomPopulation(double cheaterRate, int chromosomeSize, int populationSize) { int numberOfCheaters = (int)(populationSize * cheaterRate); for (int i = 0; i < populationSize; i++) { Chromosome chromosome = new Chromosome(chromosomeSize); Individual temp; if (i < numberOfCheaters) temp = new Individual(chromosome, false, (double)0, true); // cheater else temp = new Individual(chromosome, true, (double)0, true); // cooperator population.Add(temp); } }
public Individual(Chromosome chromosome) { this.chromosome_ = chromosome; }