def testCreateGeneration0(self): fitness = MockFitness() rand = MockRandom([2, 4, 5]) chromosomes = es.createGeneration0(3, fitness, 1.0, rand.uniform) self.assertEqual(chromosomes, [[5, 1.0], [4, 1.0], [2, 1.0]])
1. Randomly generate parents for generation 0 using uniform distribution for x1, x2 variables. Sigma = 1.0 2. Save the current best parent in generation 0 3. Do recombination on parents to create offspring - Use discrete global recombination on variables - Use intermediate global recombination on steps/sigmas 4. Mutate offspring 5. Use death penalty approach to weed out offspring that do not meet constraints 6. Create more offspring using steps 3, 4, and 5 until desired number of offspring reached 7. Do survivor selection using (mu, lambda) approach 8. Compare best of current generation with best overall. If current is better, make it the best overall 9. Repeat until maxGenerations reached """ random.seed(seed) parents = es.createGeneration0(numParents, fitness, initialSigma, random.uniform) parents = es.rank(parents, len(parents), fitness) currentBest = parents[0] for i in xrange(maxGenerations): validOffspring = [] offspringNeeded = numOffspring while offspringNeeded > 0: offspring = es.recombination(parents, offspringNeeded, vRecombination, sRecombination, random.sample) mutatedOffspring = es.mutation(offspring, random.gauss) validOffspring.extend(es.deathPenalty(mutatedOffspring, fitness)) offspringNeeded = numOffspring - len(validOffspring) parents = survivorSelection(parents, validOffspring, fitness) currentBest = es.compareBestFitness(currentBest, parents[0], fitness) if log['sample'] is not None and i % log['sample'] == 0: