Example #1
0
def generate_mutation_pairs(n):
    for i in range(n):
        LEN = random.randint(MINLEN, MAXLEN)
        g = [random.randint(0, MAXV-1) for i in range(LEN)]
        gind = make_individual(g)
        if gind.phenotype is None:
            continue
        h = onepoint_mutate(g[:], min(gind[used_idx], len(g)))
        hind = make_individual(h)
        if hind.phenotype is None:
            continue
        yield (gind, hind)
Example #2
0
def generate_random_pairs(n):
    for i in range(n):
        LEN = random.randint(MINLEN, MAXLEN)
        g = [random.randint(0, MAXV-1) for i in range(LEN)]
        gind = make_individual(g)
        if gind.phenotype is None:
            continue
        h = [random.randint(0, MAXV-1) for i in range(LEN)]
        hind = make_individual(h)
        if hind.phenotype is None:
            continue
        yield (gind, hind)
Example #3
0
def generate_crossover_pairs(n):
    for i in range(n):
        LEN = random.randint(MINLEN, MAXLEN)
        g = [random.randint(0, MAXV-1) for i in range(LEN)]
        gind = make_individual(g)
        if gind.phenotype is None:
            continue
        LEN = random.randint(MINLEN, MAXLEN)
        h = [random.randint(0, MAXV-1) for i in range(LEN)]
        hind = make_individual(h)
        if hind.phenotype is None:
            continue
        children = xover(gind, hind)
        cind0 = make_individual(children[0])
        cind1 = make_individual(children[1])
        if cind0.phenotype is not None:
            yield (gind, cind0)
            yield (hind, cind0)
        if cind1.phenotype is not None:
            yield (gind, cind1)
            yield (hind, cind1)