コード例 #1
0
def select(k, kp, evaluations):
    n = len(evaluations)
    new_population = []
    for _ in range(n):
        selecteds = []
        for _ in range(k):
            selecteds.append(evaluations[lottery.range((0, n - 1))])
        if kp >= lottery.range((0, 10000)) / 10000:
            new_population.append(__get_best(selecteds))
        else:
            new_population.append(__get_worse(selecteds))
    return new_population
コード例 #2
0
def select(evaluations):
    relative_evaluations = relative_fitness.get(evaluations)
    n = len(evaluations)
    new_population = []
    for _ in range(int(n / 2)):
        index = lottery.range((0, n - 1))
        while (not lottery.roll(int(relative_evaluations[index][1]))):
            index = lottery.range((0, n - 1))
        new_population.append(relative_evaluations[index][0])

        index_2 = lottery.range((0, n - 1))
        while (index_2 != index
               and not lottery.roll(int(relative_evaluations[index_2][1]))):
            index_2 = lottery.range((0, n - 1))
        new_population.append(relative_evaluations[index_2][0])
    return new_population
コード例 #3
0
def select(d, evaluations):
	n = len(evaluations)
	new_population = []
	for _ in range(n):
		index = lottery.range((0,n-1))
		neighbourhood = []
		new_population.append(evaluations[index][0])
コード例 #4
0
def select(evaluations):
    n = len(evaluations)
    evaluations.sort(key=lambda tup: tup[1])
    uniform_fitness = __uniform_fitness(evaluations, n)
    new_population = []
    while len(new_population) < n:
        index = lottery.range((0, n - 1))
        if lottery.roll(uniform_fitness[index][1]):
            new_population.append(uniform_fitness[index][0])
    return new_population
コード例 #5
0
def __single_point(parent_1, parent_2, prob):
    if not lottery.roll(prob):
        return (parent_1, parent_2)
    point = lottery.range((0, len(parent_1)))
    children_1 = []
    children_2 = []
    for i in range(point):
        children_1.append(parent_1[i])
        children_2.append(parent_2[i])
    for i in range(point, len(parent_1)):
        children_1.append(parent_2[i])
        children_2.append(parent_1[i])
    return (children_1, children_2)
コード例 #6
0
def __float_subject(size, bounds):
	subject = []
	realBounds = (bounds[0]*100, bounds[1]*100)
	for _ in range(size):
		subject.append(lottery.range(realBounds)/100)
	return subject
コード例 #7
0
def __integer_subject(size, bounds):
	subject = []
	for _ in range(size):
		subject.append(lottery.range(bounds))
	return subject
コード例 #8
0
def __binary_subject(size, bounds):
    subject = []
    for _ in range(size):
            subject.append(lottery.range((0,1)))
    return subject