def individual_select(self, individual_list, num): individual_left = list() individual_list_temp = copy.deepcopy(individual_list) while len(individual_left) < num: pareto_list = self.paretoAlgorithm.get_pareto_result( individual_list_temp) if len(individual_left) + len(pareto_list) <= num: individual_left += pareto_list # 从待选列表中去除已经加入的pareto结果 for temp in pareto_list: individual = None for ind in individual_list_temp: if ind.individual_id == temp.individual_id: individual = ind break if individual is not None: individual_list_temp.remove(individual) else: need_num = num - len(individual_left) crowding_distance_algorithm = CrowdingDistanceAlgorithm() crowding_sort_result = crowding_distance_algorithm.individual_select_by_crowding_distance( pareto_list, need_num) individual_left += crowding_sort_result return individual_left
def process(self): k = constant.PARETO_RESULT_NUM # 记录当前的pareto列表,元素为一个individual_task的列表 result = list() individual_id = 0 for individual_task in self.individual.individual_task_list: task_temp_1 = copy.deepcopy(individual_task) task_temp_1.exec_pos = 0 task_temp_2 = copy.deepcopy(individual_task) task_temp_2.exec_pos = 1 to_select_list = list() if len(result) > 0: for individual in result: individual_temp_1 = copy.deepcopy(individual) individual_temp_1.individual_id = individual_id individual_temp_1.individual_task_list.append(task_temp_1) individual_temp_1.schedule() to_select_list.append(individual_temp_1) individual_id += 1 individual_temp_2 = copy.deepcopy(individual) individual_temp_2.individual_id = individual_id individual_temp_2.individual_task_list.append(task_temp_2) individual_temp_2.schedule() to_select_list.append(individual_temp_2) individual_id += 1 else: individual_temp_1 = copy.deepcopy(self.individual) individual_temp_1.individual_id = individual_id individual_temp_1.individual_task_list = [task_temp_1] individual_temp_1.schedule() to_select_list.append(individual_temp_1) individual_id += 1 individual_temp_2 = copy.deepcopy(self.individual) individual_temp_2.individual_id = individual_id individual_temp_2.individual_task_list = [task_temp_2] individual_temp_2.schedule() to_select_list.append(individual_temp_2) individual_id += 1 crowding_distance_algorithm = CrowdingDistanceAlgorithm() result = crowding_distance_algorithm.individual_select_by_crowding_distance( to_select_list, k) self.pareto_result = result
def process(self, max_rel_individual, max_rel): k = constant.PARETO_RESULT_NUM # 记录当前的pareto列表,元素为一个individual_task的列表 result = list() individual_id = 0 for individual_task in self.individual.individual_task_list: task_temp_list = [] for i in range(0, 15): task_temp = copy.deepcopy(individual_task) task_temp.exec_pos = i task_temp_list.append(task_temp) to_select_list = list() if len(result) > 0: for individual in result: for i in range(0, 15): individual_temp = copy.deepcopy(individual) individual_temp.individual_id = individual_id individual_temp.individual_task_list.append( task_temp_list[i]) individual_temp.schedule() last_task = individual_temp.individual_task_list[ len(individual_temp.individual_task_list) - 1].task if last_task.reliability >= round( max_rel_individual.get_individual_task_by_id( last_task.task_id).task.reliability * self.rel_restraint / max_rel, 8): to_select_list.append(individual_temp) individual_id += 1 else: for i in range(0, 15): individual_temp = copy.deepcopy(self.individual) individual_temp.individual_id = individual_id individual_temp.individual_task_list = [task_temp_list[i]] individual_temp.schedule() last_task = individual_temp.individual_task_list[ len(individual_temp.individual_task_list) - 1].task if last_task.reliability >= round( max_rel_individual.get_individual_task_by_id( last_task.task_id).task.reliability * self.rel_restraint / max_rel, 8): to_select_list.append(individual_temp) individual_id += 1 to_select_list = ParetoAlgorithm.get_pareto_result(to_select_list) crowding_distance_algorithm = CrowdingDistanceAlgorithm() result = crowding_distance_algorithm.individual_select_by_crowding_distance( to_select_list, k) self.pareto_result = ParetoAlgorithm.get_pareto_result( self.individual_select_by_reliability(result, self.rel_restraint))
def get_filter_result(self, pareto_result): filter_result = list() for individual in pareto_result: exist = False for i in filter_result: if individual.makespan == i.makespan and individual.cost == i.cost: exist = True if exist is False and individual.reliability >= self.rel_restraint: filter_result.append(individual) crowding_distance_algorithm = CrowdingDistanceAlgorithm() return crowding_distance_algorithm.individual_select_by_crowding_distance( filter_result, constant.INDIVIDUAL_NUM)
def get_filter_result(pareto_result): filter_result = list() for individual in pareto_result: exist = False for i in filter_result: if individual.makespan == i.makespan and individual.energy == i.energy: exist = True if exist is False: filter_result.append(individual) crowding_distance_algorithm = CrowdingDistanceAlgorithm() return crowding_distance_algorithm.individual_select_by_crowding_distance(filter_result, constant.INDIVIDUAL_NUM)
def s_metric(pareto): length = len(pareto) if length == 0: return distance_sum = 0 min_distance = list() for individual in pareto: d = CrowdingDistanceAlgorithm.get_min_distance(pareto, individual) min_distance.append(d) distance_sum += d distance_average = distance_sum / length s = 0 for distance in min_distance: s += math.pow((distance - distance_average), 2) return math.sqrt(s / length)