Skip to content

Instantly share code, notes, and snippets.

@kushalvyas
Created September 8, 2016 18:43
Show Gist options
  • Save kushalvyas/ac3593026e0a431bbc47aaf4e025fe67 to your computer and use it in GitHub Desktop.
Save kushalvyas/ac3593026e0a431bbc47aaf4e025fe67 to your computer and use it in GitHub Desktop.
Example population and chromosome generation for http://bitsmakemecrazy.com/gen_8Q.html#gen_8Q
def generateChromosome():
# randomly generates a sequence of board states.
global nQueens
init_distribution = np.arange(nQueens)
np.random.shuffle(init_distribution)
return init_distribution
def generatePopulation(population_size = 100):
global POPULATION
POPULATION = population_size
population = [BoardPosition() for i in range(population_size)]
for i in range(population_size):
population[i].setSequence(generateChromosome())
population[i].setFitness(fitness(population[i].sequence))
return population
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment