def search_reactive(self, problem, iters=10): best_score = 0 reactive = Reactive(10) best_sol = Solution(problem) for _ in range(iters): sol = Solution(problem) idx, greediness = reactive.get_alpha() insertion_list, hmin, hmax = self.generate_neighborhood_stochastic( sol) while len(insertion_list) > 0 and not sol.rem_dist <= 0: threshold = hmin + greediness * (hmax - hmin) insertion_list = [ i for i in insertion_list if i.hval > threshold ] if len(insertion_list) <= 0: break rand = insertion_list[random.randint(0, len(insertion_list) - 1)] sol.insert_ins(rand) insertion_list, hmin, hmax = self.generate_neighborhood_stochastic( sol) if sol.score > best_score: best_score = sol.score best_sol = sol reactive.update(sol.score, best_score, idx) return best_score, best_sol
def test_5(): obj = Reactive() obj.add('var_1', value = 12) obj.add('var_2', value = 'd') obj.add('var_3', value = 'ghi') obj.add('var_4', equation = '3 * str(var_1) + var_2 + var_3') assert obj.var_4 == '121212dghi'
def test_4(): obj = Reactive() obj.add('var_1', value = 'abc') obj.add('var_2', value = 'd') obj.add('var_3', value = 'ghi') obj.add('var_4', equation = '3 * (var_1 + var_2) + var_3') assert obj.var_4 == 'abcdabcdabcdghi'
def test_1(): obj = Reactive() obj.add('var_1', value = 1) obj.add('var_2', value = 2) obj.add('var_3', value = 3) obj.add('var_4', equation = '3 * var_1 + var_2 - 1 * var_3') assert obj.var_4 == 2
def test_2(): obj = Reactive() obj.add('var_1', value = 'abc') assert obj.var_1 == 'abc'
def test_1(): obj = Reactive() obj.add('var_1', value = 1) assert obj.var_1 == 1
def test_3(): obj = Reactive() obj.add('var_1', value = [123, 'abc']) assert obj.var_1 == [123, 'abc']
def test_6(): obj = Reactive() obj.add('var_1', value = [2, 3]) obj.add('var_2', value = [4, 5]) obj.add('var_3', equation = 'var_1[1] + var_2[1]') assert obj.var_3 == 8