def test_find_maximum_and_minimum(self): sol1 = Solution(x=[1, 2, 3], value=1) sol2 = Solution(x=[1, 3, 4], value=2) sol3 = Solution(x=[1, 5, 6], value=3) sol_set = [sol1, sol2, sol3] assert sol1.is_equal(Solution.find_minimum(sol_set)[0]) assert sol3.is_equal(Solution.find_maximum(sol_set)[0])
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