'Updates the population by selecting the top fittest candidates,
and recombining them into a new generation.'

def update(self, top=0.5, mutation=0.5):

    p = sorted(self.population, key=self.fitness, reverse=True)
    p = p[:max(2, int(round((len(p) * top))))]
    g = []
    n = len(p)
    for candidate in self.population:
        i = randint(0, (n - 1))
        j = (choice([x for x in xrange(n) if (x != i)]) if (n > 1) else 0)
        g.append(self.combine(p[i], p[j]))
        if (random() <= mutation):
            g[(-1)] = self.mutate(g[(-1)])
    self.population = g
    self.generation += 1
