示例#1
0
    def custom_mate(ind1, ind2):
        i = random.randint(1, 3)
        if i == 1:
            corners = tools.cxPartialyMatched(ind1[0], ind2[0])
        elif i == 2:
            edges = tools.cxPartialyMatched(ind1[1], ind2[1])
        elif i == 3:
            inners = tools.cxPartialyMatched(ind1[2], ind2[2])

        return ind1, ind2
示例#2
0
 def __crossover(ind1, ind2, indpb=0):
     """
     该函数为交叉函数,对ind1和ind2执行交叉操作。
     在Deap中,可以使用的函数有cxPartialyMatched, cxUniformPartialyMatched和cxOrdered。
     具体查看https://deap.readthedocs.io/en/master/api/tools.html#operators
     """
     ind1, ind2 = tools.cxPartialyMatched(ind1, ind2)
     # ind1, ind2 = tools.cxUniformPartialyMatched(ind1, ind2, indpb)
     # ind1, ind2 = tools.cxOrdered(ind1, ind2)
     return ind1, ind2
 def crossover(self, individual_1, individual_2, probability):
     if self.method == 'Uniform':
         return tools.cxUniform(individual_1, individual_2, probability)
     elif self.method == 'TwoPoint':
         return tools.cxESTwoPoint(individual_1, individual_2)
     elif self.method == 'PartialyMatched':
         return tools.cxPartialyMatched(individual_1, individual_2)
     elif self.method == 'UniformPartialyMatched':
         return tools.cxUniformPartialyMatched(individual_1, individual_2,
                                               probability)
def mate(x, y):
    for x_attr, y_attr in zip(x, y):
        tools.cxPartialyMatched(x_attr, y_attr)
示例#5
0
def tspd_crossover(ind1, ind2):
    tools.cxPartialyMatched(ind1[0], ind2[0])
    tools.cxTwoPoint(ind1[1], ind2[1])
    return ind1, ind2
示例#6
0
def mixed_mate(ind1, ind2):
    tools.cxPartialyMatched(ind1[0], ind2[0])
    toolsx.cx_pick(ind1[1], ind2[1])
    return ind1, ind2
示例#7
0
def crossover_pmx(object1, object2):
    tools.cxPartialyMatched(object1, object2)
    return object1, object2
示例#8
0
tools.cxOrdered(ind1, ind2)

for i in range(100):
    ind1 = random.sample(range(10), 10)
    ind2 = random.sample(range(10), 10)
    tools.mutShuffleIndexes(ind1, 1)
    print(ind1)

for i in range(100):
    ind1 = random.sample(range(10), 10)
    tools.mutUniformInt(ind1, 20, 100, 1)
    print(ind1)

for i in range(100):
    ind1 = random.sample(range(100), 10)
    ind2 = random.sample(range(100), 10)
    tools.cxPartialyMatched(ind1, ind2)
    print(ind1)
    print(ind2)
    print(len(set(ind1)), len(set(ind2)))

while True:
    ind1 = random.sample(range(100), 10)
    ind2 = random.sample(range(100), 10)
    # print(ind1, ind2)
    # print(len(set(ind1)), len(set(ind2)))
    if len(set(ind1)) != len(set(ind2)):
        print(len(set(ind1)), len(set(ind2)))
    tools.cxTwoPoint(ind1, ind2)