st_time = time.time()
cross_pop, mutant_pop = [], []
// Generate crossover population
c_total = self.RouletteWheelSelection(fitness_dict, math.ceil(self.crossover_size*len(pop)))
combi = list(itertools.combinations(list(set(c_total)), 2))
co_pop = []
for i, j in zip(list(set(c_total))[::2], list(set(c_total))[1::2]):
co_pop.append((i, j))
c_rem = [i for i in combi if i not in co_pop]
diff = math.ceil(self.crossover_size*len(pop)/2) - len(co_pop)
if diff>0: co_pop += c_rem[:diff]
for child1, child2 in co_pop:
After Change
st_time = time.time()
cross_pop, mutant_pop = [], []
// Generate crossover population
c_total = self.RouletteWheelSelection(fitness_dict, int(math.ceil(self.crossover_size*len(pop))))
combi = list(itertools.combinations(list(set(c_total)), 2))
co_pop = []
for i, j in zip(list(set(c_total))[::2], list(set(c_total))[1::2]):
co_pop.append((i, j))
c_rem = [i for i in combi if i not in co_pop]
diff = int(math.ceil(self.crossover_size*len(pop)/2)) - len(co_pop)
if diff>0: co_pop += c_rem[:diff]
for child1, child2 in co_pop: