Created
September 8, 2016 18:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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