def is_valid(self, min_percent_full=0.3, min_percent_tissue=0.1, min_percent_muscle=0.1): # override super class function to redefine what constitutes a valid individuals for name, details in self.genotype.to_phenotype_mapping.items(): if np.isnan(details["state"]).any(): return False if name == "material": state = details["state"] # Discarding the robot if it doesn't have at least a given percentage of non-empty voxels if np.sum(state > 0) < np.product( self.genotype.orig_size_xyz) * min_percent_full: return False # Discarding the robot if it doesn't have at least a given percentage of tissues (materials 1 and 2) if count_occurrences( state, [1, 2]) < np.sum(state > 0) * min_percent_tissue: return False # Discarding the robot if it doesn't have at least one bone (material 2) if count_occurrences(state, [2]) == 0: return False # Discarding the robot if it doesn't have at least a given percentage of muscles (materials 3 and 4) if count_occurrences( state, [3, 4]) < np.sum(state > 0) * min_percent_muscle: return False return True
def is_valid(self, min_percent_full=0.01, min_percent_muscle=0.0, max_percent_full=0.99): # override super class function to redefine what constitutes a valid individuals for name, details in self.genotype.to_phenotype_mapping.items(): if np.isnan(details["state"]).any(): return False if name == "material": state = details["state"] # Discarding the robot if it doesn't have at least a given percentage of non-empty voxels if np.sum(state > 0) < np.product( self.genotype.orig_size_xyz) * min_percent_full: return False # Discarding the robot if it doesn't have at least a given percentage of muscles (materials 3 and 4) if count_occurrences(state, [3, 4]) < np.product( self.genotype.orig_size_xyz) * min_percent_muscle: return False # daniel: Discarding the robot if it is completely filled (trivial solution?) if np.sum(state > 0) > np.product( self.genotype.orig_size_xyz) * max_percent_full: return False return True