def runTest(self): mutator = RealCodedMutationProcreator(mutation_rate=0) choms = [ RealCodedChromosome(size=5, evaluate=arb_eval, initial_state='zeros'), RealCodedChromosome(size=5, evaluate=arb_eval, initial_state='zeros') ] mutated = mutator.mutate(choms) self.assertEqual([0, 0, 0, 0, 0], list(mutated[0].genes)) self.assertEqual([0, 0, 0, 0, 0], list(mutated[1].genes))
def test(self): seed(2) c1 = RealCodedChromosome(size=5, initial_state=(0, 1), evaluate=arb_eval) c2 = RealCodedChromosome(size=5, initial_state=(0, 1), evaluate=arb_eval) crossover = FlatCrossoverProcreator() children = crossover.procreate([c1, c2]) actuals = [ 0.37036585097396263, 0.1204957780274882, 0.55903038445280817, 0.36564642040673451, 0.39204880791908869 ] for gene, actual in zip(children[0].genes, actuals): self.assertEqual(gene, actual)
def runTest(self): mutator = RealCodedMutationProcreator(mutation_rate=1, random_state=(5, 6)) mutated = mutator.mutate( RealCodedChromosome(size=5, evaluate=arb_eval, initial_state='zeros')) for gene in mutated.genes: self.assertTrue(gene >= 5) self.assertTrue(gene <= 6)
def runTest(self): mutator = RealCodedMutationProcreator(mutation_rate=1) mutated = mutator.mutate( RealCodedChromosome(size=5, evaluate=arb_eval, initial_state='zeros')) expected = [ 0.035645217728072498, 0.36092494757777704, 0.78684060294525748, 0.19489478127792192, 0.82462008610850868 ] self.assertEqual(expected, list(mutated.genes))
def runTest(self): mutator = RealCodedMutationProcreator(mutation_rate=1) choms = [ RealCodedChromosome(size=5, evaluate=arb_eval, initial_state='zeros'), RealCodedChromosome(size=5, evaluate=arb_eval, initial_state='zeros') ] mutated = mutator.mutate(choms) self.assertIsInstance(mutated, list) c0 = [ 0.30832661028386366, 0.88044022543339817, 0.46543856301041264, 0.98869229439494866, 0.60293320750348567 ] self.assertEqual(c0, list(mutated[0].genes)) c1 = [ 0.026083263963949999, 0.84022433810931996, 0.94752328271635278, 0.90267393734810486, 0.73721915166454299 ] self.assertEqual(c1, list(mutated[1].genes))
def runTest(self): seed(2222) mutator = RealCodedMutationProcreator(mutation_rate=0.5) chroms = [ RealCodedChromosome(size=5, evaluate=arb_eval, initial_state='zeros'), RealCodedChromosome(size=5, evaluate=arb_eval, initial_state='ones'), RealCodedChromosome(size=5, evaluate=arb_eval, initial_state='ones') ] mutated = mutator.mutate(chroms) c0 = [0.0, 0.63031517659402647, 0.0, 0.0, 0.87853488435848204] self.assertEqual(c0, list(mutated[0].genes)) c1 = [ 1.0, 1.0, 0.65607322932247725, 0.79059298145077039, 0.39962985333928835 ] self.assertEqual(c1, list(mutated[1].genes)) c2 = [1.0, 0.36963020168002036, 0.83432897192878341, 1.0, 1.0] self.assertEqual(c2, list(mutated[2].genes))