def strategy_wr(self, iset, x, iset_type): if iset_type == 'pos': index = self.binary_search(iset, x, 0, len(iset) - 1) iset.insert(index, x) worst_ele = iset.pop() else: worst_ele, worst_index = Solution.find_maximum(iset) if worst_ele.get_value() > x.get_value(): iset[worst_index] = x else: worst_ele = x return worst_ele
def strategy_wr(self, iset, x, iset_type): """ Replace the worst solution in iset. :param iset: a solution set :param x: a Solution object :param iset_type: 'pos' or 'neg' :return: the worst solution """ if iset_type == 'pos': index = self.binary_search(iset, x, 0, len(iset) - 1) iset.insert(index, x) worst_ele = iset.pop() else: worst_ele, worst_index = Solution.find_maximum(iset) if worst_ele.get_value() > x.get_value(): iset[worst_index] = x else: worst_ele = x return worst_ele