From 2038b8ab24374a9f474e708246ba768ce66a2355 Mon Sep 17 00:00:00 2001 From: Kilik Kuo Date: Wed, 31 May 2017 12:38:31 +0800 Subject: [PATCH] No need to update elites memory/fitness when the worker is done. --- OpenCLGA/ocl_ga.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OpenCLGA/ocl_ga.py b/OpenCLGA/ocl_ga.py index d140c7f..4e791c5 100644 --- a/OpenCLGA/ocl_ga.py +++ b/OpenCLGA/ocl_ga.py @@ -61,6 +61,9 @@ def next(self, action): if self.openclga.action_callbacks and 'state' in self.openclga.action_callbacks: self.openclga.action_callbacks['state'](next_state) + def is_running(self): + return self.__curr_state == 'running' + ## A task to iterate GA generation in a separated thread. class GARun(Task): def __init__(self, ga, prob_mutation, prob_crossover, callback): @@ -728,6 +731,8 @@ def get_the_best(self): def update_elites(self, elites): assert self.__is_elitism_mode, 'Elitism Mode is {}'.format(self.__is_elitism_mode) assert len(elites) == self.__elitism_top + if not self.state_machine.is_running(): + return with self.__elite_lock: elites_dna_data = [] elites_fitnesses = []