From fb466b3520b569c9ac3034c9b7873b374055e1b2 Mon Sep 17 00:00:00 2001 From: Yann Weber Date: Mon, 14 May 2018 16:55:34 +0200 Subject: [PATCH] Bugfix in mutator when len(expr) == 1 --- gte/mutator.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gte/mutator.py b/gte/mutator.py index 7050233..e32e397 100644 --- a/gte/mutator.py +++ b/gte/mutator.py @@ -40,9 +40,14 @@ def mutate(expr, force = True, mutcount = 1): return res def mutatef(expr, mutcount = 1): - mutations = [mutadd, mutdel] + mutations = [mutadd] * 3 + if len(expr) > 1: + mutations += [mutdel] * 3 mutations += [mutupdtype for _ in range(3)] mutations += [mutupdval for _ in range(6)] + #mutations = [mutadd, mutdel] + #mutations += [mutupdtype for _ in range(3)] + #mutations += [mutupdval for _ in range(6)] res = copy.copy(expr) for _ in range(mutcount): mutations[randint(0, len(mutations)-1)](res) @@ -66,7 +71,10 @@ def mutupdtype(expr): return expr def mutupdval(expr): - pos = randint(0, len(expr) - 1) + if len(expr) == 1: + pos = 0 + else: + pos = randint(0, len(expr) - 1) if expr[pos].optype == RpnSymbol.VALUE: expr[pos] = RpnSymbol.rand_value() else: