I am wanting to develop a function that selects a board from the population "at random", however I want it to be biased towards boards with a lower fitness value.
# population = [(fitness, board),...] # population is a heapq in my program
def random_selection(population):
random_index = randint(0, len(population) - 1)
return population[random_index][1]
For example, (1 , board), (7, board). I want the first board to have a higher probability of being selected since it has a lower value.
How would I do this? I was thinking of using random() and creating a threshold of acceptance probability.
Additionally, would it be possible to keep track of what boards I have selected thus far? For my case, board within the heapq is unique.