From 9c89c023574c0897a6fd59a3653adc5a603a210b Mon Sep 17 00:00:00 2001 From: Michael Clarkson Date: Fri, 19 Feb 2021 10:10:40 -0500 Subject: [PATCH 1/2] Check whether any rules exist before accessing --- src/controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller.py b/src/controller.py index 87b975e..c30bd3a 100644 --- a/src/controller.py +++ b/src/controller.py @@ -77,7 +77,7 @@ def run(input_deck): sizer = sizer_from_dek(dek) log.debug(sizer) - if dek_rules[0]['name'] == 'aggregate': + if len(dek_rules) > 0 and dek_rules[0]['name'] == 'aggregate': attribute = dek_rules[0]['attribute'] # Turn back into a list to make sure ordering is preserved when we use # this in multiple places From 84ea28602a2b581317656936c79689ce9af33b79 Mon Sep 17 00:00:00 2001 From: Michael Clarkson Date: Sun, 12 Sep 2021 10:24:24 -0400 Subject: [PATCH 2/2] Fix retry logic The recursive call to `apply_rule` had the argument order wrong. It passed `try_number+1` as the argument for `tries`. The effect of that was to change `tries` to `1` on the first recursive call. Thus only one try was ever attempted. This commit fixes the argument order thus enabling retries. --- src/rule.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rule.py b/src/rule.py index afb7058..6326025 100644 --- a/src/rule.py +++ b/src/rule.py @@ -249,14 +249,14 @@ def get_strength(self, s): def __str__(self): return "".format(self.mean, self.tol) def _check(self, students): - try: + try: return abs(utility.mean(students, self.get_strength) - self.mean) < self.tol # If somehow you don't have a strength for any of the students, # consider the group to be failing the rule except EmptyMean: return False def permissable_change(self, old, new): - try: + try: b = (abs(utility.mean(old, self.get_strength) - self.mean) > abs(utility.mean(new, self.get_strength) - self.mean)) except EmptyMean: @@ -503,7 +503,7 @@ def apply_rule(rule, groups, students, tries, mixing, try_number=0): # finding new solutions for i in range(mixing): find_target_and_swap(random.choice(students), groups) - return apply_rule(rule, groups, students, try_number+1, tries, mixing) + return apply_rule(rule, groups, students, tries, mixing, try_number+1) else: return False else: