Evolve是一个用Objective-C编写的演化仿真引擎。
示例代码:
- (void)evaluateFitnessForPopulation { NSArray *organisms = self.evolutionManager.population.organisms; for (Organism *organism in organisms) { NSString *genomeString = organism.genome.sequence; NSInteger geneSequenceLength = genomeString.length; NSInteger correctCharacters = 0; for (NSInteger charIndex = 0; charIndex < geneSequenceLength; charIndex++) { if ([genomeString characterAtIndex:charIndex] == [kTargetString characterAtIndex:charIndex]) { correctCharacters++; } } organism.fitness = correctCharacters; }}
评论