Bugfix in mutator when len(expr) == 1

This commit is contained in:
Yann Weber 2018-05-14 16:55:34 +02:00
commit fb466b3520

View file

@ -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: