Skip to content

Commit

Permalink
Merge pull request #164 from cgarcia-UCO/patch-2
Browse files Browse the repository at this point in the history
Exchanging the actual subtrees (crossover.subtree)
  • Loading branch information
jmmcd authored Nov 22, 2022
2 parents 8ee2bd1 + 1c7f6f4 commit f337171
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/operators/crossover.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def do_crossover(tree0, tree1, shared_nodes):
tree0 = t1

# Swap over the subtrees between parents.
i1 = p1.children.index(t1)
i1 = [id(i) for i in p1.children].index(id(t1))
p1.children[i1] = t0

# Set the parents of the crossed-over subtrees as their new
Expand All @@ -290,7 +290,7 @@ def do_crossover(tree0, tree1, shared_nodes):
tree1 = t0

# Swap over the subtrees between parents.
i0 = p0.children.index(t0)
i0 = [id(i) for i in p0.children].index(id(t0))
p0.children[i0] = t1

# Set the parents of the crossed-over subtrees as their new
Expand All @@ -304,8 +304,8 @@ def do_crossover(tree0, tree1, shared_nodes):

# For the parent nodes of the original subtrees, get the indexes
# of the original subtrees.
i0 = p0.children.index(t0)
i1 = p1.children.index(t1)
i0 = [id(i) for i in p0.children].index(id(t0))
i1 = [id(i) for i in p1.children].index(id(t1))

# Swap over the subtrees between parents.
p0.children[i0] = t1
Expand Down

0 comments on commit f337171

Please sign in to comment.