Skip to content

Commit a722243

Browse files
Fix bug in multi-threading
- Multi-threading (despite being commented out) had a tiny bug: missing target argument (2nd argument). - Commented out code was also slightly hard to understand, added (Option 1/2) in comments to clarify where a user may choose between 2 implementations.
1 parent e3773db commit a722243

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

genetic_algorithm/basic_string.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,19 @@ def basic(target: str, genes: list[str], debug: bool = True) -> tuple[int, int,
144144

145145
# Random population created. Now it's time to evaluate.
146146

147-
# Adding a bit of concurrency can make everything faster,
147+
# (Option 1) Adding a bit of concurrency can make everything faster,
148148
#
149149
# import concurrent.futures
150150
# population_score: list[tuple[str, float]] = []
151151
# with concurrent.futures.ThreadPoolExecutor(
152152
# max_workers=NUM_WORKERS) as executor:
153-
# futures = {executor.submit(evaluate, item) for item in population}
153+
# futures = {executor.submit(evaluate, item, target) for item in population}
154154
# concurrent.futures.wait(futures)
155155
# population_score = [item.result() for item in futures]
156156
#
157157
# but with a simple algorithm like this, it will probably be slower.
158-
# We just need to call evaluate for every item inside the population.
158+
159+
# (Option 2) We just need to call evaluate for every item inside the population.
159160
population_score = [evaluate(item, target) for item in population]
160161

161162
# Check if there is a matching evolution.

0 commit comments

Comments
 (0)