示例#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
示例#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
示例#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
示例#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
示例#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))
示例#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)
    )
示例#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)
示例#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)
示例#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)))
示例#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)
示例#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)
示例#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)))