def mutate_candidate_maybe()

in src/genetic_algorithm.py [0:0]


def mutate_candidate_maybe(candidate):
    # mutation doesn't happen every time, so first check if we should do it:
    if random.random() >= MUTATION_RATE:
        return

    # there are two methods to mutate a candidate: simple swapping of 2 randomly-selected locations,
    # or a randomly-selected displacement, which moves one location to a new spot in the candidate,
    # shifting everything else up.  We split the mutation types evenly, 50% for each.
    # The type of mutation to use is strongly dependent on the type of problem you are solving.
    randval = random.random()
    if randval < 0.5:
        swap_mutation(candidate)
    else:
        displacement_mutation(candidate)