def initialize(self, reseed=True):
        b = timer()
        self.test_settings(self.settings)
        self.gen = 0
        sd = self.settings['rand_seed']
        if reseed:
            prng.seed(sd)
        self.settings['seed_used'] = sd
        self._print('initializing... seed = %d' % self.settings['seed_used'])
        self.crossover = self.pop.model_genome.crossover  # get the crossover op from the first genome
        self.pop.settings = self.settings  #should these be shared?
        self.size_pop(self.settings['pop_size'])

        self.settings['crossover'] = str(self.crossover).split()[0][1:]
        self.settings['selector'] = str(self.pop.selector).split()[0][1:]
        self.settings['scaler'] = str(self.pop.scaler).split()[0][1:]
        self.settings['genome_type'] = str(
            self.pop.model_genome).split()[0][1:]

        self.pop.initialize(self.settings)
        self.stats = {
            'selections': 0,
            'crossovers': 0,
            'mutations': 0,
            'replacements': 0,
            'pop_evals': 1,
            'ind_evals': 0
        }
        self.stats.update(self.pop.stats)
        self.step_time = timer() - b
        self.init_dbase()
    def initialize(self, mode='serial', reseed=True):
        b = timer()
        #same as galg
        self.test_settings(self.settings)
        self.gen = 0
        sd = self.settings['rand_seed']
        if reseed:
            prng.seed(sd)
        self.settings['seed_used'] = sd
        self._print('initializing... seed = %d' % self.settings['seed_used'])
        self.crossover = self.pop[
            0].crossover  # get the crossover op from the first genome
        self.pop.settings = self.settings
        #end same as galg

        #set up my population to hold the best from each sub-pop
        self.pop._size(0)  #erase any current member of the pop
        self.pop._size(self.settings['num_pops'])
        self.crossover = self.pop[0].crossover

        #extract the galg settings so we don't get a ton of warnings
        #and create the sub ga_s
        sub_ga_settings = {}
        self.GAs = []
        for key in galg.valid_settings:
            sub_ga_settings[key] = self.settings[key]
        for i in range(self.settings['num_pops']):
            self.GAs.append(galg(self.pop.clone()))
            self.GAs[i].settings = sub_ga_settings.copy()

        self.settings['crossover'] = str(self.crossover).split()[0][1:]
        self.settings['selector'] = str(self.pop.selector).split()[0][1:]
        self.settings['scaler'] = str(self.pop.scaler).split()[0][1:]
        self.settings['genome_type'] = str(
            self.pop.model_genome).split()[0][1:]
        self._print(self.settings)

        if mode[0] == 'p' or mode[0] == 'P':
            # XXX: what?
            """
                sys.setcheckinterval(1000)
                finished = sync.event()
                bar = sync.barrier(len(self.GAs))
                for ga in self.GAs:
                        thread.start_new_thread(GA_initializer,(bar,finished,ga))
                finished.wait()
                sys.setcheckinterval(10)
                """
        else:
            for ga in self.GAs:
                ga.initialize(reseed=False)
        cnt = 0
        for ga in self.GAs:
            self.pop[cnt] = ga.pop.best()
            cnt = cnt + 1
        self.pop.sort()
        self.init_stats()
        self.step_time = timer() - b
        self.init_dbase()
Example #3
0
    def initialize(self, mode='serial', reseed=True):
        b = timer()
        #same as galg
        self.test_settings(self.settings)
        self.gen = 0
        sd = self.settings['rand_seed']
        if reseed:
            prng.seed(sd)
        self.settings['seed_used'] = sd
        self._print('initializing... seed = %d' % self.settings['seed_used'])
        self.crossover = self.pop[0].crossover # get the crossover op from the first genome
        self.pop.settings = self.settings
        #end same as galg

        #set up my population to hold the best from each sub-pop
        self.pop._size(0) #erase any current member of the pop
        self.pop._size(self.settings['num_pops'])
        self.crossover = self.pop[0].crossover

        #extract the galg settings so we don't get a ton of warnings
        #and create the sub ga_s
        sub_ga_settings = {}
        self.GAs = []
        for key in galg.valid_settings:
            sub_ga_settings[key] = self.settings[key]
        for i in range(self.settings['num_pops']):
            self.GAs.append(galg(self.pop.clone()))
            self.GAs[i].settings = sub_ga_settings.copy()

        self.settings['crossover'] = str(self.crossover).split()[0][1:]
        self.settings['selector'] = str(self.pop.selector).split()[0][1:]
        self.settings['scaler'] = str(self.pop.scaler).split()[0][1:]
        self.settings['genome_type'] = str(self.pop.model_genome).split()[0][1:]
        self._print(self.settings)

        if mode[0] == 'p' or mode[0] == 'P':
            # XXX: what?
            """
                sys.setcheckinterval(1000)
                finished = sync.event()
                bar = sync.barrier(len(self.GAs))
                for ga in self.GAs:
                        thread.start_new_thread(GA_initializer,(bar,finished,ga))
                finished.wait()
                sys.setcheckinterval(10)
                """
        else:
            for ga in self.GAs: ga.initialize(reseed = False)
        cnt = 0
        for ga in self.GAs:
            self.pop[cnt] = ga.pop.best()
            cnt = cnt + 1
        self.pop.sort()
        self.init_stats()
        self.step_time = timer() - b
        self.init_dbase()
Example #4
0
    def initialize(self, reseed=True):
        b = timer()
        self.test_settings(self.settings)
        self.gen = 0
        sd = self.settings['rand_seed']
        if reseed:
            prng.seed(sd)
        self.settings['seed_used'] = sd
        self._print('initializing... seed = %d' % self.settings['seed_used'])
        self.crossover = self.pop.model_genome.crossover # get the crossover op from the first genome
        self.pop.settings = self.settings #should these be shared?
        self.size_pop(self.settings['pop_size'])

        self.settings['crossover'] = str(self.crossover).split()[0][1:]
        self.settings['selector'] = str(self.pop.selector).split()[0][1:]
        self.settings['scaler'] = str(self.pop.scaler).split()[0][1:]
        self.settings['genome_type'] = str(self.pop.model_genome).split()[0][1:]

        self.pop.initialize(self.settings);
        self.stats = {'selections':0,'crossovers':0,'mutations':0,
                          'replacements':0,'pop_evals':1,'ind_evals':0}
        self.stats.update(self.pop.stats)
        self.step_time = timer() - b
        self.init_dbase()