Bugfix in mutator when len(expr) == 1
This commit is contained in:
parent
bd862590b2
commit
fb466b3520
1 changed files with 10 additions and 2 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue