From f98f0c978e5d1b1cc4e1bc6ab75d9f6f9bd5cbbc Mon Sep 17 00:00:00 2001 From: Paul Morelle Date: Sat, 13 Apr 2024 07:24:52 +0200 Subject: [PATCH] Fix a typo in example_custom_operators In the crossover function, the split point is chosen in the range of the offspring size, instead of the solution size. An out-of-range split point is silently ignored by the range selection: it selects all genes from parent1, and none from parent2. However, the error can be demonstrated by throwing an exception if the split point is out of range. --- examples/example_custom_operators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/example_custom_operators.py b/examples/example_custom_operators.py index 88d3e6aa..84949aa3 100644 --- a/examples/example_custom_operators.py +++ b/examples/example_custom_operators.py @@ -41,7 +41,7 @@ def crossover_func(parents, offspring_size, ga_instance): parent1 = parents[idx % parents.shape[0], :].copy() parent2 = parents[(idx + 1) % parents.shape[0], :].copy() - random_split_point = numpy.random.choice(range(offspring_size[0])) + random_split_point = numpy.random.choice(range(offspring_size[1])) parent1[random_split_point:] = parent2[random_split_point:]