def __init__(self, center=0): self.problem = Problem.TspProblem(center) # 创建种群 self.population_size = POPULATION_SIZE self.population = [] self.choice_rate = 0 for i in range(0, self.population_size): gene = valuable_result(self.create_result()) life = Individuals(gene, self.problem.result_evaluation(gene)) self.population.append(life) self.choice_rate += life.alive_rate()
def __init__(self, center=0): self.problem = Problem.TspProblem(center) cities = self.problem.city_size # 初始化蚁群 self.ant_size = int(cities * 2 / 3) Ant.init_ant_class(cities, self.problem.center_position, self.problem.parallel_number) self.search_ant_array = [Ant() for i in range(self.ant_size)] # 初始化信息素 self.max_pheromone = 0.0 self.min_pheromone = 0.0 self.city_pheromone_array = np.ones((cities, cities))