PGA/nature.py
def operate(self):
        """
        operate the nature, include rank, select, cross, mutate, new add, experience apply
        :return: None
        """
        self.__ranking__()
        print('Ranking OK.', end='\t')
        bad_chromo_list = []
        for chromo in self.chromo_list[int(self.reserve * len(self.chromo_list)):]:
            if random.random() < self.bad_reserve_p:
                bad_chromo_list.append(chromo)
        self.chromo_list = self.chromo_list[:int(self.reserve * len(self.chromo_list))]
        self.chromo_list.extend(bad_chromo_list)
        print('Select OK {}.'.format(len(self.chromo_list)), end='\t')
        self.__random_add__(self.new_chromo_num)
        print('New Chromo Add OK {}.'.format(self.new_chromo_num), end='\t')
        old_chromo_list = []
        for chromo in self.chromo_list:
            old_chromo_list.append(chromo.deepcopy())
        chromo_copy1 = self.chromo_list[::2]
        chromo_copy2 = self.chromo_list[1::2]
        random.shuffle(chromo_copy2)
        if len(chromo_copy2) < len(chromo_copy1):
            chromo_copy1.pop()
        for chromo1, chromo2 in zip(chromo_copy1, chromo_copy2):
            if random.random() < cross_p:
                chromo1_cross, chromo2_cross, r = self.__crossover__(chromo1, chromo2)
                if r == 1:
                    self.chromo_list.append(chromo1)
                    self.chromo_list.append(chromo2)
        print('Cross OK {}.'.format(len(self.chromo_list)), end='\t')
        del chromo_copy1
        del chromo_copy2
        for chromo in old_chromo_list:
            self.chromo_list.append(chromo.deepcopy())
        for idx, chromo in enumerate(self.chromo_list):
            chromo.mutate()
        self.chromo_list.extend(old_chromo_list)
        del old_chromo_list
        print('Mutate OK.', end='\t')
        add_num = self.chromo_num - len(self.chromo_list)
        self.__random_add__(num=add_num)

        self.__experience_apply__()
        print('Experience Apply OK.', end='\t')
        print('Total {} Chromo.'.format(len(self.chromo_list)))
        self.__ranking__()
        self.chromo_list = self.chromo_list[:self.chromo_num]

        operate the nature, include rank, select, cross, mutate, new add, experience apply
        :return: None
        
operate the nature, include rank, select, cross, mutate, new add, experience apply
operate the nature include rank select cross mutate new add experience apply
def operate(self):
        self.__ranking__()
        print('Ranking OK.', end='\t')
        bad_chromo_list = []
        for chromo in self.chromo_list[int(self.reserve * len(self.chromo_list)):]:
            if random.random() < self.bad_reserve_p:
                bad_chromo_list.append(chromo)
        self.chromo_list = self.chromo_list[:int(self.reserve * len(self.chromo_list))]
        self.chromo_list.extend(bad_chromo_list)
        print('Select OK {}.'.format(len(self.chromo_list)), end='\t')
        self.__random_add__(self.new_chromo_num)
        print('New Chromo Add OK {}.'.format(self.new_chromo_num), end='\t')
        old_chromo_list = []
        for chromo in self.chromo_list:
            old_chromo_list.append(chromo.deepcopy())
        chromo_copy1 = self.chromo_list[::2]
        chromo_copy2 = self.chromo_list[1::2]
        random.shuffle(chromo_copy2)
        if len(chromo_copy2) < len(chromo_copy1):
            chromo_copy1.pop()
        for chromo1, chromo2 in zip(chromo_copy1, chromo_copy2):
            if random.random() < cross_p:
                chromo1_cross, chromo2_cross, r = self.__crossover__(chromo1, chromo2)
                if r == 1:
                    self.chromo_list.append(chromo1)
                    self.chromo_list.append(chromo2)
        print('Cross OK {}.'.format(len(self.chromo_list)), end='\t')
        del chromo_copy1
        del chromo_copy2
        for chromo in old_chromo_list:
            self.chromo_list.append(chromo.deepcopy())
        for idx, chromo in enumerate(self.chromo_list):
            chromo.mutate()
        self.chromo_list.extend(old_chromo_list)
        del old_chromo_list
        print('Mutate OK.', end='\t')
        add_num = self.chromo_num - len(self.chromo_list)
        self.__random_add__(num=add_num)
        self.__experience_apply__()
        print('Experience Apply OK.', end='\t')
        print('Total {} Chromo.'.format(len(self.chromo_list)))
        self.__ranking__()
        self.chromo_list = self.chromo_list[:self.chromo_num]
def operate ( self ) : self . __ranking__ ( ) print ( 'Ranking OK.' , end = '\t' ) bad_chromo_list = [ ] for chromo in self . chromo_list [ int ( self . reserve * len ( self . chromo_list ) ) : ] : if random . random ( ) < self . bad_reserve_p : bad_chromo_list . append ( chromo ) self . chromo_list = self . chromo_list [ : int ( self . reserve * len ( self . chromo_list ) ) ] self . chromo_list . extend ( bad_chromo_list ) print ( 'Select OK {}.' . format ( len ( self . chromo_list ) ) , end = '\t' ) self . __random_add__ ( self . new_chromo_num ) print ( 'New Chromo Add OK {}.' . format ( self . new_chromo_num ) , end = '\t' ) old_chromo_list = [ ] for chromo in self . chromo_list : old_chromo_list . append ( chromo . deepcopy ( ) ) chromo_copy1 = self . chromo_list [ : : 2 ] chromo_copy2 = self . chromo_list [ 1 : : 2 ] random . shuffle ( chromo_copy2 ) if len ( chromo_copy2 ) < len ( chromo_copy1 ) : chromo_copy1 . pop ( ) for chromo1 , chromo2 in zip ( chromo_copy1 , chromo_copy2 ) : if random . random ( ) < cross_p : chromo1_cross , chromo2_cross , r = self . __crossover__ ( chromo1 , chromo2 ) if r == 1 : self . chromo_list . append ( chromo1 ) self . chromo_list . append ( chromo2 ) print ( 'Cross OK {}.' . format ( len ( self . chromo_list ) ) , end = '\t' ) del chromo_copy1 del chromo_copy2 for chromo in old_chromo_list : self . chromo_list . append ( chromo . deepcopy ( ) ) for idx , chromo in enumerate ( self . chromo_list ) : chromo . mutate ( ) self . chromo_list . extend ( old_chromo_list ) del old_chromo_list print ( 'Mutate OK.' , end = '\t' ) add_num = self . chromo_num - len ( self . chromo_list ) self . __random_add__ ( num = add_num ) self . __experience_apply__ ( ) print ( 'Experience Apply OK.' , end = '\t' ) print ( 'Total {} Chromo.' . format ( len ( self . chromo_list ) ) ) self . __ranking__ ( ) self . chromo_list = self . chromo_list [ : self . chromo_num ]
operate the nature, include rank, select, cross, mutate, new add, experience apply
operate the nature include rank select cross mutate new add experience apply
"""
        operate the nature, include rank, select, cross, mutate, new add, experience apply
        :return: None
        """
None
self