Skip to content

Commit f337171

Browse files
authored
Merge pull request #164 from cgarcia-UCO/patch-2
Exchanging the actual subtrees (crossover.subtree)
2 parents 8ee2bd1 + 1c7f6f4 commit f337171

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/operators/crossover.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def do_crossover(tree0, tree1, shared_nodes):
276276
tree0 = t1
277277

278278
# Swap over the subtrees between parents.
279-
i1 = p1.children.index(t1)
279+
i1 = [id(i) for i in p1.children].index(id(t1))
280280
p1.children[i1] = t0
281281

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

292292
# Swap over the subtrees between parents.
293-
i0 = p0.children.index(t0)
293+
i0 = [id(i) for i in p0.children].index(id(t0))
294294
p0.children[i0] = t1
295295

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

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

310310
# Swap over the subtrees between parents.
311311
p0.children[i0] = t1

0 commit comments

Comments
 (0)