Esempio n. 1
0
def mutate_string_genome(string, p, char_set_size, **kwargs):
    if random.random() <= p:
        pos = random.randint(0, len(string) - 1)
        char_list = list(string)
        char_list[pos] = random.choice(char_set(char_set_size))
        string = char_list_to_str(char_list)

    return string
Esempio n. 2
0
def mutate_bit_genome(bitstring, p, **kwargs):
    if random.random() <= p:
        pos = random.randint(0, len(bitstring) - 1)
        char_list = list(bitstring)
        char_list[pos] = bit_flip(char_list[pos])
        bitstring = char_list_to_str(char_list)

    return bitstring
Esempio n. 3
0
def mutate_string_genome(string, p, char_set_size, **kwargs):
    if random.random() <= p:
        pos = random.randint(0, len(string) - 1)
        char_list = list(string)
        char_list[pos] = random.choice(char_set(char_set_size))
        string = char_list_to_str(char_list)

    return string
Esempio n. 4
0
def mutate_bit_genome(bitstring, p, **kwargs):
    if random.random() <= p:
        pos = random.randint(0, len(bitstring) - 1)
        char_list = list(bitstring)
        char_list[pos] = bit_flip(char_list[pos])
        bitstring = char_list_to_str(char_list)

    return bitstring
Esempio n. 5
0
def generate_initial_population(population_size, genome_size, char_set_size,
                                **kwargs):
    S = char_set(char_set_size)
    return tuple(
        char_list_to_str(random.choice(S) for _ in range(genome_size))
        for _ in range(population_size))
Esempio n. 6
0
def generate_initial_population(population_size, genome_size, char_set_size, **kwargs):
    S = char_set(char_set_size)
    return tuple(
        char_list_to_str(random.choice(S) for _ in range(genome_size))
        for _ in range(population_size)
    )
Esempio n. 7
0
def mutate_string_components(string, p, char_set_size, **kwargs):
    return char_list_to_str(random.choice(char_set(char_set_size)) if random.random() <= p else c for c in string)
Esempio n. 8
0
def mutate_bit_components(bitstring, p, **kwargs):
    return char_list_to_str(bit_flip(b) if random.random() <= p else b for b in bitstring)
Esempio n. 9
0
def mix(a, b):
    """
    for each component, randomly pick a value from a random parent
    """
    return char_list_to_str(a[i] if random_bool() else b[i] for i in range(len(a)))
Esempio n. 10
0
def mutate_string_components(string, p, char_set_size, **kwargs):
    return char_list_to_str(
        random.choice(char_set(char_set_size)) if random.random() <= p else c
        for c in string)
Esempio n. 11
0
def mutate_bit_components(bitstring, p, **kwargs):
    return char_list_to_str(
        bit_flip(b) if random.random() <= p else b for b in bitstring)
Esempio n. 12
0
def mix(a, b):
    """
    for each component, randomly pick a value from a random parent
    """
    return char_list_to_str(a[i] if random_bool() else b[i]
                            for i in range(len(a)))